TDME2  1.9.200
EnvMapEditorTabController.cpp
Go to the documentation of this file.
2 
3 #include <array>
4 #include <string>
5 
6 #include <tdme/tdme.h>
8 #include <tdme/engine/Entity.h>
12 #include <tdme/gui/nodes/GUINode.h>
17 #include <tdme/gui/GUI.h>
18 #include <tdme/gui/GUIParser.h>
19 #include <tdme/math/Vector3.h>
28 #include <tdme/utilities/Action.h>
29 #include <tdme/utilities/Console.h>
32 #include <tdme/utilities/Float.h>
33 #include <tdme/utilities/Integer.h>
35 
36 using std::array;
37 using std::string;
38 
40 
67 
68 EnvMapEditorTabController::EnvMapEditorTabController(EnvMapEditorTabView* view)
69 {
70  this->view = view;
71  this->popUps = view->getPopUps();
72 }
73 
75 }
76 
78 {
79  this->screenNode = screenNode;
80 }
81 
83 {
84 }
85 
87 {
88  switch (command) {
89  case COMMAND_SAVE:
90  {
91  auto fileName = view->getPrototype() != nullptr?view->getPrototype()->getFileName():"";
92  try {
93  if (fileName.empty() == true) throw ExceptionBase("Could not save file. No filename known");
94  view->saveFile(
95  Tools::getPathName(fileName),
96  Tools::getFileName(fileName)
97  );
98  } catch (Exception& exception) {
99  showInfoPopUp("Warning", string(exception.what()));
100  }
101  }
102  break;
103  case COMMAND_SAVEAS:
104  {
105  class OnEnvMapSave: public virtual Action
106  {
107  public:
108  void performAction() override {
109  try {
110  envMapEditorTabController->view->saveFile(
111  envMapEditorTabController->popUps->getFileDialogScreenController()->getPathName(),
112  envMapEditorTabController->popUps->getFileDialogScreenController()->getFileName()
113  );
114  } catch (Exception& exception) {
115  envMapEditorTabController->showInfoPopUp("Warning", string(exception.what()));
116  }
117  envMapEditorTabController->popUps->getFileDialogScreenController()->close();
118  }
119  OnEnvMapSave(EnvMapEditorTabController* envMapEditorTabController): envMapEditorTabController(envMapEditorTabController) {
120  }
121  private:
122  EnvMapEditorTabController* envMapEditorTabController;
123  };
124 
125  auto fileName = view->getPrototype() != nullptr?view->getPrototype()->getFileName():"";
126  vector<string> extensions = {
127  "tenvmap"
128  };
130  fileName.empty() == false?Tools::getPathName(fileName):string(),
131  "Save to: ",
132  extensions,
133  Tools::getFileName(fileName),
134  false,
135  new OnEnvMapSave(this)
136  );
137  }
138  break;
139  default:
140  showInfoPopUp("Warning", "This command is not supported yet");
141  break;
142  }
143 }
144 
145 void EnvMapEditorTabController::onDrop(const string& payload, int mouseX, int mouseY) {
146  showInfoPopUp("Warning", "You can not drop a file here");
147 }
148 
149 void EnvMapEditorTabController::showInfoPopUp(const string& caption, const string& message)
150 {
151  popUps->getInfoDialogScreenController()->show(caption, message);
152 }
153 
155 {
156  for (const auto& applyNode: applyNodesRenderPasses) {
157  if (node->getId() == applyNode) {
159  break;
160  }
161  }
162  for (const auto& applyNode: applyNodesLocation) {
163  if (node->getId() == applyNode) {
164  applyLocation();
165  break;
166  }
167  }
168 }
169 
171 }
172 
174 }
175 
177 }
178 
179 void EnvMapEditorTabController::onTooltipShowRequest(GUINode* node, int mouseX, int mouseY) {
180  int tooltipLeft, tooltipTop;
181  if (view->getEditorView()->getCurrentTabTooltipPosition(screenNode, mouseX, mouseY, tooltipLeft, tooltipTop) == false) return;
182  //
183  popUps->getTooltipScreenController()->show(tooltipLeft, tooltipTop, node->getToolTip());
184 }
185 
188 }
189 
191 {
192 }
193 
195  string xml;
196  xml+= "<selectbox-option image=\"resources/engine/images/folder.png\" text=\"" + GUIParser::escape("Prototype") + "\" value=\"" + GUIParser::escape("prototype") + "\" />\n";
198 
201  string("<dropdown-option text=\"Property\" value=\"property\" />\n")
202  );
203 }
204 
205 void EnvMapEditorTabController::updateDetails(const string& outlinerNode) {
207  string("<template id=\"details_environmentmapping\" src=\"resources/engine/gui/template_details_environmentmapping.xml\" />\n") +
208  string("<template id=\"details_location\" src=\"resources/engine/gui/template_details_location.xml\" />\n")
209  );
210 
211  try {
212  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("details_environmentmapping"))->getActiveConditions().add("open");
213  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("details_location"))->getActiveConditions().add("open");
214 
215  auto frequency = view->getEnvironmentMapFrequency();
216  switch (frequency) {
217  case 60LL * 60LL * 24LL * 1000LL:
218  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_frequency_details"))->getActiveConditions().removeAll();
219  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_frequency"))->getController()->setValue(MutableString(1));
220  break;
221  case 0LL:
222  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_frequency_details"))->getActiveConditions().removeAll();
223  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_frequency"))->getController()->setValue(MutableString(2));
224  break;
225  default:
226  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_frequency"))->getController()->setValue(MutableString(3));
227  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_frequency_details"))->getActiveConditions().set("custom");
228  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_frequency_value"))->getController()->setValue(MutableString(static_cast<int32_t>(frequency)));
229  }
230 
231  auto renderPassMask = view->getEnvironmentMapRenderPassMask();
232  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_renderpass_standard"))->getController()->setValue(MutableString((renderPassMask & Entity::RENDERPASS_STANDARD) == Entity::RENDERPASS_STANDARD?"1":""));
233  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_renderpass_sky"))->getController()->setValue(MutableString((renderPassMask & Entity::RENDERPASS_SKY) == Entity::RENDERPASS_SKY?"1":""));
234  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_renderpass_terrain"))->getController()->setValue(MutableString((renderPassMask & Entity::RENDERPASS_TERRAIN) == Entity::RENDERPASS_TERRAIN?"1":""));
235  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_renderpass_water"))->getController()->setValue(MutableString((renderPassMask & Entity::RENDERPASS_WATER) == Entity::RENDERPASS_WATER?"1":""));
236  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_renderpass_postprocessing"))->getController()->setValue(MutableString((renderPassMask & Entity::RENDERPASS_POST_POSTPROCESSING) == Entity::RENDERPASS_POST_POSTPROCESSING?"1":""));
237 
238  auto environmentMapTranslation = view->getEnvironmentMapTranslation();
239  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("location_translation_x"))->getController()->setValue(MutableString(environmentMapTranslation.getX()));
240  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("location_translation_y"))->getController()->setValue(MutableString(environmentMapTranslation.getY()));
241  required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("location_translation_z"))->getController()->setValue(MutableString(environmentMapTranslation.getZ()));
242  } catch (Exception& exception) {
243  Console::println("EnvMapEditorTabController::updateDetails(): An error occurred: " + string(exception.what()));
244  showInfoPopUp("Warning", string(exception.what()));
245  }
246 }
247 
249  auto prototype = view->getPrototype();
250  if (prototype == nullptr) return;
251 
252  //
253  try {
254  //
255  int64_t frequency = -1LL;
256  switch (Integer::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_frequency"))->getController()->getValue().getString())) {
257  case 1:
258  frequency = 60LL * 60LL * 24LL * 1000LL;
259  break;
260  case 2:
261  frequency = 0LL;
262  break;
263  case 3:
264  frequency = Integer::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_frequency_value"))->getController()->getValue().getString());
265  break;
266  }
267  view->setEnvironmentMapFrequency(frequency);
268  prototype->setEnvironmentMapTimeRenderUpdateFrequency(frequency);
269 
270  //
271  int32_t renderPassMask = 0;
272  renderPassMask+= required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_renderpass_standard"))->getController()->getValue().equals("1") == true?Entity::RENDERPASS_STANDARD:0;
273  renderPassMask+= required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_renderpass_sky"))->getController()->getValue().equals("1") == true?Entity::RENDERPASS_SKY:0;
274  renderPassMask+= required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_renderpass_terrain"))->getController()->getValue().equals("1") == true?Entity::RENDERPASS_TERRAIN:0;
275  renderPassMask+= required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_renderpass_water"))->getController()->getValue().equals("1") == true?Entity::RENDERPASS_WATER:0;
276  renderPassMask+= required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendersettings_renderpass_postprocessing"))->getController()->getValue().equals("1") == true?Entity::RENDERPASS_POST_POSTPROCESSING:0;
277  view->setEnvironmentMapRenderPassMask(renderPassMask);
278  prototype->setEnvironmentMapRenderPassMask(renderPassMask);
279  } catch (Exception& exception) {
280  Console::println("EnvMapEditorTabController::applyRenderPasses(): An error occurred: " + string(exception.what()));
281  showInfoPopUp("Warning", string(exception.what()));
282  }
283 }
284 
286  try {
287  Vector3 environmentMapTranslation(
288  Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("location_translation_x"))->getController()->getValue().getString()),
289  Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("location_translation_y"))->getController()->getValue().getString()),
290  Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("location_translation_z"))->getController()->getValue().getString())
291  );
292  view->setEnvironmentMapTranslation(environmentMapTranslation);
293  } catch (Exception& exception) {
294  Console::println("EnvMapEditorTabController::applyLocation(): An error occurred: " + string(exception.what()));
295  showInfoPopUp("Warning", string(exception.what()));
296  }
297 }
298 
300  required_dynamic_cast<GUITextNode*>(screenNode->getNodeById(view->getTabId() + "_tab_text_info"))->setText(text);
301 }
Engine entity.
Definition: Entity.h:30
Prototype definition.
Definition: Prototype.h:55
GUI parser.
Definition: GUIParser.h:40
GUI element node conditions.
GUI node controller base class.
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.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
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.
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 tenvmap prototype.
void setEnvironmentMapTranslation(const Vector3 &translation)
Set environment map translation.
void setEnvironmentMapRenderPassMask(int32_t renderPassMask)
Set environment map render passes.
void setEnvironmentMapFrequency(int64_t frequency)
Set environment map frequency.
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
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
Float class.
Definition: Float.h:27
Integer class.
Definition: Integer.h:25
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