small editor palette refactor
Remove unused editor_display::palette_report_ member Added 'tristate_palette' interface to that classes inheriting from common_palette don't have to implement select_fg_item/select_bg_item
This commit is contained in:
parent
3cd73e407b
commit
672ef61a34
9 changed files with 18 additions and 44 deletions
|
@ -59,7 +59,6 @@ editor_display::editor_display(const display_context * dc, CVideo& video,
|
|||
const config& theme_cfg, const config& level)
|
||||
: display(dc, video, boost::shared_ptr<wb::manager>(), reports_object, theme_cfg, level)
|
||||
, brush_locations_()
|
||||
, palette_report_()
|
||||
{
|
||||
clear_screen();
|
||||
}
|
||||
|
|
|
@ -38,8 +38,6 @@ public:
|
|||
const editor_map& map() const { return static_cast<const editor_map&>(get_map()); }
|
||||
void rebuild_terrain(const map_location &loc);
|
||||
|
||||
void set_palette_report(const config& palette_report) {palette_report_ = palette_report;}
|
||||
|
||||
protected:
|
||||
void pre_draw();
|
||||
/**
|
||||
|
@ -54,8 +52,6 @@ protected:
|
|||
|
||||
std::set<map_location> brush_locations_;
|
||||
|
||||
private:
|
||||
config palette_report_;
|
||||
};
|
||||
|
||||
} //end namespace editor
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
|
||||
struct SDL_Rect;
|
||||
class config;
|
||||
|
||||
namespace editor {
|
||||
class editor_display;
|
||||
|
||||
/**
|
||||
* Stores the info about the groups in a nice format.
|
||||
|
@ -51,8 +51,6 @@ public:
|
|||
|
||||
virtual sdl_handler_vector handler_members() { return sdl_handler_vector(); }
|
||||
|
||||
virtual void select_fg_item(const std::string& item_id) = 0;
|
||||
virtual void select_bg_item(const std::string& item_id) = 0;
|
||||
|
||||
/** Scroll the editor-palette up one step if possible. */
|
||||
virtual bool scroll_up() = 0;
|
||||
|
@ -70,7 +68,6 @@ public:
|
|||
virtual void set_group(size_t index) = 0;
|
||||
virtual void next_group() = 0;
|
||||
virtual void prev_group() = 0;
|
||||
virtual const config active_group_report() = 0;
|
||||
virtual const std::vector<item_group>& get_groups() const = 0;
|
||||
|
||||
/** Menu expanding for palette group list */
|
||||
|
@ -87,6 +84,17 @@ public:
|
|||
|
||||
};
|
||||
|
||||
// a palette containing tristtate buttons.
|
||||
class tristate_palette : public common_palette
|
||||
{
|
||||
public:
|
||||
tristate_palette(display &gui)
|
||||
: common_palette(gui)
|
||||
{
|
||||
}
|
||||
virtual void select_fg_item(const std::string& item_id) = 0;
|
||||
virtual void select_bg_item(const std::string& item_id) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -185,8 +185,6 @@ void editor_palette<Item>::set_group(const std::string& id)
|
|||
if(active_group().empty()) {
|
||||
ERR_ED << "No items found in group with the id: '" << id << "'." << std::endl;
|
||||
}
|
||||
|
||||
gui_.set_palette_report(active_group_report());
|
||||
}
|
||||
template void editor_palette<t_translation::t_terrain>::set_group(const std::string& id);
|
||||
template void editor_palette<unit_type>::set_group(const std::string& id);
|
||||
|
@ -218,24 +216,6 @@ template size_t editor_palette<t_translation::t_terrain>::active_group_index();
|
|||
template size_t editor_palette<unit_type>::active_group_index();
|
||||
template size_t editor_palette<overlay>::active_group_index();
|
||||
|
||||
template<class Item>
|
||||
const config editor_palette<Item>::active_group_report()
|
||||
{
|
||||
config cfg;
|
||||
config& report = cfg.add_child("element");
|
||||
for (size_t i = 0 ; i < groups_.size(); i++) {
|
||||
if (groups_[i].id == active_group_) {
|
||||
std::string groupname = groups_[i].name;
|
||||
report["image"] = groups_[i].icon;
|
||||
report["tooltip"] = groupname;
|
||||
}
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
template const config editor_palette<t_translation::t_terrain>::active_group_report();
|
||||
template const config editor_palette<unit_type>::active_group_report();
|
||||
template const config editor_palette<overlay>::active_group_report();
|
||||
|
||||
template<class Item>
|
||||
void editor_palette<Item>::adjust_size(const SDL_Rect& target)
|
||||
{
|
||||
|
|
|
@ -20,15 +20,14 @@
|
|||
#include "tristate_button.hpp"
|
||||
|
||||
namespace editor {
|
||||
|
||||
template<class Item>
|
||||
class editor_palette : public common_palette {
|
||||
class editor_palette : public tristate_palette {
|
||||
|
||||
public:
|
||||
|
||||
editor_palette(editor_display &gui, const config& /*cfg*/
|
||||
, size_t item_size, size_t item_width, mouse_action** active_mouse_action)
|
||||
: common_palette(gui)
|
||||
: tristate_palette(gui)
|
||||
, groups_()
|
||||
, gui_(gui)
|
||||
, item_size_(item_size)
|
||||
|
@ -93,8 +92,6 @@ public:
|
|||
virtual bool scroll_down();
|
||||
virtual bool can_scroll_down();
|
||||
|
||||
virtual const config active_group_report();
|
||||
|
||||
void swap();
|
||||
|
||||
virtual std::string get_help_string() = 0;
|
||||
|
|
|
@ -40,9 +40,6 @@ public:
|
|||
virtual bool scroll_down() { return false;}
|
||||
virtual bool can_scroll_down() { return false;}
|
||||
|
||||
virtual void select_fg_item(const std::string& /*item_id*/) {}
|
||||
virtual void select_bg_item(const std::string& /*item_id*/) {}
|
||||
|
||||
//drawing
|
||||
virtual void adjust_size(const SDL_Rect& /*target*/) {}
|
||||
virtual void draw() {}
|
||||
|
@ -72,7 +69,6 @@ public:
|
|||
virtual void set_group(size_t /*index*/) {}
|
||||
virtual void next_group() {}
|
||||
virtual void prev_group() {}
|
||||
virtual const config active_group_report() { return config();}
|
||||
virtual const std::vector<item_group>& get_groups() const { return empty_; }
|
||||
|
||||
/** Menu expanding for palette group list */
|
||||
|
|
|
@ -38,7 +38,7 @@ const int font_size = font::SIZE_SMALL;
|
|||
const int checkbox_horizontal_padding = font::SIZE_SMALL / 2;
|
||||
|
||||
tristate_button::tristate_button(CVideo& video,
|
||||
editor::common_palette* palette,
|
||||
editor::tristate_palette* palette,
|
||||
std::string button_image_name,
|
||||
const bool auto_join) :
|
||||
widget(video, auto_join),
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace gui {
|
||||
|
||||
//This button has 4 states, why it is called tristate?
|
||||
class tristate_button : public widget
|
||||
{
|
||||
|
||||
|
@ -35,7 +36,7 @@ public:
|
|||
enum PRESSED_STATE { LEFT, RIGHT, BOTH, NONE };
|
||||
|
||||
tristate_button(CVideo& video,
|
||||
editor::common_palette* palette,
|
||||
editor::tristate_palette* palette,
|
||||
std::string button_image="",
|
||||
const bool auto_join=true);
|
||||
|
||||
|
@ -108,7 +109,7 @@ private:
|
|||
|
||||
int base_height_, base_width_;
|
||||
|
||||
editor::common_palette* palette_;
|
||||
editor::tristate_palette* palette_;
|
||||
|
||||
std::string item_id_;
|
||||
|
||||
|
|
|
@ -110,9 +110,6 @@ void editor_toolkit::hotkey_set_mouse_action(hotkey::HOTKEY_COMMAND command)
|
|||
mouse_action_ = i->second;
|
||||
palette_manager_->adjust_size();
|
||||
|
||||
/** @todo make active_palette() private again. */
|
||||
gui_.set_palette_report(palette_manager_->active_palette().active_group_report());
|
||||
|
||||
set_mouseover_overlay();
|
||||
gui_.invalidate_game_status();
|
||||
palette_manager_->active_palette().hide(false);
|
||||
|
|
Loading…
Add table
Reference in a new issue