Skip to content

Commit

Permalink
Unit Advance: some layout improvements, code cleanup and clarificatio…
Browse files Browse the repository at this point in the history
…n, and a minor issue fix

The fix is disabling ESC-closing of the dialog.
  • Loading branch information
Vultraz committed Aug 10, 2016
1 parent ebf90fb commit 5398980
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
11 changes: 7 additions & 4 deletions data/gui/window/unit_advance.cfg
Expand Up @@ -21,12 +21,11 @@
[grid]
[row]
[column]
grow_factor = 1
grow_factor = 0
horizontal_grow = "true"

# Smaller border deliberately
border = "all"
border_size = 1
border_size = 5

[image]
id = "advancement_image"
definition = "default"
Expand All @@ -35,6 +34,7 @@
[/column]

[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
Expand Down Expand Up @@ -133,6 +133,8 @@
[row]
grow_factor=0
[column]
border = "all"
border_size = 5
[label]
definition = "default"
label = _ "What should our victorious unit become?"
Expand All @@ -142,6 +144,7 @@
[row]
grow_factor=1
[column]
horizontal_grow = "true"
{_GUI_ADVANCE_LIST}
[/column]
[/row]
Expand Down
8 changes: 6 additions & 2 deletions src/dialogs.cpp
Expand Up @@ -106,13 +106,17 @@ int advance_unit_dialog(const map_location &loc)

if(previews.size() > 1 || always_display) {
gui2::tunit_advance dlg(previews, num_real_advances);

dlg.show(CVideo::get_singleton());

if(dlg.get_retval() == gui2::twindow::OK) {
return dlg.get_selected_index();
} else {
assert(false);
}

// This should be unreachable, since canceling is disabled for the dialog
assert(false);
}

return 0;
}

Expand Down
30 changes: 14 additions & 16 deletions src/gui/dialogs/unit_advance.cpp
Expand Up @@ -29,16 +29,7 @@
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "units/unit.hpp"
//#include "gettext.hpp"
#include "help/help.hpp"
//#include "marked-up_text.hpp"
//#include "play_controller.hpp"
//#include "resources.hpp"
//#include "team.hpp"
//#include "actions/attack.hpp" // for get_advanced_unit, get_amla_unit
//#include "units/types.hpp"
//#include "whiteboard/manager.hpp"
//#include "game_preferences.hpp"

#include "utils/functional.hpp"

Expand All @@ -50,7 +41,7 @@ REGISTER_DIALOG(unit_advance)
tunit_advance::tunit_advance(const unit_ptr_vector& samples, size_t real)
: previews_(samples)
, selected_index_(0)
, real_(real)
, last_real_advancement_(real)
{
}

Expand All @@ -76,21 +67,25 @@ void tunit_advance::pre_show(twindow& window)

for(size_t i = 0; i < previews_.size(); i++) {
const unit& sample = *previews_[i];

std::map<std::string, string_map> row_data;
string_map column;

std::string image_string, name = sample.type_name();
if(i >= real_) {
auto iter = sample
.get_modifications()
.child_range("advancement")
.second;
std::string image_string, name = sample.type_name();

// This checks if we've finished iterating over the last unit type advancements
// and are into the modification-based advancements.
if(i >= last_real_advancement_) {
auto iter = sample.get_modifications().child_range("advancement").second;
iter--;

if(iter->has_attribute("image")) {
image_string = iter->get("image")->str();
}

name = iter->get("description")->str();
}

if(image_string.empty()) {
image_string = sample.type().image() + sample.image_mods();
}
Expand All @@ -105,6 +100,9 @@ void tunit_advance::pre_show(twindow& window)
}

list_item_clicked(window);

// Disable ESC existing
window.set_escape_disabled(true);
}

void tunit_advance::list_item_clicked(twindow& window)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/unit_advance.hpp
Expand Up @@ -44,7 +44,7 @@ class tunit_advance : public tdialog

const unit_ptr_vector& previews_;

size_t selected_index_, real_;
size_t selected_index_, last_real_advancement_;
};

} // namespace gui2
Expand Down

0 comments on commit 5398980

Please sign in to comment.