Skip to content

Commit

Permalink
feat: show item and ground avoidables (block pathfinder) (#103)
Browse files Browse the repository at this point in the history
Feature that enables to check an option to show in the map an icon of avoidable items and grounds (block pathfinder).
  • Loading branch information
phacUFPE authored Aug 14, 2024
1 parent 1409cdd commit 6ef5ba1
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 2 deletions.
1 change: 1 addition & 0 deletions data/menubar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<item name="Show Wall Hoo$ks" hotkey="K" action="SHOW_WALL_HOOKS" help="Show indicators for wall hooks."/>
<item name="Show Pickupables" action="SHOW_PICKUPABLES" help="Show indicators for pickupable items."/>
<item name="Show Moveables" action="SHOW_MOVEABLES" help="Show indicators for moveable items."/>
<item name="Show Avoidables" action="SHOW_AVOIDABLES" help="Show indicators for avoidable items."/>
</menu>
</menu>
<menu name="$Window">
Expand Down
Binary file added icons/avoidable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions icons/avoidable.xpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* XPM */
static const char *avoidable_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 4 1 ",
" c black",
". c #ED1C24",
"X c magenta",
"o c white",
/* pixels */
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"XXXX XXXXXXXXXXXX XXXX",
"XXX oooo XXXXXXXXXX oooo XXX",
"XX oooooo XXXXXXXX oooooo XX",
"X ooo ooo XXXXXX ooo ooo X",
"X ooo XX ooo XXXXXX ooo XX ooo X",
"X oo XXXX oo XXXXXX oo XXXX oo X",
"X oo XXXX oo XXXXXX oo XXXX oo X",
"X oo XXXX oo XXXXXX oo XXXX oo X",
"X ooo XX ooo XXXXXX ooo XX ooo X",
"X oo XX oo XXXXXX oo XX oo X",
"XX ooo ooo XXXXXXXX ooo ooo XX",
"XX oooooo XXXXXXXX oooooo XX",
"XXX oooo XXXXXXXXXX oooo XXX",
"XXXX oo XXXXXXXXXXXX oo XXXX",
"XXXXX XX XXXX XX XXXXX",
"XXXXXXXXXX ... XX ... XXXXXXXXXX",
"XXXXXXXXXX ... XX ... XXXXXXXXXX",
"XXXXX .... .... XXXXX",
"XXXXX ooooo ...... ooooo XXXXX",
"XXXXX ooooooo .... ooooooo XXXXX",
"XXXXX oooo .... oooo XXXXX",
"XXXXXXXX ...... XXXXXXXX",
"XXXXXXXXXX .... .... XXXXXXXXXX",
"XXXXXXXXXX ... X ... XXXXXXXXXX",
"XXXXXXXXXX ... XX ... XXXXXXXXXX",
"XXXXXXXXXXX XXXX XXXXXXXXXXX",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
};
3 changes: 3 additions & 0 deletions source/artprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "main.h"
#include "artprovider.h"

#include "../icons/avoidable.xpm"
#include "../icons/circular_1.xpm"
#include "../icons/circular_2.xpm"
#include "../icons/circular_3.xpm"
Expand Down Expand Up @@ -158,6 +159,8 @@ wxBitmap ArtProvider::CreateBitmap(const wxArtID &id, const wxArtClient &client,
return wxBitmap(moveable_xpm);
} else if (id == ART_PICKUPABLE_MOVEABLE) {
return wxBitmap(pickupable_moveable_xpm);
} else if (id == ART_AVOIDABLE) {
return wxBitmap(avoidable_xpm);
}
}

Expand Down
1 change: 1 addition & 0 deletions source/artprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#define ART_PICKUPABLE wxART_MAKE_ART_ID(ART_PICKUPABLE)
#define ART_MOVEABLE wxART_MAKE_ART_ID(ART_MOVEABLE)
#define ART_PICKUPABLE_MOVEABLE wxART_MAKE_ART_ID(ART_PICKUPABLE_MOVEABLE)
#define ART_AVOIDABLE wxART_MAKE_ART_ID(ART_AVOIDABLE)

#define ART_MOVE wxART_MAKE_ART_ID(ART_MOVE)
#define ART_REMOTE wxART_MAKE_ART_ID(ART_REMOTE)
Expand Down
1 change: 1 addition & 0 deletions source/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ bool GraphicManager::loadEditorSprites() {
sprite_space[EDITOR_SPRITE_PICKUPABLE_ITEM] = GameSprite::createFromBitmap(ART_PICKUPABLE);
sprite_space[EDITOR_SPRITE_MOVEABLE_ITEM] = GameSprite::createFromBitmap(ART_MOVEABLE);
sprite_space[EDITOR_SPRITE_PICKUPABLE_MOVEABLE_ITEM] = GameSprite::createFromBitmap(ART_PICKUPABLE_MOVEABLE);
sprite_space[EDITOR_SPRITE_AVOIDABLE_ITEM] = GameSprite::createFromBitmap(ART_AVOIDABLE);

return true;
}
Expand Down
3 changes: 2 additions & 1 deletion source/gui_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ enum EditorActionID {
TOOLBAR_SIZES_7,
TOOLBAR_HOOKS,
TOOLBAR_PICKUPABLES,
TOOLBAR_MOVEABLES
TOOLBAR_MOVEABLES,
TOOLBAR_AVOIDABLES
};

enum ToolBarID {
Expand Down
3 changes: 3 additions & 0 deletions source/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ class Item : public ItemAttributes {

// Item types
bool hasProperty(enum ITEMPROPERTY prop) const;
bool isAvoidable() const {
return getItemType().blockPathfinder;
}
bool isBlocking() const {
return getItemType().unpassable;
}
Expand Down
4 changes: 4 additions & 0 deletions source/main_menubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ MainMenuBar::MainMenuBar(MainFrame* frame) :
MAKE_ACTION(SHOW_WALL_HOOKS, wxITEM_CHECK, OnChangeViewSettings);
MAKE_ACTION(SHOW_PICKUPABLES, wxITEM_CHECK, OnChangeViewSettings);
MAKE_ACTION(SHOW_MOVEABLES, wxITEM_CHECK, OnChangeViewSettings);
MAKE_ACTION(SHOW_AVOIDABLES, wxITEM_CHECK, OnChangeViewSettings);

MAKE_ACTION(WIN_MINIMAP, wxITEM_NORMAL, OnMinimapWindow);
MAKE_ACTION(WIN_ACTIONS_HISTORY, wxITEM_NORMAL, OnActionsHistoryWindow);
Expand Down Expand Up @@ -491,6 +492,7 @@ void MainMenuBar::LoadValues() {
CheckItem(SHOW_WALL_HOOKS, g_settings.getBoolean(Config::SHOW_WALL_HOOKS));
CheckItem(SHOW_PICKUPABLES, g_settings.getBoolean(Config::SHOW_PICKUPABLES));
CheckItem(SHOW_MOVEABLES, g_settings.getBoolean(Config::SHOW_MOVEABLES));
CheckItem(SHOW_AVOIDABLES, g_settings.getBoolean(Config::SHOW_AVOIDABLES));
}

void MainMenuBar::LoadRecentFiles() {
Expand Down Expand Up @@ -537,6 +539,7 @@ void MainMenuBar::UpdateIndicatorsMenu() {
CheckItem(SHOW_WALL_HOOKS, g_settings.getBoolean(Config::SHOW_WALL_HOOKS));
CheckItem(SHOW_PICKUPABLES, g_settings.getBoolean(Config::SHOW_PICKUPABLES));
CheckItem(SHOW_MOVEABLES, g_settings.getBoolean(Config::SHOW_MOVEABLES));
CheckItem(SHOW_AVOIDABLES, g_settings.getBoolean(Config::SHOW_AVOIDABLES));
}

bool MainMenuBar::Load(const FileName &path, wxArrayString &warnings, wxString &error) {
Expand Down Expand Up @@ -2102,6 +2105,7 @@ void MainMenuBar::OnChangeViewSettings(wxCommandEvent &event) {
g_settings.setInteger(Config::SHOW_WALL_HOOKS, IsItemChecked(MenuBar::SHOW_WALL_HOOKS));
g_settings.setInteger(Config::SHOW_PICKUPABLES, IsItemChecked(MenuBar::SHOW_PICKUPABLES));
g_settings.setInteger(Config::SHOW_MOVEABLES, IsItemChecked(MenuBar::SHOW_MOVEABLES));
g_settings.setInteger(Config::SHOW_AVOIDABLES, IsItemChecked(MenuBar::SHOW_AVOIDABLES));

g_gui.RefreshView();
g_gui.root->GetAuiToolBar()->UpdateIndicators();
Expand Down
1 change: 1 addition & 0 deletions source/main_menubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ namespace MenuBar {
SHOW_WALL_HOOKS,
SHOW_PICKUPABLES,
SHOW_MOVEABLES,
SHOW_AVOIDABLES,
WIN_MINIMAP,
WIN_ACTIONS_HISTORY,
NEW_PALETTE,
Expand Down
7 changes: 7 additions & 0 deletions source/main_toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ MainToolBar::MainToolBar(wxWindow* parent, wxAuiManager* manager) {
indicators_toolbar->ToggleTool(TOOLBAR_HOOKS, g_settings.getBoolean(Config::SHOW_WALL_HOOKS));
indicators_toolbar->ToggleTool(TOOLBAR_PICKUPABLES, g_settings.getBoolean(Config::SHOW_PICKUPABLES));
indicators_toolbar->ToggleTool(TOOLBAR_MOVEABLES, g_settings.getBoolean(Config::SHOW_MOVEABLES));
indicators_toolbar->ToggleTool(TOOLBAR_AVOIDABLES, g_settings.getBoolean(Config::SHOW_AVOIDABLES));

manager->AddPane(standard_toolbar, wxAuiPaneInfo().Name(STANDARD_BAR_NAME).ToolbarPane().Top().Row(1).Position(1).Floatable(false));
manager->AddPane(brushes_toolbar, wxAuiPaneInfo().Name(BRUSHES_BAR_NAME).ToolbarPane().Top().Row(1).Position(2).Floatable(false));
Expand Down Expand Up @@ -285,6 +286,7 @@ void MainToolBar::UpdateIndicators() {
indicators_toolbar->ToggleTool(TOOLBAR_HOOKS, g_settings.getBoolean(Config::SHOW_WALL_HOOKS));
indicators_toolbar->ToggleTool(TOOLBAR_PICKUPABLES, g_settings.getBoolean(Config::SHOW_PICKUPABLES));
indicators_toolbar->ToggleTool(TOOLBAR_MOVEABLES, g_settings.getBoolean(Config::SHOW_MOVEABLES));
indicators_toolbar->ToggleTool(TOOLBAR_AVOIDABLES, g_settings.getBoolean(Config::SHOW_AVOIDABLES));

g_gui.GetAuiManager()->Update();
}
Expand Down Expand Up @@ -628,6 +630,11 @@ void MainToolBar::OnIndicatorsButtonClick(wxCommandEvent &event) {
g_gui.root->UpdateIndicatorsMenu();
g_gui.RefreshView();
break;
case TOOLBAR_AVOIDABLES:
g_settings.setInteger(Config::SHOW_AVOIDABLES, toggled);
g_gui.root->UpdateIndicatorsMenu();
g_gui.RefreshView();
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions source/map_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void MapCanvas::OnPaint(wxPaintEvent &event) {
options.show_hooks = g_settings.getBoolean(Config::SHOW_WALL_HOOKS);
options.show_pickupables = g_settings.getBoolean(Config::SHOW_PICKUPABLES);
options.show_moveables = g_settings.getBoolean(Config::SHOW_MOVEABLES);
options.show_avoidables = g_settings.getBoolean(Config::SHOW_AVOIDABLES);
options.hide_items_when_zoomed = g_settings.getBoolean(Config::HIDE_ITEMS_WHEN_ZOOMED);
}

Expand Down
13 changes: 12 additions & 1 deletion source/map_drawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void DrawingOptions::SetDefault() {
show_hooks = false;
show_pickupables = false;
show_moveables = false;
show_avoidables = false;
hide_items_when_zoomed = true;
}

Expand Down Expand Up @@ -112,6 +113,7 @@ void DrawingOptions::SetIngame() {
show_hooks = false;
show_pickupables = false;
show_moveables = false;
show_avoidables = false;
hide_items_when_zoomed = false;
}

Expand Down Expand Up @@ -1736,12 +1738,13 @@ void MapDrawer::DrawTileIndicators(TileLocation* location) {
int x, y;
getDrawPosition(location->getPosition(), x, y);

if (zoom < 10.0 && (options.show_pickupables || options.show_moveables)) {
if (zoom < 10.0 && (options.show_pickupables || options.show_moveables || options.show_avoidables)) {
uint8_t red = 0xFF, green = 0xFF, blue = 0xFF;
if (tile->isHouseTile()) {
green = 0x00;
blue = 0x00;
}

for (const Item* item : tile->items) {
const ItemType &type = g_items.getItemType(item->getID());
if ((type.pickupable && options.show_pickupables) || (type.moveable && options.show_moveables)) {
Expand All @@ -1753,9 +1756,17 @@ void MapDrawer::DrawTileIndicators(TileLocation* location) {
DrawIndicator(x, y, EDITOR_SPRITE_MOVEABLE_ITEM, red, green, blue);
}
}

if (type.blockPathfinder && options.show_avoidables) {
DrawIndicator(x, y, EDITOR_SPRITE_AVOIDABLE_ITEM, red, green, blue);
}
}
}

if (options.show_avoidables && tile->ground && tile->ground->isAvoidable()) {
DrawIndicator(x, y, EDITOR_SPRITE_AVOIDABLE_ITEM);
}

if (options.show_houses && tile->isHouseExit()) {
if (tile->hasHouseExit(current_house_id)) {
DrawIndicator(x, y, EDITOR_SPRITE_HOUSE_EXIT);
Expand Down
1 change: 1 addition & 0 deletions source/map_drawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct DrawingOptions {
bool show_hooks;
bool show_pickupables;
bool show_moveables;
bool show_avoidables;
bool hide_items_when_zoomed;
};

Expand Down
1 change: 1 addition & 0 deletions source/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace Config {
SHOW_WALL_HOOKS,
SHOW_PICKUPABLES,
SHOW_MOVEABLES,
SHOW_AVOIDABLES,
SHOW_AS_MINIMAP,
SHOW_ONLY_TILEFLAGS,
SHOW_ONLY_MODIFIED_TILES,
Expand Down
1 change: 1 addition & 0 deletions source/sprites.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ enum {
EDITOR_SPRITE_PICKUPABLE_ITEM,
EDITOR_SPRITE_MOVEABLE_ITEM,
EDITOR_SPRITE_PICKUPABLE_MOVEABLE_ITEM,
EDITOR_SPRITE_AVOIDABLE_ITEM,

EDITOR_SPRITE_LAST
};
Expand Down

0 comments on commit 6ef5ba1

Please sign in to comment.