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.]]

Conflicts:
	changelog
  • Loading branch information
LovCAPONE authored and irydacea committed Oct 6, 2014
1 parent 3410eec commit 5c8eb65
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
3 changes: 3 additions & 0 deletions changelog
Expand Up @@ -103,6 +103,9 @@ Version 1.11.16:
language (bug #22092).
* Fixed mouse tracking issue with workaround by changing the default window
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:
* Fixed a regression in 1.11.14 causing WML parser/preprocessor errors to
not interrupt the game load sequence or display an error message in-game,
Expand Down
33 changes: 23 additions & 10 deletions src/gui/dialogs/gamestate_inspector.cpp
Expand Up @@ -139,6 +139,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 @@ -174,14 +176,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 @@ -234,7 +240,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 @@ -264,11 +275,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 5c8eb65

Please sign in to comment.