1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148 | #include "fsCGuiMessageDispatcher.h"
#include "fsCProfileManager.h"
#include <fsCore/fsIHardware.h>
#include <fsCore/src/debug/fsAssert.h>
#include <fsCore/src/fsCResourceName.h>
#include "../src/components/gui/elements/fsCButtonComponent.h"
#include "../src/components/gui/fsIGuiComponent.h"
#include "fsCore/fsIResourceNamePathAdjuster.h"
#include "fsILevelBasedAppCoreMain.h"
const fsCUniqueId fsCGuiMessageDispatcher::mEventCloseGuiMsg("closeGui");
const fsCUniqueId fsCGuiMessageDispatcher::mEventLoadGuiMsg("loadGui");
const fsCUniqueId fsCGuiMessageDispatcher::mEventLoadGuiTutorialMsg("loadGuiTut");
const fsCUniqueId fsCGuiMessageDispatcher::mEventLaunchBrowserMsg("launchBrowser");
const fsCUniqueId fsCGuiMessageDispatcher::mTutorialButtonPressedMsg("tutorialButtonPressed");
const fsCUniqueId fsCGuiMessageDispatcher::mEventLoadLevelMsg("loadLevel");
const fsCUniqueId fsCGuiMessageDispatcher::mEventLoadChapterMsg("loadChapter");
fsBool fsCGuiMessageDispatcher::messageDispatchDo(const fsCUniqueId& pMessageType, const sMessageParameters& pParam)
{
if (mEventCloseGuiMsg == pMessageType)
{
closeGuiMessageHandle(pParam);
return true;
}
if (mEventLoadGuiMsg == pMessageType)
{
loadGuiMessageHandle(pParam);
return true;
}
if (mEventLoadLevelMsg == pMessageType)
{
loadLevelMessageHandle(pParam);
return true;
}
if (mEventLoadChapterMsg == pMessageType)
{
loadChapterMessageHandle(pParam);
return true;
}
if (mEventLoadGuiTutorialMsg == pMessageType)
{
loadGuiMessageHandle(pParam);
const fsStr name = static_cast<const fsCButtonComponent::sButtonEventMsgParam&>(pParam).mParent->parentGet()->nameGet();
fsCGuiMessageDispatcher::messageDispatchDo(mTutorialButtonPressedMsg, sStrMessageParam(name));
return true;
}
if (mEventLaunchBrowserMsg == pMessageType)
{
fsStr targetUrl = static_cast<const fsCButtonComponent::sButtonEventMsgParam&>(pParam).mStr;
if (!targetUrl.emptyGet())
{
fsCAppCoreMain::instanceGet()->hardwareGet()->browserLaunch(targetUrl);
}
return true;
}
return fsIMessageDispatcher::messageDispatchDo(pMessageType, pParam);
}
void fsCGuiMessageDispatcher::closeGuiMessageHandle(const sMessageParameters& pParam)
{
const fsCButtonComponent::sButtonEventMsgParam& strParam = static_cast<const
fsCButtonComponent::sButtonEventMsgParam&>(pParam);
fsCEntity* gui = fsCAppCoreMain::instanceGet()->sceneGet()->entityNamed(strParam.mStr);
if (!gui)
{
gui = fsCAppCoreMain::instanceGet()->appOverlayEntityNamed(strParam.mStr);
}
fsAssert(gui != nullptr, "Gui %s not found for closing.\n", strParam.mStr.utf8Get());
gui->destroy();
}
void fsCGuiMessageDispatcher::loadLevelMessageHandle(const sMessageParameters& pParam) const<--- Either there is a missing 'override', or the member function 'fsCGuiMessageDispatcher::loadLevelMessageHandle' can be static.
{
const fsCButtonComponent::sButtonEventMsgParam& btnParam = static_cast<const
fsCButtonComponent::sButtonEventMsgParam&>(pParam);
fsStr levelFilename = btnParam.mStr;
fsILevelBasedAppCoreMain::instanceGet()->nextLocationSet(levelFilename);
fsILevelBasedAppCoreMain::instanceGet()->fadeOut();
}
void fsCGuiMessageDispatcher::loadChapterMessageHandle(const sMessageParameters& pParam) const
{
const fsCButtonComponent::sButtonEventMsgParam& btnParam = static_cast<const fsCButtonComponent::sButtonEventMsgParam&>(pParam);
fsStr gameName = btnParam.mStr;
fsCProfileManager::instanceGet()->chapterSet(gameName);
const fsStr sep = fsIResourceNamePathAdjuster::mPathSeparator;
fsStr chapterMainMenu = fsStr("chapters") + sep + btnParam.mStr + sep + "assets" + sep + "gui" + sep + "mainMenu" + sep + "mainMenu.txt";
fsCEntity* parentGui = btnParam.mParent->parentGet();
while ((parentGui != nullptr) && (!entityHasGuiComponentGet(parentGui)))
{
parentGui = dynamic_cast<fsCEntity*>(parentGui->parentGet());
}
if (!parentGui) // no more non modal parents to add to so just add to the scene
{
parentGui = fsCAppCoreMain::instanceGet()->sceneGet();
}
fsILevelBasedAppCoreMain::chapterLoaderEnable();
fsIGuiComponent::guiCreateFromFile(fsCResourceName(chapterMainMenu, fsCResourceName::eRES_LOCATION_ASSETS), parentGui,true);
}
void fsCGuiMessageDispatcher::loadGuiMessageHandle(const sMessageParameters& pParam) const
{
const fsCButtonComponent::sButtonEventMsgParam& btnParam = static_cast<const
fsCButtonComponent::sButtonEventMsgParam&>(pParam);
fsStr guiFilename = btnParam.mStr;
fsCEntity* parentGui = btnParam.mParent->parentGet();
while ((parentGui != nullptr) && (!entityHasGuiComponentGet(parentGui)))
{
parentGui = dynamic_cast<fsCEntity*>(parentGui->parentGet());
}
if (!parentGui) // no more non modal parents to add to so just add to the scene
{
parentGui = fsCAppCoreMain::instanceGet()->sceneGet();
}
fsIGuiComponent::guiCreateFromFile(fsCResourceName(guiFilename, fsCResourceName::eRES_LOCATION_ASSETS), parentGui,
true);
}
fsBool fsCGuiMessageDispatcher::entityHasGuiComponentGet(const fsINode* const pNode) const
{
const fsCEntity* const entPtr = dynamic_cast<const fsCEntity* const>(pNode);
if (entPtr != nullptr)
{
return nullptr != entPtr->firstComponentOfFamilyType<fsIGuiComponent>();
}
return false;
}
fsCGuiMessageDispatcher::fsCGuiMessageDispatcher()
{
}
fsCGuiMessageDispatcher::~fsCGuiMessageDispatcher()
{
}
|