From 0e20a10218ab9f641e2ebd89258e89ba71c0268d Mon Sep 17 00:00:00 2001 From: tritonas00 Date: Sun, 29 Aug 2021 11:52:21 +0300 Subject: [PATCH 1/6] added AS shortcuts in console --- source/main/CMakeLists.txt | 1 + .../gui/panels/GUI_AngelScriptExamples.cpp | 151 ++++++++++++++++++ .../main/gui/panels/GUI_AngelScriptExamples.h | 49 ++++++ source/main/gui/panels/GUI_ConsoleWindow.cpp | 20 ++- 4 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 source/main/gui/panels/GUI_AngelScriptExamples.cpp create mode 100644 source/main/gui/panels/GUI_AngelScriptExamples.h diff --git a/source/main/CMakeLists.txt b/source/main/CMakeLists.txt index 02ead1556f..ccc4ab44bd 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 6797f518fd..5c37afa05c 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(); } From eaefa93e75d1e90c81a6acdbb7b979ea09e4e390 Mon Sep 17 00:00:00 2001 From: tritonas00 Date: Mon, 30 Aug 2021 03:19:09 +0300 Subject: [PATCH 2/6] use instance - fixed second column --- source/main/gui/panels/GUI_ConsoleWindow.cpp | 2 +- source/main/gui/panels/GUI_ConsoleWindow.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/source/main/gui/panels/GUI_ConsoleWindow.cpp b/source/main/gui/panels/GUI_ConsoleWindow.cpp index 5c37afa05c..e37f7e7e24 100644 --- a/source/main/gui/panels/GUI_ConsoleWindow.cpp +++ b/source/main/gui/panels/GUI_ConsoleWindow.cpp @@ -84,7 +84,7 @@ void ConsoleWindow::Draw() ImGui::SetColumnWidth(1, 160); ImGui::SetColumnWidth(2, 400); - AngelScriptExamples().Draw(); + m_angelscript_examples.Draw(); ImGui::Columns(1); // reset ImGui::EndMenu(); diff --git a/source/main/gui/panels/GUI_ConsoleWindow.h b/source/main/gui/panels/GUI_ConsoleWindow.h index d500602a52..eb13959995 100644 --- a/source/main/gui/panels/GUI_ConsoleWindow.h +++ b/source/main/gui/panels/GUI_ConsoleWindow.h @@ -28,6 +28,7 @@ #include "Application.h" #include "GUI_ConsoleView.h" #include "OgreImGui.h" +#include "GUI_AngelScriptExamples.h" #include #include @@ -49,6 +50,8 @@ class ConsoleWindow private: + AngelScriptExamples m_angelscript_examples; + static int TextEditCallback(ImGuiTextEditCallbackData *data); void TextEditCallbackProc(ImGuiTextEditCallbackData *data); From 76985bf48610b2c4d4aab511f944424ec6eeff41 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 4 Dec 2021 17:41:11 +0100 Subject: [PATCH 3/6] AngelScriptExamples UI: use console command 'as' Because it echoes the code and also reports error if used in main menu. --- .../gui/panels/GUI_AngelScriptExamples.cpp | 22 +++++++++++++------ .../main/gui/panels/GUI_AngelScriptExamples.h | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/source/main/gui/panels/GUI_AngelScriptExamples.cpp b/source/main/gui/panels/GUI_AngelScriptExamples.cpp index 79acd57156..ece4eccbbd 100644 --- a/source/main/gui/panels/GUI_AngelScriptExamples.cpp +++ b/source/main/gui/panels/GUI_AngelScriptExamples.cpp @@ -58,7 +58,7 @@ void AngelScriptExamples::DrawRowSlider(const char* nameStr, std::string codeStr { ImGui::PushID(nameStr); ImGui::AlignFirstTextHeightToWidgets(); - if (ImGui::Selectable(nameStr)) { App::GetScriptEngine()->executeString(fmt::format(codeStr, var_ref)); } + if (ImGui::Selectable(nameStr)) { this->ExecuteString(fmt::format(codeStr, var_ref)); } ImGui::NextColumn(); ImGui::AlignFirstTextHeightToWidgets(); ImGui::PushItemWidth(-1); @@ -74,7 +74,7 @@ void AngelScriptExamples::DrawRowSlider(const char* nameStr, std::string codeStr void AngelScriptExamples::DrawRowText(const char* nameStr, std::string codeStr, const char* descStr) { ImGui::AlignFirstTextHeightToWidgets(); - if (ImGui::Selectable(nameStr)) { App::GetScriptEngine()->executeString(codeStr); } + if (ImGui::Selectable(nameStr)) { this->ExecuteString(codeStr); } ImGui::NextColumn(); ImGui::AlignFirstTextHeightToWidgets(); ImGui::Text(""); @@ -87,7 +87,7 @@ void AngelScriptExamples::DrawRowText(const char* nameStr, std::string codeStr, 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)); } + if (ImGui::Selectable(nameStr)) { this->ExecuteString(fmt::format(codeStr, var_ref)); } ImGui::NextColumn(); ImGui::AlignFirstTextHeightToWidgets(); ImGui::Checkbox(label, &var_ref); @@ -101,7 +101,7 @@ void AngelScriptExamples::DrawRowInt(const char* nameStr, std::string codeStr, c { ImGui::PushID(nameStr); ImGui::AlignFirstTextHeightToWidgets(); - if (ImGui::Selectable(nameStr)) { App::GetScriptEngine()->executeString(fmt::format(codeStr, var_ref)); } + if (ImGui::Selectable(nameStr)) { this->ExecuteString(fmt::format(codeStr, var_ref)); } ImGui::NextColumn(); ImGui::AlignFirstTextHeightToWidgets(); ImGui::PushItemWidth(-1); @@ -118,7 +118,7 @@ void AngelScriptExamples::DrawRowIntNode(const char* nameStr, std::string codeSt { ImGui::PushID(nameStr); ImGui::AlignFirstTextHeightToWidgets(); - if (ImGui::Selectable(nameStr)) { App::GetScriptEngine()->executeString(fmt::format(codeStr, node_x, node_y, node_z)); } + if (ImGui::Selectable(nameStr)) { this->ExecuteString(fmt::format(codeStr, node_x, node_y, node_z)); } ImGui::NextColumn(); ImGui::AlignFirstTextHeightToWidgets(); ImGui::PushItemWidth(-1); @@ -135,7 +135,7 @@ void AngelScriptExamples::DrawRowIntCheckbox(const char* nameStr, std::string co { ImGui::PushID(nameStr); ImGui::AlignFirstTextHeightToWidgets(); - if (ImGui::Selectable(nameStr)) { App::GetScriptEngine()->executeString(fmt::format(codeStr, var_ref, on)); } + if (ImGui::Selectable(nameStr)) { this->ExecuteString(fmt::format(codeStr, var_ref, on)); } ImGui::NextColumn(); ImGui::AlignFirstTextHeightToWidgets(); ImGui::PushItemWidth(96); @@ -148,4 +148,12 @@ void AngelScriptExamples::DrawRowIntCheckbox(const char* nameStr, std::string co ImGui::Text(descStr); ImGui::PopID(); ImGui::NextColumn(); -} \ No newline at end of file +} + +void AngelScriptExamples::ExecuteString(std::string const& code) +{ + // Use console command 'as' because it echoes the entered code, + // which allows the user to see it and learn. + // Also reports error when not usable, i.e. in main menu. + App::GetConsole()->doCommand(fmt::format("as {}", code)); +} diff --git a/source/main/gui/panels/GUI_AngelScriptExamples.h b/source/main/gui/panels/GUI_AngelScriptExamples.h index 5b6b5dc13b..35f8cd7ee7 100644 --- a/source/main/gui/panels/GUI_AngelScriptExamples.h +++ b/source/main/gui/panels/GUI_AngelScriptExamples.h @@ -35,6 +35,8 @@ class AngelScriptExamples 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); + void ExecuteString(std::string const& code); //!< Runs code using 'as' console command. + float scale = 1.f; float mass = 1000.f; bool reset = false; From 8e637f7060c176aca4b15a43c1b6da87e10ac034 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 4 Dec 2021 18:12:15 +0100 Subject: [PATCH 4/6] Console UI: fixed horiz. scrollbar hiding bottom line. --- source/main/gui/panels/GUI_ConsoleView.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/main/gui/panels/GUI_ConsoleView.cpp b/source/main/gui/panels/GUI_ConsoleView.cpp index c02a1d46b7..7c14321a9a 100644 --- a/source/main/gui/panels/GUI_ConsoleView.cpp +++ b/source/main/gui/panels/GUI_ConsoleView.cpp @@ -98,21 +98,28 @@ void ConsoleView::DrawConsoleMessages() ImGui::SetScrollY(ImGui::GetScrollMaxY() + (num_incoming * line_h) + 100.f); } + // Calculate visible area height + float view_height = ImGui::GetWindowHeight(); + if (ImGui::GetScrollMaxX() > 0) // Account for horizontal scrollbar, if visible. + { + view_height -= ImGui::GetStyle().ScrollbarSize; + } + // Calculate message range and cursor pos int msg_start = 0, msg_count = 0; ImVec2 cursor = ImGui::GetWindowPos(); if (ImGui::GetScrollMaxY() == 0) // No scrolling { msg_count = (int)m_display_messages.size(); - cursor += ImVec2(0, ImGui::GetWindowHeight() - (msg_count * line_h)); // Align to bottom + cursor += ImVec2(0, view_height - (msg_count * line_h)); // Align to bottom } else // Scrolling { const float scroll_rel = ImGui::GetScrollY()/ImGui::GetScrollMaxY(); - const float scroll_offset = ((dummy_h - ImGui::GetWindowHeight()) *scroll_rel); + const float scroll_offset = ((dummy_h - view_height) * scroll_rel); msg_start = std::max(0, (int)(scroll_offset/line_h)); - msg_count = std::min((int)(ImGui::GetWindowHeight() / line_h)+2, // Bias (2) for partially visible messages (1 top, 1 bottom) + msg_count = std::min((int)(view_height / line_h)+2, // Bias (2) for partially visible messages (1 top, 1 bottom) (int)m_display_messages.size() - msg_start); const float line_offset = scroll_offset/line_h; From 7d1952126dcaee4ba863cf35066671fd4d23ef95 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 4 Dec 2021 18:26:54 +0100 Subject: [PATCH 5/6] Console command 'as': print messages _after_ code. --- source/main/system/ConsoleCmd.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/source/main/system/ConsoleCmd.cpp b/source/main/system/ConsoleCmd.cpp index 9ce8e7bffb..da6fd9f0bb 100644 --- a/source/main/system/ConsoleCmd.cpp +++ b/source/main/system/ConsoleCmd.cpp @@ -320,19 +320,25 @@ class AsCmd: public ConsoleCmd // we want to notify any running scripts that we might change something (prevent cheating) App::GetScriptEngine()->triggerEvent(SE_ANGELSCRIPT_MANIPULATIONS); - Str<1000> code; // Re-compose the code snippet + // Re-compose the code snippet + Str<1000> code; for (int i = 1; i < args.size(); ++i) { code << " " << args[i]; } - App::GetScriptEngine()->executeString(code.ToCStr()); + + // Echo the code back to console user. reply_type = Console::CONSOLE_SYSTEM_REPLY; reply << " >>> " << code.ToCStr(); + App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, reply_type, reply.ToCStr()); + + // Run the code - will output script messages/AngelScript errors. + App::GetScriptEngine()->executeString(code.ToCStr()); #else reply_type = Console::CONSOLE_SYSTEM_ERROR; reply << _L("Scripting disabled in this build"); -#endif App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, reply_type, reply.ToCStr()); +#endif } }; From eb48c9f1f40542655581215fa7ecb2f816a8746a Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 4 Dec 2021 18:41:26 +0100 Subject: [PATCH 6/6] AngelScript examples UI: localized descriptions. --- .../gui/panels/GUI_AngelScriptExamples.cpp | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/source/main/gui/panels/GUI_AngelScriptExamples.cpp b/source/main/gui/panels/GUI_AngelScriptExamples.cpp index ece4eccbbd..fdcf14f2c3 100644 --- a/source/main/gui/panels/GUI_AngelScriptExamples.cpp +++ b/source/main/gui/panels/GUI_AngelScriptExamples.cpp @@ -21,37 +21,37 @@ 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); + this->DrawRowSlider("void scaleTruck()", "game.getCurrentTruck().scaleTruck({})", _LC("AngelScript", "Scales the truck"), 1.f, 1.5f, scale); + this->DrawRowText("string getTruckName()", "game.log(game.getCurrentTruck().getTruckName())", _LC("AngelScript", "Gets the name of the truck")); + this->DrawRowText("string getTruckFileName()", "game.log(game.getCurrentTruck().getTruckFileName())", _LC("AngelScript", "Gets the name of the truck file")); + this->DrawRowText("string getSectionConfig()", "game.log(game.getCurrentTruck().getSectionConfig())", _LC("AngelScript", "Gets the name of the loaded section for a truck")); + this->DrawRowText("int getTruckType()", "game.log(' ' + game.getCurrentTruck().getTruckType())", _LC("AngelScript", "Gets the type of the truck")); + this->DrawRowCheckbox("void reset()", "game.getCurrentTruck().reset({})", _LC("AngelScript", "Resets the truck"), reset, "Keep position"); + this->DrawRowText("void parkingbrakeToggle()", "game.getCurrentTruck().parkingbrakeToggle()", _LC("AngelScript", "Toggles the parking brake")); + this->DrawRowText("void tractioncontrolToggle()", "game.getCurrentTruck().tractioncontrolToggle()", _LC("AngelScript", "Toggles the tracktion control")); + this->DrawRowText("void antilockbrakeToggle()", "game.getCurrentTruck().antilockbrakeToggle()", _LC("AngelScript", "Toggles the anti-lock brakes")); + this->DrawRowText("void beaconsToggle()", "game.getCurrentTruck().beaconsToggle()", _LC("AngelScript", "Toggles the beacons")); + this->DrawRowText("void toggleCustomParticles()", "game.getCurrentTruck().toggleCustomParticles()", _LC("AngelScript", "Toggles the custom particles")); + this->DrawRowText("int getNodeCount()", "game.log(' ' + game.getCurrentTruck().getNodeCount())", _LC("AngelScript", "Gets the total amount of nodes of the truck")); + this->DrawRowCheckbox("float getTotalMass()", "game.log(' ' + game.getCurrentTruck().getTotalMass({}))", _LC("AngelScript", "Gets the total mass of the truck"), locked, "With locked"); + this->DrawRowText("int getWheelNodeCount()", "game.log(' ' + game.getCurrentTruck().getWheelNodeCount())", _LC("AngelScript", "Gets the total amount of nodes of the wheels of the truck")); + this->DrawRowSlider("void setMass()", "game.getCurrentTruck().setMass({})", _LC("AngelScript", "Sets the mass of the truck"), 1000.f, 10000.f, mass); + this->DrawRowText("bool getBrakeLightVisible()", "game.log(' ' + game.getCurrentTruck().getBrakeLightVisible())", _LC("AngelScript", "Returns true if the brake light is enabled")); + this->DrawRowInt("bool getCustomLightVisible()", "game.log(' ' + game.getCurrentTruck().getCustomLightVisible({}))", _LC("AngelScript", "Returns true if the custom light with the number is enabled"), light); + this->DrawRowIntCheckbox("void setCustomLightVisible()", "game.getCurrentTruck().setCustomLightVisible({}, {})", _LC("AngelScript", "Enables or disables the custom light"), custom_light, visible, "On"); + this->DrawRowText("bool getBeaconMode()", "game.log(' ' + game.getCurrentTruck().getBeaconMode())", _LC("AngelScript", "Gets the mode of the beacon")); + this->DrawRowInt("void setBlinkType()", "game.getCurrentTruck().setBlinkType({})", _LC("AngelScript", "Sets the blinking type"), blink); + this->DrawRowText("int getBlinkType()", "game.log(' ' + game.getCurrentTruck().getBlinkType())", _LC("AngelScript", "Gets the blinking type")); + this->DrawRowText("bool getCustomParticleMode()", "game.log(' ' + game.getCurrentTruck().getCustomParticleMode())", _LC("AngelScript", "Gets the custom particles mode")); + this->DrawRowText("bool getReverseLightVisible()", "game.log(' ' + game.getCurrentTruck().getReverseLightVisible())", _LC("AngelScript", "Returns true if the reverse lights are enabled")); + this->DrawRowText("float getHeadingDirectionAngle()", "game.log(' ' + game.getCurrentTruck().getHeadingDirectionAngle())", _LC("AngelScript", "Returns the angle in which the truck is heading")); + this->DrawRowText("bool isLocked()", "game.log(' ' + game.getCurrentTruck().isLocked())", _LC("AngelScript", "Returns true if a hook of this truck is locked")); + this->DrawRowText("float getWheelSpeed()", "game.log(' ' + game.getCurrentTruck().getWheelSpeed())", _LC("AngelScript", "Gets the current wheel speed of the vehicle")); + this->DrawRowText("float getSpeed()", "game.log(' ' + game.getCurrentTruck().getSpeed())", _LC("AngelScript", "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 )", _LC("AngelScript", "Gets the G-forces that this truck is currently experiencing")); + this->DrawRowText("float getRotation()", "game.log(' ' + game.getCurrentTruck().getRotation())", _LC("AngelScript", "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 )", _LC("AngelScript", "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 )", _LC("AngelScript", "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)