Files
wagic/projects/mtg/src/GameStateStory.cpp
Xawotihs f68c106e7e - Modified gameObserver and related classes to be able to work with a precise JGE instance given at construction and not the static global one. That allows to run gameObserver without JGE instance (for example in a worker thread).
- Added an "ACTION_LOGGING_TESTING" mode in the gameObserver. When this is defined, the game reloads itself in every update. I want to use that to track undo problems. Be aware that it kills performances and crashes with the testsuite if you want to activate it.
- Various cleanup/refactor of the game observer.
- Added a gameObserver == operator to compare two games
- Added player mode to the player serialization
- Added a multi-threaded mode to AI_CHANGE_TESTING. For the moment it's only useable with Qt. If you want to use it without, just defined a thread_count higher than 1.
- Refactored random generator class to use list intead of queue
- Defined a specific type for interrupt decision instead of int
2011-11-13 22:36:34 +00:00

132 lines
2.8 KiB
C++

#include "PrecompiledHeader.h"
#include "GameStateStory.h"
#include "StoryFlow.h"
#include "SimpleMenu.h"
#include "GameApp.h"
#include <dirent.h>
GameStateStory::GameStateStory(GameApp* parent) :
GameState(parent, "story")
{
flow = NULL;
menu = NULL;
}
GameStateStory::~GameStateStory()
{
End();
}
void GameStateStory::loadStoriesMenu(const char * root)
{
SAFE_DELETE(menu);
stories.clear();
vector<string>subFolders = JFileSystem::GetInstance()->scanfolder(root);
for (size_t i = 0; i < subFolders.size(); ++i)
{
string subfolder = ensureFolder(subFolders[i]);
string filename = root + subfolder + "story.xml";
if (FileExists(filename))
{
subfolder.resize(subfolder.length() - 1); //remove trailing slash
stories.push_back(subfolder);
}
}
switch (stories.size())
{
case 0:
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
break;
case 1:
flow = NEW StoryFlow(stories[0]);
break;
default:
menu = NEW SimpleMenu(JGE::GetInstance(), 103, this, Fonts::MENU_FONT, 150, 60);
for (size_t i = 0; i < stories.size(); ++i)
{
menu->Add(i, stories[i].c_str());
}
menu->Add(kCancelMenuID, "Cancel");
}
}
void GameStateStory::Start()
{
flow = NULL;
menu = NULL;
loadStoriesMenu("campaigns/");
}
void GameStateStory::Update(float dt)
{
if (!menu && mEngine->GetButtonClick(JGE_BTN_MENU))
{
menu = NEW SimpleMenu(JGE::GetInstance(), 100, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 25);
menu->Add(0, "Back to main menu");
menu->Add(kCancelMenuID, "Cancel");
}
if (menu)
{
menu->Update(dt);
if (menu->isClosed())
SAFE_DELETE(menu);
//return;
}
if (flow)
{
if (flow->currentPageId == "End")
{
if (mEngine->GetButtonClick(JGE_BTN_OK) || mEngine->GetButtonClick(JGE_BTN_SEC))
{
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
}
}
flow->Update(dt);
}
}
void GameStateStory::Render()
{
if (flow)
flow->Render();
if (menu)
menu->Render();
}
void GameStateStory::End()
{
SAFE_DELETE(flow);
SAFE_DELETE(menu);
}
void GameStateStory::ButtonPressed(int controllerId, int controlId)
{
menu->Close();
switch (controllerId)
{
case 100:
if (controlId == -1)
{
}
else
{
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
}
break;
default:
if (controlId == -1)
{
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
}
else
{
flow = NEW StoryFlow(stories[controlId]);
}
}
}