From 7065ed9fde535e14b45a3e8bad1dfc74ea663b9f Mon Sep 17 00:00:00 2001 From: Subhraman Sarkar Date: Thu, 5 Sep 2024 21:20:22 +0530 Subject: [PATCH] item tool: add right-click to remove functionality --- src/editor/action/mouse/mouse_action_item.cpp | 13 +++++++++++++ src/editor/action/mouse/mouse_action_item.hpp | 13 +++++++------ src/editor/palette/editor_palettes.cpp | 14 -------------- src/editor/palette/item_palette.cpp | 2 +- src/hotkey/hotkey_command.cpp | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/editor/action/mouse/mouse_action_item.cpp b/src/editor/action/mouse/mouse_action_item.cpp index 42332d0873d..6a4bd2563e9 100644 --- a/src/editor/action/mouse/mouse_action_item.cpp +++ b/src/editor/action/mouse/mouse_action_item.cpp @@ -57,6 +57,19 @@ std::unique_ptr mouse_action_item::click_left(editor_display& dis return nullptr; } +std::unique_ptr mouse_action_item::click_right(editor_display& disp, int x, int y) +{ + start_hex_ = disp.hex_clicked_on(x, y); + if (!disp.get_map().on_board(start_hex_)) { + return nullptr; + } + + disp.remove_overlay(start_hex_); + + click_ = true; + return nullptr; +} + std::unique_ptr mouse_action_item::drag_left(editor_display& disp, int x, int y, bool& /*partial*/, editor_action* /*last_undo*/) { map_location hex = disp.hex_clicked_on(x, y); diff --git a/src/editor/action/mouse/mouse_action_item.hpp b/src/editor/action/mouse/mouse_action_item.hpp index 4945e468e97..291c1ea6fee 100644 --- a/src/editor/action/mouse/mouse_action_item.hpp +++ b/src/editor/action/mouse/mouse_action_item.hpp @@ -37,16 +37,21 @@ public: } bool has_context_menu() const override { - return true; + return false; } void move(editor_display& disp, const map_location& hex) override; /** - * TODO + * Left clicking places the currently selected item on the x,y map hex */ std::unique_ptr click_left(editor_display& disp, int x, int y) override; + /** + * Right clicking removes the item on the x,y map hex + */ + std::unique_ptr click_right(editor_display& disp, int x, int y) override; + /** * TODO */ @@ -60,10 +65,6 @@ public: */ std::unique_ptr drag_end_left(editor_display& disp, int x, int y) override; - std::unique_ptr click_right(editor_display& /*disp*/, int /*x*/, int /*y*/) override { - return nullptr; - } - virtual void set_mouse_overlay(editor_display& disp) override; void set_item_mouse_overlay(editor_display& disp, const overlay& u); diff --git a/src/editor/palette/editor_palettes.cpp b/src/editor/palette/editor_palettes.cpp index c88b6bdea29..fadd9a8670c 100644 --- a/src/editor/palette/editor_palettes.cpp +++ b/src/editor/palette/editor_palettes.cpp @@ -122,7 +122,6 @@ void editor_palette::set_group(const std::string& id) found = true; std::shared_ptr palette_menu_button = gui_.find_menu_button("menu-editor-terrain"); if (palette_menu_button) { - //palette_menu_button->set_label(group.name); palette_menu_button->set_tooltip_string(group.name); palette_menu_button->set_overlay(group.icon); } @@ -298,13 +297,11 @@ void editor_palette::layout() } const std::string item_id = active_group()[item_index]; - //typedef std::map item_map_wurscht; typename item_map::iterator item = item_map_.find(item_id); texture item_base, item_overlay; std::stringstream tooltip_text; setup_item((*item).second, item_base, item_overlay, tooltip_text); - bool is_core = non_core_items_.find(get_id((*item).second)) == non_core_items_.end(); if (!is_core) { tooltip_text << " " @@ -318,17 +315,6 @@ void editor_palette::layout() tile.set_item_image(item_base, item_overlay); tile.set_item_id(item_id); -// if (get_id((*item).second) == selected_bg_item_ -// && get_id((*item).second) == selected_fg_item_) { -// tile.set_pressed(gui::tristate_button::BOTH); -// } else if (get_id((*item).second) == selected_bg_item_) { -// tile.set_pressed(gui::tristate_button::RIGHT); -// } else if (get_id((*item).second) == selected_fg_item_) { -// tile.set_pressed(gui::tristate_button::LEFT); -// } else { -// tile.set_pressed(gui::tristate_button::NONE); -// } - if (is_selected_bg_item(get_id(item->second)) && is_selected_fg_item(get_id(item->second))) { tile.set_pressed(gui::tristate_button::BOTH); diff --git a/src/editor/palette/item_palette.cpp b/src/editor/palette/item_palette.cpp index f342c5962d6..8273b99047b 100644 --- a/src/editor/palette/item_palette.cpp +++ b/src/editor/palette/item_palette.cpp @@ -29,7 +29,7 @@ namespace editor { std::string item_palette::get_help_string() { - return selected_fg_item().name; + return _("Left-click: Place item ") + selected_fg_item().name + _(" | Right-click to remove"); } void item_palette::setup(const game_config_view& cfg) diff --git a/src/hotkey/hotkey_command.cpp b/src/hotkey/hotkey_command.cpp index dfd15c2da34..9ccc606c715 100644 --- a/src/hotkey/hotkey_command.cpp +++ b/src/hotkey/hotkey_command.cpp @@ -205,7 +205,7 @@ constexpr std::array master_hotkey_list {{ { HOTKEY_EDITOR_TOOL_STARTING_POSITION, "editor-tool-starting-position", N_("Starting Positions Tool"), false, scope_editor, HKCAT_TOOLS, N_("Left mouse button displays player selection, right clears. Number keys scroll to the starting position, alt+number sets respective starting position under cursor, delete clears.") }, { HOTKEY_EDITOR_TOOL_LABEL, "editor-tool-label", N_("Label Tool"), false, scope_editor, HKCAT_TOOLS, N_("Left mouse button sets or drags a label, right clears.") }, { HOTKEY_EDITOR_TOOL_UNIT, "editor-tool-unit", N_("Unit Tool"), false, scope_editor, HKCAT_TOOLS, N_("Left mouse button sets a new unit or moves a unit via drag and drop, right brings up a context menu. Needs a defined side.") }, - { HOTKEY_EDITOR_TOOL_ITEM, "editor-tool-item", N_("Item Tool"), false, scope_editor, HKCAT_TOOLS, N_("Left mouse button sets a new item.") }, + { HOTKEY_EDITOR_TOOL_ITEM, "editor-tool-item", N_("Item Tool"), false, scope_editor, HKCAT_TOOLS, N_("Left mouse button sets a new item. Right click removes item.") }, { HOTKEY_EDITOR_TOOL_VILLAGE, "editor-tool-village", N_("Village Tool"), false, scope_editor, HKCAT_TOOLS, N_("Left mouse button sets the village ownership to the current side, right clears. Needs a defined side.") }, { HOTKEY_EDITOR_UNIT_TOGGLE_CANRECRUIT, "editor-toggle-canrecruit", N_("Can Recruit"), false, scope_editor, HKCAT_TOOLS, N_("Toggle the recruit attribute of a unit.") },