attempt to fix crash in editor starting positions tool.

This commit is contained in:
gfgtdf 2016-09-12 15:54:32 +02:00
parent 9cc80973f8
commit 2ff3d2d3aa

View File

@ -242,26 +242,27 @@ void location_palette::adjust_size(const SDL_Rect& target)
palette_y_ = target.y; palette_y_ = target.y;
const int button_height = 30; const int button_height = 30;
int bottom = target.y + target.h; int bottom = target.y + target.h;
if (!button_goto_) {
button_goto_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_height, target.w - 10, button_height }, _("Go To"), [this]() {
button_add_.reset(); //static_cast<mouse_action_starting_position&>(toolkit_.get_mouse_action()). ??
button_delete_.reset(); map_location pos = disp_.get_map().special_location(selected_item_);
button_goto_.reset(); if (pos.valid()) {
disp_.scroll_to_tile(pos, display::WARP);
button_goto_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_height, target.w - 10, button_height }, _("Go To"), [this]() { }
//static_cast<mouse_action_starting_position&>(toolkit_.get_mouse_action()). ?? }));
map_location pos = disp_.get_map().special_location(selected_item_); button_add_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_height, target.w - 10, button_height }, _("Add"), [this]() {
if (pos.valid()) { std::string newid;
disp_.scroll_to_tile(pos, display::WARP); if (gui2::tedit_text::execute(_("New Location Identifer"), "", newid, video())) {
} add_item(newid);
})); }
button_add_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_height, target.w - 10, button_height }, _("Add"), [this]() { }));
std::string newid; button_delete_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_height, target.w - 10, button_height }, _("Delete"), nullptr));
if (gui2::tedit_text::execute(_("New Location Identifer"), "", newid, video())) { }
add_item(newid); else {
} button_goto_->set_location(SDL_Rect{ target.x , bottom -= button_height, target.w - 10, button_height });
})); button_add_->set_location(SDL_Rect{ target.x , bottom -= button_height, target.w - 10, button_height });
button_delete_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_height, target.w - 10, button_height }, _("Delete"), nullptr)); button_delete_->set_location(SDL_Rect{ target.x , bottom -= button_height, target.w - 10, button_height });
}
const int space_for_items = bottom - target.y; const int space_for_items = bottom - target.y;
const int items_fitting = space_for_items / item_space_; const int items_fitting = space_for_items / item_space_;
@ -271,6 +272,7 @@ void location_palette::adjust_size(const SDL_Rect& target)
//TODO: we should write our own ptr_vector class, boost::ptr_vector has a lot of flaws. //TODO: we should write our own ptr_vector class, boost::ptr_vector has a lot of flaws.
buttons_.resize(items_fitting, &lpi); buttons_.resize(items_fitting, &lpi);
} }
set_location(target); set_location(target);
set_dirty(true); set_dirty(true);
gui_.video().clear_help_string(help_handle_); gui_.video().clear_help_string(help_handle_);