diff --git a/source/main/CMakeLists.txt b/source/main/CMakeLists.txt
index a0fc8fd2d3..9d7a102c35 100644
--- a/source/main/CMakeLists.txt
+++ b/source/main/CMakeLists.txt
@@ -120,6 +120,7 @@ set(SOURCE_FILES
gui/mygui/Dialog.{h,cpp}
gui/mygui/GuiPanelBase.h
gui/mygui/WrapsAttribute.h
+ gui/panels/GUI_AngelScriptExamples.{h,cpp}
gui/panels/GUI_ConsoleView.{h,cpp}
gui/panels/GUI_ConsoleWindow.{h,cpp}
gui/panels/GUI_DirectionArrow.{h,cpp}
diff --git a/source/main/gui/panels/GUI_AngelScriptExamples.cpp b/source/main/gui/panels/GUI_AngelScriptExamples.cpp
new file mode 100644
index 0000000000..79acd57156
--- /dev/null
+++ b/source/main/gui/panels/GUI_AngelScriptExamples.cpp
@@ -0,0 +1,151 @@
+/*
+ This source file is part of Rigs of Rods
+ Copyright 2021 tritonas00
+ For more information, see http://www.rigsofrods.org/
+ Rigs of Rods is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 3, as
+ published by the Free Software Foundation.
+ Rigs of Rods is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with Rigs of Rods. If not, see .
+*/
+
+
+#include "GUI_AngelScriptExamples.h"
+#include "ScriptEngine.h"
+
+using namespace RoR;
+
+void AngelScriptExamples::Draw()
+{
+ this->DrawRowSlider("void scaleTruck()", "game.getCurrentTruck().scaleTruck({})", "Scales the truck", 1.f, 1.5f, scale);
+ this->DrawRowText("string getTruckName()", "game.log(game.getCurrentTruck().getTruckName())", "Gets the name of the truck");
+ this->DrawRowText("string getTruckFileName()", "game.log(game.getCurrentTruck().getTruckFileName())", "Gets the name of the truck file");
+ this->DrawRowText("string getSectionConfig()", "game.log(game.getCurrentTruck().getSectionConfig())", "Gets the name of the loaded section for a truck");
+ this->DrawRowText("int getTruckType()", "game.log(' ' + game.getCurrentTruck().getTruckType())", "Gets the type of the truck");
+ this->DrawRowCheckbox("void reset()", "game.getCurrentTruck().reset({})", "Resets the truck", reset, "Keep position");
+ this->DrawRowText("void parkingbrakeToggle()", "game.getCurrentTruck().parkingbrakeToggle()", "Toggles the parking brake");
+ this->DrawRowText("void tractioncontrolToggle()", "game.getCurrentTruck().tractioncontrolToggle()", "Toggles the tracktion control");
+ this->DrawRowText("void antilockbrakeToggle()", "game.getCurrentTruck().antilockbrakeToggle()", "Toggles the anti-lock brakes");
+ this->DrawRowText("void beaconsToggle()", "game.getCurrentTruck().beaconsToggle()", "Toggles the beacons");
+ this->DrawRowText("void toggleCustomParticles()", "game.getCurrentTruck().toggleCustomParticles()", "Toggles the custom particles");
+ this->DrawRowText("int getNodeCount()", "game.log(' ' + game.getCurrentTruck().getNodeCount())", "Gets the total amount of nodes of the truck");
+ this->DrawRowCheckbox("float getTotalMass()", "game.log(' ' + game.getCurrentTruck().getTotalMass({}))", "Gets the total mass of the truck", locked, "With locked");
+ this->DrawRowText("int getWheelNodeCount()", "game.log(' ' + game.getCurrentTruck().getWheelNodeCount())", "Gets the total amount of nodes of the wheels of the truck");
+ this->DrawRowSlider("void setMass()", "game.getCurrentTruck().setMass({})", "Sets the mass of the truck", 1000.f, 10000.f, mass);
+ this->DrawRowText("bool getBrakeLightVisible()", "game.log(' ' + game.getCurrentTruck().getBrakeLightVisible())", "Returns true if the brake light is enabled");
+ this->DrawRowInt("bool getCustomLightVisible()", "game.log(' ' + game.getCurrentTruck().getCustomLightVisible({}))", "Returns true if the custom light with the number is enabled", light);
+ this->DrawRowIntCheckbox("void setCustomLightVisible()", "game.getCurrentTruck().setCustomLightVisible({}, {})", "Enables or disables the custom light", custom_light, visible, "On");
+ this->DrawRowText("bool getBeaconMode()", "game.log(' ' + game.getCurrentTruck().getBeaconMode())", "Gets the mode of the beacon");
+ this->DrawRowInt("void setBlinkType()", "game.getCurrentTruck().setBlinkType({})", "Sets the blinking type", blink);
+ this->DrawRowText("int getBlinkType()", "game.log(' ' + game.getCurrentTruck().getBlinkType())", "Gets the blinking type");
+ this->DrawRowText("bool getCustomParticleMode()", "game.log(' ' + game.getCurrentTruck().getCustomParticleMode())", "Gets the custom particles mode");
+ this->DrawRowText("bool getReverseLightVisible()", "game.log(' ' + game.getCurrentTruck().getReverseLightVisible())", "Returns true if the reverse lights are enabled");
+ this->DrawRowText("float getHeadingDirectionAngle()", "game.log(' ' + game.getCurrentTruck().getHeadingDirectionAngle())", "Returns the angle in which the truck is heading");
+ this->DrawRowText("bool isLocked()", "game.log(' ' + game.getCurrentTruck().isLocked())", "Returns true if a hook of this truck is locked");
+ this->DrawRowText("float getWheelSpeed()", "game.log(' ' + game.getCurrentTruck().getWheelSpeed())", "Gets the current wheel speed of the vehicle");
+ this->DrawRowText("float getSpeed()", "game.log(' ' + game.getCurrentTruck().getSpeed())", "Gets the current speed of the vehicle");
+ this->DrawRowText("vector3 getGForces()", "game.log(' ' + game.getCurrentTruck().getGForces().x + ' ' + game.getCurrentTruck().getGForces().y + ' ' + game.getCurrentTruck().getGForces().z )", "Gets the G-forces that this truck is currently experiencing");
+ this->DrawRowText("float getRotation()", "game.log(' ' + game.getCurrentTruck().getRotation())", "Gets the current rotation of the vehicle");
+ this->DrawRowText("vector3 getVehiclePosition()", "game.log(' ' + game.getCurrentTruck().getVehiclePosition().x + ' ' + game.getCurrentTruck().getVehiclePosition().y + ' ' + game.getCurrentTruck().getVehiclePosition().z )", "Gets the current position of the vehicle");
+ this->DrawRowIntNode("vector3 getNodePosition()", "game.log(' ' + game.getCurrentTruck().getNodePosition({}).x + ' ' + game.getCurrentTruck().getNodePosition({}).y + ' ' + game.getCurrentTruck().getNodePosition({}).z )", "Gets the node position", node, node, node, node);
+}
+
+void AngelScriptExamples::DrawRowSlider(const char* nameStr, std::string codeStr, const char* descStr, float min, float max, float &var_ref)
+{
+ ImGui::PushID(nameStr);
+ ImGui::AlignFirstTextHeightToWidgets();
+ if (ImGui::Selectable(nameStr)) { App::GetScriptEngine()->executeString(fmt::format(codeStr, var_ref)); }
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::PushItemWidth(-1);
+ ImGui::SliderFloat(_LC("Console", ""), &var_ref, min, max);
+ ImGui::PopItemWidth();
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::Text(descStr);
+ ImGui::PopID();
+ ImGui::NextColumn();
+}
+
+void AngelScriptExamples::DrawRowText(const char* nameStr, std::string codeStr, const char* descStr)
+{
+ ImGui::AlignFirstTextHeightToWidgets();
+ if (ImGui::Selectable(nameStr)) { App::GetScriptEngine()->executeString(codeStr); }
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::Text("");
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::Text(descStr);
+ ImGui::NextColumn();
+}
+
+void AngelScriptExamples::DrawRowCheckbox(const char* nameStr, std::string codeStr, const char* descStr, bool &var_ref, const char* label)
+{
+ ImGui::AlignFirstTextHeightToWidgets();
+ if (ImGui::Selectable(nameStr)) { App::GetScriptEngine()->executeString(fmt::format(codeStr, var_ref)); }
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::Checkbox(label, &var_ref);
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::Text(descStr);
+ ImGui::NextColumn();
+}
+
+void AngelScriptExamples::DrawRowInt(const char* nameStr, std::string codeStr, const char* descStr, int &var_ref)
+{
+ ImGui::PushID(nameStr);
+ ImGui::AlignFirstTextHeightToWidgets();
+ if (ImGui::Selectable(nameStr)) { App::GetScriptEngine()->executeString(fmt::format(codeStr, var_ref)); }
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::PushItemWidth(-1);
+ ImGui::InputInt("", &var_ref, 1, 1);
+ ImGui::PopItemWidth();
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::Text(descStr);
+ ImGui::PopID();
+ ImGui::NextColumn();
+}
+
+void AngelScriptExamples::DrawRowIntNode(const char* nameStr, std::string codeStr, const char* descStr, int &var_ref, int &node_x, int &node_y, int &node_z)
+{
+ ImGui::PushID(nameStr);
+ ImGui::AlignFirstTextHeightToWidgets();
+ if (ImGui::Selectable(nameStr)) { App::GetScriptEngine()->executeString(fmt::format(codeStr, node_x, node_y, node_z)); }
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::PushItemWidth(-1);
+ ImGui::InputInt("", &var_ref, 1, 1);
+ ImGui::PopItemWidth();
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::Text(descStr);
+ ImGui::PopID();
+ ImGui::NextColumn();
+}
+
+void AngelScriptExamples::DrawRowIntCheckbox(const char* nameStr, std::string codeStr, const char* descStr, int &var_ref, bool &on, const char* label)
+{
+ ImGui::PushID(nameStr);
+ ImGui::AlignFirstTextHeightToWidgets();
+ if (ImGui::Selectable(nameStr)) { App::GetScriptEngine()->executeString(fmt::format(codeStr, var_ref, on)); }
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::PushItemWidth(96);
+ ImGui::InputInt("", &var_ref, 1, 1);
+ ImGui::PopItemWidth();
+ ImGui::SameLine();
+ ImGui::Checkbox(label, &on);
+ ImGui::NextColumn();
+ ImGui::AlignFirstTextHeightToWidgets();
+ ImGui::Text(descStr);
+ ImGui::PopID();
+ ImGui::NextColumn();
+}
\ No newline at end of file
diff --git a/source/main/gui/panels/GUI_AngelScriptExamples.h b/source/main/gui/panels/GUI_AngelScriptExamples.h
new file mode 100644
index 0000000000..5b6b5dc13b
--- /dev/null
+++ b/source/main/gui/panels/GUI_AngelScriptExamples.h
@@ -0,0 +1,49 @@
+/*
+ This source file is part of Rigs of Rods
+ Copyright 2021 tritonas00
+ For more information, see http://www.rigsofrods.org/
+ Rigs of Rods is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 3, as
+ published by the Free Software Foundation.
+ Rigs of Rods is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with Rigs of Rods. If not, see .
+*/
+
+/// @file
+
+#pragma once
+
+#include "Application.h"
+#include "GUI_ConsoleView.h"
+
+
+namespace RoR {
+
+class AngelScriptExamples
+{
+public:
+ void Draw();
+private:
+ void DrawRowSlider(const char* nameStr, std::string codeStr, const char* descStr, float min, float max, float &var_ref);
+ void DrawRowText(const char* nameStr, std::string codeStr, const char* descStr);
+ void DrawRowCheckbox(const char* nameStr, std::string codeStr, const char* descStr, bool &var_ref, const char* label);
+ void DrawRowInt(const char* nameStr, std::string codeStr, const char* descStr, int &var_ref);
+ void DrawRowIntCheckbox(const char* nameStr, std::string codeStr, const char* descStr, int &var_ref, bool &on, const char* label);
+ void DrawRowIntNode(const char* nameStr, std::string codeStr, const char* descStr, int &var_ref, int &node_x, int &node_y, int &node_z);
+
+ float scale = 1.f;
+ float mass = 1000.f;
+ bool reset = false;
+ bool locked = false;
+ int light = 1;
+ int blink = 1;
+ int node = 1;
+ bool visible = false;
+ int custom_light = 1;
+};
+
+} // namespace RoR
\ No newline at end of file
diff --git a/source/main/gui/panels/GUI_ConsoleWindow.cpp b/source/main/gui/panels/GUI_ConsoleWindow.cpp
index fd8ab5f49e..d00d0205ce 100644
--- a/source/main/gui/panels/GUI_ConsoleWindow.cpp
+++ b/source/main/gui/panels/GUI_ConsoleWindow.cpp
@@ -22,6 +22,7 @@
#include "GUI_ConsoleWindow.h"
#include "GUIManager.h"
+#include "GUI_AngelScriptExamples.h"
#include "Language.h"
@@ -51,10 +52,11 @@ void ConsoleWindow::Draw()
}
if (ImGui::BeginMenu(_LC("Console", "Commands")))
{
- ImGui::Dummy(ImVec2(550.f, 1.f)); // Manually resize width (DearIMGUI bug workaround)
+ ImGui::Dummy(ImVec2(700.f, 1.f)); // Manually resize width (DearIMGUI bug workaround)
ImGui::Columns(3);
ImGui::SetColumnWidth(0, 100); // TODO: Calculate dynamically
ImGui::SetColumnWidth(1, 170); // TODO: Calculate dynamically
+ ImGui::SetColumnWidth(2, 500); // TODO: Calculate dynamically
for (auto& cmd_pair: App::GetConsole()->GetCommands())
{
@@ -72,6 +74,22 @@ void ConsoleWindow::Draw()
ImGui::Columns(1); // reset
ImGui::EndMenu();
}
+#ifdef USE_ANGELSCRIPT
+ ImGui::SetNextWindowSize(ImVec2((ImGui::GetIO().DisplaySize.x / 2), (ImGui::GetIO().DisplaySize.y / 1.5)));
+ if (ImGui::BeginMenu(_LC("Console", "AngelScript")))
+ {
+ ImGui::Dummy(ImVec2(720.f, 1.f)); // Manually resize width (DearIMGUI bug workaround)
+ ImGui::Columns(3);
+ ImGui::SetColumnWidth(0, 230);
+ ImGui::SetColumnWidth(1, 160);
+ ImGui::SetColumnWidth(2, 400);
+
+ AngelScriptExamples().Draw();
+
+ ImGui::Columns(1); // reset
+ ImGui::EndMenu();
+ }
+#endif
ImGui::EndMenuBar();
}