widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #01184
[Merge] lp:~widelands-dev/widelands/save_dialog_improvements into lp:widelands
cghislai has proposed merging lp:~widelands-dev/widelands/save_dialog_improvements into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #706284 in widelands: "Default save file name is always the first in list"
https://bugs.launchpad.net/widelands/+bug/706284
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/save_dialog_improvements/+merge/174566
I added extra info already preloaded in the various io dialogs : save game, load game and load replay.
I also added a field in the game SaveHandler to remember a loaded savegame filename. When opening the save dialog, the entries are parsed and the corresponding filename is selected. Otherwise, no selection is performed and the field is left blank.
To retrieve the localized string for the win condition, the scripts are loaded in the dialog constructors (or on each selection in for replays), and run on each selection. I am not sure if they are cached or not. Code has been ported from the launchSGP dialog.
--
https://code.launchpad.net/~widelands-dev/widelands/save_dialog_improvements/+merge/174566
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/save_dialog_improvements into lp:widelands.
=== modified file 'src/game_io/game_loader.cc'
--- src/game_io/game_loader.cc 2013-02-25 17:03:31 +0000
+++ src/game_io/game_loader.cc 2013-07-13 16:35:31 +0000
@@ -36,6 +36,7 @@
namespace Widelands {
+// Allocate a new string for m_filename
Game_Loader::Game_Loader(const std::string & path, Game & game) :
m_fs(*g_fs->MakeSubFileSystem(path)), m_game(game)
{}
=== modified file 'src/logic/game.cc'
--- src/logic/game.cc 2013-07-08 03:35:09 +0000
+++ src/logic/game.cc 2013-07-13 16:35:31 +0000
@@ -412,6 +412,9 @@
gl.load_game();
}
+ // Store the filename for further saves
+ save_handler().set_cur_filename(filename);
+
set_game_controller(GameController::createSinglePlayer(*this, true, player_nr));
try {
bool const result = run(&loaderUI, Loaded);
=== modified file 'src/save_handler.h'
--- src/save_handler.h 2013-02-10 19:36:24 +0000
+++ src/save_handler.h 2013-07-13 16:35:31 +0000
@@ -34,12 +34,14 @@
int32_t m_lastSaveTime;
bool m_initialized;
bool m_allow_autosaving;
+ std::string m_cur_filename;
void initialize(int32_t currenttime);
public:
- SaveHandler() : m_lastSaveTime(0), m_initialized(false), m_allow_autosaving(true) {}
+ SaveHandler() : m_lastSaveTime(0), m_initialized(false), m_allow_autosaving(true), m_cur_filename("")
+ {}
void think(Widelands::Game &, int32_t currenttime);
std::string create_file_name(std::string dir, std::string filename);
bool save_game
@@ -48,6 +50,8 @@
std::string * error = 0);
static std::string get_base_dir() {return "save";}
+ const std::string get_cur_filename() {return m_cur_filename;}
+ void set_cur_filename(std::string filename) {m_cur_filename = filename;}
void set_allow_autosaving(bool t) {m_allow_autosaving = t;}
bool get_allow_autosaving() {return m_allow_autosaving;}
};
=== modified file 'src/ui_fsmenu/loadgame.cc'
--- src/ui_fsmenu/loadgame.cc 2013-02-21 19:02:21 +0000
+++ src/ui_fsmenu/loadgame.cc 2013-07-13 16:35:31 +0000
@@ -29,6 +29,7 @@
#include "log.h"
#include "logic/game.h"
#include "ui_basic/messagebox.h"
+#include <scripting/scripting.h>
#include <cstdio>
@@ -82,6 +83,14 @@
get_w() * 7 / 10, get_h() * 3 / 8,
_("Gametime:"), UI::Align_Right),
m_tagametime(this, get_w() * 71 / 100, get_h() * 3 / 8),
+ m_label_players
+ (this,
+ get_w() * 7 / 10, get_h() * 41 / 100,
+ _("Players:"), UI::Align_Right),
+ m_ta_players
+ (this, get_w() * 71 / 100, get_h() * 41 / 100),
+ m_ta_win_condition
+ (this, get_w() * 71 / 100, get_h() * 9 / 20),
m_settings(gsp),
m_ctrl(gc)
@@ -101,10 +110,15 @@
m_tamapname .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
m_label_gametime.set_font(m_fn, m_fs, UI_FONT_CLR_FG);
m_tagametime .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
+ m_label_players .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
+ m_ta_players .set_font(m_fn, m_fs, UI_FONT_CLR_FG);
+ m_ta_win_condition.set_font(m_fn, m_fs, UI_FONT_CLR_FG);
m_list .set_font(m_fn, m_fs);
m_list.selected.connect(boost::bind(&Fullscreen_Menu_LoadGame::map_selected, this, _1));
m_list.double_clicked.connect(boost::bind(&Fullscreen_Menu_LoadGame::double_clicked, this, _1));
fill_list();
+
+ g.lua().register_scripts(*g_fs, "win_conditions", "scripting/win_conditions");
}
void Fullscreen_Menu_LoadGame::think()
@@ -201,6 +215,22 @@
sprintf(buf, "%02i:%02i", hours, minutes);
m_tagametime.set_text(buf);
+
+ sprintf(buf, "%i", gpdp.get_player_nr());
+ m_ta_players.set_text(buf);
+
+ // Retrieve win condition title
+ std::string win_name;
+ try {
+ boost::shared_ptr<LuaTable> t = m_game.lua().run_script
+ ("win_conditions", gpdp.get_win_condition());
+ win_name = t->get_string("name");
+ } catch (LuaScriptNotExistingError &) {
+ win_name = _("Scenario");
+ } catch (LuaTableKeyError &) {
+ win_name = gpdp.get_win_condition();
+ }
+ m_ta_win_condition.set_text(win_name);
} else {
no_selection();
}
=== modified file 'src/ui_fsmenu/loadgame.h'
--- src/ui_fsmenu/loadgame.h 2012-12-31 11:21:15 +0000
+++ src/ui_fsmenu/loadgame.h 2013-07-13 16:35:31 +0000
@@ -73,6 +73,9 @@
UI::Textarea m_tamapname;
UI::Textarea m_label_gametime;
UI::Textarea m_tagametime;
+ UI::Textarea m_label_players;
+ UI::Textarea m_ta_players;
+ UI::Textarea m_ta_win_condition;
std::string m_filename;
filenameset_t m_gamefiles;
=== modified file 'src/ui_fsmenu/loadreplay.cc'
--- src/ui_fsmenu/loadreplay.cc 2013-02-21 19:02:21 +0000
+++ src/ui_fsmenu/loadreplay.cc 2013-07-13 16:35:31 +0000
@@ -28,6 +28,7 @@
#include "logic/game.h"
#include "logic/replay.h"
#include "ui_basic/messagebox.h"
+#include <scripting/scripting.h>
Fullscreen_Menu_LoadReplay::Fullscreen_Menu_LoadReplay() :
Fullscreen_Menu_Base("choosemapmenu.jpg"),
@@ -73,7 +74,15 @@
(this,
get_w() * 7 / 10, get_h() * 3 / 8,
_("Gametime:"), UI::Align_Right),
- m_tagametime(this, get_w() * 71 / 100, get_h() * 3 / 8)
+ m_tagametime(this, get_w() * 71 / 100, get_h() * 3 / 8),
+ m_label_players
+ (this,
+ get_w() * 7 / 10, get_h() * 41 / 100,
+ _("Players:"), UI::Align_Right),
+ m_ta_players
+ (this, get_w() * 71 / 100, get_h() * 41 / 100),
+ m_ta_win_condition
+ (this, get_w() * 71 / 100, get_h() * 9 / 20)
{
m_back.sigclicked.connect(boost::bind(&Fullscreen_Menu_LoadReplay::end_modal, boost::ref(*this), 0));
m_ok.sigclicked.connect(boost::bind(&Fullscreen_Menu_LoadReplay::clicked_ok, boost::ref(*this)));
@@ -81,13 +90,24 @@
(boost::bind
(&Fullscreen_Menu_LoadReplay::clicked_delete, boost::ref(*this)));
- m_title.set_textstyle(ts_big());
m_list.set_font(ui_fn(), fs_small());
m_list.selected.connect(boost::bind(&Fullscreen_Menu_LoadReplay::replay_selected, this, _1));
m_list.double_clicked.connect
(boost::bind(&Fullscreen_Menu_LoadReplay::double_clicked, this, _1));
+
+ m_title .set_font(ui_fn(), fs_big(), UI_FONT_CLR_FG);
+ m_label_mapname .set_font(ui_fn(), fs_small(), UI_FONT_CLR_FG);
+ m_tamapname .set_font(ui_fn(), fs_small(), UI_FONT_CLR_FG);
+ m_label_gametime.set_font(ui_fn(), fs_small(), UI_FONT_CLR_FG);
+ m_tagametime .set_font(ui_fn(), fs_small(), UI_FONT_CLR_FG);
+ m_label_players .set_font(ui_fn(), fs_small(), UI_FONT_CLR_FG);
+ m_ta_players .set_font(ui_fn(), fs_small(), UI_FONT_CLR_FG);
+ m_ta_win_condition.set_font(ui_fn(), fs_small(), UI_FONT_CLR_FG);
+ m_list .set_font(ui_fn(), fs_small());
m_back.set_font(font_small());
m_ok.set_font(font_small());
+ m_delete.set_font(font_small());
+
fill_list();
}
@@ -163,6 +183,8 @@
return;
}
+ game.lua().register_scripts(*g_fs, "win_conditions", "scripting/win_conditions");
+
m_ok.set_enabled(true);
m_delete.set_enabled(true);
m_tamapname.set_text(gpdp.get_mapname());
@@ -176,6 +198,22 @@
sprintf(buf, "%02i:%02i", hours, minutes);
m_tagametime.set_text(buf);
+
+ sprintf(buf, "%i", gpdp.get_player_nr());
+ m_ta_players.set_text(buf);
+
+ // Retrieve win condition title
+ std::string win_name;
+ try {
+ boost::shared_ptr<LuaTable> t = game.lua().run_script
+ ("win_conditions", gpdp.get_win_condition());
+ win_name = t->get_string("name");
+ } catch (LuaScriptNotExistingError &) {
+ win_name = _("Scenario");
+ } catch (LuaTableKeyError &) {
+ win_name = gpdp.get_win_condition();
+ }
+ m_ta_win_condition.set_text(win_name);
} else {
no_selection();
}
=== modified file 'src/ui_fsmenu/loadreplay.h'
--- src/ui_fsmenu/loadreplay.h 2013-02-10 19:36:24 +0000
+++ src/ui_fsmenu/loadreplay.h 2013-07-13 16:35:31 +0000
@@ -58,6 +58,9 @@
UI::Textarea m_tamapname;
UI::Textarea m_label_gametime;
UI::Textarea m_tagametime;
+ UI::Textarea m_label_players;
+ UI::Textarea m_ta_players;
+ UI::Textarea m_ta_win_condition;
std::string m_filename;
};
=== modified file 'src/wui/game_main_menu_save_game.cc'
--- src/wui/game_main_menu_save_game.cc 2013-03-01 23:12:08 +0000
+++ src/wui/game_main_menu_save_game.cc 2013-07-13 16:35:31 +0000
@@ -28,6 +28,7 @@
#include "interactive_gamebase.h"
#include "io/filesystem/layered_filesystem.h"
#include "profile/profile.h"
+#include <scripting/scripting.h>
#include <boost/format.hpp>
using boost::format;
@@ -67,6 +68,12 @@
(this, DESCRIPTION_X, 45, 0, 20, _("Game Time: "), UI::Align_CenterLeft),
m_gametime
(this, DESCRIPTION_X, 60, 0, 20, " ", UI::Align_CenterLeft),
+ m_players_label
+ (this, DESCRIPTION_X, 85, 0, 20, " ", UI::Align_CenterLeft),
+ m_win_condition_label
+ (this, DESCRIPTION_X, 110, 0, 20, _("Win condition: "), UI::Align_CenterLeft),
+ m_win_condition
+ (this, DESCRIPTION_X, 125, 0, 20, " ", UI::Align_CenterLeft),
m_curdir(SaveHandler::get_base_dir())
{
m_editbox =
@@ -110,6 +117,13 @@
center_to_parent();
move_to_top();
+ igbase().game().lua().register_scripts(*g_fs, "win_conditions", "scripting/win_conditions");
+
+ std::string cur_filename = parent.game().save_handler().get_cur_filename();
+ if (cur_filename.size() > 0) {
+ select_by_name(cur_filename);
+ }
+
m_editbox->focus();
}
@@ -143,6 +157,25 @@
_("%02ud%02uh%02u'%02u\"%03u"),
days, hours, minutes, seconds, gametime);
m_gametime.set_text(buf);
+
+ if (gpdp.get_player_nr() > 1)
+ sprintf(buf, _("%i players"), gpdp.get_player_nr());
+ else
+ sprintf(buf, _("%i player"), gpdp.get_player_nr());
+ m_players_label.set_text(buf);
+
+ // Retrieve win condition title
+ std::string win_name;
+ try {
+ boost::shared_ptr<LuaTable> t = igbase().game().lua().run_script
+ ("win_conditions", gpdp.get_win_condition());
+ win_name = t->get_string("name");
+ } catch (LuaScriptNotExistingError &) {
+ win_name = _("Scenario");
+ } catch (LuaTableKeyError &) {
+ win_name = gpdp.get_win_condition();
+ }
+ m_win_condition.set_text(win_name);
}
/**
@@ -177,9 +210,17 @@
m_ls.add(FileSystem::FS_FilenameWoExt(name).c_str(), name);
} catch (const _wexception &) {} // we simply skip illegal entries
}
+}
- if (m_ls.size())
- m_ls.select(0);
+void Game_Main_Menu_Save_Game::select_by_name(std::string name)
+{
+ for (uint idx = 0; idx < m_ls.size(); idx++) {
+ const std::string val = m_ls[idx];
+ if (name.compare(val) == 0) {
+ m_ls.select(idx);
+ return;
+ }
+ }
}
/*
=== modified file 'src/wui/game_main_menu_save_game.h'
--- src/wui/game_main_menu_save_game.h 2013-01-20 21:27:20 +0000
+++ src/wui/game_main_menu_save_game.h 2013-07-13 16:35:31 +0000
@@ -40,6 +40,7 @@
(Interactive_GameBase &, UI::UniqueWindow::Registry & registry);
void fill_list();
+ void select_by_name(std::string name);
private:
Interactive_GameBase & igbase();
void die() {UI::UniqueWindow::die();}
@@ -53,7 +54,8 @@
UI::Listselect<std::string> m_ls;
UI::EditBox * m_editbox;
- UI::Textarea m_name_label, m_name, m_gametime_label, m_gametime;
+ UI::Textarea m_name_label, m_name, m_gametime_label, m_gametime, m_players_label,
+ m_win_condition_label, m_win_condition;
UI::Button * m_button_ok;
std::string m_curdir;
std::string m_parentdir;
Follow ups