Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/savegamemenu.cc89
-rw-r--r--src/client/savegamemenu.h13
2 files changed, 90 insertions, 12 deletions
diff --git a/src/client/savegamemenu.cc b/src/client/savegamemenu.cc
index ea766a2..a0da087 100644
--- a/src/client/savegamemenu.cc
+++ b/src/client/savegamemenu.cc
@@ -10,8 +10,11 @@
#include "core/application.h"
#include "core/gameinterface.h"
#include "core/gameserver.h"
+#include "model/material.h"
#include "client/savegamemenu.h"
#include "filesystem/filesystem.h"
+#include "render/screenshot.h"
+#include "render/textures.h"
#include "ui/ui.h"
#include "sys/sys.h"
@@ -49,6 +52,11 @@ SaveGameMenu::SaveGameMenu(ui::Widget *parent, const char *label, const Mode mod
savegamemenu_filelistview = new ui::ListView(this);
savegamemenu_filelistview->set_label("files");
+ // savegame screenshot
+ savegamemenu_screenshot = new ui::Bitmap(this);
+ savegamemenu_screenshot->set_background(true);
+ savegamemenu_screenshot->set_border(true);
+
// savegame description title
savegamemenu_descrtitle = new ui::Label(this);
savegamemenu_descrtitle->set_label("subtitle");
@@ -116,13 +124,13 @@ void SaveGameMenu::resize()
savegamemenu_titlelabel->bottom() + padding
);
- // resize eject button
+ // resize delete button
savegamemenu_deletebutton->set_size(icon_size, icon_size);
savegamemenu_deletebutton->set_location(
- savegamemenu_filelistview->right() - icon_size,
+ savegamemenu_filelistview->left(),
savegamemenu_filelistview->bottom() + padding
);
-
+
// resize description title
savegamemenu_descrtitle->set_size(
width() - savegamemenu_filelistview->right() - 2.0f * padding,
@@ -130,19 +138,38 @@ void SaveGameMenu::resize()
);
savegamemenu_descrtitle->set_location(
savegamemenu_filelistview->right() + padding,
- savegamemenu_filelistview->top()
+ savegamemenu_filelistview->top() + ui::UI::elementsize.width() + padding
);
-
+
// resize description label
savegamemenu_descrlabel->set_size(
savegamemenu_descrtitle->width(),
- savegamemenu_filelistview->bottom() - savegamemenu_descrtitle->bottom() - ui::UI::elementsize.width() - 2.0f * padding
+ savegamemenu_filelistview->bottom() - savegamemenu_descrtitle->bottom() - padding
);
savegamemenu_descrlabel->set_location(
savegamemenu_filelistview->right() + padding,
savegamemenu_descrtitle->bottom() + padding
);
+ // resize screenshot
+ model::Material *screenshotmaterial = model::Material::find("ui/screenshot");
+ if (screenshotmaterial) {
+ float sx = savegamemenu_descrtitle->width() / screenshotmaterial->size().width();
+ float sy = ui::UI::elementsize.width() / screenshotmaterial->size().height();
+ float s = math::min (sx, sy);
+ savegamemenu_screenshot->set_size(screenshotmaterial->size().width() * s, screenshotmaterial->size().height() * s);
+ } else {
+ savegamemenu_screenshot->set_size(
+ ui::UI::elementsize.width(),
+ ui::UI::elementsize.width()
+ );
+ }
+ savegamemenu_screenshot->set_location(
+ savegamemenu_descrtitle->left() + (savegamemenu_descrtitle->width() - savegamemenu_screenshot->width()) * 0.5f,
+ savegamemenu_filelistview->top() + (ui::UI::elementsize.width() - savegamemenu_screenshot->height()) * 0.5f
+ );
+
+
// resize save button
savegamemenu_savebutton->set_size(ui::UI::elementsize);
savegamemenu_savebutton->set_location(
@@ -243,6 +270,17 @@ void SaveGameMenu::refresh()
show_file_info();
}
+void SaveGameMenu::hide()
+{
+ Window::hide();
+
+ model::Material *screenshotmaterial = model::Material::find("ui/screenshot");
+ if (screenshotmaterial && screenshotmaterial->texture().size()) {
+ render::Textures::unload(screenshotmaterial->texture());
+ screenshotmaterial->set_texture("");
+ }
+}
+
void SaveGameMenu::show()
{
Window::show();
@@ -260,6 +298,7 @@ void SaveGameMenu::show_file_info()
savegamemenu_confirmdeletebutton->hide();
savegamemenu_cancelbutton->hide();
savegamemenu_descrlabel->hide();
+ savegamemenu_screenshot->hide();
if (savegamemenu_filelistview->selected()) {
savegamemenu_savebutton->show();
@@ -275,12 +314,31 @@ void SaveGameMenu::show_file_info()
std::ostringstream descrstr;
//descrstr << descr << '\n';
- descrstr << info; // info has a traling newline
+ descrstr << info; // info has a trailing newline
descrstr << timestamp << '\n';
savegamemenu_deletebutton->enable();
savegamemenu_descrtitle->set_text(savename);
savegamemenu_descrlabel->set_text(descrstr.str().c_str());
+
+ model::Material *screenshotmaterial = model::Material::find("ui/screenshot");
+ if (!screenshotmaterial) {
+ screenshotmaterial = new model::Material("ui/screenshot");
+ model::Material::add(screenshotmaterial);
+ screenshotmaterial ->set_flags(model::Material::Texture);
+ screenshotmaterial ->set_flags(model::Material::Bright);
+ } else if (screenshotmaterial->texture().size()) {
+ render::Textures::unload(screenshotmaterial->texture());
+ }
+
+ std::string screenshotfilename("savegames/" + savename);
+ screenshotmaterial->set_texture(screenshotfilename);
+
+ savegamemenu_screenshot->set_texture("ui/screenshot");
+ savegamemenu_screenshot->show();
+
+ resize();
+
} else {
// new savegame, immediatly show the save game dialog
show_save_dialog();
@@ -471,6 +529,14 @@ void SaveGameMenu::deletegame(std::string savename)
::remove(filename.c_str());
}
+void SaveGameMenu::savescreenshot(std::string savename)
+{
+ std::string filename(filesystem::writedir() + "savegames/" + savename + ".jpg");
+
+ render::Screenshot::savegameshot(filename);
+
+}
+
void SaveGameMenu::savegame(std::string savename, const std::string & description)
{
if (!core::server() || !core::server()->module())
@@ -505,8 +571,8 @@ void SaveGameMenu::savegame(std::string savename, const std::string & descriptio
filesystem::OFileStream ofs("savegames/" + savename + ".ini");
+ core::application()->notify_message(core::Message::Info, "Saving " + savename);
con_debug << "Saving " << ofs.filename() << std::endl;
- core::application()->notify_message(core::Message::Info, "Saving '" + savename + "'");
ofs << "; Project::OSiRiON" << std::endl;
ofs << "; savegame data" << std::endl;
@@ -550,13 +616,16 @@ void SaveGameMenu::savegame(std::string savename, const std::string & descriptio
core::server()->module()->game_save(core::localplayer(), ofs);
ofs.close();
+
+ // save screenshot
+ savescreenshot(savename);
}
void SaveGameMenu::loadgame(std::string savename) {
filesystem::IniFile inifile("savegames/" + savename);
if (!inifile.is_open()) {
- con_warn << "Could not open file " << inifile.filename() << "!" << std::endl;
+ con_warn << "Could not open savegames/" + savename << ".ini" << std::endl;
return;
}
@@ -567,7 +636,7 @@ void SaveGameMenu::loadgame(std::string savename) {
core::application()->connect("");
con_debug << "Loading " << inifile.filename() << std::endl;
- core::application()->notify_message(core::Message::Info, "Loading '" + savename + "'");
+ core::application()->notify_message(core::Message::Info, "Loading " + savename);
if (core::application()->connected() && core::server() && core::server()->module()) {
core::server()->module()->game_load(core::localplayer(), inifile);
diff --git a/src/client/savegamemenu.h b/src/client/savegamemenu.h
index d8dde05..b26bbdf 100644
--- a/src/client/savegamemenu.h
+++ b/src/client/savegamemenu.h
@@ -7,6 +7,7 @@
#ifndef __INCLUDED_CLIENT_SAVEGAMEMENU_H__
#define __INCLUDED_CLIENT_SAVEGAMEMENU_H__
+#include "ui/bitmap.h"
#include "ui/button.h"
#include "ui/iconbutton.h"
#include "ui/inputbox.h"
@@ -25,10 +26,13 @@ public:
SaveGameMenu(ui::Widget *parent = 0, const char *label = 0, const Mode mode = Save);
virtual ~SaveGameMenu();
+ /// load the specified savegame
static void loadgame(std::string savename);
+ /// save the current game state to the specified savegame name
static void savegame(std::string savename, const std::string & description);
+ /// delete the specified savegame
static void deletegame(std::string savename);
protected:
@@ -43,6 +47,8 @@ protected:
virtual void show();
+ virtual void hide();
+
/**
* @brief show file info for the selected savegame
* */
@@ -66,6 +72,9 @@ protected:
void refresh();
private:
+ /// save a screenshot for a specified savegame
+ static void savescreenshot(std::string savename);
+
void get_savegame_info(const std::string & savename, std::string &game_descr, std::string &game_info, std::string &game_timestamp);
Mode savegamemenu_mode;
@@ -85,8 +94,8 @@ private:
ui::Button *savegamemenu_confirmsavebutton;
ui::Button *savegamemenu_confirmdeletebutton;
-
-
+ ui::Bitmap *savegamemenu_screenshot;
+
}; // class SaveGameMenu