~widelands-dev/widelands/localizeable_shipnames

« back to all changes in this revision

Viewing changes to src/ui_fsmenu/loadgame.cc

  • Committer: GunChleoc
  • Date: 2017-04-22 08:40:21 UTC
  • mfrom: (8298.1.40 trunk)
  • Revision ID: fios@foramnagaidhlig.net-20170422084021-4u3vp59d9jkdfx63
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
            tablew_,
92
92
            tableh_,
93
93
            g_gr->images().get("images/ui_basic/but3.png"),
94
 
            true),
 
94
            UI::TableRows::kMultiDescending),
95
95
 
96
96
     is_replay_(is_replay),
97
97
     // Main title
99
99
            get_w() / 2,
100
100
            tabley_ / 3,
101
101
            is_replay_ ? _("Choose a replay") : _("Choose a saved game"),
102
 
            UI::Align::kHCenter),
 
102
            UI::Align::kCenter),
103
103
 
104
104
     // Savegame description
105
 
     label_mapname_(this, right_column_x_, tabley_, "", UI::Align::kLeft),
 
105
     label_mapname_(this, right_column_x_, tabley_),
106
106
     ta_mapname_(this,
107
107
                 right_column_x_ + indent_,
108
108
                 get_y_from_preceding(label_mapname_) + padding_,
109
109
                 get_right_column_w(right_column_x_ + indent_),
110
110
                 2 * label_height_ - padding_),
111
111
 
112
 
     label_gametime_(this,
113
 
                     right_column_x_,
114
 
                     get_y_from_preceding(ta_mapname_) + 2 * padding_,
115
 
                     "",
116
 
                     UI::Align::kLeft),
 
112
     label_gametime_(this, right_column_x_, get_y_from_preceding(ta_mapname_) + 2 * padding_),
117
113
     ta_gametime_(this,
118
114
                  right_column_tab_,
119
115
                  label_gametime_.get_y(),
120
116
                  get_right_column_w(right_column_tab_),
121
117
                  label_height_),
122
118
 
123
 
     label_players_(
124
 
        this, right_column_x_, get_y_from_preceding(ta_gametime_), "", UI::Align::kLeft),
 
119
     label_players_(this, right_column_x_, get_y_from_preceding(ta_gametime_)),
125
120
     ta_players_(this,
126
121
                 right_column_tab_,
127
122
                 label_players_.get_y(),
128
123
                 get_right_column_w(right_column_tab_),
129
124
                 label_height_),
130
125
 
131
 
     label_version_(this, right_column_x_, get_y_from_preceding(ta_players_), "", UI::Align::kLeft),
132
 
     ta_version_(this, right_column_tab_, label_version_.get_y(), "", UI::Align::kLeft),
 
126
     label_version_(this, right_column_x_, get_y_from_preceding(ta_players_)),
 
127
     ta_version_(this, right_column_tab_, label_version_.get_y()),
133
128
 
134
 
     label_win_condition_(this,
135
 
                          right_column_x_,
136
 
                          get_y_from_preceding(ta_version_) + 3 * padding_,
137
 
                          "",
138
 
                          UI::Align::kLeft),
 
129
     label_win_condition_(this, right_column_x_, get_y_from_preceding(ta_version_) + 3 * padding_),
139
130
     ta_win_condition_(this,
140
131
                       right_column_x_ + indent_,
141
132
                       get_y_from_preceding(label_win_condition_) + padding_,
151
142
             g_gr->images().get("images/ui_basic/but0.png"),
152
143
             _("Delete")),
153
144
 
154
 
     ta_errormessage_(this,
155
 
                      right_column_x_,
156
 
                      get_y_from_preceding(ta_mapname_) + 2 * padding_,
157
 
                      get_right_column_w(right_column_x_),
158
 
                      delete_.get_y() - get_y_from_preceding(ta_mapname_) - 6 * padding_),
 
145
     ta_long_generic_message_(this,
 
146
                              right_column_x_,
 
147
                              get_y_from_preceding(ta_mapname_) + 2 * padding_,
 
148
                              get_right_column_w(right_column_x_),
 
149
                              delete_.get_y() - get_y_from_preceding(ta_mapname_) - 6 * padding_),
159
150
 
160
151
     minimap_y_(get_y_from_preceding(ta_win_condition_) + 3 * padding_),
161
152
     minimap_w_(get_right_column_w(right_column_x_)),
188
179
                ta_mapname_.set_tooltip(_("The map that this game is based on"));
189
180
                delete_.set_tooltip(_("Delete this game"));
190
181
        }
 
182
        set_thinks(false);
191
183
        minimap_icon_.set_visible(false);
192
184
 
193
185
        back_.sigclicked.connect(boost::bind(&FullscreenMenuLoadGame::clicked_back, boost::ref(*this)));
194
186
        ok_.sigclicked.connect(boost::bind(&FullscreenMenuLoadGame::clicked_ok, boost::ref(*this)));
195
187
        delete_.sigclicked.connect(
196
188
           boost::bind(&FullscreenMenuLoadGame::clicked_delete, boost::ref(*this)));
197
 
        table_.add_column(130, _("Save Date"), _("The date this game was saved"), UI::Align::kLeft);
 
189
        table_.add_column(130, _("Save Date"), _("The date this game was saved"));
198
190
        if (is_replay_ || settings_->settings().multiplayer) {
199
191
                std::vector<std::string> modes;
200
192
                if (is_replay_) {
221
213
                   /** TRANSLATORS: Game Mode table column when choosing a game/replay to load. */
222
214
                   /** TRANSLATORS: Keep this to 5 letters maximum. */
223
215
                   /** TRANSLATORS: A tooltip will explain if you need to use an abbreviation. */
224
 
                   _("Mode"), (boost::format("%s %s") % mode_tooltip_1 % mode_tooltip_2).str(),
225
 
                   UI::Align::kLeft);
 
216
                   _("Mode"), (boost::format("%s %s") % mode_tooltip_1 % mode_tooltip_2).str());
226
217
        }
227
218
        table_.add_column(0, _("Description"),
228
219
                          _("The filename that the game was saved under followed by the map’s name, "
240
231
 
241
232
void FullscreenMenuLoadGame::layout() {
242
233
        // TODO(GunChleoc): Implement when we have box layout for the details.
 
234
        table_.layout();
243
235
}
244
236
 
245
237
void FullscreenMenuLoadGame::think() {
271
263
        if (!table_.has_selection()) {
272
264
                return;
273
265
        }
274
 
        const SavegameData& gamedata = games_data_[table_.get_selected()];
275
 
 
276
 
        std::string message =
277
 
           (boost::format("%s %s\n") % label_mapname_.get_text() % gamedata.mapname).str();
278
 
 
279
 
        message = (boost::format("%s %s %s\n") % message % label_win_condition_.get_text() %
280
 
                   gamedata.wincondition)
281
 
                     .str();
282
 
 
283
 
        message =
284
 
           (boost::format("%s %s %s\n") % message % _("Save Date:") % gamedata.savedatestring).str();
285
 
 
286
 
        message = (boost::format("%s %s %s\n") % message % label_gametime_.get_text() %
287
 
                   gametimestring(gamedata.gametime))
288
 
                     .str();
289
 
 
290
 
        message =
291
 
           (boost::format("%s %s %s\n\n") % message % label_players_.get_text() % gamedata.nrplayers)
292
 
              .str();
293
 
 
294
 
        message = (boost::format("%s %s %s\n") % message % _("Filename:") % gamedata.filename).str();
295
 
 
296
 
        if (is_replay_) {
297
 
                message =
298
 
                   (boost::format("%s\n\n%s") % _("Do you really want to delete this replay?") % message)
 
266
        std::set<uint32_t> selections = table_.selections();
 
267
        size_t no_selections = selections.size();
 
268
        std::string message;
 
269
        if (no_selections > 1) {
 
270
                if (is_replay_) {
 
271
                        message = (boost::format(ngettext("Do you really want to delete this %d replay?",
 
272
                                                          "Do you really want to delete these %d replays?",
 
273
                                                          no_selections)) %
 
274
                                   no_selections)
 
275
                                     .str();
 
276
                } else {
 
277
                        message = (boost::format(ngettext("Do you really want to delete this %d game?",
 
278
                                                          "Do you really want to delete these %d games?",
 
279
                                                          no_selections)) %
 
280
                                   no_selections)
 
281
                                     .str();
 
282
                }
 
283
                message = (boost::format("%s\n%s") % message % filename_list_string()).str();
 
284
 
 
285
        } else {
 
286
                const SavegameData& gamedata = games_data_[table_.get_selected()];
 
287
 
 
288
                message = (boost::format("%s %s\n") % label_mapname_.get_text() % gamedata.mapname).str();
 
289
 
 
290
                message = (boost::format("%s %s %s\n") % message % label_win_condition_.get_text() %
 
291
                           gamedata.wincondition)
 
292
                             .str();
 
293
 
 
294
                message =
 
295
                   (boost::format("%s %s %s\n") % message % _("Save Date:") % gamedata.savedatestring).str();
 
296
 
 
297
                message = (boost::format("%s %s %s\n") % message % label_gametime_.get_text() %
 
298
                           gametimestring(gamedata.gametime))
 
299
                             .str();
 
300
 
 
301
                message =
 
302
                   (boost::format("%s %s %s\n\n") % message % label_players_.get_text() % gamedata.nrplayers)
299
303
                      .str();
300
 
        } else {
301
 
                message =
302
 
                   (boost::format("%s\n\n%s") % _("Do you really want to delete this game?") % message).str();
 
304
 
 
305
                message = (boost::format("%s %s %s\n") % message % _("Filename:") % gamedata.filename).str();
 
306
 
 
307
                if (is_replay_) {
 
308
                        message =
 
309
                           (boost::format("%s\n\n%s") % _("Do you really want to delete this replay?") % message)
 
310
                              .str();
 
311
                } else {
 
312
                        message =
 
313
                           (boost::format("%s\n\n%s") % _("Do you really want to delete this game?") % message)
 
314
                              .str();
 
315
                }
303
316
        }
304
317
 
305
318
        UI::WLMessageBox confirmationBox(
306
 
           this, _("Confirm deleting file"), message, UI::WLMessageBox::MBoxType::kOkCancel);
 
319
           this, ngettext("Confirm deleting file", "Confirm deleting files", no_selections), message,
 
320
           UI::WLMessageBox::MBoxType::kOkCancel);
 
321
 
307
322
        if (confirmationBox.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kOk) {
308
 
                g_fs->fs_unlink(gamedata.filename);
309
 
                if (is_replay_) {
310
 
                        g_fs->fs_unlink(gamedata.filename + WLGF_SUFFIX);
 
323
                for (const uint32_t index : selections) {
 
324
                        const std::string& deleteme = games_data_[table_.get(table_.get_record(index))].filename;
 
325
                        g_fs->fs_unlink(deleteme);
 
326
                        if (is_replay_) {
 
327
                                g_fs->fs_unlink(deleteme + WLGF_SUFFIX);
 
328
                        }
311
329
                }
312
330
                fill_table();
313
331
        }
314
332
}
315
333
 
 
334
std::string FullscreenMenuLoadGame::filename_list_string() {
 
335
        std::set<uint32_t> selections = table_.selections();
 
336
        boost::format message;
 
337
        int counter = 0;
 
338
        for (const uint32_t index : selections) {
 
339
                ++counter;
 
340
                // TODO(GunChleoc): We can exceed the texture size for the font renderer,
 
341
                // so we have to restrict this for now.
 
342
                if (counter > 50) {
 
343
                        message = boost::format("%s\n%s") % message % "...";
 
344
                        break;
 
345
                }
 
346
                const SavegameData& gamedata = games_data_[table_.get(table_.get_record(index))];
 
347
 
 
348
                if (gamedata.errormessage.empty()) {
 
349
                        message =
 
350
                           boost::format("%s\n%s") % message %
 
351
                           /** TRANSLATORS %1% = map name, %2% = save date. */
 
352
                           (boost::format(_("%1%, saved on %2%")) % gamedata.mapname % gamedata.savedatestring);
 
353
                } else {
 
354
                        message = boost::format("%s\n%s") % message % gamedata.filename;
 
355
                }
 
356
        }
 
357
        return message.str();
 
358
}
 
359
 
316
360
bool FullscreenMenuLoadGame::set_has_selection() {
317
 
        bool has_selection = table_.has_selection();
 
361
        bool has_selection = table_.selections().size() < 2;
318
362
        ok_.set_enabled(has_selection);
319
 
        delete_.set_enabled(has_selection);
 
363
        delete_.set_enabled(table_.has_selection());
320
364
 
321
365
        if (!has_selection) {
322
366
                label_mapname_.set_text(std::string());
344
388
}
345
389
 
346
390
void FullscreenMenuLoadGame::entry_selected() {
 
391
        size_t selections = table_.selections().size();
347
392
        if (set_has_selection()) {
348
393
 
349
394
                const SavegameData& gamedata = games_data_[table_.get_selected()];
350
 
                ta_errormessage_.set_text(gamedata.errormessage);
 
395
                ta_long_generic_message_.set_text(gamedata.errormessage);
351
396
 
352
397
                if (gamedata.errormessage.empty()) {
353
 
                        ta_errormessage_.set_visible(false);
 
398
                        ta_long_generic_message_.set_visible(false);
354
399
                        ta_mapname_.set_text(gamedata.mapname);
355
400
                        ta_gametime_.set_text(gametimestring(gamedata.gametime));
356
401
 
439
484
                        minimap_icon_.set_no_frame();
440
485
                        minimap_image_.reset();
441
486
 
442
 
                        ta_errormessage_.set_visible(true);
 
487
                        ta_long_generic_message_.set_visible(true);
443
488
                        ok_.set_enabled(false);
444
489
                }
 
490
        } else if (selections > 1) {
 
491
                label_mapname_.set_text(
 
492
                   (boost::format(ngettext("Selected %d file:", "Selected %d files:", selections)) %
 
493
                    selections)
 
494
                      .str());
 
495
                ta_long_generic_message_.set_visible(true);
 
496
                ta_long_generic_message_.set_text(filename_list_string());
445
497
        }
446
498
}
447
499