Fixed the drawing errors in the map editor.
Restored most of its former functions.
This commit is contained in:
parent
e673bf69b2
commit
68a7ea1bc4
17 changed files with 177 additions and 189 deletions
|
@ -75,7 +75,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
|
|||
context_manager_->get_map_context().set_starting_position_labels(gui());
|
||||
cursor::set(cursor::NORMAL);
|
||||
image::set_color_adjustment(preferences::editor::tod_r(), preferences::editor::tod_g(), preferences::editor::tod_b());
|
||||
// TODO enable if you can say what the purpose of the code is.
|
||||
// TODO enable if you can say what the purpose of the code is. I think it is old stuff and deserves to be removed.
|
||||
/* theme& theme = gui().get_theme();
|
||||
const theme::menu* default_tool_menu = NULL;
|
||||
foreach (const theme::menu& m, theme.menus()) {
|
||||
|
@ -85,9 +85,9 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
|
|||
}
|
||||
}*/
|
||||
|
||||
gui().redraw_everything();
|
||||
//TODO
|
||||
// toolkit_->adjust_size();
|
||||
events::raise_draw_event();
|
||||
//events::raise_draw_event();
|
||||
/* TODO enable if you can say what the purpose of the code is.
|
||||
if (default_tool_menu != NULL) {
|
||||
const SDL_Rect& menu_loc = default_tool_menu->location(get_display().screen_area());
|
||||
|
@ -95,7 +95,6 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
|
|||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void editor_controller::init_gui()
|
||||
|
@ -167,26 +166,17 @@ void editor_controller::do_screenshot(const std::string& screenshot_filename /*
|
|||
|
||||
void editor_controller::quit_confirm(EXIT_STATUS mode)
|
||||
{
|
||||
std::vector<std::string> modified;
|
||||
foreach (map_context* mc, context_manager_->map_contexts_) {
|
||||
if (mc->modified()) {
|
||||
if (!mc->get_filename().empty()) {
|
||||
modified.push_back(mc->get_filename());
|
||||
} else {
|
||||
modified.push_back(_("(New Map)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string modified;
|
||||
size_t amount = context_manager_->modified_maps(modified);
|
||||
|
||||
std::string message;
|
||||
if (modified.empty()) {
|
||||
if (amount == 0) {
|
||||
message = _("Do you really want to quit?");
|
||||
} else if (modified.size() == 1) {
|
||||
} else if (amount == 1) {
|
||||
message = _("Do you really want to quit? Changes in the map since the last save will be lost.");
|
||||
} else {
|
||||
message = _("Do you really want to quit? The following maps were modified and all changes since the last save will be lost:");
|
||||
foreach (std::string& str, modified) {
|
||||
message += "\n" + str;
|
||||
}
|
||||
message += modified;
|
||||
}
|
||||
const int res = gui2::show_message(gui().video(), _("Quit"), message, gui2::tmessage::yes_no_buttons);
|
||||
if(res != gui2::twindow::CANCEL) {
|
||||
|
@ -227,7 +217,7 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
|
|||
|
||||
switch (active_menu_) {
|
||||
case editor::MAP:
|
||||
if (i < context_manager_->map_contexts_.size()) {
|
||||
if (i < context_manager_->open_maps()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -406,8 +396,7 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
|
|||
return true;
|
||||
//TODO rename that hotkey
|
||||
case HOTKEY_EDITOR_TERRAIN_PALETTE_SWAP:
|
||||
//TODO
|
||||
// mouse_action_->get_palette()->swap();
|
||||
toolkit_->palette_manager_->active_palette().swap();
|
||||
toolkit_->set_mouseover_overlay();
|
||||
return true;
|
||||
case HOTKEY_EDITOR_PARTIAL_UNDO:
|
||||
|
@ -470,7 +459,7 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
|
|||
return true;
|
||||
case HOTKEY_EDITOR_SELECTION_FILL:
|
||||
//TODO
|
||||
// fill_selection();
|
||||
//fill_selection();
|
||||
return true;
|
||||
case HOTKEY_EDITOR_SELECTION_RANDOMIZE:
|
||||
context_manager_->perform_refresh(editor_action_shuffle_area(
|
||||
|
@ -653,7 +642,7 @@ void editor_controller::cut_selection()
|
|||
{
|
||||
copy_selection();
|
||||
//TODO
|
||||
//perform_refresh(editor_action_paint_area(get_map().selection(), terrain_palette_->selected_bg_item()));
|
||||
//context_manager_->perform_refresh(editor_action_paint_area(get_map().selection(), selected_bg_terrain()));
|
||||
}
|
||||
|
||||
void editor_controller::export_selection_coords()
|
||||
|
@ -690,8 +679,6 @@ void editor_controller::perform_refresh_delete(editor_action* action, bool drag_
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void editor_controller::refresh_image_cache()
|
||||
{
|
||||
image::flush_cache();
|
||||
|
@ -701,6 +688,8 @@ void editor_controller::refresh_image_cache()
|
|||
void editor_controller::display_redraw_callback(display&)
|
||||
{
|
||||
toolkit_->adjust_size();
|
||||
//TODO
|
||||
//seems not to be needed and speeds up drawing?
|
||||
//gui().invalidate_all();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ editor_display::editor_display(CVideo& video, const editor_map* map,
|
|||
: display(video, map, theme_cfg, level)
|
||||
, brush_locations_()
|
||||
, toolbar_hint_()
|
||||
, terrain_report_()
|
||||
, palette_report_()
|
||||
{
|
||||
clear_screen();
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ void editor_display::draw_sidebar()
|
|||
text = toolbar_hint_;
|
||||
refresh_report("editor_tool_hint", element);
|
||||
|
||||
refresh_report("terrain_image", terrain_report_);
|
||||
refresh_report("terrain_image", palette_report_);
|
||||
}
|
||||
|
||||
} //end namespace editor
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
void rebuild_terrain(const map_location &loc);
|
||||
void set_toolbar_hint(const std::string& value) { toolbar_hint_ = value; }
|
||||
|
||||
void set_terrain_report(const config terrain_report) {terrain_report_ = terrain_report;};
|
||||
void set_palette_report(const config palette_report) {palette_report_ = palette_report;};
|
||||
|
||||
protected:
|
||||
void pre_draw();
|
||||
|
@ -55,7 +55,7 @@ protected:
|
|||
std::string toolbar_hint_;
|
||||
|
||||
private:
|
||||
config terrain_report_;
|
||||
config palette_report_;
|
||||
};
|
||||
|
||||
} //end namespace editor
|
||||
|
|
|
@ -65,6 +65,23 @@ private:
|
|||
bool refreshed_;
|
||||
};
|
||||
|
||||
size_t context_manager::modified_maps(std::string& message) {
|
||||
std::vector<std::string> modified;
|
||||
foreach (map_context* mc, map_contexts_) {
|
||||
if (mc->modified()) {
|
||||
if (!mc->get_filename().empty()) {
|
||||
modified.push_back(mc->get_filename());
|
||||
} else {
|
||||
modified.push_back(_("(New Map)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (std::string& str, modified) {
|
||||
message += "\n" + str;
|
||||
}
|
||||
return modified.size();
|
||||
}
|
||||
|
||||
context_manager::context_manager(editor_display& gui, const config& game_config)
|
||||
: gui_(gui)
|
||||
, game_config_(game_config)
|
||||
|
@ -257,10 +274,9 @@ void context_manager::resize_map_dialog()
|
|||
if(gui2::teditor_resize_map::execute(w, h, dir, copy, gui_.video())) {
|
||||
|
||||
if (w != get_map().w() || h != get_map().h()) {
|
||||
//TODO
|
||||
// t_translation::t_terrain fill = palette_manager_->selected_bg_item();
|
||||
t_translation::t_terrain fill = get_selected_bg_terrain();
|
||||
if (copy) {
|
||||
// fill = t_translation::NONE_TERRAIN;
|
||||
fill = t_translation::NONE_TERRAIN;
|
||||
}
|
||||
int x_offset = get_map().w() - w;
|
||||
int y_offset = get_map().h() - h;
|
||||
|
@ -303,9 +319,8 @@ void context_manager::resize_map_dialog()
|
|||
x_offset = 0;
|
||||
break;
|
||||
}
|
||||
//TODO
|
||||
//editor_action_resize_map a(w, h, x_offset, y_offset, fill);
|
||||
//perform_refresh(a);
|
||||
editor_action_resize_map a(w, h, x_offset, y_offset, fill);
|
||||
perform_refresh(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@ namespace editor {
|
|||
|
||||
class context_manager {
|
||||
|
||||
public:
|
||||
size_t modified_maps(std::string& modified);
|
||||
|
||||
private:
|
||||
editor_display& gui_;
|
||||
|
||||
|
@ -45,6 +48,8 @@ public:
|
|||
|
||||
public:
|
||||
|
||||
size_t open_maps(void) { return map_contexts_.size(); };
|
||||
|
||||
/**
|
||||
* Peform an action on the current map_context, then refresh the display.
|
||||
*/
|
||||
|
@ -160,9 +165,11 @@ public:
|
|||
/** Switches the context to the one under the specified index. */
|
||||
void switch_context(const int index);
|
||||
|
||||
private:
|
||||
/** The currently opened map context object */
|
||||
std::vector<map_context*> map_contexts_;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Save the map under a given filename.
|
||||
* @return true on success
|
||||
|
|
|
@ -43,35 +43,35 @@ public:
|
|||
|
||||
virtual ~common_palette() {}
|
||||
|
||||
//event handling
|
||||
virtual bool left_mouse_click(const int x, const int y) = 0;
|
||||
virtual bool right_mouse_click(const int x, const int y) = 0;
|
||||
|
||||
virtual void set_group(size_t index) = 0;
|
||||
|
||||
virtual void set_start_item(size_t index) = 0;
|
||||
|
||||
//TODO
|
||||
// virtual size_t active_group_index() = 0;
|
||||
|
||||
virtual const std::vector<item_group>& get_groups() const = 0;
|
||||
|
||||
/** Scroll the editor-palette up one step if possible. */
|
||||
virtual bool scroll_up() = 0;
|
||||
|
||||
/** Scroll the editor-palette down one step if possible. */
|
||||
virtual bool scroll_down() = 0;
|
||||
|
||||
virtual void swap() = 0;
|
||||
|
||||
//drawing
|
||||
virtual void adjust_size(const size_specs& size) = 0;
|
||||
|
||||
virtual void draw(bool) = 0;
|
||||
|
||||
virtual size_t num_items() = 0;
|
||||
//group
|
||||
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;
|
||||
|
||||
//item
|
||||
virtual size_t num_items() = 0;
|
||||
virtual size_t start_num() = 0;
|
||||
virtual void set_start_item(size_t index) = 0;
|
||||
virtual void swap() = 0;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -104,11 +104,11 @@ 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 << "'.\n";
|
||||
}
|
||||
gui_.set_terrain_report(active_group_report());
|
||||
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);
|
||||
template void editor_palette<void*>::set_group(const std::string& id);
|
||||
//template void editor_palette<void*>::set_group(const std::string& id);
|
||||
|
||||
template<class Item>
|
||||
void editor_palette<Item>::set_group(size_t index)
|
||||
|
@ -118,7 +118,7 @@ void editor_palette<Item>::set_group(size_t index)
|
|||
}
|
||||
template void editor_palette<t_translation::t_terrain>::set_group(size_t index);
|
||||
template void editor_palette<unit_type>::set_group(size_t index);
|
||||
template void editor_palette<void*>::set_group(size_t index);
|
||||
//template void editor_palette<void*>::set_group(size_t index);
|
||||
|
||||
template<class Item>
|
||||
size_t editor_palette<Item>::active_group_index()
|
||||
|
@ -134,7 +134,7 @@ size_t editor_palette<Item>::active_group_index()
|
|||
}
|
||||
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<void*>::active_group_index();
|
||||
//template size_t editor_palette<void*>::active_group_index();
|
||||
|
||||
template<class Item>
|
||||
const config editor_palette<Item>::active_group_report()
|
||||
|
@ -152,7 +152,7 @@ const config editor_palette<Item>::active_group_report()
|
|||
}
|
||||
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<void*>::active_group_report();
|
||||
//template const config editor_palette<void*>::active_group_report();
|
||||
|
||||
template<class Item>
|
||||
void editor_palette<Item>::adjust_size(const size_specs& size)
|
||||
|
@ -167,52 +167,38 @@ void editor_palette<Item>::adjust_size(const size_specs& size)
|
|||
}
|
||||
template void editor_palette<t_translation::t_terrain>::adjust_size(const size_specs& size);
|
||||
template void editor_palette<unit_type>::adjust_size(const size_specs& size);
|
||||
template void editor_palette<void*>::adjust_size(const size_specs& size);
|
||||
|
||||
//template void editor_palette<void*>::adjust_size(const size_specs& size);
|
||||
|
||||
template<class Item>
|
||||
void editor_palette<Item>::select_fg_item(std::string item_id)
|
||||
{
|
||||
if (selected_fg_item_ != item_id) {
|
||||
selected_fg_item_ = item_id;
|
||||
//TODO
|
||||
//set_dirty();
|
||||
//update_report();
|
||||
}
|
||||
}
|
||||
template void editor_palette<t_translation::t_terrain>::select_fg_item(std::string terrain_id);
|
||||
template void editor_palette<unit_type>::select_fg_item(std::string unit_id);
|
||||
template void editor_palette<void*>::select_fg_item(std::string unit_id);
|
||||
|
||||
|
||||
//template void editor_palette<void*>::select_fg_item(std::string unit_id);
|
||||
|
||||
template<class Item>
|
||||
void editor_palette<Item>::select_bg_item(std::string item_id)
|
||||
{
|
||||
if (selected_bg_item_ != item_id) {
|
||||
selected_bg_item_ = item_id;
|
||||
//TODO
|
||||
//set_dirty();
|
||||
//update_report();
|
||||
}
|
||||
}
|
||||
template void editor_palette<t_translation::t_terrain>::select_bg_item(std::string terrain_id);
|
||||
template void editor_palette<unit_type>::select_bg_item(std::string unit_id);
|
||||
template void editor_palette<void*>::select_bg_item(std::string unit_id);
|
||||
|
||||
//template void editor_palette<void*>::select_bg_item(std::string unit_id);
|
||||
|
||||
template<class Item>
|
||||
void editor_palette<Item>::swap()
|
||||
{
|
||||
std::swap(selected_fg_item_, selected_bg_item_);
|
||||
//TODO
|
||||
//set_dirty();
|
||||
//update_report();
|
||||
}
|
||||
template void editor_palette<t_translation::t_terrain>::swap();
|
||||
template void editor_palette<unit_type>::swap();
|
||||
template void editor_palette<void*>::swap();
|
||||
|
||||
//template void editor_palette<void*>::swap();
|
||||
|
||||
template<class Item>
|
||||
size_t editor_palette<Item>::num_items()
|
||||
|
@ -242,10 +228,6 @@ void editor_palette<Item>::draw(bool)
|
|||
dstrect.w = item_size_;
|
||||
dstrect.h = item_size_;
|
||||
|
||||
//TODO
|
||||
//Reset the tile background
|
||||
//bg_restore(dstrect);
|
||||
|
||||
std::stringstream tooltip_text;
|
||||
|
||||
const std::string item_id = active_group()[counter];
|
||||
|
@ -294,7 +276,7 @@ void editor_palette<Item>::draw(bool)
|
|||
}
|
||||
template void editor_palette<t_translation::t_terrain>::draw(bool);
|
||||
template void editor_palette<unit_type>::draw(bool);
|
||||
template void editor_palette<void*>::draw(bool);
|
||||
//template void editor_palette<void*>::draw(bool);
|
||||
|
||||
template<class Item>
|
||||
int editor_palette<Item>::tile_selected(const int x, const int y) const
|
||||
|
|
|
@ -27,8 +27,6 @@ class editor_palette : public common_palette {
|
|||
public:
|
||||
editor_palette(editor_display &gui, const size_specs &sizes, const config& /*cfg*/
|
||||
, size_t item_size, size_t item_width, mouse_action** active_mouse_action)
|
||||
//TODO
|
||||
// Item& fore, Item& back)
|
||||
: groups_()
|
||||
, gui_(gui)
|
||||
, size_specs_(sizes)
|
||||
|
@ -48,29 +46,24 @@ public:
|
|||
, selected_bg_item_()
|
||||
, active_mouse_action_(active_mouse_action)
|
||||
{
|
||||
//TODO
|
||||
//adjust_size(size_specs_);
|
||||
};
|
||||
//TODO
|
||||
//, selected_fg_item_(fore)
|
||||
//, selected_bg_item_(back)
|
||||
|
||||
void set_group(size_t index);
|
||||
|
||||
const std::vector<item_group>& get_groups() const { return groups_; };
|
||||
|
||||
size_t active_group_index();
|
||||
|
||||
virtual void draw(bool);
|
||||
|
||||
bool left_mouse_click(const int, const int);
|
||||
bool right_mouse_click(const int, const int);
|
||||
|
||||
/** Scroll the editor-palette to the top. */
|
||||
void scroll_top();
|
||||
|
||||
/** Scroll the editor-palette to the bottom. */
|
||||
void scroll_bottom();
|
||||
void next_group() {
|
||||
set_group( (active_group_index() +1) % (groups_.size() -1) );
|
||||
};
|
||||
void prev_group() {
|
||||
set_group( (active_group_index() -1) % (groups_.size() -1) );
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the size of this widget.
|
||||
|
@ -79,12 +72,24 @@ public:
|
|||
*/
|
||||
void adjust_size(const size_specs& size);
|
||||
|
||||
|
||||
|
||||
/** Return the number of the tile that is at coordinates (x, y) in the panel. */
|
||||
int tile_selected(const int x, const int y) const;
|
||||
|
||||
bool scroll_up();
|
||||
bool scroll_down();
|
||||
|
||||
private:
|
||||
|
||||
size_t active_group_index();
|
||||
|
||||
/** Scroll the editor-palette to the top. */
|
||||
void scroll_top();
|
||||
|
||||
/** Scroll the editor-palette to the bottom. */
|
||||
void scroll_bottom();
|
||||
|
||||
virtual void draw_item(SDL_Rect& dstrect, const Item& item, std::stringstream& tooltip) = 0;
|
||||
|
||||
virtual const std::string& get_id(const Item& item) = 0;
|
||||
|
@ -94,10 +99,9 @@ private:
|
|||
|
||||
virtual const std::string& active_group_id() {return active_group_;};
|
||||
|
||||
public:
|
||||
virtual const config active_group_report();
|
||||
|
||||
bool scroll_up();
|
||||
bool scroll_down();
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
@ -140,8 +144,8 @@ protected:
|
|||
|
||||
private:
|
||||
|
||||
/** Return the number of terrains in the palette. */
|
||||
size_t num_items(); //{ return item_map_.size(); };
|
||||
/** Return the number of items in the palette. */
|
||||
size_t num_items();
|
||||
|
||||
void draw_old(bool);
|
||||
|
||||
|
|
|
@ -41,16 +41,8 @@ private:
|
|||
|
||||
virtual void draw_item(SDL_Rect& /*dstrect*/, const unit_type& /*terrain*/,
|
||||
std::stringstream& /*tooltip_text*/) {};
|
||||
|
||||
// virtual void update_report();
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
empty_palette::empty_palette(editor_display &gui, const size_specs &sizes, const config& cfg,
|
||||
mouse_action** active_mouse_action)
|
||||
: editor_palette<void*>(gui, sizes, cfg, 0, 0, active_mouse_action) {};
|
||||
*/
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -35,11 +35,6 @@ namespace editor {
|
|||
|
||||
size_specs::size_specs()
|
||||
: palette_x(0)
|
||||
//TODO
|
||||
// , terrain_size(default_terrain_size)
|
||||
// , terrain_padding(0)
|
||||
// , terrain_space(1)
|
||||
// , terrain_width(default_terrain_width)
|
||||
, palette_y(0)
|
||||
, palette_h(20)
|
||||
, palette_w(10)
|
||||
|
@ -52,9 +47,6 @@ size_specs::size_specs()
|
|||
|
||||
void adjust_sizes(const display &disp, size_specs &sizes) {
|
||||
/** @todo Hardcoded coordinates for brush selection, make them themeable. */
|
||||
//TODO
|
||||
// sizes.terrain_size = item_size;
|
||||
// sizes.terrain_width = item_width;
|
||||
sizes.brush_x = disp.map_outside_area().w + 12;
|
||||
sizes.brush_y = (disp.h() >= 768) ? 340 : 270;
|
||||
/** @todo Hardcoded coordinates for terrain palette, make them themeable. */
|
||||
|
@ -62,9 +54,6 @@ void adjust_sizes(const display &disp, size_specs &sizes) {
|
|||
sizes.palette_y = sizes.brush_y + 33;
|
||||
sizes.palette_w = 174; // sizes.terrain_space * sizes.terrain_width;
|
||||
sizes.palette_h = disp.h() - sizes.palette_y;
|
||||
//TODO
|
||||
// sizes.terrain_padding = (disp.h() >= 768) ? 3 : 1;
|
||||
// sizes.terrain_space = sizes.terrain_size + sizes.terrain_padding;
|
||||
}
|
||||
|
||||
} // end namespace editor
|
||||
|
|
|
@ -34,11 +34,6 @@ struct size_specs {
|
|||
* adjust_sizes().
|
||||
*/
|
||||
size_specs();
|
||||
//TODO
|
||||
// size_t terrain_size;
|
||||
// size_t terrain_padding;
|
||||
// size_t terrain_space;
|
||||
// size_t terrain_width;
|
||||
size_t palette_x;
|
||||
size_t palette_y;
|
||||
size_t palette_h;
|
||||
|
|
|
@ -28,15 +28,14 @@ palette_manager::palette_manager(editor_display& gui, const size_specs &sizes, c
|
|||
: gui::widget(gui.video()),
|
||||
gui_(gui),
|
||||
size_specs_(sizes),
|
||||
palette_start_(0),
|
||||
palette_start_(sizes.palette_y),
|
||||
mouse_action_(active_mouse_action),
|
||||
terrain_palette_(new terrain_palette(gui, sizes, cfg, active_mouse_action)),
|
||||
unit_palette_(new unit_palette(gui,sizes,cfg,active_mouse_action)),
|
||||
empty_palette_(new empty_palette(gui,sizes,cfg,active_mouse_action))
|
||||
{
|
||||
terrain_palette_->setup(cfg);
|
||||
unit_palette_->setup(cfg);
|
||||
set_dirty();
|
||||
terrain_palette_->setup(cfg);
|
||||
}
|
||||
|
||||
void palette_manager::set_group(size_t index)
|
||||
|
@ -57,13 +56,8 @@ void palette_manager::adjust_size()
|
|||
set_location(rect);
|
||||
palette_start_ = size_specs_.palette_y;
|
||||
|
||||
//TODO
|
||||
// rect.y = items_start_;
|
||||
// rect.h = space_for_items;
|
||||
bg_register(rect);
|
||||
|
||||
(*mouse_action_)->get_palette().adjust_size(size_specs_);
|
||||
|
||||
active_palette().adjust_size(size_specs_);
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
|
@ -133,12 +127,7 @@ void palette_manager::draw(bool force)
|
|||
|
||||
const SDL_Rect &loc = location();
|
||||
|
||||
SDL_Rect palrect;
|
||||
palrect.x = loc.x;
|
||||
palrect.y = palette_start_;
|
||||
palrect.w = size_specs_.palette_w;
|
||||
palrect.h = size_specs_.palette_h;
|
||||
tooltips::clear_tooltips(palrect);
|
||||
tooltips::clear_tooltips(loc);
|
||||
|
||||
active_palette().draw(force);
|
||||
|
||||
|
@ -172,6 +161,11 @@ void palette_manager::handle_event(const SDL_Event& event) {
|
|||
if (mouse_button_event.button == SDL_BUTTON_LEFT) {
|
||||
left_mouse_click(mousex, mousey);
|
||||
}
|
||||
/* TODO
|
||||
if (mouse_button_event.button == SDL_BUTTON_MIDDLE) {
|
||||
middle_mouse_click(mousex, mousey);
|
||||
}
|
||||
*/
|
||||
if (mouse_button_event.button == SDL_BUTTON_RIGHT) {
|
||||
right_mouse_click(mousex, mousey);
|
||||
}
|
||||
|
@ -182,14 +176,12 @@ void palette_manager::handle_event(const SDL_Event& event) {
|
|||
scroll_down();
|
||||
}
|
||||
if (mouse_button_event.button == SDL_BUTTON_WHEELLEFT) {
|
||||
//TODO
|
||||
// set_group( (active_palette().active_group_index() -1) % (groups_.size() -1) );
|
||||
// gui_.set_terrain_report(active_group_report());
|
||||
active_palette().prev_group();
|
||||
scroll_top();
|
||||
}
|
||||
if (mouse_button_event.button == SDL_BUTTON_WHEELRIGHT) {
|
||||
//TODO
|
||||
// set_group( (active_palette().active_group_index() +1) % (groups_.size() -1) );
|
||||
// gui_.set_terrain_report(active_group_report());
|
||||
active_palette().next_group();
|
||||
scroll_top();
|
||||
}
|
||||
}
|
||||
if (mouse_button_event.type == SDL_MOUSEBUTTONUP) {
|
||||
|
@ -201,8 +193,7 @@ void palette_manager::handle_event(const SDL_Event& event) {
|
|||
|
||||
void palette_manager::left_mouse_click(const int mousex, const int mousey)
|
||||
{
|
||||
if (
|
||||
active_palette().left_mouse_click(mousex, mousey) ) {
|
||||
if ( active_palette().left_mouse_click(mousex, mousey) ) {
|
||||
set_dirty();
|
||||
gui_.invalidate_game_status();
|
||||
}
|
||||
|
@ -210,8 +201,7 @@ void palette_manager::left_mouse_click(const int mousex, const int mousey)
|
|||
|
||||
void palette_manager::right_mouse_click(const int mousex, const int mousey)
|
||||
{
|
||||
if (
|
||||
active_palette().right_mouse_click(mousex, mousey) ) {
|
||||
if ( active_palette().right_mouse_click(mousex, mousey) ) {
|
||||
set_dirty();
|
||||
gui_.invalidate_game_status();
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public:
|
|||
// int tile_selected(const int x, const int y) const;
|
||||
|
||||
|
||||
private:
|
||||
public:
|
||||
|
||||
common_palette& active_palette(); //{ return (*mouse_action_)->get_palette(); };
|
||||
|
||||
|
|
|
@ -26,10 +26,17 @@
|
|||
|
||||
namespace {
|
||||
static std::string selected_terrain;
|
||||
static t_translation::t_terrain bg_terrain;
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace editor {
|
||||
|
||||
t_translation::t_terrain get_selected_bg_terrain() {
|
||||
return bg_terrain;
|
||||
}
|
||||
|
||||
std::string get_selected_terrain()
|
||||
{
|
||||
return selected_terrain;
|
||||
|
@ -47,6 +54,11 @@ void terrain_palette::update_report()
|
|||
selected_terrain = msg.str();
|
||||
}
|
||||
|
||||
void terrain_palette::select_bg_item(std::string item_id) {
|
||||
editor_palette::select_bg_item(item_id);
|
||||
bg_terrain = selected_bg_item();
|
||||
}
|
||||
|
||||
void terrain_palette::setup(const config& cfg)
|
||||
{
|
||||
// Get the available terrains temporary in items
|
||||
|
@ -122,8 +134,9 @@ void terrain_palette::setup(const config& cfg)
|
|||
|
||||
}
|
||||
|
||||
select_fg_item("grassland");
|
||||
select_bg_item("mountains");
|
||||
// Set the default terrain
|
||||
select_fg_item("mountains");
|
||||
select_bg_item("grassland");
|
||||
|
||||
// Set the default group
|
||||
set_group("all");
|
||||
|
@ -132,7 +145,7 @@ void terrain_palette::setup(const config& cfg)
|
|||
ERR_ED << "No items found.\n";
|
||||
}
|
||||
|
||||
update_report();
|
||||
// update_report();
|
||||
}
|
||||
|
||||
void terrain_palette::draw_item(SDL_Rect& dstrect, const t_translation::t_terrain& terrain, std::stringstream& tooltip_text) {
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace editor {
|
|||
|
||||
std::string get_selected_terrain();
|
||||
|
||||
t_translation::t_terrain get_selected_bg_terrain();
|
||||
|
||||
/** Palette where the terrain to be drawn can be selected. */
|
||||
class terrain_palette : public editor_palette<t_translation::t_terrain> {
|
||||
|
@ -41,6 +42,8 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
virtual void select_bg_item(std::string item_id);
|
||||
|
||||
virtual const std::string& get_id(const t_translation::t_terrain& terrain);
|
||||
|
||||
virtual void draw_item(SDL_Rect& dstrect, const t_translation::t_terrain& terrain, std::stringstream& tooltip_text);
|
||||
|
|
|
@ -75,6 +75,10 @@ void unit_palette::setup(const config& /*cfg*/)
|
|||
//std::stable_partition(items.begin(), items.end(), is_valid_terrain);
|
||||
|
||||
// Set the default group
|
||||
|
||||
select_fg_item("Elvish Fighter");
|
||||
select_bg_item("Elvish Archer");
|
||||
|
||||
set_group("human");
|
||||
|
||||
if(active_group().empty()) {
|
||||
|
|
|
@ -40,7 +40,6 @@ editor_toolkit::editor_toolkit(editor_display& gui, const CKey& key, const confi
|
|||
init_brushes(game_config);
|
||||
init_sidebar(game_config);
|
||||
init_mouse_actions(game_config);
|
||||
palette_manager_->adjust_size();
|
||||
}
|
||||
|
||||
editor_toolkit::~editor_toolkit()
|
||||
|
@ -75,14 +74,58 @@ void editor_toolkit::init_sidebar(const config& game_config)
|
|||
palette_manager_.reset(new palette_manager(gui_, *size_specs_, game_config, &mouse_action_));
|
||||
}
|
||||
|
||||
void editor_toolkit::init_mouse_actions(const config& game_config)
|
||||
{
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_PAINT,
|
||||
new mouse_action_paint(&brush_, key_, *palette_manager_->terrain_palette_.get())));
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_FILL,
|
||||
new mouse_action_fill(key_, *palette_manager_->terrain_palette_.get())));
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_SELECT,
|
||||
new mouse_action_select(&brush_, key_, *palette_manager_->empty_palette_.get())));
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_STARTING_POSITION,
|
||||
new mouse_action_starting_position(key_, *palette_manager_->empty_palette_.get())));
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_LABEL,
|
||||
new mouse_action_map_label(key_, *palette_manager_->empty_palette_.get())));
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_UNIT,
|
||||
new mouse_action_unit(key_, *palette_manager_->unit_palette_.get())));
|
||||
|
||||
//TODO
|
||||
// mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_PASTE,
|
||||
// new mouse_action_paste(clipboard_, key_, *palette_manager_->empty_palette_.get())));
|
||||
|
||||
foreach (const theme::menu& menu, gui_.get_theme().menus()) {
|
||||
if (menu.items().size() == 1) {
|
||||
hotkey::HOTKEY_COMMAND hk = hotkey::get_hotkey(menu.items().front()).get_id();
|
||||
mouse_action_map::iterator i = mouse_actions_.find(hk);
|
||||
if (i != mouse_actions_.end()) {
|
||||
i->second->set_toolbar_button(&menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (const config &c, game_config.child_range("editor_tool_hint")) {
|
||||
mouse_action_map::iterator i =
|
||||
mouse_actions_.find(hotkey::get_hotkey(c["id"]).get_id());
|
||||
if (i != mouse_actions_.end()) {
|
||||
mouse_action_hints_.insert(std::make_pair(i->first, c["text"]));
|
||||
}
|
||||
}
|
||||
|
||||
mouse_action_ = (mouse_actions_.find(hotkey::HOTKEY_EDITOR_TOOL_PAINT))->second;
|
||||
set_mouseover_overlay();
|
||||
}
|
||||
|
||||
|
||||
void editor_toolkit::hotkey_set_mouse_action(hotkey::HOTKEY_COMMAND command)
|
||||
{
|
||||
std::map<hotkey::HOTKEY_COMMAND, mouse_action*>::iterator i = mouse_actions_.find(command);
|
||||
if (i != mouse_actions_.end()) {
|
||||
mouse_action_ = i->second;
|
||||
//TODO is the draw call needed?
|
||||
palette_manager_->adjust_size();
|
||||
palette_manager_->draw(true);
|
||||
|
||||
//TODO make active_palette() privat again.
|
||||
//palette_manager_->switch_palette();
|
||||
gui_.set_palette_report(palette_manager_->active_palette().active_group_report());
|
||||
|
||||
set_mouseover_overlay();
|
||||
redraw_toolbar();
|
||||
gui_.invalidate_game_status();
|
||||
|
@ -96,7 +139,7 @@ void editor_toolkit::hotkey_set_mouse_action(hotkey::HOTKEY_COMMAND command)
|
|||
void editor_toolkit::fill_selection()
|
||||
{
|
||||
//TODO
|
||||
/*
|
||||
/*
|
||||
perform_refresh(editor_action_paint_area(get_map().selection(),
|
||||
toolkit_->terrain_palette_->selected_fg_item()));
|
||||
*/
|
||||
|
@ -173,43 +216,5 @@ void editor_toolkit::redraw_toolbar()
|
|||
toolbar_dirty_ = false;
|
||||
}
|
||||
|
||||
void editor_toolkit::init_mouse_actions(const config& game_config)
|
||||
{
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_PAINT,
|
||||
new mouse_action_paint(&brush_, key_, *palette_manager_->terrain_palette_.get())));
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_FILL,
|
||||
new mouse_action_fill(key_, *palette_manager_->terrain_palette_.get())));
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_SELECT,
|
||||
new mouse_action_select(&brush_, key_, *palette_manager_->empty_palette_.get())));
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_STARTING_POSITION,
|
||||
new mouse_action_starting_position(key_, *palette_manager_->empty_palette_.get())));
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_LABEL,
|
||||
new mouse_action_map_label(key_, *palette_manager_->empty_palette_.get())));
|
||||
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_UNIT,
|
||||
new mouse_action_unit(key_, *palette_manager_->unit_palette_.get())));
|
||||
|
||||
// mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_PASTE,
|
||||
// new mouse_action_paste(clipboard_, key_, *palette_manager_->empty_palette_.get())));
|
||||
|
||||
foreach (const theme::menu& menu, gui_.get_theme().menus()) {
|
||||
if (menu.items().size() == 1) {
|
||||
hotkey::HOTKEY_COMMAND hk = hotkey::get_hotkey(menu.items().front()).get_id();
|
||||
mouse_action_map::iterator i = mouse_actions_.find(hk);
|
||||
if (i != mouse_actions_.end()) {
|
||||
i->second->set_toolbar_button(&menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (const config &c, game_config.child_range("editor_tool_hint")) {
|
||||
mouse_action_map::iterator i =
|
||||
mouse_actions_.find(hotkey::get_hotkey(c["id"]).get_id());
|
||||
if (i != mouse_actions_.end()) {
|
||||
mouse_action_hints_.insert(std::make_pair(i->first, c["text"]));
|
||||
}
|
||||
}
|
||||
|
||||
hotkey_set_mouse_action(hotkey::HOTKEY_EDITOR_TOOL_PAINT);
|
||||
}
|
||||
|
||||
|
||||
} //Namespace editor
|
||||
|
|
Loading…
Add table
Reference in a new issue