TDME2  1.9.200
TriggerEditorTabController.cpp
Go to the documentation of this file.
2 
3 #include <memory>
4 #include <string>
5 
6 #include <tdme/tdme.h>
11 #include <tdme/gui/nodes/GUINode.h>
14 #include <tdme/gui/GUI.h>
15 #include <tdme/gui/GUIParser.h>
30 #include <tdme/utilities/Action.h>
31 #include <tdme/utilities/Console.h>
35 
36 using std::make_unique;
37 using std::string;
38 using std::unique_ptr;
39 
41 
68 
69 TriggerEditorTabController::TriggerEditorTabController(TriggerEditorTabView* view)
70 {
71  this->view = view;
72  this->popUps = view->getPopUps();
73  this->basePropertiesSubController = make_unique<BasePropertiesSubController>(view->getEditorView(), "prototype");
74  this->prototypePhysicsSubController = make_unique<PrototypePhysicsSubController>(view->getEditorView(), view, false);
75  this->prototypeDisplaySubController = make_unique<PrototypeDisplaySubController>(view->getEditorView(), view, this->prototypePhysicsSubController->getView());
76  this->prototypeScriptSubController = make_unique<PrototypeScriptSubController>(view->getEditorView());
77 }
78 
80 }
81 
83 {
84  this->screenNode = screenNode;
89 }
90 
92 {
93 }
94 
96 {
97  switch (command) {
98  case COMMAND_SAVE:
99  {
100  auto fileName = view->getPrototype() != nullptr?view->getPrototype()->getFileName():"";
101  try {
102  if (fileName.empty() == true) throw ExceptionBase("Could not save file. No filename known");
103  view->saveFile(
104  Tools::getPathName(fileName),
105  Tools::getFileName(fileName)
106  );
107  } catch (Exception& exception) {
108  showInfoPopUp("Warning", string(exception.what()));
109  }
110  }
111  break;
112  case COMMAND_SAVEAS:
113  {
114  class OnTriggerSave: public virtual Action
115  {
116  public:
117  void performAction() override {
118  try {
119  triggerEditorTabController->view->saveFile(
120  triggerEditorTabController->popUps->getFileDialogScreenController()->getPathName(),
121  triggerEditorTabController->popUps->getFileDialogScreenController()->getFileName()
122  );
123  } catch (Exception& exception) {
124  triggerEditorTabController->showInfoPopUp("Warning", string(exception.what()));
125  }
126  triggerEditorTabController->popUps->getFileDialogScreenController()->close();
127  }
128  OnTriggerSave(TriggerEditorTabController* triggerEditorTabController): triggerEditorTabController(triggerEditorTabController) {
129  }
130  private:
131  TriggerEditorTabController* triggerEditorTabController;
132  };
133 
134  auto fileName = view->getPrototype() != nullptr?view->getPrototype()->getFileName():"";
135  vector<string> extensions = {
136  "ttrigger"
137  };
139  fileName.empty() == false?Tools::getPathName(fileName):string(),
140  "Save to: ",
141  extensions,
142  Tools::getFileName(fileName),
143  false,
144  new OnTriggerSave(this)
145  );
146  }
147  break;
148  default:
149  showInfoPopUp("Warning", "This command is not supported yet");
150  break;
151  }
152 }
153 
154 void TriggerEditorTabController::onDrop(const string& payload, int mouseX, int mouseY) {
155  if (prototypePhysicsSubController->onDrop(payload, mouseX, mouseY, view->getPrototype()) == true) return;
156  if (prototypeScriptSubController->onDrop(payload, mouseX, mouseY, view->getPrototype()) == true) return;
157  showInfoPopUp("Warning", "You can not drop a file here");
158 }
159 
161 {
162  if (basePropertiesSubController->onChange(node, view->getPrototype(), view->getPrototype()) == true) return;
163  if (prototypeDisplaySubController->onChange(node, view->getPrototype()) == true) return;
164  if (prototypePhysicsSubController->onChange(node, view->getPrototype()) == true) return;
165  if (prototypeScriptSubController->onChange(node, view->getPrototype()) == true) return;
166  //
167  if (node->getId() == "selectbox_outliner") {
168  auto outlinerNode = view->getEditorView()->getScreenController()->getOutlinerSelection();
169  updateDetails(outlinerNode);
170  }
171 }
172 
174  if (basePropertiesSubController->onFocus(node, view->getPrototype()) == true) return;
175 }
176 
178  if (basePropertiesSubController->onUnfocus(node, view->getPrototype()) == true) return;
179 }
180 
182  basePropertiesSubController->onContextMenuRequest(node, mouseX, mouseY, view->getPrototype());
183  prototypePhysicsSubController->onContextMenuRequest(node, mouseX, mouseY, view->getPrototype());
184 }
185 
186 void TriggerEditorTabController::onTooltipShowRequest(GUINode* node, int mouseX, int mouseY) {
187  int tooltipLeft, tooltipTop;
188  if (view->getEditorView()->getCurrentTabTooltipPosition(screenNode, mouseX, mouseY, tooltipLeft, tooltipTop) == false) return;
189  //
190  popUps->getTooltipScreenController()->show(tooltipLeft, tooltipTop, node->getToolTip());
191 }
192 
195 }
196 
198 {
199  if (basePropertiesSubController->onAction(type, node, view->getPrototype()) == true) return;
200  if (prototypeDisplaySubController->onAction(type, node, view->getPrototype()) == true) return;
201  if (prototypePhysicsSubController->onAction(type, node, view->getPrototype()) == true) return;
202  if (prototypeScriptSubController->onAction(type, node, view->getPrototype()) == true) return;
203 }
204 
206  string xml;
207  xml+= "<selectbox-parent-option image=\"resources/engine/images/folder.png\" text=\"" + GUIParser::escape("Prototype") + "\" value=\"" + GUIParser::escape("prototype") + "\">\n";
208  auto prototype = view->getPrototype();
209  if (prototype != nullptr) {
210  basePropertiesSubController->createBasePropertiesXML(prototype, xml);
211  prototypeScriptSubController->createScriptXML(prototype, xml);
212  prototypePhysicsSubController->createOutlinerPhysicsXML(prototype, xml);
213  }
214  xml+= "</selectbox-parent-option>\n";
216 
219  string("<dropdown-option text=\"Property\" value=\"property\" />\n") +
220  string("<dropdown-option text=\"BV\" value=\"boundingvolume\" />\n")
221  );
222 }
223 
224 void TriggerEditorTabController::updateDetails(const string& outlinerNode) {
225  view->getEditorView()->setDetailsContent(string());
226  basePropertiesSubController->updateDetails(view->getPrototype(), outlinerNode);
227  prototypeDisplaySubController->updateDetails(view->getPrototype(), outlinerNode);
228  prototypePhysicsSubController->updateDetails(view->getPrototype(), outlinerNode);
229  prototypePhysicsSubController->getView()->setDisplayBoundingVolume(true);
230  prototypeScriptSubController->updateDetails(view->getPrototype(), outlinerNode);
231 }
232 
234  required_dynamic_cast<GUITextNode*>(screenNode->getNodeById(view->getTabId() + "_tab_text_info"))->setText(text);
235 }
236 
237 void TriggerEditorTabController::showInfoPopUp(const string& caption, const string& message)
238 {
239  popUps->getInfoDialogScreenController()->show(caption, message);
240 }
Prototype definition.
Definition: Prototype.h:55
GUI parser.
Definition: GUIParser.h:40
GUI node base class.
Definition: GUINode.h:64
const string & getToolTip()
Definition: GUINode.h:346
const string & getId()
Definition: GUINode.h:339
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
void show(const string &cwd, const string &captionText, const vector< string > &extensions, const string &fileName, bool enableFilter, Action *applyAction, Action *cancelAction=nullptr, const string &settingsFileName=".filedialog.properties", const string &settingsPathName=string())
Shows the file dialog pop up.
void show(const string &caption, const string &message)
Shows the pop up.
void show(int mouseX, int mouseY, const string &tooltip)
Show tooltip.
Pop ups controller accessor class.
Definition: PopUps.h:29
FileDialogScreenController * getFileDialogScreenController()
Definition: PopUps.h:61
TooltipScreenController * getTooltipScreenController()
Definition: PopUps.h:131
InfoDialogScreenController * getInfoDialogScreenController()
Definition: PopUps.h:75
void onContextMenuRequest(GUIElementNode *node, int mouseX, int mouseY) override
On context menu request.
void onDrop(const string &payload, int mouseX, int mouseY) override
On drop.
void updateInfoText(const MutableString &text)
Update info text line.
void onCommand(TabControllerCommand command) override
On command.
void updateDetails(const string &outlinerNode)
Update details panel.
unique_ptr< PrototypeScriptSubController > prototypeScriptSubController
unique_ptr< PrototypePhysicsSubController > prototypePhysicsSubController
unique_ptr< PrototypeDisplaySubController > prototypeDisplaySubController
void showInfoPopUp(const string &caption, const string &message)
Show the information pop up / modal.
void onAction(GUIActionListenerType type, GUIElementNode *node) override
void onTooltipShowRequest(GUINode *node, int mouseX, int mouseY) override
On tooltip show request.
void saveFile(const string &pathName, const string &fileName)
Saving prototype as tempty prototype.
void setOutlinerAddDropDownContent(const string &xml)
Set outliner add drop down content.
Definition: EditorView.cpp:400
void setOutlinerContent(const string &xml)
Set outliner content.
Definition: EditorView.cpp:396
EditorScreenController * getScreenController()
Definition: EditorView.h:69
void setDetailsContent(const string &xml)
Set details content.
Definition: EditorView.cpp:404
bool getCurrentTabTooltipPosition(GUIScreenNode *screenNode, int mouseX, int mouseY, int &tooltipLeft, int &tooltipTop)
Determine current tab tooltip position.
Definition: EditorView.cpp:439
Console class.
Definition: Console.h:29
Exception base class.
Definition: ExceptionBase.h:19
Mutable utf8 aware string class.
Definition: MutableString.h:23
std::exception Exception
Exception base class.
Definition: Exception.h:18
Tab controller, which connects UI with logic.
Definition: TabController.h:34
Action Interface.
Definition: Action.h:11