Skip to content

Commit

Permalink
Merge branch 'main' into fix_update_unknown_fluid
Browse files Browse the repository at this point in the history
  • Loading branch information
phacUFPE authored Aug 16, 2024
2 parents cf1c860 + 292edc8 commit 902183e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 68 deletions.
8 changes: 4 additions & 4 deletions data/menubar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<item name="Find $Action" action="SEARCH_ON_MAP_ACTION" help="Find all items with an action ID on map."/>
<item name="Find $Container" action="SEARCH_ON_MAP_CONTAINER" help="Find all containers on map."/>
<item name="Find $Writeable" action="SEARCH_ON_MAP_WRITEABLE" help="Find all writeable items on map."/>
<item name="Find $Duplicate Items" action="SEARCH_ON_MAP_DUPLICATE" help="Find all positions where there are duplicate items on the map."/>
<item name="Find $Duplicated Items" action="SEARCH_ON_MAP_DUPLICATED_ITEMS" help="Find all positions where there are duplicated items on the map."/>
<item name="Find Walls $Upon Walls" action="SEARCH_ON_MAP_WALLS_UPON_WALLS" help="Find all positions where there are walls/windows/doors on walls/windows/doors on the map."/>
</menu>
<separator/>
Expand All @@ -55,7 +55,7 @@
<item name="$Remove Items by ID..." action="MAP_REMOVE_ITEMS" help="Removes all items with the selected ID from the map."/>
<item name="Remove $all corpses..." action="MAP_REMOVE_CORPSES" help="Removes all corpses from the map."/>
<item name="Remove all $unreachable tiles..." action="MAP_REMOVE_UNREACHABLE_TILES" help="Removes all tiles that cannot be reached (or seen) by the player from the map."/>
<item name="Remove all $duplicates items..." action="REMOVE_ON_MAP_DUPLICATE_ITEMS" help="Removes all items duplicates on map."/>
<item name="Remove all $duplicated items..." action="REMOVE_ON_MAP_DUPLICATED_ITEMS" help="Removes all items duplicated on map."/>
<item name="Remove empty monsters spawns" action="MAP_REMOVE_EMPTY_MONSTERS_SPAWNS" help="Removes all empty monsters spawns from the map."/>
<item name="Remove empty npcs spawns" action="MAP_REMOVE_EMPTY_NPCS_SPAWNS" help="Removes all empty npcs spawns from the map."/>
<item name="$Clear Invalid Houses" action="CLEAR_INVALID_HOUSES" help="Clears house tiles not belonging to any house."/>
Expand Down Expand Up @@ -85,7 +85,7 @@
<item name="Find Item on Selection" action="SEARCH_ON_SELECTION_ITEM" help="Find items on selected area."/>
<item name="Remove Item on Selection" action="REMOVE_ON_SELECTION_ITEM" help="Remove item on selected area."/>
<item name="Remove Monsters on Selection" action="REMOVE_ON_SELECTION_MONSTER" help="Remove monsters on selected area."/>
<item name="Remove Duplicates Items on Selection" action="REMOVE_ON_SELECTION_DUPLICATE_ITEMS" help="Removes all items duplicates selected area."/>
<item name="Remove Duplicated Items on Selection" action="REMOVE_ON_SELECTION_DUPLICATED_ITEMS" help="Removes all items duplicated selected area."/>
<separator/>
<menu name="$Find on Selection">
<item name="Find $Everything" action="SEARCH_ON_SELECTION_EVERYTHING" help="Find all unique/action/text/container items."/>
Expand All @@ -94,7 +94,7 @@
<item name="Find $Action" action="SEARCH_ON_SELECTION_ACTION" help="Find all items with an action ID on selected area."/>
<item name="Find $Container" action="SEARCH_ON_SELECTION_CONTAINER" help="Find all containers on selected area."/>
<item name="Find $Writeable" action="SEARCH_ON_SELECTION_WRITEABLE" help="Find all writeable items on selected area."/>
<item name="Find $Duplicate Items" action="SEARCH_ON_SELECTION_DUPLICATE" help="Find all positions where there are duplicate items on selected area."/>
<item name="Find $Duplicated Items" action="SEARCH_ON_SELECTION_DUPLICATED_ITEMS" help="Find all positions where there are duplicated items on selected area."/>
<item name="Find Walls $Upon Walls" action="SEARCH_ON_SELECTION_WALLS_UPON_WALLS" help="Find all positions where there are walls/windows/doors on walls/windows/doors on selected area."/>
</menu>
<separator/>
Expand Down
97 changes: 37 additions & 60 deletions source/main_menubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ MainMenuBar::MainMenuBar(MainFrame* frame) :
MAKE_ACTION(GOTO_WEBSITE, wxITEM_NORMAL, OnGotoWebsite);
MAKE_ACTION(ABOUT, wxITEM_NORMAL, OnAbout);

MAKE_ACTION(SEARCH_ON_MAP_DUPLICATE, wxITEM_NORMAL, OnSearchForDuplicateItemsOnMap);
MAKE_ACTION(SEARCH_ON_SELECTION_DUPLICATE, wxITEM_NORMAL, OnSearchForDuplicateItemsOnSelection);
MAKE_ACTION(REMOVE_ON_MAP_DUPLICATE_ITEMS, wxITEM_NORMAL, OnRemoveForDuplicateItemsOnMap);
MAKE_ACTION(REMOVE_ON_SELECTION_DUPLICATE_ITEMS, wxITEM_NORMAL, OnRemoveForDuplicateItemsOnSelection);
MAKE_ACTION(SEARCH_ON_MAP_DUPLICATED_ITEMS, wxITEM_NORMAL, OnSearchForDuplicateItemsOnMap);
MAKE_ACTION(SEARCH_ON_SELECTION_DUPLICATED_ITEMS, wxITEM_NORMAL, OnSearchForDuplicateItemsOnSelection);
MAKE_ACTION(REMOVE_ON_MAP_DUPLICATED_ITEMS, wxITEM_NORMAL, OnRemoveForDuplicateItemsOnMap);
MAKE_ACTION(REMOVE_ON_SELECTION_DUPLICATED_ITEMS, wxITEM_NORMAL, OnRemoveForDuplicateItemsOnSelection);

MAKE_ACTION(SEARCH_ON_MAP_WALLS_UPON_WALLS, wxITEM_NORMAL, OnSearchForWallsUponWallsOnMap);
MAKE_ACTION(SEARCH_ON_SELECTION_WALLS_UPON_WALLS, wxITEM_NORMAL, OnSearchForWallsUponWallsOnSelection);
Expand Down Expand Up @@ -421,10 +421,10 @@ void MainMenuBar::Update() {

EnableItem(DEBUG_VIEW_DAT, loaded);

EnableItem(SEARCH_ON_MAP_DUPLICATE, is_host);
EnableItem(SEARCH_ON_SELECTION_DUPLICATE, has_selection && is_host);
EnableItem(REMOVE_ON_MAP_DUPLICATE_ITEMS, is_local);
EnableItem(REMOVE_ON_SELECTION_DUPLICATE_ITEMS, is_local && has_selection);
EnableItem(SEARCH_ON_MAP_DUPLICATED_ITEMS, is_host);
EnableItem(SEARCH_ON_SELECTION_DUPLICATED_ITEMS, has_selection && is_host);
EnableItem(REMOVE_ON_MAP_DUPLICATED_ITEMS, is_local);
EnableItem(REMOVE_ON_SELECTION_DUPLICATED_ITEMS, is_local && has_selection);

EnableItem(SEARCH_ON_MAP_WALLS_UPON_WALLS, is_host);
EnableItem(SEARCH_ON_SELECTION_WALLS_UPON_WALLS, is_host && has_selection);
Expand Down Expand Up @@ -1163,9 +1163,8 @@ void MainMenuBar::OnSearchForItemOnSelection(wxCommandEvent &WXUNUSED(event)) {
g_gui.DestroyLoadBar();

if (finder.limitReached()) {
wxString msg;
msg << "The configured limit has been reached. Only " << finder.maxCount << " results will be displayed.";
g_gui.PopupDialog("Notice", msg, wxOK);
const auto message = wxString::Format("The configured limit has been reached. Only %d results will be displayed.", finder.maxCount);
g_gui.PopupDialog("Notice", message, wxOK);
}

SearchResultWindow* window = g_gui.ShowSearchWindow();
Expand Down Expand Up @@ -1204,12 +1203,10 @@ void MainMenuBar::OnRemoveItemOnSelection(wxCommandEvent &WXUNUSED(event)) {
g_gui.GetCurrentEditor()->clearActions();
g_gui.CreateLoadBar("Searching item on selection to remove...");
OnMapRemoveItems::RemoveItemCondition condition(dialog.getResultID());
int64_t count = RemoveItemOnMap(g_gui.GetCurrentMap(), condition, true);
const auto itemsRemoved = RemoveItemOnMap(g_gui.GetCurrentMap(), condition, true);
g_gui.DestroyLoadBar();

wxString msg;
msg << count << " items removed.";
g_gui.PopupDialog("Remove Item", msg, wxOK);
g_gui.PopupDialog("Remove Item", wxString::Format("%d items removed.", itemsRemoved), wxOK);
g_gui.GetCurrentMap().doChange();
g_gui.RefreshView();
}
Expand All @@ -1223,12 +1220,10 @@ void MainMenuBar::OnRemoveMonstersOnSelection(wxCommandEvent &WXUNUSED(event)) {

g_gui.GetCurrentEditor()->clearActions();
g_gui.CreateLoadBar("Searching monsters on selection to remove...");
int64_t count = RemoveMonstersOnMap(g_gui.GetCurrentMap(), true);
const auto monstersRemoved = RemoveMonstersOnMap(g_gui.GetCurrentMap(), true);
g_gui.DestroyLoadBar();

wxString msg;
msg << count << " monsters removed.";
g_gui.PopupDialog("Remove Monsters", msg, wxOK);
g_gui.PopupDialog("Remove Monsters", wxString::Format("%d monsters removed.", monstersRemoved), wxOK);
g_gui.GetCurrentMap().doChange();
g_gui.RefreshView();
}
Expand Down Expand Up @@ -2337,11 +2332,9 @@ void MainMenuBar::SearchItems(bool unique, bool action, bool container, bool wri
return;
}

if (onSelection) {
g_gui.CreateLoadBar("Searching on selected area...");
} else {
g_gui.CreateLoadBar("Searching on map...");
}
const auto searchType = onSelection ? "selected area" : "map";

g_gui.CreateLoadBar(wxString::Format("Searching on %s...", searchType));

OnSearchForStuff::Searcher searcher;
searcher.search_unique = unique;
Expand Down Expand Up @@ -2411,7 +2404,7 @@ namespace SearchDuplicatedItems {
if (foundTiles.count(tile) == 0) {
std::unordered_set<int> itemIDs;
for (Item* existingItem : tile->items) {
if (itemIDs.count(existingItem->getID()) > 0) {
if (itemIDs.count(existingItem->getID()) > 0 && !existingItem->hasElevation()) {
foundTiles.insert(tile);
break;
}
Expand All @@ -2427,11 +2420,9 @@ void MainMenuBar::SearchDuplicatedItems(bool onSelection /* = false*/) {
return;
}

if (onSelection) {
g_gui.CreateLoadBar("Searching on selected area...");
} else {
g_gui.CreateLoadBar("Searching on map...");
}
const auto searchType = onSelection ? "selected area" : "map";

g_gui.CreateLoadBar(wxString::Format("Searching on %s...", searchType));

SearchDuplicatedItems::condition finder;

Expand All @@ -2440,17 +2431,14 @@ void MainMenuBar::SearchDuplicatedItems(bool onSelection /* = false*/) {

g_gui.DestroyLoadBar();

size_t setSize = foundTiles.size();

wxString msg;
msg << setSize << " duplicate items founded.";
const auto tilesFoundAmount = foundTiles.size();

g_gui.PopupDialog("Search completed", msg, wxOK);
g_gui.PopupDialog("Search completed", wxString::Format("%d tiles with duplicated items founded.", tilesFoundAmount), wxOK);

SearchResultWindow* result = g_gui.ShowSearchWindow();
result->Clear();
for (const Tile* tile : foundTiles) {
result->AddPosition("Duplicate items", tile->getPosition());
result->AddPosition("Duplicated items", tile->getPosition());
}
}

Expand Down Expand Up @@ -2482,7 +2470,7 @@ namespace RemoveDuplicatesItems {
}

std::unordered_set<int> itemIDsDuplicates;
for (Item* itemInTile : tile->items) {
for (const auto &itemInTile : tile->items) {
if (itemInTile && itemInTile->getID() == item->getID()) {
if (itemIDsDuplicates.count(itemInTile->getID()) > 0) {
itemIDsDuplicates.clear();
Expand All @@ -2503,28 +2491,22 @@ void MainMenuBar::RemoveDuplicatesItems(bool onSelection /* = false*/) {
return;
}

int ok = g_gui.PopupDialog("Remove Duplicate Items", "Do you want to remove all duplicates items from the map?", wxYES | wxNO);
const auto removalType = onSelection ? "selected area" : "map";

if (ok == wxID_YES) {
g_gui.GetCurrentEditor()->getSelection().clear();
const auto dialogResult = g_gui.PopupDialog("Remove Duplicated Items", wxString::Format("Do you want to remove all duplicated items from the %s?", removalType), wxYES | wxNO);

if (dialogResult == wxID_YES) {
g_gui.GetCurrentEditor()->clearActions();

RemoveDuplicatesItems::condition func;

if (onSelection) {
g_gui.CreateLoadBar("Searching on selected area for items to remove...");
} else {
g_gui.CreateLoadBar("Searching on map for items to remove...");
}
g_gui.CreateLoadBar(wxString::Format("Searching on %s for items to remove...", removalType));

long long removed = RemoveItemDuplicateOnMap(g_gui.GetCurrentMap(), func, onSelection);
const auto removedAmount = RemoveItemDuplicateOnMap(g_gui.GetCurrentMap(), func, onSelection);

g_gui.DestroyLoadBar();

wxString msg;
msg << removed << " duplicate items deleted.";

g_gui.PopupDialog("Search completed", msg, wxOK);
g_gui.PopupDialog("Search completed", wxString::Format("%d duplicated items removed.", removedAmount), wxOK);

g_gui.GetCurrentMap().doChange();
}
Expand Down Expand Up @@ -2580,11 +2562,9 @@ void MainMenuBar::SearchWallsUponWalls(bool onSelection /* = false*/) {
return;
}

if (onSelection) {
g_gui.CreateLoadBar("Searching on selected area...");
} else {
g_gui.CreateLoadBar("Searching on map...");
}
const auto searchType = onSelection ? "selected area" : "map";

g_gui.CreateLoadBar(wxString::Format("Searching on %s...", searchType));

SearchWallsUponWalls::condition finder;

Expand All @@ -2594,12 +2574,9 @@ void MainMenuBar::SearchWallsUponWalls(bool onSelection /* = false*/) {

g_gui.DestroyLoadBar();

size_t setSize = foundTiles.size();

wxString msg;
msg << setSize << " items under walls and doors founded.";
const auto tilesFoundAmount = foundTiles.size();

g_gui.PopupDialog("Search completed", msg, wxOK);
g_gui.PopupDialog("Search completed", wxString::Format("%d items under walls and doors founded.", tilesFoundAmount), wxOK);

SearchResultWindow* result = g_gui.ShowSearchWindow();
result->Clear();
Expand Down
8 changes: 4 additions & 4 deletions source/main_menubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ namespace MenuBar {
EXTENSIONS,
GOTO_WEBSITE,
ABOUT,
SEARCH_ON_MAP_DUPLICATE,
SEARCH_ON_SELECTION_DUPLICATE,
REMOVE_ON_MAP_DUPLICATE_ITEMS,
REMOVE_ON_SELECTION_DUPLICATE_ITEMS,
SEARCH_ON_MAP_DUPLICATED_ITEMS,
SEARCH_ON_SELECTION_DUPLICATED_ITEMS,
REMOVE_ON_MAP_DUPLICATED_ITEMS,
REMOVE_ON_SELECTION_DUPLICATED_ITEMS,
SEARCH_ON_MAP_WALLS_UPON_WALLS,
SEARCH_ON_SELECTION_WALLS_UPON_WALLS,
};
Expand Down

0 comments on commit 902183e

Please sign in to comment.