TDME2  1.9.200
InputDialogScreenController.cpp
Go to the documentation of this file.
2 
3 #include <memory>
4 #include <string>
5 
6 #include <tdme/tdme.h>
7 #include <tdme/engine/Engine.h>
12 #include <tdme/gui/nodes/GUINode.h>
16 #include <tdme/gui/GUI.h>
17 #include <tdme/gui/GUIParser.h>
20 #include <tdme/utilities/Action.h>
21 #include <tdme/utilities/Console.h>
24 
25 using std::string;
26 using std::unique_ptr;
27 
29 
39 using tdme::gui::GUI;
47 
48 InputDialogScreenController::InputDialogScreenController(PopUps* popUps)
49 {
50  this->popUps = popUps;
51 }
52 
54 }
55 
57 {
58  return screenNode;
59 }
60 
62 {
64 }
65 
67 {
68  try {
69  screenNode = GUIParser::parse("resources/engine/gui", "popup_inputdialog.xml");
70  screenNode->setEnabled(false);
75  tabsHeaderNode = required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("inputdialog_tabs-header"));
76  inputNode = required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("inputdialog_inputtext"));
77  } catch (Exception& exception) {
78  Console::println("InputDialogScreenController::initialize(): An error occurred: " + string(exception.what()));
79  }
80 }
81 
83 {
84  screenNode = nullptr;
85 }
86 
87 
88 void InputDialogScreenController::show(const string& captionText, const string& inputText, Action* applyAction, Action* cancelAction)
89 {
90  required_dynamic_cast<GUIParentNode*>(screenNode->getInnerNodeById(tabsHeaderNode->getId()))->replaceSubNodes("<tab id=\"inputdialog_caption\" image=\"resources/engine/images/attention.png\" text=\"" + GUIParser::escape(captionText)+ "\" closeable=\"true\"/>", true);
91  this->inputNode->getController()->setValue(inputText);
92  this->applyAction = unique_ptr<Action>(applyAction);
93  this->cancelAction = unique_ptr<Action>(cancelAction);
94  //
95  screenNode->setEnabled(true);
96  Engine::getInstance()->getGUI()->setFoccussedNode(inputNode);
97 }
98 
100 {
101  screenNode->setEnabled(false);
102  applyAction = nullptr;
103  cancelAction = nullptr;
104 }
105 
107 {
108 }
109 
111 {
112  if (type == GUIActionListenerType::PERFORMED) {
113  if (node->getId() == "inputdialog_apply") {
114  if (applyAction != nullptr) applyAction->performAction();
115  applyAction = nullptr;
116  cancelAction = nullptr;
117  } else
118  if (node->getId() == "inputdialog_cancel" ||
119  StringTools::startsWith(node->getId(), "inputdialog_caption_close_") == true) { // TODO: a.drewke, check with DH
120  if (cancelAction != nullptr) cancelAction->performAction();
121  applyAction = nullptr;
122  cancelAction = nullptr;
123  close();
124  }
125  }
126 }
127 
129  GUI::setDisableTabFocusControl(node->getScreenNode() != screenNode);
130 }
131 
133 }
134 
135 void InputDialogScreenController::onTooltipShowRequest(GUINode* node, int mouseX, int mouseY) {
136  popUps->getTooltipScreenController()->show(mouseX, mouseY, node->getToolTip());
137 }
138 
141 }
Engine main class.
Definition: Engine.h:131
GUI parser.
Definition: GUIParser.h:40
GUI module class.
Definition: GUI.h:64
GUI node controller base class.
virtual void setValue(const MutableString &value)=0
Set value.
virtual const MutableString & getValue()=0
GUI node base class.
Definition: GUINode.h:64
const string & getToolTip()
Definition: GUINode.h:346
GUINodeController * getController()
Definition: GUINode.h:661
GUIScreenNode * getScreenNode()
Definition: GUINode.h:325
const string & getId()
Definition: GUINode.h:339
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:42
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
void setEnabled(bool enabled)
Set enabled.
void addChangeListener(GUIChangeListener *listener)
Add change listener.
void addTooltipRequestListener(GUITooltipRequestListener *listener)
Add tooltip request listener.
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.
void show(const string &captionText, const string &inputText, Action *applyAction, Action *cancelAction=nullptr)
Shows the input dialog pop up.
void onAction(GUIActionListenerType type, GUIElementNode *node) override
void onTooltipShowRequest(GUINode *node, int mouseX, int mouseY) override
On tooltip show request.
void show(int mouseX, int mouseY, const string &tooltip)
Show tooltip.
Pop ups controller accessor class.
Definition: PopUps.h:29
TooltipScreenController * getTooltipScreenController()
Definition: PopUps.h:131
Console class.
Definition: Console.h:29
const string & getString() const
String tools class.
Definition: StringTools.h:22
std::exception Exception
Exception base class.
Definition: Exception.h:18
GUI action listener interface.
Action Interface.
Definition: Action.h:11