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 | #include "gfCLocaleSelectGui.h"
#include "fsIDisplay.h"
#include "fsIFile.h"
#include "fsIResourceNamePathAdjuster.h"
#include "fsRenderer/src/fsCBrushManager.h"
#include "fsRenderer/src/components/fsCTextSpriteComponent.h"
#include "fsRenderer/src/components/fsISpriteComponent.h"
#include "src/fsCAppSettings.h"
#include "src/fsCLocalisedStrings.h"
#include "src/fsCProfileManager.h"
#include "src/fsCResourceName.h"
#include "src/fsCVariableTable.h"
#include "src/fsILevelBasedAppCoreMain.h"
#include "src/components/gui/elements/fsCButtonComponent.h"
#include "src/components/gui/elements/fsCCheckBoxComponent.h"
#include "src/components/gui/elements/fsCCheckBoxGroupComponent.h"
const fsCUniqueId gfCLocaleSelectGui::mTypeId("gfCLocaleSelectGui");
fsBool gfCLocaleSelectGui::onButtonClicked(fsCButtonComponent* pButtonComp)
{
const fsStr& btnName = pButtonComp->parentGet()->nameGet();
if ("LocaleSelectApplyButton" == btnName)
{
auto languageGroup = parentGet()->firstChildEntityWithComponentsOfFamilyType<fsCCheckBoxGroupComponent>();
auto languages = languageGroup->childEntitiesWithComponentsOfFamilyType<fsCCheckBoxComponent>();
for (const auto& language: languages)<--- Consider using std::any_of algorithm instead of a raw loop.
{
if (language->componentGet<fsCCheckBoxComponent>()->valueGet())
{
fsCProfileManager::instanceGet()->savedDataGet()->strSet(fsCGlobalSavedData::mCurrentLocale, language->nameGet());
fsCProfileManager::instanceGet()->allDataSave(false);
fsCAppCoreMain::instanceGet()->localeGet()->localeSet(language->nameGet());
if (parentGet()->nameGet() == "localeSelectInitGui")
{
parentGet()->destroy();
fsCAppCoreMain::instanceGet()->childAddToAppScene(
fsIGuiComponent::guiCreateFromFile(fsCResourceName("notPacked/splashScreen.txt",
fsCResourceName::eRES_LOCATION_ASSETS)));
}
else
{
fsILevelBasedAppCoreMain::instanceGet()->quitToMenuSet();
}
return true;
}
}
return true;
}
return false;
}
void gfCLocaleSelectGui::initialiseFromVariableTableDo(const fsCVariableTable& pVars)
{
fsIGuiComponent::initialiseFromVariableTableDo(pVars);
mLocaleEntityLayoutFile = pVars.strGet("localeEntityLayoutFile");
auto currentLocale = fsCProfileManager::instanceGet()->savedDataGet()->strGet(fsCGlobalSavedData::mCurrentLocale);
currentLocale = currentLocale.emptyGet() ? "en" : currentLocale;
if (fsCEntity* const langEnt = parentGet()->childFind("languageSelect"))
{
if (fsITextSpriteComponent* const txt = langEnt->textComponentGet())
{
txt->textSet(fsCLocalisedStrings::localisedStringGet("languageSelectTitle" + currentLocale));
}
}
auto languageGroup = parentGet()->firstChildEntityWithComponentsOfFamilyType<fsCCheckBoxGroupComponent>();
const auto languages = fsCAppCoreMain::instanceGet()->localeGet()->supportedLanguagesGet();
auto stride = 32;
fsVec2d pos( 0.0f, 0.0f);
for (const auto& language: languages)
{
auto languageOptionFolder = mLocaleEntityLayoutFile;
languageOptionFolder.erase(languageOptionFolder.rfind(fsIResourceNamePathAdjuster::mPathSeparator) + 1);
const auto languageOption = guiCreateFromFile(fsCResourceName(mLocaleEntityLayoutFile,
fsCResourceName::eRES_LOCATION_ASSETS), languageGroup, false);
languageOption->posSet(pos);
languageOption->nameSet(language.first);
pos.y += stride;
auto languageButton = languageOption->componentGet<fsCCheckBoxComponent>();
languageButton->groupInitialise();
languageOption->firstChildEntityWithComponentsOfFamilyType<fsCTextSpriteComponent>()->textComponentGet()->textSet(
fsCLocalisedStrings::localisedStringGet("languageSelect" + language.first));
}
}
fsIComponent* gfCLocaleSelectGui::create(fsCEntity* pParent)
{
return new gfCLocaleSelectGui(pParent);
}
gfCLocaleSelectGui::gfCLocaleSelectGui(fsCEntity* const pParent) :
fsIGuiComponent(pParent)
{
}
gfCLocaleSelectGui::~gfCLocaleSelectGui()
{
}
|