Add basic functionality to SaveGameDialog

actorid
scrawl 11 years ago
parent cf79a83d4f
commit 2e87cbc231

@ -63,8 +63,8 @@ namespace MWBase
/// \note \a slot must belong to \a character.
virtual MWState::Character *getCurrentCharacter() = 0;
///< \attention Do not call this function to check if there is a current character. Use
/// characterBegin()!=characterEnd() instead.
///< \attention Do not call this function to check if there is a current character.
/// Instead, assume there is a character if getState() == Running.
virtual CharacterIterator characterBegin() = 0;
///< Any call to SaveGame and getCurrentCharacter can invalidate the returned

@ -18,10 +18,16 @@ namespace MWGui
MainMenu::MainMenu(int w, int h)
: OEngine::GUI::Layout("openmw_mainmenu.layout")
, mButtonBox(0), mWidth (w), mHeight (h)
, mSaveGameDialog(NULL)
{
updateMenu();
}
MainMenu::~MainMenu()
{
delete mSaveGameDialog;
}
void MainMenu::onResChange(int w, int h)
{
mWidth = w;
@ -56,27 +62,15 @@ namespace MWGui
MWBase::Environment::get().getStateManager()->newGame();
}
else if (name == "loadgame")
else
{
// for testing purpose, pick the first slot of the first character:
const MWState::Character& character =
*MWBase::Environment::get().getStateManager()->characterBegin();
const MWState::Slot& slot = *character.begin();
MWBase::Environment::get().getStateManager()->loadGame (&character, &slot);
// MWGui::SaveGameDialog* dialog = new MWGui::SaveGameDialog();
// dialog->setLoadOrSave(true);
// dialog->setVisible(true);
}
if (!mSaveGameDialog)
mSaveGameDialog = new SaveGameDialog();
if (name == "loadgame")
mSaveGameDialog->setLoadOrSave(true);
else if (name == "savegame")
{
// for testing purpose, save into a new slot:
MWBase::Environment::get().getStateManager()->saveGame (0);
// MWGui::SaveGameDialog* dialog = new MWGui::SaveGameDialog();
// dialog->setLoadOrSave(false);
// dialog->setVisible(true);
mSaveGameDialog->setLoadOrSave(false);
mSaveGameDialog->setVisible(true);
}
}

@ -5,6 +5,8 @@
namespace MWGui
{
class SaveGameDialog;
class MainMenu : public OEngine::GUI::Layout
{
int mWidth;
@ -13,6 +15,7 @@ namespace MWGui
public:
MainMenu(int w, int h);
~MainMenu();
void onResChange(int w, int h);
@ -27,6 +30,8 @@ namespace MWGui
void onButtonClicked (MyGUI::Widget* sender);
void updateMenu();
SaveGameDialog* mSaveGameDialog;
};
}

@ -1,12 +1,68 @@
#include "savegamedialog.hpp"
#include "widgets.hpp"
#include "../mwbase/statemanager.hpp"
#include "../mwbase/environment.hpp"
#include "../mwstate/character.hpp"
namespace
{
std::string getMonth(int m)
{
std::string month;
switch (m) {
case 0:
month = "#{sMonthMorningstar}";
break;
case 1:
month = "#{sMonthSunsdawn}";
break;
case 2:
month = "#{sMonthFirstseed}";
break;
case 3:
month = "#{sMonthRainshand}";
break;
case 4:
month = "#{sMonthSecondseed}";
break;
case 5:
month = "#{sMonthMidyear}";
break;
case 6:
month = "#{sMonthSunsheight}";
break;
case 7:
month = "#{sMonthLastseed}";
break;
case 8:
month = "#{sMonthHeartfire}";
break;
case 9:
month = "#{sMonthFrostfall}";
break;
case 10:
month = "#{sMonthSunsdusk}";
break;
case 11:
month = "#{sMonthEveningstar}";
break;
default:
break;
}
return month;
}
}
namespace MWGui
{
SaveGameDialog::SaveGameDialog()
: WindowModal("openmw_savegame_dialog.layout")
, mSaving(true)
, mCurrentCharacter(NULL)
{
getWidget(mScreenshot, "Screenshot");
getWidget(mCharacterSelection, "SelectCharacter");
@ -18,21 +74,57 @@ namespace MWGui
getWidget(mSpacer, "Spacer");
mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SaveGameDialog::onOkButtonClicked);
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SaveGameDialog::onCancelButtonClicked);
mCharacterSelection->eventComboChangePosition += MyGUI::newDelegate(this, &SaveGameDialog::onCharacterSelected);
mSaveList->eventListChangePosition += MyGUI::newDelegate(this, &SaveGameDialog::onSlotSelected);
}
void SaveGameDialog::open()
{
WindowModal::open();
center();
MWBase::StateManager* mgr = MWBase::Environment::get().getStateManager();
if (mgr->characterBegin() == mgr->characterEnd())
return;
// If we are running, there must be a current character
if (mgr->getState() == MWBase::StateManager::State_Running)
{
mCurrentCharacter = mgr->getCurrentCharacter();
}
mCharacterSelection->removeAllItems();
for (MWBase::StateManager::CharacterIterator it = mgr->characterBegin(); it != mgr->characterEnd(); ++it)
{
std::stringstream title;
title << it->getSignature().mPlayerName;
title << " (Level " << it->getSignature().mPlayerLevel << " " << it->getSignature().mPlayerClass << ")";
mCharacterSelection->addItem (title.str());
if (mCurrentCharacter == &*it)
mCharacterSelection->setIndexSelected(mCharacterSelection->getItemCount()-1);
}
fillSaveList();
}
void SaveGameDialog::setLoadOrSave(bool load)
{
mSaving = !load;
mSaveNameEdit->setVisible(!load);
mCharacterSelection->setUserString("Hidden", load ? "false" : "true");
mCharacterSelection->setVisible(load);
mSpacer->setUserString("Hidden", load ? "false" : "true");
if (!load)
{
mCurrentCharacter = MWBase::Environment::get().getStateManager()->getCurrentCharacter();
}
center();
}
@ -43,7 +135,94 @@ namespace MWGui
void SaveGameDialog::onOkButtonClicked(MyGUI::Widget *sender)
{
// Get the selected slot, if any
unsigned int i=0;
const MWState::Slot* slot = NULL;
for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end(); ++it,++i)
{
if (i == mSaveList->getIndexSelected())
slot = &*it;
}
if (mSaving)
{
MWBase::Environment::get().getStateManager()->saveGame (slot);
}
else
{
MWBase::Environment::get().getStateManager()->loadGame (mCurrentCharacter, slot);
}
setVisible(false);
}
void SaveGameDialog::onCharacterSelected(MyGUI::ComboBox *sender, size_t pos)
{
MWBase::StateManager* mgr = MWBase::Environment::get().getStateManager();
unsigned int i=0;
const MWState::Character* character = NULL;
for (MWBase::StateManager::CharacterIterator it = mgr->characterBegin(); it != mgr->characterEnd(); ++it, ++i)
{
if (i == pos)
character = &*it;
}
assert(character && "Can't find selected character");
mCurrentCharacter = character;
fillSaveList();
}
void SaveGameDialog::fillSaveList()
{
mSaveList->removeAllItems();
if (!mCurrentCharacter)
return;
for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end(); ++it)
{
mSaveList->addItem(it->mPath.string());
}
onSlotSelected(mSaveList, MyGUI::ITEM_NONE);
}
void SaveGameDialog::onSlotSelected(MyGUI::ListBox *sender, size_t pos)
{
if (pos == MyGUI::ITEM_NONE)
{
mInfoText->setCaption("");
return;
}
const MWState::Slot* slot = NULL;
unsigned int i=0;
for (MWState::Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end(); ++it, ++i)
{
if (i == pos)
slot = &*it;
}
assert(slot && "Can't find selected slot");
std::stringstream text;
time_t time = slot->mTimeStamp;
struct tm* timeinfo;
timeinfo = localtime(&time);
text << asctime(timeinfo) << "\n";
text << "Level " << slot->mProfile.mPlayerLevel << "\n";
text << slot->mProfile.mPlayerCell << "\n";
//text << "Time played: " << slot->mProfile.mTimePlayed << "\n";
int hour = int(slot->mProfile.mInGameTime.mGameHour);
bool pm = hour >= 12;
if (hour >= 13) hour -= 12;
if (hour == 0) hour = 12;
text <<
slot->mProfile.mInGameTime.mDay << " "
<< getMonth(slot->mProfile.mInGameTime.mMonth)
<< " " << hour << " " << (pm ? "#{sSaveMenuHelp05}" : "#{sSaveMenuHelp04}");
mInfoText->setCaptionWithReplacing(text.str());
}
}

@ -3,6 +3,11 @@
#include "windowbase.hpp"
namespace MWState
{
class Character;
}
namespace MWGui
{
@ -17,10 +22,15 @@ namespace MWGui
void onCancelButtonClicked (MyGUI::Widget* sender);
void onOkButtonClicked (MyGUI::Widget* sender);
void onCharacterSelected (MyGUI::ComboBox* sender, size_t pos);
void onSlotSelected (MyGUI::ListBox* sender, size_t pos);
void fillSaveList();
private:
MyGUI::ImageBox* mScreenshot;
bool mSaving;
MyGUI::ComboBox* mCharacterSelection;
MyGUI::EditBox* mInfoText;
@ -30,6 +40,8 @@ namespace MWGui
MyGUI::EditBox* mSaveNameEdit;
MyGUI::Widget* mSpacer;
const MWState::Character* mCurrentCharacter;
};
}

@ -72,9 +72,28 @@ void MWState::StateManager::saveGame (const Slot *slot)
/// \todo store content file list
profile.mPlayerName = player.getClass().getName (player);
profile.mPlayerLevel = player.getClass().getNpcStats (player).getLevel();
profile.mPlayerClass = player.get<ESM::NPC>()->mBase->mId;
/// \todo player cell
/// \todo gamehour
profile.mPlayerClass = player.get<ESM::NPC>()->mBase->mClass;
std::string cellName;
if (player.getCell()->mCell->isExterior())
{
if (player.getCell()->mCell->mName != "")
cellName = player.getCell()->mCell->mName;
else
{
const ESM::Region* region =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Region>().search(player.getCell()->mCell->mRegion);
if (region)
cellName = region->mName;
else
cellName = MWBase::Environment::get().getWindowManager()->getGameSettingString("sDefaultCellname", "Wilderness");
}
}
else
cellName = player.getCell()->mCell->mName;
profile.mPlayerCell = cellName;
profile.mInGameTime.mGameHour = world.getTimeStamp().getHour();
profile.mInGameTime.mDay = world.getDay();
profile.mInGameTime.mMonth = world.getMonth();
/// \todo year
@ -113,6 +132,8 @@ void MWState::StateManager::loadGame (const Character *character, const Slot *sl
/// \todo read saved game data
mCharacterManager.setCurrentCharacter(character);
mState = State_Running;
}

@ -17,8 +17,6 @@
<Widget type="ComboBox" skin="MW_ComboBox" position="0 0 200 24" name="SelectCharacter">
<Property key="Caption" value="Select Character"/>
<Property key="AddItem" value="Gandalf (Level 654)"/>
<Property key="AddItem" value="Frodo (Level 3)"/>
<UserString key="HStretch" value="true"/>
</Widget>
@ -26,11 +24,6 @@
<Widget type="ListBox" skin="MW_List" position="0 0 200 200" name="SaveList">
<UserString key="HStretch" value="true"/>
<UserString key="VStretch" value="true"/>
<Property key="AddItem" value="Quicksave"/>
<Property key="AddItem" value="Autosave"/>
<Property key="AddItem" value="Save 3"/>
<Property key="AddItem" value="Save 2"/>
<Property key="AddItem" value="Save 1"/>
</Widget>
</Widget>
@ -51,8 +44,6 @@
<Widget type="AutoSizedEditBox" skin="SandText" position="0 0 263 0" name="InfoText">
<Property key="Static" value="true"/>
<Property key="MultiLine" value="true"/>
<Property key="Caption" value="4:21 AM\nTuesday, November 5, 2013\n\nLevel 23\nBalmora, Guild of Mages\n16 Last Seed (Day 12) 9 a.m. "/>
</Widget>

Loading…
Cancel
Save