Fission FSN
Loading...
Searching...
No Matches
fsIGuiComponent.h
Go to the documentation of this file.
1/********************************************************************
2*
3* Created: 17/3/2014 10:37
4*
5* File: fsIGuiComponent.h
6*
7* Author: Mick Waites
8*
9* Purpose: Base class for all menus/GUIs.
10*
11*********************************************************************/
12
13#ifndef fsIGuiComponenthdr
14#define fsIGuiComponenthdr
15
16#include <map>
17
18#include <fsCore/fsStr.h>
19
21#include "../fsIComponent.h"
22#include "fsCGuiParseTree.h"
23
24class fsCResourceName;
25class fsCUniqueId;
28class fsINode;
29
30
32{
33public:
34
35 template <typename TComponent>
36 TComponent* siblingEntityComponentGet() const;
37 template <typename TComponent>
38 TComponent* siblingEntityFamilyComponentGet() const;
39
40 static void flush();
41
42 void listenerComponentsRegister(fsCEntity* const pRoot) const;
43 void listenerComponentsDeRegister(fsCEntity* const pRoot) const;
44
45 static fsCEntity* guiCreateFromCommands(fsStr& pCommands, fsCEntity* pParent = nullptr, fsBool pModal = true,
46 fsBool pNewGrammarMode = false);
47 static fsCEntity* guiCreateFromFile(const fsCResourceName& pGuiLayoutFileName, fsCEntity* pParent = nullptr,
48 fsBool pModal = true);
49
50 // Pure parse (no engine calls) and construction-from-tree, split out of
51 // guiCreateFromCommands so the parse side can be snapshot-tested on its own.
52 // pNewGrammarMode selects which file-format signal (.gui vs legacy .txt)
53 // was resolved for this parse; see newGrammarFileNameResolve. Gates:
54 // `key: value` as an alternate to legacy `key = value` (see colonKeyGet);
55 // explicit `use NAME` mixins alongside the legacy
56 // bare-identifier-if-recognised-style heuristic (see commandProcess);
57 // typed `(x, y)`/`[elem, ...]` values (see newGrammarValueRead); and
58 // contiguous-include-at-top-of-file enforcement (in parseToTree itself).
59 static fsCGuiParseTree parseToTree(fsStr& pCommands, fsBool pNewGrammarMode = false);
60 static fsCEntity* constructFromTree(const fsCGuiParseTree& pTree, fsCEntity* pParent = nullptr,
61 fsBool pModal = true);
62
63 // Resolves pLegacyFileName to its .gui sibling if one exists next to it
64 // (existence-check dispatch, not content-sniffing - mirrors the
65 // coords.txt/Spine.json pattern in level.rs), leaving pOutResolvedFileName
66 // as pLegacyFileName unchanged otherwise. Returns whether new-grammar mode
67 // was selected. Public so the running-order loader can share the one
68 // resolver (fsIRunningOrder), no drift.
69 static fsBool newGrammarFileNameResolve(const fsStr& pLegacyFileName, fsStr& pOutResolvedFileName);
70
71 virtual fsBool onButtonClicked(fsCButtonComponent* pButtonComp);
72
74 static fsBool entityHasGuiComponentGet(const fsINode* pNode);
75
76protected:
77
78 void layoutFileProcess();
79
80 void initialiseFromVariableTableDo(const fsCVariableTable& pVars) override;
81
82 fsIGuiComponent(fsCEntity* pParent);
83 virtual ~fsIGuiComponent();
84
85private:
86
87 static std::map<fsStr, fsStr> mStyles;
88 static std::vector<fsStr> mStylesIncluded;
89
90 static fsStr* mGuiLayoutFileName;
91
92 static void unknownCommandProcess(const fsStr& pCommand, fsStr& pCommands);
93 static fsBool commandProcess(const fsStr& pCommand, fsStr& pCommands, std::map<fsStr, fsStr>& pStyles,
94 fsBool pNewGrammarMode);
95 static void newGrammarIncludeContiguityCheck(fsStr pCommands);
96
97 static fsS32 styleCharacterCountGet(fsStr& pCommands);
98
99 static std::unique_ptr<fsCGuiParseNode> guiElementParse(const fsCUniqueId& pComponentId,
100 const fsStr& pComponentTypeName, fsStr& pCommands,
101 std::map<fsStr, fsStr>& pStyles,
102 fsCGuiParseNode* pParentNode, fsBool pNewGrammarMode);
103 static fsBool colonKeyGet(fsStr& pCommands, fsStr& pOutKey);
104 static fsCEntity* constructFromTree(const fsCGuiParseNode& pNode, fsCEntity* pParent, fsBool pMakeModal);
105 static fsStr newGrammarValueRead(fsStr& pCommands);
106 static void variableInsertIntoTree(const fsStr& pVariable, fsStr& pCommands, std::map<fsStr, fsStr>& pParams,
107 fsBool pNewGrammarMode);
108 static fsBool fileContentsInclude(fsStr& pCommands);
109 static void styleDefinitionAdd(fsStr& pCommands, std::map<fsStr, fsStr>& pStyles);
110 static fsBool styleDefinitionDecodeAndInsertIntoCommands(const fsStr& pStyleName, fsStr& pCommands,
111 std::map<fsStr, fsStr>& pStyles);
112};
113
114template <typename TComponent>
116{
117 fsCEntity* const guiRootEnt = this->parentGet();
118 std::vector<fsCEntity*> canditates = guiRootEnt->childEntitiesWithComponentsOfFamilyType<TComponent>();
119 if (!canditates.empty())
120 {
121 return canditates.front()->componentGet<TComponent>();
122 }
123 return nullptr;
124}
125
126template <typename TComponent>
128{
129 fsCEntity* const guiRootEnt = this->parentGet();
130 std::vector<fsCEntity*> canditates = guiRootEnt->childEntitiesWithComponentsOfFamilyType<TComponent>();
131 if (!canditates.empty())
132 {
133 return canditates.front()->firstComponentOfFamilyType<TComponent>();
134 }
135 return nullptr;
136}
137
138#endif
Definition fsCButtonComponent.h:26
Definition fsCEntity.h:39
std::vector< fsCEntity * > childEntitiesWithComponentsOfFamilyType()
Definition fsCEntity.h:185
Definition fsCResourceName.h:32
Definition fsCUniqueId.h:21
Definition fsCVariableTable.h:27
fsIComponent(fsCEntity *pParent)
Definition fsIComponent.cpp:86
fsCEntity * parentGet() const
Definition fsIComponent.cpp:76
TComponent * siblingEntityFamilyComponentGet() const
Definition fsIGuiComponent.h:127
void listenerComponentsRegister(fsCEntity *const pRoot) const
Definition fsIGuiComponent.cpp:78
static fsCEntity * guiCreateFromFile(const fsCResourceName &pGuiLayoutFileName, fsCEntity *pParent=nullptr, fsBool pModal=true)
Definition fsIGuiComponent.cpp:185
fsIGuiComponent(fsCEntity *pParent)
Definition fsIGuiComponent.cpp:726
static fsIGuiComponent * guiParentGetFromComponent(const fsIComponent *pComponent)
Definition fsIGuiComponent.cpp:700
TComponent * siblingEntityComponentGet() const
Definition fsIGuiComponent.h:115
virtual ~fsIGuiComponent()
Definition fsIGuiComponent.cpp:731
void layoutFileProcess()
Definition fsIGuiComponent.cpp:27
void initialiseFromVariableTableDo(const fsCVariableTable &pVars) override
Definition fsIGuiComponent.cpp:685
static void flush()
Definition fsIGuiComponent.cpp:91
virtual fsBool onButtonClicked(fsCButtonComponent *pButtonComp)
Definition fsIGuiComponent.cpp:695
void listenerComponentsDeRegister(fsCEntity *const pRoot) const
Definition fsIGuiComponent.cpp:85
static fsCEntity * constructFromTree(const fsCGuiParseTree &pTree, fsCEntity *pParent=nullptr, fsBool pModal=true)
Definition fsIGuiComponent.cpp:312
static fsBool entityHasGuiComponentGet(const fsINode *pNode)
Definition fsIGuiComponent.cpp:716
static fsBool newGrammarFileNameResolve(const fsStr &pLegacyFileName, fsStr &pOutResolvedFileName)
Definition fsIGuiComponent.cpp:165
static fsCGuiParseTree parseToTree(fsStr &pCommands, fsBool pNewGrammarMode=false)
Definition fsIGuiComponent.cpp:286
static fsCEntity * guiCreateFromCommands(fsStr &pCommands, fsCEntity *pParent=nullptr, fsBool pModal=true, fsBool pNewGrammarMode=false)
Definition fsIGuiComponent.cpp:202
Definition fsINode.h:30
Definition fsStr.h:23
bool fsBool
Definition fsBaseTypes.h:26
int fsS32
Definition fsBaseTypes.h:20
Definition fsCGuiParseTree.h:23
Definition fsCGuiParseTree.h:40