Merge branch 'gamestate_dialogue_improvements'

Improves the gamestate inspection dialogue. It fixes a long-standing
assertion issue and also reduces the amount of redundant work done.

Note the dialogue can still be improved further, but the currently
shown dialogue is /a/ valid way to show its contents.

The merge fixes bug #22095, possibly #15615 and #21785.
This commit is contained in:
Mark de Wever 2014-06-09 14:27:16 +02:00
commit 7efb1ba73b
6 changed files with 73 additions and 17 deletions

View file

@ -56,6 +56,9 @@ Version 1.13.0-dev:
* Classic Theme which restores the 1.10 UI.
* Made orb and minmap colors configurable by the game preferences.
* Remove 'allow_new_game=no' entries from random map new game list
* Fixed bug #22095: An assertion failure in the gamestate inspector.
* Changed: A listbox can now update its size when rows are added.
* Changed: Avoid listboxes to handle mouse clicks twice.
* WML engine:
* Added customizable recall costs for unit types and individual units,
using the new recall_cost attribute in [unit_type] and [unit].

View file

@ -84,14 +84,12 @@ static void inspect_ai(twindow& window, int side)
* my_dialog_class::inner_view_class
* &my_dialog_class::inner_view_class::member_function>);
*/
template <class D, class V, void (V::*fptr)(twindow&)>
template <class D, class V, void (V::*fptr)()>
void dialog_view_callback(twidget& caller)
{
D* dialog = dynamic_cast<D*>(caller.dialog());
assert(dialog);
twindow* window = dynamic_cast<twindow*>(caller.get_window());
assert(window);
(*(dialog->get_view()).*fptr)(*window);
(*(dialog->get_view()).*fptr)();
}
@ -575,24 +573,21 @@ public:
{
}
void pre_show(CVideo& /*video*/, twindow& window)
void pre_show(CVideo& /*video*/, twindow& /*window*/)
{
controller_.show_stuff_types_list();
controller_.update_view_from_model();
window.invalidate_layout(); // workaround for assertion failure
}
void handle_stuff_list_item_clicked(twindow& window)
void handle_stuff_list_item_clicked()
{
controller_.handle_stuff_list_item_clicked();
window.invalidate_layout(); // workaround for assertion failure
}
void handle_stuff_types_list_item_clicked(twindow& window)
void handle_stuff_types_list_item_clicked()
{
controller_.handle_stuff_types_list_item_clicked();
window.invalidate_layout(); // workaround for assertion failure
}
@ -611,15 +606,13 @@ public:
*model_.stuff_list,
boost::bind(&tgamestate_inspector::view::
handle_stuff_list_item_clicked,
this,
boost::ref(window)));
this));
connect_signal_notify_modified(
*model_.stuff_types_list,
boost::bind(&tgamestate_inspector::view::
handle_stuff_list_item_clicked,
this,
boost::ref(window)));
this));
#else
model_.stuff_list->set_callback_value_change(

View file

@ -66,8 +66,10 @@ tlistbox::tlistbox(const bool has_minimum,
void tlistbox::add_row(const string_map& item, const int index)
{
assert(generator_);
generator_->create_item(
const tgrid& row = generator_->create_item(
index, list_builder_, item, callback_list_item_clicked);
resize_content(row);
}
void
@ -75,8 +77,10 @@ tlistbox::add_row(const std::map<std::string /* widget id */, string_map>& data,
const int index)
{
assert(generator_);
generator_->create_item(
const tgrid& row = generator_->create_item(
index, list_builder_, data, callback_list_item_clicked);
resize_content(row);
}
void tlistbox::remove_row(const unsigned row, unsigned count)
@ -315,6 +319,26 @@ void tlistbox::resize_content(const int width_modification,
}
}
void tlistbox::resize_content(const twidget& row)
{
if(row.get_visible() == tvisible::invisible) {
return;
}
DBG_GUI_L << LOG_HEADER << " current size " << content_grid()->get_size()
<< " row size " << row.get_best_size() << ".\n";
const tpoint content = content_grid()->get_size();
tpoint size = row.get_best_size();
if(size.x < content.x) {
size.x = 0;
} else {
size.x -= content.x;
}
resize_content(size.x, size.y);
}
void tlistbox::layout_children()
{
layout_children(false);

View file

@ -303,6 +303,15 @@ private:
void resize_content(const int width_modification,
const int height_modification);
/**
* Resizes the content.
*
* The resize happens when a new row is added to the contents.
*
* @param row The new row added to the listbox.
*/
void resize_content(const twidget& row);
/** Layouts the children if needed. */
void layout_children(const bool force);

View file

@ -264,7 +264,17 @@ void tscrollbar_container::request_reduce_width(const unsigned maximum_width)
horizontal_scrollbar_grid_->set_visible(twidget::tvisible::visible);
size = get_best_size();
const tpoint scrollbar_size = horizontal_scrollbar_grid_->get_best_size();
tpoint scrollbar_size = horizontal_scrollbar_grid_->get_best_size();
/*
* If the vertical bar is not invisible it's size needs to be added to the
* minimum size.
*/
if(vertical_scrollbar_grid_->get_visible()
!= twidget::tvisible::invisible) {
scrollbar_size.x += vertical_scrollbar_grid_->get_best_size().x;
}
// If showing the scrollbar increased the width, hide and abort.
if(horizontal_scrollbar_mode_ == auto_visible_first_run && scrollbar_size.x

View file

@ -265,9 +265,26 @@ ttoggle_panel::signal_handler_pre_left_button_click(const event::tevent event)
DBG_GUI_E << get_control_type() << "[" << id() << "]: " << event << ".\n";
set_value(true);
#if 0
/*
* Disabled since it causes issues with gamestate inspector (bug #22095).
* It was added in b84f2ebff0b53c7e4194da315c43f62a08494c52 for the lobby,
* since that code is still experimental, prefer to fix a real issue caused
* by it.
*
* The issue is that the gui2::tlistbox::add_row code was changed to
* increase the content size. Before the list was shown the list was
* cleared. The clear operation did not reduce the size (since the widgets
* were not shown yet). The add operation afterwards again reserved the
* space causing the size of the listbox to be twice the required space.
*
* 2014.06.09 -- Mordante
*/
if(callback_state_change_) {
callback_state_change_(*this);
}
#endif
}
void ttoggle_panel::signal_handler_left_button_click(const event::tevent event,