4 #include <unordered_map>
34 using std::unordered_map;
60 ContextMenuScreenController::ContextMenuScreenController(
PopUps* popUps): popUps(popUps)
64 ContextMenuScreenController::~ContextMenuScreenController()
66 for (
const auto& [actionId, action]:
actions)
delete action;
79 screenNode = GUIParser::parse(
"resources/engine/gui",
"popup_contextmenu.xml");
87 tscriptMethods.
load(
"resources/engine/code-completion/",
"tscript-methods.properties");
89 Console::println(
"ContextMenuScreenController::initialize(): An error occurred: " +
string(exception.what()));
99 auto x =
static_cast<int>((float)mouseX * (
float)
screenNode->
getScreenWidth() / (float)Engine::getInstance()->getGUI()->getWidth());
100 auto y =
static_cast<int>((float)mouseY * (
float)
screenNode->
getScreenHeight() / (float)Engine::getInstance()->getGUI()->getHeight());
121 if (actionIt !=
actions.end()) {
123 if (actionIt->second !=
nullptr) actionIt->second->performAction();
125 if (StringTools::startsWith(node->
getValue(),
"miniscript.method.") ==
true) {
135 if (node->
getId() ==
"context_menu_addnode_search") {
141 for (
const auto& [methodNameCandidate, methodDescription]: properties) {
142 auto methodName = string(
"unknown");
143 if (StringTools::startsWith(methodNameCandidate,
"miniscript.basemethod.") ==
true) {
144 methodName = StringTools::substring(methodNameCandidate,
string(
"miniscript.basemethod.").size());
146 if (StringTools::startsWith(methodNameCandidate,
"miniscript.logicmethod.") ==
true) {
147 methodName = StringTools::substring(methodNameCandidate,
string(
"miniscript.logicmethod.").size());
149 if (StringTools::startsWith(methodNameCandidate,
"miniscript.") ==
true) {
150 methodName = StringTools::substring(methodNameCandidate,
string(
"miniscript.").size());
152 if (StringTools::toLowerCase(methodName).find(searchValue) != string::npos) {
154 "<context-menu-item value=\"miniscript.method." + GUIParser::escape(methodName) +
"\" template=\"context-menu-item_template_addnode.xml\" category=\"" + GUIParser::escape(methodName) +
"\" name=\"" + GUIParser::escape(methodDescription) +
"\" />",
172 for (
const auto& [actionId, action]:
actions)
delete action;
178 "<template src=\"resources/engine/gui/template_visualcode_addnodemenu.xml\" />",
185 for (
const auto& [methodNameCandidate, methodDescription]: properties) {
186 auto methodName = string(
"unknown");
187 if (StringTools::startsWith(methodNameCandidate,
"miniscript.basemethod.") ==
true) {
188 methodName = StringTools::substring(methodNameCandidate,
string(
"miniscript.basemethod.").size());
190 if (StringTools::startsWith(methodNameCandidate,
"miniscript.logicmethod.") ==
true) {
191 methodName = StringTools::substring(methodNameCandidate,
string(
"miniscript.logicmethod.").size());
193 if (StringTools::startsWith(methodNameCandidate,
"miniscript.") ==
true) {
194 methodName = StringTools::substring(methodNameCandidate,
string(
"miniscript.").size());
197 "<context-menu-item value=\"miniscript.method." + GUIParser::escape(methodName) +
"\" template=\"context-menu-item_template_addnode.xml\" category=\"" + GUIParser::escape(methodName) +
"\" name=\"" + GUIParser::escape(methodDescription) +
"\" />",
205 "<context-menu-item text=\"" + GUIParser::escape(text) +
"\" id=\"" + GUIParser::escape(
id) +
"\" />",
208 auto actionIt =
actions.find(
id);
209 if (actionIt !=
actions.end() && actionIt->second !=
nullptr)
delete actionIt->second;
210 if (action !=
nullptr)
actions[id] = action;
215 "<menu-separator />",
229 const auto& mouseEvents = Engine::getInstance()->getGUI()->getMouseEvents();
230 const auto& keyboardEvents = Engine::getInstance()->getGUI()->getKeyboardEvents();
231 for (
const auto& event: mouseEvents) {
232 if (event.isProcessed() ==
true)
continue;
233 if (event.getType() == GUIMouseEvent::MOUSEEVENT_RELEASED &&
241 for (
const auto& event: keyboardEvents) {
242 if (event.isProcessed() ==
true)
continue;
243 if (event.getKeyCode() == GUIKeyboardEvent::KEYCODE_ESCAPE) {
const string & getValue()
GUI node controller base class.
virtual const MutableString & getValue()=0
GUI node requested constraints requested constraints type enum.
GUINode_RequestedConstraints & getRequestsConstraints()
const string & getToolTip()
GUINodeController * getController()
GUIScreenNode * getScreenNode()
GUINode_ComputedConstraints & getComputedConstraints()
GUI parent node base class thats supporting child nodes.
GUI screen node that represents a screen that can be rendered via GUI system.
void setInputEventHandler(GUIInputEventHandler *inputEventHandler)
Set input event handler.
void setEnabled(bool enabled)
Set enabled.
void addChangeListener(GUIChangeListener *listener)
Add change listener.
void addTooltipRequestListener(GUITooltipRequestListener *listener)
Add tooltip request listener.
void layout() override
Layout.
void addActionListener(GUIActionListener *listener)
Add action listener.
void addFocusListener(GUIFocusListener *listener)
Add focus listener.
GUINode * getInnerNodeById(const string &nodeId)
Get inner GUI node by id.
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
Mutable utf8 aware string class.
const string & getString() const
Properties class, which helps out with storeing or loading key value pairs from/to property files.
const unordered_map< string, string > & getProperties()
void load(const string &pathName, const string &fileName, FileSystemInterface *fileSystem=nullptr)
Load property file.
std::exception Exception
Exception base class.
GUI action listener interface.
GUI change listener interface.
GUI focus listener interface.
GUI node requested constraints entity.
GUINode_RequestedConstraints_RequestedConstraintsType * topType
GUINode_RequestedConstraints_RequestedConstraintsType * leftType