Skip to content

Commit

Permalink
Modified the game state inspector for the bug #22337
Browse files Browse the repository at this point in the history
(Bug in inspect long array)

When an array are more than 20000 characters, its label
is duplicated for the number of "pages" that needs to
display its content

[[Minor style fixes from shadowm.]]
  • Loading branch information
LovCAPONE authored and irydacea committed Oct 6, 2014
1 parent e20e7d7 commit ddbdec3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog
Expand Up @@ -125,6 +125,7 @@ Version 1.13.0-dev:
resolution for OS X to 800 x 600 (bug #20332).
* Removed the "Replay viewer" text label from the replay controller theme,
because it caused problems for translators and was unnecessary
* Fixed bug #22337: Bug in inspect long arrays
* WML engine:
* Added customizable recall costs for unit types and individual units,
using the new recall_cost attribute in [unit_type] and [unit].
Expand Down
33 changes: 23 additions & 10 deletions src/gui/dialogs/gamestate_inspector.cpp
Expand Up @@ -140,6 +140,8 @@ class tgamestate_inspector::model
tcontrol* inspector_name;
tbutton* copy_button;

static const unsigned int max_inspect_win_len = 20000;


void clear_stuff_list()
{
Expand Down Expand Up @@ -175,14 +177,18 @@ class tgamestate_inspector::model
}


void set_inspect_window_text(const std::string& s)
void set_inspect_window_text(const std::string& s, unsigned int page = 0)
{
std::string s_ = s;
if(s_.length() > 20000) { // workaround for known bug
s_.resize(20000);
}
unsigned int reminder = (s.length() - (max_inspect_win_len * page));
std::string s_ = s.substr(max_inspect_win_len * page, reminder > max_inspect_win_len ? max_inspect_win_len : reminder);
inspect->set_label(s_);
}


unsigned int get_num_page(const std::string& s)
{
return (s.length() / max_inspect_win_len) + (s.length() % max_inspect_win_len > 0 ? 1 : 0);
}
};

class single_mode_controller
Expand Down Expand Up @@ -235,7 +241,12 @@ class variable_mode_controller : public single_mode_controller

FOREACH(const AUTO & c, vars.all_children_range())
{
model_.add_row_to_stuff_list("[" + c.key + "]", "[" + c.key + "]");
unsigned int num_pages = model_.get_num_page(config_to_string(c.cfg));
for (unsigned int i = 0; i < num_pages; i++) {
std::ostringstream cur_str;
cur_str << "[" << c.key << "] " << (i + 1) << "/" << num_pages;
model_.add_row_to_stuff_list(cur_str.str(), cur_str.str());
}
}

model_.set_inspect_window_text("");
Expand Down Expand Up @@ -265,11 +276,13 @@ class variable_mode_controller : public single_mode_controller

FOREACH(const AUTO & c, vars.all_children_range())
{
if(selected == i) {
model_.set_inspect_window_text(config_to_string(c.cfg));
return;
for (unsigned int j = 0; j < model_.get_num_page(config_to_string(c.cfg)); ++j) {
if (selected == i) {
model_.set_inspect_window_text(config_to_string(c.cfg), j);
return;
}
i++;
}
i++;
}
}

Expand Down

0 comments on commit ddbdec3

Please sign in to comment.