TDME2 1.9.121
PrototypeDisplaySubController.cpp
Go to the documentation of this file.
2
3#include <array>
4
5#include <tdme/tdme.h>
17#include <tdme/gui/GUI.h>
18#include <tdme/gui/GUIParser.h>
19#include <tdme/math/Vector2.h>
20#include <tdme/math/Vector3.h>
21#include <tdme/math/Vector4.h>
35
36using std::array;
37
65
66PrototypeDisplaySubController::PrototypeDisplaySubController(EditorView* editorView, TabView* tabView, PrototypePhysicsSubView* physicsView)
67{
68 this->editorView = editorView;
69 this->tabView = tabView;
71 this->physicsView = physicsView;
72 this->popUps = editorView->getPopUps();
73}
74
76 delete view;
77}
78
80{
81 return view;
82}
83
85{
86 this->screenNode = screenNode;
87}
88
90{
91 return displayShadowing;
92}
93
95{
96 return displayGround;
97}
98
100{
102}
103
105 xml+= " <selectbox-option image=\"resources/engine/images/rendering.png\" text=\"Rendering\" value=\"rendering\" />\n";
106}
107
110 "<template id=\"details_rendering\" src=\"resources/engine/gui/template_details_rendering.xml\" />\n"
111 );
112
113 string shaderXML;
114 {
115 for (auto& shader: Engine::getRegisteredShader(Engine::ShaderType::SHADERTYPE_OBJECT3D)) {
116 shaderXML =
117 shaderXML +
118 "<dropdown-option text=\"" +
119 GUIParser::escapeQuotes(shader) +
120 "\" value=\"" +
121 GUIParser::escapeQuotes(shader) +
122 "\" " +
123 (shader == "default"?"selected=\"true\" " : "") +
124 "/>\n";
125 }
126 }
127
128 try {
129 // physics
130 required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("details_rendering"))->getActiveConditions().add("open");
131 if (prototype->getType() == Prototype_Type::MODEL) required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("details_rendering"))->getActiveConditions().add("shader");
132
133 required_dynamic_cast<GUIParentNode*>(screenNode->getInnerNodeById("rendering_shader"))->replaceSubNodes(shaderXML, true);
134 required_dynamic_cast<GUIParentNode*>(screenNode->getInnerNodeById("rendering_distance_shader"))->replaceSubNodes(shaderXML, true);
135
136 required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_shader"))->getController()->setValue(MutableString(prototype->getShader()));
137 required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_distance_shader"))->getController()->setValue(MutableString(prototype->getDistanceShader()));
138 required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_distanceshader_distance"))->getController()->setValue(MutableString(prototype->getDistanceShaderDistance()));
139 required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_contributes_shadows"))->getController()->setValue(MutableString(prototype->isContributesShadows() == true?"1":""));
140 required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_receives_shadows"))->getController()->setValue(MutableString(prototype->isReceivesShadows() == true?"1":""));
141 required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_render_groups"))->getController()->setValue(MutableString(prototype->isRenderGroups() == true?"1":""));
142
143 } catch (Exception& exception) {
144 Console::println(string("PrototypeDisplaySubController::setDisplayDetails(): An error occurred: ") + exception.what());
145 showErrorPopUp("Warning", (string(exception.what())));
146 }
147
148 //
149 setDisplayShaderDetails(prototype);
151}
152
153void PrototypeDisplaySubController::updateDetails(Prototype* prototype, const string& outlinerNode) {
154 if (outlinerNode == "rendering") setDisplayDetails(prototype);
155}
156
158 try {
159 prototype->setShader(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_shader"))->getController()->getValue().getString());
160 prototype->setDistanceShader(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_distance_shader"))->getController()->getValue().getString());
161 prototype->setDistanceShaderDistance(Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_distanceshader_distance"))->getController()->getValue().getString()));
162 prototype->setContributesShadows(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_contributes_shadows"))->getController()->getValue().getString() == "1");
163 prototype->setReceivesShadows(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_receives_shadows"))->getController()->getValue().getString() == "1");
164 prototype->setRenderGroups(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById("rendering_render_groups"))->getController()->getValue().getString() == "1");
165 } catch (Exception& exception) {
166 Console::println(string("PrototypeDisplaySubController::applyDisplayDetails(): An error occurred: ") + exception.what());
167 showErrorPopUp("Warning", (string(exception.what())));
168 }
169 setDisplayShaderDetails(prototype);
171}
172
173void PrototypeDisplaySubController::createDisplayShaderDetailsXML(Prototype* prototype, const string& shaderParameterPrefix, const string& shader, const EntityShaderParameters& shaderParameters, string& xml) {
174 auto defaultShaderParameters = Engine::getShaderParameterDefaults(shader);
175 if (defaultShaderParameters.empty() == false) {
176 for (auto& parameterIt: defaultShaderParameters) {
177 auto& parameterName = parameterIt.first;
178 auto parameter = shaderParameters.getShaderParameter(parameterName);
179 auto parameterValue = parameter.toString();
180 auto parameterType = "string";
181 switch (parameter.getType()) {
182 case ShaderParameter::TYPE_FLOAT:
183 xml+= "<template name=\"" + GUIParser::escapeQuotes(parameterName) + "\" id=\"" + GUIParser::escapeQuotes(shaderParameterPrefix + parameterName) + "\" src=\"resources/engine/gui/template_details_rendering_shader_float.xml\" value=\"" + parameterValue + "\" />\n";
184 break;
185 case ShaderParameter::TYPE_INTEGER:
186 xml+= "<template name=\"" + GUIParser::escapeQuotes(parameterName) + "\" id=\"" + GUIParser::escapeQuotes(shaderParameterPrefix + parameterName) + "\" src=\"resources/engine/gui/template_details_rendering_shader_int.xml\" value=\"" + parameterValue + "\" />\n";
187 break;
188 case ShaderParameter::TYPE_BOOLEAN:
189 xml+= "<template name=\"" + GUIParser::escapeQuotes(parameterName) + "\" id=\"" + GUIParser::escapeQuotes(shaderParameterPrefix + parameterName) + "\" src=\"resources/engine/gui/template_details_rendering_shader_bool.xml\" value=\"" + parameterValue + "\" />\n";
190 break;
191 case ShaderParameter::TYPE_VECTOR2:
192 {
193 auto vec2 = parameter.getVector2Value();
194 xml+= "<template name=\"" + GUIParser::escapeQuotes(parameterName) + "\" id=\"" + GUIParser::escapeQuotes(shaderParameterPrefix + parameterName) + "\" src=\"resources/engine/gui/template_details_rendering_shader_vector2.xml\" value_x=\"" + to_string(vec2.getX()) + "\" value_y=\"" + to_string(vec2.getY()) + "\" />\n";
195 }
196 break;
197 case ShaderParameter::TYPE_VECTOR3:
198 {
199 auto vec3 = parameter.getVector3Value();
200 xml+= "<template name=\"" + GUIParser::escapeQuotes(parameterName) + "\" id=\"" + GUIParser::escapeQuotes(shaderParameterPrefix + parameterName) + "\" src=\"resources/engine/gui/template_details_rendering_shader_vector3.xml\" value_x=\"" + to_string(vec3.getX()) + "\" value_y=\"" + to_string(vec3.getY()) + "\" value_z=\"" + to_string(vec3.getZ()) + "\" />\n";
201 }
202 break;
203 case ShaderParameter::TYPE_VECTOR4:
204 {
205 auto vec4 = parameter.getVector4Value();
206 xml+= "<template name=\"" + GUIParser::escapeQuotes(parameterName) + "\" id=\"" + GUIParser::escapeQuotes(shaderParameterPrefix + parameterName) + "\" src=\"resources/engine/gui/template_details_rendering_shader_vector4.xml\" value_x=\"" + to_string(vec4.getX()) + "\" value_y=\"" + to_string(vec4.getY()) + "\" value_z=\"" + to_string(vec4.getZ()) + "\" value_w=\"" + to_string(vec4.getW()) + "\" />\n";
207 }
208 break;
209 case ShaderParameter::TYPE_NONE:
210 break;
211 }
212 }
213 }
214 if (xml.empty() == false) {
215 xml+=
216 string("<space height=\"5\" />") + string("\n") +
217 string("<menu-separator />") + string("\n") +
218 string("<space height=\"5\" />") + string("\n");
219
220 }
221}
222
224 string xml;
225 createDisplayShaderDetailsXML(prototype, "rendering.shader.", prototype->getShader(), prototype->getShaderParameters(), xml);
226 try {
227 required_dynamic_cast<GUIParentNode*>(screenNode->getNodeById("rendering_shader_details"))->replaceSubNodes(xml, false);
228 } catch (Exception& exception) {
229 Console::println(string("PrototypeDisplaySubController::setDisplayShaderDetails(): An error occurred: ") + exception.what());
230 showErrorPopUp("Warning", (string(exception.what())));
231 }
232}
233
235 string xml;
236 createDisplayShaderDetailsXML(prototype, "rendering.distanceshader.", prototype->getDistanceShader(), prototype->getDistanceShaderParameters(), xml);
237 try {
238 required_dynamic_cast<GUIParentNode*>(screenNode->getNodeById("rendering_distanceshader_details"))->replaceSubNodes(xml, false);
239 } catch (Exception& exception) {
240 Console::println(string("PrototypeDisplaySubController::setDisplayDistanceShaderDetails(): An error occurred: ") + exception.what());
241 showErrorPopUp("Warning", (string(exception.what())));
242 }
243}
244
245void PrototypeDisplaySubController::applyDisplayShaderDetails(Prototype* prototype, const string& shaderParameterPrefix, const string& parameterName, EntityShaderParameters& shaderParameters) {
246 try {
247 auto parameter = shaderParameters.getShaderParameter(parameterName);
248 switch (parameter.getType()) {
249 case ShaderParameter::TYPE_FLOAT:
250 shaderParameters.setShaderParameter(
251 parameterName,
253 Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName))->getController()->getValue().getString())
254 )
255 );
256 break;
257 case ShaderParameter::TYPE_INTEGER:
258 shaderParameters.setShaderParameter(
259 parameterName,
261 Integer::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName))->getController()->getValue().getString())
262 )
263 );
264 break;
265 case ShaderParameter::TYPE_BOOLEAN:
266 shaderParameters.setShaderParameter(
267 parameterName,
269 required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName))->getController()->getValue().getString() == "1"
270 )
271 );
272 break;
273 case ShaderParameter::TYPE_VECTOR2:
274 shaderParameters.setShaderParameter(
275 parameterName,
277 Vector2(
278 Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName + "_x"))->getController()->getValue().getString()),
279 Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName + "_y"))->getController()->getValue().getString())
280 )
281 )
282 );
283 break;
284 case ShaderParameter::TYPE_VECTOR3:
285 shaderParameters.setShaderParameter(
286 parameterName,
288 Vector3(
289 Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName + "_x"))->getController()->getValue().getString()),
290 Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName + "_y"))->getController()->getValue().getString()),
291 Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName + "_z"))->getController()->getValue().getString())
292 )
293 )
294 );
295 break;
296 case ShaderParameter::TYPE_VECTOR4:
297 shaderParameters.setShaderParameter(
298 parameterName,
300 Vector4(
301 Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName + "_x"))->getController()->getValue().getString()),
302 Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName + "_y"))->getController()->getValue().getString()),
303 Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName + "_z"))->getController()->getValue().getString()),
304 Float::parse(required_dynamic_cast<GUIElementNode*>(screenNode->getNodeById(shaderParameterPrefix + parameterName + "_w"))->getController()->getValue().getString())
305 )
306 )
307 );
308 break;
309 case ShaderParameter::TYPE_NONE:
310 break;
311 }
312 } catch (Exception& exception) {
313 Console::println(string("PrototypeDisplaySubController::applyDisplayShaderDetails(): An error occurred: ") + exception.what());
314 showErrorPopUp("Warning", (string(exception.what())));
315 }
316}
317
319 for (auto& applyDisplayNode: applyDisplayNodes) {
320 if (node->getId() == applyDisplayNode) {
321 applyDisplayDetails(prototype);
322 break;
323 }
324 }
325 for (auto& applyDisplayUpdateRenderingNode: applyDisplayUpdateRenderingNodes) {
326 if (node->getId() == applyDisplayUpdateRenderingNode) {
328 break;
329 }
330 }
331 if (StringTools::startsWith(node->getId(), "rendering.shader.") == true) {
332 auto shaderParameters = prototype->getShaderParameters();
333 applyDisplayShaderDetails(prototype, "rendering.shader.", StringTools::substring(node->getId(), string("rendering.shader.").size(), node->getId().size()), shaderParameters);
334 prototype->setShaderParameters(shaderParameters);
335 view->updateShaderParameters(prototype);
336 }
337 if (StringTools::startsWith(node->getId(), "rendering.distanceshader.") == true) {
338 auto distanceShaderParameters = prototype->getDistanceShaderParameters();
339 applyDisplayShaderDetails(prototype, "rendering.distanceshader.", StringTools::substring(node->getId(), string("rendering.distanceshader.").size(), node->getId().size()), distanceShaderParameters);
340 prototype->setDistanceShaderParameters(distanceShaderParameters);
341 view->updateShaderParameters(prototype);
342 }
343 if (node->getId() == tabView->getTabId() + "_tab_checkbox_grid") view->setDisplayGroundPlate(node->getController()->getValue().equals("1"));
344}
345
346void PrototypeDisplaySubController::showErrorPopUp(const string& caption, const string& message)
347{
348 popUps->getInfoDialogScreenController()->show(caption, message);
349}
Engine main class.
Definition: Engine.h:122
TDME2 engine entity shader parameters.
void setShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set shader parameter for given parameter name.
const ShaderParameter getShaderParameter(const string &parameterName) const
Returns shader parameter for given parameter name, if the value does not exist, the default will be r...
Shader parameter model class.
const string toString(float value) const
Prototype definition.
Definition: Prototype.h:49
void setContributesShadows(bool contributesShadows)
Enable/disable contributes shadows.
Definition: Prototype.h:343
void setShader(const string &id)
Set shader.
Definition: Prototype.h:406
void setDistanceShaderParameters(const EntityShaderParameters &parameters)
Set distance shader parameters.
Definition: Prototype.h:472
const string & getShader()
Get shader.
Definition: Prototype.h:398
float getDistanceShaderDistance()
Get distance shader distance.
Definition: Prototype.h:432
bool isRenderGroups()
Is using render groups.
Definition: Prototype.h:382
const string & getDistanceShader()
Get distance shader.
Definition: Prototype.h:415
void setDistanceShaderDistance(float distance)
Set distance shader distance.
Definition: Prototype.h:440
void setDistanceShader(const string &id)
Set distance shader.
Definition: Prototype.h:423
const EntityShaderParameters & getDistanceShaderParameters()
Get distance shader parameters.
Definition: Prototype.h:464
void setShaderParameters(EntityShaderParameters &parameters)
Set shader parameters.
Definition: Prototype.h:456
void setRenderGroups(bool renderGroups)
Set using render groups.
Definition: Prototype.h:390
const EntityShaderParameters & getShaderParameters()
Get shader parameters.
Definition: Prototype.h:448
void setReceivesShadows(bool receivesShadows)
Enable/disable receives shadows.
Definition: Prototype.h:358
GUI parser.
Definition: GUIParser.h:39
GUI node controller base class.
virtual const MutableString & getValue()=0
GUI node base class.
Definition: GUINode.h:63
const string & getId()
Definition: GUINode.h:329
GUINodeController * getController()
Definition: GUINode.h:586
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:57
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
GUINode * getInnerNodeById(const string &nodeId)
Get inner GUI node by id.
2D vector 2 class
Definition: Vector2.h:19
3D vector 3 class
Definition: Vector3.h:22
3D vector 4 class
Definition: Vector4.h:19
void show(const string &caption, const string &message)
Shows the pop up.
InfoDialogScreenController * getInfoDialogScreenController()
Definition: PopUps.h:49
void createDisplayPropertiesXML(Prototype *prototype, string &xml)
Create display properties XML.
void createDisplayShaderDetailsXML(Prototype *prototype, const string &shaderParameterPrefix, const string &shader, const EntityShaderParameters &shaderParameters, string &xml)
Create display shader details XML.
void updateDetails(Prototype *prototype, const string &outlinerNode)
Update details panel.
void onValueChanged(GUIElementNode *node, Prototype *prototype)
On value changed.
void showErrorPopUp(const string &caption, const string &message)
Shows the error pop up.
void applyDisplayShaderDetails(Prototype *prototype, const string &shaderParameterPrefix, const string &parameterName, EntityShaderParameters &shaderParameters)
Apply display shader details.
void setDisplayDistanceShaderDetails(Prototype *prototype)
Set display distance shader details.
void updateShaderParameters(Prototype *prototype)
Update shader parameters.
void setDisplayGroundPlate(bool groundPlate)
Set up ground plate visibility.
void setDetailsContent(const string &xml)
Set details content.
Definition: EditorView.cpp:218
Console class.
Definition: Console.h:26
Float class.
Definition: Float.h:23
Integer class.
Definition: Integer.h:26
Mutable string class.
Definition: MutableString.h:16
bool equals(const string &s2) const
Equals.
String tools class.
Definition: StringTools.h:20
std::exception Exception
Exception base class.
Definition: Exception.h:19
virtual void updateRendering()=0
Update rendering.
virtual const string & getTabId()=0