Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/savegamemenu.cc236
-rw-r--r--src/client/savegamemenu.h27
2 files changed, 240 insertions, 23 deletions
diff --git a/src/client/savegamemenu.cc b/src/client/savegamemenu.cc
index be26cd4..5e8f369 100644
--- a/src/client/savegamemenu.cc
+++ b/src/client/savegamemenu.cc
@@ -49,17 +49,44 @@ SaveGameMenu::SaveGameMenu(ui::Widget *parent, const char *label, const Mode mod
savegamemenu_filelistview = new ui::ListView(this);
savegamemenu_filelistview->set_label("files");
- // savegame desription label
+ // savegame description title
+ savegamemenu_descrtitle = new ui::Label(this);
+ savegamemenu_descrtitle->set_label("subtitle");
+ savegamemenu_descrtitle->set_background(false);
+ savegamemenu_descrtitle->set_border(false);
+ savegamemenu_descrtitle->set_font(ui::root()->font_large());
+ savegamemenu_descrtitle->set_alignment(ui::AlignCenter);
+
+ // savegame description label
savegamemenu_descrlabel = new ui::Label(this);
- savegamemenu_descrlabel->set_label("description");
+ savegamemenu_descrlabel->set_label("info");
+ savegamemenu_descrlabel->set_background(true);
+ savegamemenu_descrlabel->set_border(true);
// save button
savegamemenu_savebutton = new ui::Button(this, "Save");
- //savegamemenu_descrinput = new ui::InputBox(this);
+ savegamemenu_savebutton->set_label("save");
// delete button
savegamemenu_deletebutton = new ui::IconButton(this, "bitmaps/icons/button_delete");
savegamemenu_deletebutton->set_label("delete");
+
+ // cancel save/load/overwrite button
+ savegamemenu_cancelbutton = new ui::Button(this, "Cancel");
+ savegamemenu_cancelbutton->set_label("cancel");
+
+ // confirm save/load/overwrite button
+ savegamemenu_confirmsavebutton = new ui::Button(this, "Confirm");
+ savegamemenu_confirmsavebutton->set_label("confirmsave");
+
+ // confirm save/load/overwrite button
+ savegamemenu_confirmdeletebutton = new ui::Button(this, "Delete");
+ savegamemenu_confirmdeletebutton->set_label("confirmdelete");
+
+ // description input box
+ savegamemenu_descrinput = new ui::InputBox(this);
+ savegamemenu_descrinput->set_label("description");
+ savegamemenu_descrinput->hide();
}
SaveGameMenu::~SaveGameMenu()
@@ -96,18 +123,49 @@ void SaveGameMenu::resize()
savegamemenu_filelistview->bottom() + padding
);
+ // resize description title
+ savegamemenu_descrtitle->set_size(
+ width() - savegamemenu_filelistview->right() - 2.0f * padding,
+ savegamemenu_descrtitle->font()->height()
+ );
+ savegamemenu_descrtitle->set_location(
+ savegamemenu_filelistview->right() + padding,
+ savegamemenu_filelistview->top()
+ );
+
// resize description label
savegamemenu_descrlabel->set_size(
- width() - savegamemenu_filelistview->right() - 2.0f * padding,
- savegamemenu_filelistview->height() - ui::UI::elementsize.height() - padding
+ savegamemenu_descrtitle->width(),
+ savegamemenu_filelistview->bottom() - savegamemenu_descrtitle->bottom() - ui::UI::elementsize.width() - 2.0f * padding
+ );
+ savegamemenu_descrlabel->set_location(
+ savegamemenu_filelistview->right() + padding,
+ savegamemenu_descrtitle->bottom() + padding
);
- savegamemenu_descrlabel->set_location(savegamemenu_filelistview->right() + padding, savegamemenu_filelistview->top());
// resize save button
savegamemenu_savebutton->set_size(ui::UI::elementsize);
savegamemenu_savebutton->set_location(
savegamemenu_descrlabel->left() + (savegamemenu_descrlabel->width() - ui::UI::elementsize.width()) * 0.5f,
savegamemenu_descrlabel->bottom() + padding);
+
+ // resize save/load/overwrite confirm button
+ savegamemenu_confirmsavebutton->set_size(ui::UI::elementsize);
+ savegamemenu_confirmsavebutton->set_location(
+ savegamemenu_descrlabel->left() + (savegamemenu_descrlabel->width() - 2.0f * ui::UI::elementsize.width() - padding) * 0.5f,
+ savegamemenu_descrlabel->bottom() + padding
+ );
+
+ // resize cancel button
+ savegamemenu_cancelbutton->set_size(ui::UI::elementsize);
+ savegamemenu_cancelbutton->set_location(
+ savegamemenu_confirmsavebutton->right() + padding,
+ savegamemenu_descrlabel->bottom() + padding
+ );
+
+ // resize confirm delete button
+ savegamemenu_confirmdeletebutton->set_size(ui::UI::elementsize);
+ savegamemenu_confirmdeletebutton->set_location(savegamemenu_confirmsavebutton->location());
}
void SaveGameMenu::refresh()
@@ -124,6 +182,10 @@ void SaveGameMenu::refresh()
savegamemenu_savebutton->hide();
savegamemenu_savebutton->enable();
+ savegamemenu_confirmsavebutton->hide();
+ savegamemenu_confirmdeletebutton->hide();
+ savegamemenu_cancelbutton->hide();
+
if (savegamemenu_mode == Save) {
listitem = new ui::ListItem(savegamemenu_filelistview, "NEW SAVEGAME");
listitem->set_label("new");
@@ -157,11 +219,15 @@ void SaveGameMenu::refresh()
std::string descr;
std::string timestamp;
- get_savegame_info(savename, descr, timestamp);
+ std::string info;
+
+ get_savegame_info(savename, descr, info, timestamp);
if (descr.size()) {
std::ostringstream descrstr;
- descrstr << descr << '\n'<< timestamp;
+ descrstr << descr << '\n';
+ descrstr << timestamp;
+
listitem = new ui::ListItem(savegamemenu_filelistview, descrstr.str().c_str());
listitem->set_value(savename);
listitem->set_sortkey(timestamp);
@@ -186,26 +252,110 @@ void SaveGameMenu::show()
void SaveGameMenu::show_file_info()
{
+ savegamemenu_descrtitle->clear();
savegamemenu_descrlabel->clear();
savegamemenu_deletebutton->disable();
+
+ savegamemenu_confirmsavebutton->hide();
+ savegamemenu_confirmdeletebutton->hide();
+ savegamemenu_cancelbutton->hide();
+ savegamemenu_descrlabel->hide();
+
+ if (savegamemenu_filelistview->selected()) {
+ savegamemenu_savebutton->show();
+ savegamemenu_descrlabel->show();
- if (savegamemenu_filelistview->selected()) {
std::string savename(savegamemenu_filelistview->selected()->value().c_str());
- savegamemenu_descrlabel->set_text(savegamemenu_filelistview->selected()->text() + '\n' + '\n' + savename);
if (savename.size()) {
+ std::string descr;
+ std::string timestamp;
+ std::string info;
+
+ get_savegame_info(savename, descr, info, timestamp);
+
+ std::ostringstream descrstr;
+ //descrstr << descr << '\n';
+ descrstr << info; // info has a traling newline
+ descrstr << timestamp << '\n';
+
savegamemenu_deletebutton->enable();
+ savegamemenu_descrtitle->set_text(savename);
+ savegamemenu_descrlabel->set_text(descrstr.str().c_str());
+ } else {
+ // new savegame, immediatly show the save game dialog
+ show_save_dialog();
+ return;
}
- savegamemenu_savebutton->show();
}
}
+void SaveGameMenu::show_save_dialog()
+{
+ if (!savegamemenu_filelistview->selected()) {
+ return;
+ }
+ std::string savename(savegamemenu_filelistview->selected()->value().c_str());
+ if (!savename.size()) {
+ savegamemenu_descrtitle->set_text("New savegame");
+ savegamemenu_confirmsavebutton->set_text("Save");
+ } else {
+ savegamemenu_descrtitle->set_text("Overwrite game '" + savename + "'?");
+ savegamemenu_confirmsavebutton->set_text("Overwrite");
+ }
+
+ savegamemenu_savebutton->hide();
+ savegamemenu_confirmsavebutton->show();
+ savegamemenu_cancelbutton->show();
+}
+
+void SaveGameMenu::show_load_dialog()
+{
+ if (!savegamemenu_filelistview->selected()) {
+ return;
+ }
+ std::string savename(savegamemenu_filelistview->selected()->value().c_str());
+ if (!savename.size()) {
+ return;
+ }
+
+ savegamemenu_descrtitle->set_text("Load game '" + savename + "'?");
+ savegamemenu_confirmsavebutton->set_text("Load");
+
+ savegamemenu_savebutton->hide();
+ savegamemenu_confirmsavebutton->show();
+ savegamemenu_cancelbutton->show();
+}
+
+void SaveGameMenu::show_delete_dialog()
+{
+ if (!savegamemenu_filelistview->selected()) {
+ return;
+ }
+ std::string savename(savegamemenu_filelistview->selected()->value().c_str());
+ if (!savename.size()) {
+ return;
+ }
+
+ savegamemenu_descrtitle->set_text(savename);
+ savegamemenu_descrtitle->set_text("Delete game '" + savename + "'?");
+
+ savegamemenu_savebutton->hide();
+ savegamemenu_confirmdeletebutton->show();
+ savegamemenu_cancelbutton->show();
+}
+
bool SaveGameMenu::on_keypress(const int key, const unsigned int modifier)
{
if (key == SDLK_ESCAPE) {
if (visible()) {
- // hide the parent mainwindow
- parent()->hide();
- return true;
+ if (savegamemenu_cancelbutton->visible()) {
+ show_file_info();
+ return true;
+ } else {
+ // hide the parent mainwindow
+ parent()->hide();
+ return true;
+ }
}
}
@@ -220,7 +370,11 @@ bool SaveGameMenu::on_emit(ui::Widget *sender, const ui::Widget::Event event, vo
parent()->hide();
return true;
}
- } else if (sender == savegamemenu_savebutton) {
+ } else if (sender == savegamemenu_cancelbutton) {
+ if (event == ui::Widget::EventButtonClicked) {
+ show_file_info();
+ }
+ } else if (sender == savegamemenu_confirmsavebutton) {
if (event == ui::Widget::EventButtonClicked) {
if (savegamemenu_mode == Save) {
if (savegamemenu_filelistview->selected()) {
@@ -234,14 +388,30 @@ bool SaveGameMenu::on_emit(ui::Widget *sender, const ui::Widget::Event event, vo
}
}
return true;
- }
- } else if (sender == savegamemenu_deletebutton) {
+ }
+ } else if (sender == savegamemenu_savebutton) {
+ if (event == ui::Widget::EventButtonClicked) {
+ if (savegamemenu_mode == Save) {
+ show_save_dialog();
+ } else {
+ show_load_dialog();
+ }
+ return true;
+ }
+ } else if (sender == savegamemenu_confirmdeletebutton) {
if (event == ui::Widget::EventButtonClicked) {
if (savegamemenu_filelistview->selected()) {
deletegame(savegamemenu_filelistview->selected()->value());
refresh();
}
return true;
+ }
+ } else if (sender == savegamemenu_deletebutton) {
+ if (event == ui::Widget::EventButtonClicked) {
+ if (savegamemenu_filelistview->selected()) {
+ show_delete_dialog();
+ }
+ return true;
}
} else if (sender == savegamemenu_filelistview) {
if (event == ui::Widget::EventListViewChanged) {
@@ -253,11 +423,17 @@ bool SaveGameMenu::on_emit(ui::Widget *sender, const ui::Widget::Event event, vo
return Window::on_emit(sender, event, data);
}
-void SaveGameMenu::get_savegame_info(const std::string & savename, std::string &game_descr, std::string &game_timestamp)
+void SaveGameMenu::get_savegame_info(const std::string & savename,
+ std::string &game_descr,
+ std::string &game_info,
+ std::string &game_timestamp)
{
filesystem::IniFile inifile("savegames/" + savename);
+ std::string infostr;
+
game_descr.clear();
+ game_info.clear();
game_timestamp.clear();
if (!inifile.is_open()) {
@@ -274,6 +450,11 @@ void SaveGameMenu::get_savegame_info(const std::string & savename, std::string &
} else if (inifile.got_key_string("timestamp", game_timestamp)) {
continue;
+
+ } else if (inifile.got_key_string("info", infostr)) {
+ game_info.append(infostr);
+ game_info += '\n';
+ continue;
}
}
}
@@ -329,15 +510,26 @@ void SaveGameMenu::savegame(std::string savename)
ofs << "; savegame data" << std::endl;
ofs << std::endl;
- ofs << "[savegame]" << std::endl;
+ ofs << "[savegame]" << std::endl;
ofs << "description=";
if (core::localcontrol()->state() == core::Entity::Docked) {
// FIXME implement entity->dock()
- ofs << core::localplayer()->view()->name();
+ ofs << core::localplayer()->view()->name() << std::endl;
} else {
- ofs << core::localplayer()->zone()->name();
+ ofs << core::localplayer()->zone()->name() << std::endl;
}
- ofs << std::endl;
+
+ ofs << "info=";
+ if (core::localcontrol()->state() == core::Entity::Docked) {
+ // FIXME implement entity->dock()
+ ofs << core::localplayer()->view()->name() << ", ";
+ }
+ ofs << core::localplayer()->zone()->name() << std::endl;
+
+ if (core::localcontrol()->info()) {
+ ofs << "info=" << core::localcontrol()->info()->name() << std::endl;
+ }
+ ofs << "info=" << core::localplayer()->credits() << " credits" << std::endl;
int year = 0; int month = 0; int day = 0; int hours = 0; int minutes = 0; int seconds = 0; int msec = 0;
sys::get_localtime(year, month, day, hours, minutes, seconds, msec);
diff --git a/src/client/savegamemenu.h b/src/client/savegamemenu.h
index 2d895d8..d615102 100644
--- a/src/client/savegamemenu.h
+++ b/src/client/savegamemenu.h
@@ -43,12 +43,30 @@ protected:
virtual void show();
+ /**
+ * @brief show file info for the selected savegame
+ * */
void show_file_info();
+ /**
+ * @brief show confirm save dialog
+ * */
+ void show_save_dialog();
+
+ /**
+ * @brief show confirm load dialog
+ * */
+ void show_load_dialog();
+
+ /**
+ * @brief show confirm delete dialog
+ * */
+ void show_delete_dialog();
+
void refresh();
private:
- void get_savegame_info(const std::string & savename, std::string &game_descr, std::string &game_timestamp);
+ void get_savegame_info(const std::string & savename, std::string &game_descr, std::string &game_info, std::string &game_timestamp);
Mode savegamemenu_mode;
@@ -57,10 +75,17 @@ private:
ui::ListView *savegamemenu_filelistview;
ui::IconButton *savegamemenu_deletebutton;
+ ui::Label *savegamemenu_descrtitle;
ui::Label *savegamemenu_descrlabel;
ui::InputBox *savegamemenu_descrinput;
ui::Button *savegamemenu_savebutton;
+ ui::Button *savegamemenu_cancelbutton;
+
+ ui::Button *savegamemenu_confirmsavebutton;
+ ui::Button *savegamemenu_confirmdeletebutton;
+
+
}; // class SaveGameMenu