#include "pch.h"
class GameStateContainerImpl : public GameStateContainer {
private:
static Color s_colorLight;
static Color s_colorDark;
static Color s_colorBackground;
TRef<Modeler> m_pmodeler;
TRef<ColumnPane> m_pcolTiles;
TRef<Image> m_pimage;
TRef<StringPane> m_pstringPaneTime;
TRef<IEngineFont> m_pfontTitles;
int m_secondsOld;
TRef<ButtonPane> m_pbuttonClose;
public:
GameStateContainerImpl(
Modeler* pmodeler,
IEngineFont* pfontTitles,
IEngineFont* pfontTime,
ButtonPane* pbutton
) :
m_pmodeler(pmodeler),
m_pfontTitles(pfontTitles),
m_secondsOld(-1),
m_pbuttonClose(pbutton)
{
m_pcolTiles = new ColumnPane();
TRef<Pane> ppaneInfo =
new BorderPane(
1,
0,
s_colorLight,
new BorderPane(
0,
0,
s_colorDark,
new BorderPane(
0,
0,
s_colorLight,
new BorderPane(
0,
0,
s_colorBackground,
m_pcolTiles
)
)
)
);
TRef<Pane> ppaneFooter = new ImagePane(pmodeler->LoadImage("gamestatefooterbmp", false));
m_pstringPaneTime = new StringPane(ZString("2:00"), pfontTime);
m_pstringPaneTime->SetOffset(WinPoint(50, 3));
m_pstringPaneTime->SetTextColor(Color::White());
ppaneFooter->InsertAtBottom(m_pstringPaneTime);
TRef<ColumnPane> pcol = new ColumnPane();
pcol->InsertAtBottom(new ImagePane(pmodeler->LoadImage("gamestateheaderbmp", false)));
pcol->InsertAtBottom(new FillPane(WinPoint(0, 1), s_colorLight));
pcol->InsertAtBottom(ppaneInfo);
pcol->InsertAtBottom(ppaneFooter);
m_pimage =
CreatePaneImage(
pmodeler->GetEngine(),
SurfaceType3D(),
true,
pcol
);
}
TRef<StringPane> AddGameStateTile(
const ZString& strTitle,
Pane* ppane
) {
TRef<StringPane> pstringPane = new StringPane(ZString(), m_pfontTitles);
m_pcolTiles->InsertAtBottom(
new BorderPane(
0,
1,
s_colorBackground,
new ColumnPane(
new ImagePane(m_pmodeler->LoadImage(strTitle, false)),
new BorderPane(
3,
1,
s_colorBackground,
new ColumnPane(
pstringPane,
ppane
)),
ppane
)
)
);
m_pcolTiles->InsertAtBottom(new FillPane(WinPoint(0, 1), s_colorLight));
return pstringPane;
}
TRef<Image> GetImage()
{
return m_pimage;
}
TRef<IEngineFont> GetFont()
{
return m_pfontTitles;
}
void SetTimeElapsed(int seconds)
{
if (seconds != m_secondsOld)
{
m_secondsOld = seconds;
if (seconds < 0)
{
m_pstringPaneTime->SetString("Game Starting");
}
else
{
int minutes = seconds / 60;
seconds -= minutes * 60;
m_pstringPaneTime->SetString(
"Time Elapsed: " + ZString(minutes) + ":"
+ ((seconds > 9) ? ZString(seconds) : ("0" + ZString(seconds)))
);
}
}
}
void SetTimeRemaining(int seconds)
{
if (seconds != m_secondsOld)
{
m_secondsOld = seconds;
if (seconds < 0)
{
m_pstringPaneTime->SetString("Game Over");
}
else
{
int minutes = seconds / 60;
seconds -= minutes * 60;
m_pstringPaneTime->SetString(
"Time Remaining: " + ZString(minutes) + ":"
+ ((seconds > 9) ? ZString(seconds) : ("0" + ZString(seconds)))
);
}
}
}
IEventSource* GetCloseEvent()
{
return m_pbuttonClose->GetEventSource();
}
};
Color GameStateContainerImpl::s_colorLight(
255.0f / 255.0f,
255.0f / 255.0f,
255.0f / 255.0f
);
Color GameStateContainerImpl::s_colorDark(
21.0f / 255.0f,
11.0f / 255.0f,
19.0f / 255.0f
);
Color GameStateContainerImpl::s_colorBackground(
13.0f / 255.0f, 13.0f / 255.0f, 13.0f / 255.0f
);
TRef<GameStateContainer> CreateGameStateContainer(
Modeler* pmodeler,
IEngineFont* pfontTitles,
IEngineFont* pfontTime,
ButtonPane* pbutton
) {
return new GameStateContainerImpl(pmodeler, pfontTitles, pfontTime, pbutton);
}