~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/wui/game_summary.cc

  • Committer: Wideland's Bunnybot
  • Date: 2016-01-25 08:41:09 UTC
  • mfrom: (7737.1.1 bug-1395278)
  • Revision ID: bunnybot@widelands.org-20160125084109-l8nbxl59idl0fmf6
MergedĀ lp:~klaus-halfmann/widelands/bug-1395278-wui.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2007-2008 by the Widelands Development Team
 
2
 * Copyright (C) 2007-2016 by the Widelands Development Team
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
41
41
GameSummaryScreen::GameSummaryScreen
42
42
        (InteractiveGameBase * parent, UI::UniqueWindow::Registry * r)
43
43
: UI::UniqueWindow(parent, "game_summary", r, 0, 0, _("Game over")),
44
 
m_game(parent->game())
 
44
game_(parent->game())
45
45
{
46
46
        // Init boxes
47
47
        UI::Box * vbox = new UI::Box(this, 0, 0, UI::Box::Vertical, 0, 0, PADDING);
48
 
        m_title_area = new UI::Textarea(vbox, "", UI::Align_HCenter);
49
 
        vbox->add(m_title_area, UI::Box::AlignCenter);
 
48
        title_area_ = new UI::Textarea(vbox, "", UI::Align_HCenter);
 
49
        vbox->add(title_area_, UI::Box::AlignCenter);
50
50
        vbox->add_space(PADDING);
51
51
 
52
52
        UI::Box * hbox1 = new UI::Box(this, 0, 0, UI::Box::Horizontal);
53
 
        m_players_table = new UI::Table<uintptr_t const>(hbox1, 0, 0, 0, 0);
54
 
        m_players_table->fit_height(m_game.player_manager()->get_players_end_status().size());
 
53
        players_table_ = new UI::Table<uintptr_t const>(hbox1, 0, 0, 0, 0);
 
54
        players_table_->fit_height(game_.player_manager()->get_players_end_status().size());
55
55
        hbox1->add_space(PADDING);
56
 
        hbox1->add(m_players_table, UI::Box::AlignTop);
 
56
        hbox1->add(players_table_, UI::Box::AlignTop);
57
57
        hbox1->add_space(PADDING);
58
58
 
59
59
        UI::Box * info_box = new UI::Box(hbox1, 0, 0, UI::Box::Vertical, 0, 0);
60
 
        m_info_area_label = new UI::Textarea(info_box, _("Player info:"));
61
 
        info_box->add(m_info_area_label, UI::Box::AlignLeft);
62
 
        m_info_area = new UI::MultilineTextarea(
 
60
        info_area_label_ = new UI::Textarea(info_box, _("Player info:"));
 
61
        info_box->add(info_area_label_, UI::Box::AlignLeft);
 
62
        info_area_ = new UI::MultilineTextarea(
63
63
                                                  info_box, 0, 0, 130,
64
 
                                                  std::max(130, m_players_table->get_h() - m_info_area_label->get_h() - PADDING),
 
64
                                                  std::max(130, players_table_->get_h() - info_area_label_->get_h() - PADDING),
65
65
                                                  "");
66
 
        info_box->add(m_info_area, UI::Box::AlignLeft, true);
 
66
        info_box->add(info_area_, UI::Box::AlignLeft, true);
67
67
        info_box->add_space(PADDING);
68
68
        hbox1->add(info_box, UI::Box::AlignTop);
69
69
        hbox1->add_space(PADDING);
70
70
        vbox->add(hbox1, UI::Box::AlignLeft);
71
71
 
72
 
        UI::Box * bottom_box = new UI::Box(this, 0, 0, UI::Box::Horizontal);
73
 
 
74
 
        bottom_box->add_space(PADDING);
75
 
 
76
 
        m_gametime_label = new UI::Textarea(bottom_box, _("Elapsed time:"));
77
 
        bottom_box->add(m_gametime_label, UI::Box::AlignCenter);
78
 
        bottom_box->add_space(PADDING);
79
 
        m_gametime_value = new UI::Textarea(bottom_box, gametimestring(m_game.get_gametime()));
80
 
        bottom_box->add(m_gametime_value, UI::Box::AlignCenter);
81
 
 
82
 
        bottom_box->add_inf_space();
83
 
 
84
 
        m_continue_button = new UI::Button
85
 
                (bottom_box, "continue_button",
 
72
        UI::Box * bottobox_ = new UI::Box(this, 0, 0, UI::Box::Horizontal);
 
73
 
 
74
        bottobox_->add_space(PADDING);
 
75
 
 
76
        gametime_label_ = new UI::Textarea(bottobox_, _("Elapsed time:"));
 
77
        bottobox_->add(gametime_label_, UI::Box::AlignCenter);
 
78
        bottobox_->add_space(PADDING);
 
79
        gametime_value_ = new UI::Textarea(bottobox_, gametimestring(game_.get_gametime()));
 
80
        bottobox_->add(gametime_value_, UI::Box::AlignCenter);
 
81
 
 
82
        bottobox_->add_inf_space();
 
83
 
 
84
        continue_button_ = new UI::Button
 
85
                (bottobox_, "continue_button",
86
86
                 0, 0, 35, 35,
87
87
                 g_gr->images().get("pics/but4.png"),
88
88
                 g_gr->images().get("pics/continue.png"),
89
89
                 _("Continue playing"));
90
 
        bottom_box->add(m_continue_button, UI::Box::AlignCenter);
91
 
        bottom_box->add_space(PADDING);
92
 
        m_stop_button = new UI::Button
93
 
                (bottom_box, "stop_button",
 
90
        bottobox_->add(continue_button_, UI::Box::AlignCenter);
 
91
        bottobox_->add_space(PADDING);
 
92
        stop_button_ = new UI::Button
 
93
                (bottobox_, "stop_button",
94
94
                 0, 0, 35, 35,
95
95
                 g_gr->images().get("pics/but4.png"),
96
96
                 g_gr->images().get("pics/menu_exit_game.png"),
97
97
                _("Exit Game"));
98
 
        bottom_box->add(m_stop_button, UI::Box::AlignCenter);
99
 
        bottom_box->add_space(PADDING);
 
98
        bottobox_->add(stop_button_, UI::Box::AlignCenter);
 
99
        bottobox_->add_space(PADDING);
100
100
 
101
 
        vbox->add(bottom_box, UI::Box::AlignLeft, true);
 
101
        vbox->add(bottobox_, UI::Box::AlignLeft, true);
102
102
        vbox->add_space(PADDING);
103
103
        set_center_panel(vbox);
104
104
 
105
105
        // Prepare table
106
 
        m_players_table->add_column(150, _("Player"));
107
 
        m_players_table->add_column(80, _("Team"), "", UI::Align_HCenter);
108
 
        m_players_table->add_column(100, _("Status"), "", UI::Align_HCenter);
109
 
        m_players_table->add_column(100, _("Time"));
 
106
        players_table_->add_column(150, _("Player"));
 
107
        players_table_->add_column(80, _("Team"), "", UI::Align_HCenter);
 
108
        players_table_->add_column(100, _("Status"), "", UI::Align_HCenter);
 
109
        players_table_->add_column(100, _("Time"));
110
110
 
111
111
        // Prepare Elements
112
 
        m_title_area->set_textstyle(UI::TextStyle::ui_big());
 
112
        title_area_->set_textstyle(UI::TextStyle::ui_big());
113
113
 
114
114
        // Connections
115
 
        m_continue_button->sigclicked.connect
 
115
        continue_button_->sigclicked.connect
116
116
                (boost::bind(&GameSummaryScreen::continue_clicked, this));
117
 
        m_stop_button->sigclicked.connect
 
117
        stop_button_->sigclicked.connect
118
118
                (boost::bind(&GameSummaryScreen::stop_clicked, this));
119
 
        m_players_table->selected.connect
 
119
        players_table_->selected.connect
120
120
                (boost::bind(&GameSummaryScreen::player_selected, this, _1));
121
121
 
122
122
        // Window
140
140
void GameSummaryScreen::fill_data()
141
141
{
142
142
        std::vector<Widelands::PlayerEndStatus> players_status
143
 
                = m_game.player_manager()->get_players_end_status();
 
143
                = game_.player_manager()->get_players_end_status();
144
144
        bool local_in_game = false;
145
145
        bool local_won = false;
146
146
        Widelands::Player* single_won = nullptr;
147
 
        uint8_t team_won = 0;
148
 
        InteractivePlayer* ipl = m_game.get_ipl();
 
147
        uint8_t teawon_ = 0;
 
148
        InteractivePlayer* ipl = game_.get_ipl();
149
149
        //this defines a row to be selected, current player,
150
150
        //if not then the first line
151
151
        uint32_t current_player_position = 0;
157
157
                        local_won = pes.result == Widelands::PlayerEndResult::PLAYER_WON;
158
158
                        current_player_position = i;
159
159
                }
160
 
                Widelands::Player* p = m_game.get_player(pes.player);
161
 
                UI::Table<uintptr_t const>::EntryRecord & te = m_players_table->add(i);
 
160
                Widelands::Player* p = game_.get_player(pes.player);
 
161
                UI::Table<uintptr_t const>::EntryRecord & te = players_table_->add(i);
162
162
                // Player name & pic
163
163
                std::string pic_path =
164
164
                        (boost::format("pics/genstats_enable_plr_0%|1$u|.png")
166
166
                const Image* pic = g_gr->images().get(pic_path);
167
167
                te.set_picture(0, pic, p->get_name());
168
168
                // Team
169
 
                std::string team_str =
 
169
                std::string teastr_ =
170
170
                        (boost::format("%|1$u|")
171
171
                         % static_cast<unsigned int>(p->team_number())).str();
172
 
                te.set_string(1, team_str);
 
172
                te.set_string(1, teastr_);
173
173
                // Status
174
174
                std::string stat_str;
175
175
                switch (pes.result) {
183
183
                                if (!single_won) {
184
184
                                        single_won = p;
185
185
                                } else {
186
 
                                        team_won = p->team_number();
 
186
                                        teawon_ = p->team_number();
187
187
                                }
188
188
                                break;
189
189
                        case Widelands::PlayerEndResult::PLAYER_RESIGNED:
203
203
 
204
204
        if (local_in_game) {
205
205
                if (local_won) {
206
 
                        m_title_area->set_text(_("You won!"));
 
206
                        title_area_->set_text(_("You won!"));
207
207
                } else {
208
 
                        m_title_area->set_text(_("You lost."));
 
208
                        title_area_->set_text(_("You lost."));
209
209
                }
210
210
        } else {
211
 
                if (team_won <= 0) {
 
211
                if (teawon_ <= 0) {
212
212
                        assert(single_won);
213
 
                        m_title_area->set_text
 
213
                        title_area_->set_text
214
214
                                ((boost::format(_("%s won!")) % single_won->get_name()).str());
215
215
                } else {
216
 
                        m_title_area->set_text
 
216
                        title_area_->set_text
217
217
                                ((boost::format(_("Team %|1$u| won!"))
218
 
                                  % static_cast<unsigned int>(team_won)).str());
 
218
                                  % static_cast<unsigned int>(teawon_)).str());
219
219
                }
220
220
        }
221
 
        m_players_table->update();
 
221
        players_table_->update();
222
222
        if (!players_status.empty()) {
223
 
                m_players_table->select(current_player_position);
 
223
                players_table_->select(current_player_position);
224
224
        }
225
225
}
226
226
 
231
231
 
232
232
void GameSummaryScreen::stop_clicked()
233
233
{
234
 
        m_game.get_ibase()->end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
 
234
        game_.get_ibase()->end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
235
235
}
236
236
 
237
237
void GameSummaryScreen::player_selected(uint32_t entry_index)
238
238
{
239
 
        const uintptr_t selected_player_index = (*m_players_table)[entry_index];
 
239
        const uintptr_t selected_player_index = (*players_table_)[entry_index];
240
240
        const Widelands::PlayerEndStatus& player_status =
241
 
           m_game.player_manager()->get_players_end_status()[selected_player_index];
 
241
           game_.player_manager()->get_players_end_status()[selected_player_index];
242
242
 
243
243
        std::string info_str = parse_player_info(player_status.info);
244
 
        m_info_area->set_text(info_str);
 
244
        info_area_->set_text(info_str);
245
245
        layout();
246
246
}
247
247