mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-21 20:08:40 +03:00
Added support for vec2 and vec3
This commit is contained in:
@@ -179,6 +179,35 @@ void NetScriptPanel::Draw(Nuake::Entity entity)
|
||||
field.Value = currentValue;
|
||||
}
|
||||
|
||||
if (field.Type == Nuake::NetScriptExposedVarType::Vector2)
|
||||
{
|
||||
if (!field.Value.has_value())
|
||||
{
|
||||
field.Value = field.DefaultValue;
|
||||
}
|
||||
|
||||
|
||||
Nuake::Vector2 currentValue = std::any_cast<Nuake::Vector2>(field.Value);
|
||||
const std::string sliderName = "##" + field.Name + "slider";
|
||||
ImGuiHelper::DrawVec2(sliderName, ¤tValue);
|
||||
|
||||
field.Value = currentValue;
|
||||
}
|
||||
|
||||
if (field.Type == Nuake::NetScriptExposedVarType::Vector3)
|
||||
{
|
||||
if (!field.Value.has_value())
|
||||
{
|
||||
field.Value = field.DefaultValue;
|
||||
}
|
||||
|
||||
Nuake::Vector3 currentValue = std::any_cast<Nuake::Vector3>(field.Value);
|
||||
const std::string sliderName = "##" + field.Name + "slider";
|
||||
ImGuiHelper::DrawVec3(sliderName, ¤tValue);
|
||||
|
||||
field.Value = currentValue;
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "src/Core/Core.h"
|
||||
#include "src/Core/Maths.h"
|
||||
#include "src/Core/FileSystem.h"
|
||||
#include "src/Core/Logger.h"
|
||||
#include "src/Resource/Serializable.h"
|
||||
@@ -70,6 +71,30 @@ namespace Nuake {
|
||||
varJ["Value"] = std::any_cast<std::string>(e.Value);
|
||||
varJ["DefaultValue"] = std::any_cast<std::string>(e.DefaultValue);
|
||||
break;
|
||||
case NetScriptExposedVarType::Vector2:
|
||||
{
|
||||
Vector2 value = std::any_cast<Vector2>(e.Value);
|
||||
varJ["Value"][0] = value.x;
|
||||
varJ["Value"][1] = value.y;
|
||||
|
||||
value = std::any_cast<Vector2>(e.DefaultValue);
|
||||
varJ["DefaultValue"][0] = value.x;
|
||||
varJ["DefaultValue"][1] = value.y;
|
||||
break;
|
||||
}
|
||||
case NetScriptExposedVarType::Vector3:
|
||||
{
|
||||
Vector3 value = std::any_cast<Vector3>(e.Value);
|
||||
varJ["Value"][0] = value.x;
|
||||
varJ["Value"][1] = value.y;
|
||||
varJ["Value"][2] = value.z;
|
||||
|
||||
value = std::any_cast<Vector3>(e.DefaultValue);
|
||||
varJ["DefaultValue"][0] = value.x;
|
||||
varJ["DefaultValue"][1] = value.y;
|
||||
varJ["DefaultValue"][2] = value.z;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
varJ["Value"] = 0;
|
||||
break;
|
||||
@@ -121,6 +146,31 @@ namespace Nuake {
|
||||
exposedVar.Value = (std::string)exposedVarJson["Value"];
|
||||
exposedVar.DefaultValue = (std::string)exposedVarJson["DefaultValue"];
|
||||
break;
|
||||
case NetScriptExposedVarType::Vector2:
|
||||
{
|
||||
float x = exposedVarJson["Value"][0];
|
||||
float y = exposedVarJson["Value"][1];
|
||||
|
||||
exposedVar.Value = Vector2(x, y);
|
||||
|
||||
x = exposedVarJson["DefaultValue"][0];
|
||||
y = exposedVarJson["DefaultValue"][1];
|
||||
|
||||
exposedVar.DefaultValue = Vector2(x, y);
|
||||
break;
|
||||
}
|
||||
case NetScriptExposedVarType::Vector3:
|
||||
{
|
||||
float x = exposedVarJson["Value"][0];
|
||||
float y = exposedVarJson["Value"][1];
|
||||
float z = exposedVarJson["Value"][2];
|
||||
exposedVar.Value = Vector3(x, y, z);
|
||||
|
||||
x = exposedVarJson["DefaultValue"][0];
|
||||
y = exposedVarJson["DefaultValue"][1];
|
||||
z = exposedVarJson["DefaultValue"][2];
|
||||
exposedVar.DefaultValue = Vector3(x, y, z);
|
||||
}
|
||||
default:
|
||||
exposedVar.DefaultValue = 0;
|
||||
break;
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
|
||||
class ImGuiHelper {
|
||||
public:
|
||||
static void DrawVec3(const std::string label, glm::vec3* values, float resetValue = 0.0f, float columnWidth = 100.0, float rate = 0.1f, float min = 0.0f) {
|
||||
static void DrawVec3(const std::string label, glm::vec3* values, float resetValue = 0.0f, float columnWidth = 100.0, float rate = 0.1f, float min = 0.0f)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
auto boldFont = io.Fonts->Fonts[0];
|
||||
|
||||
@@ -68,4 +69,51 @@ public:
|
||||
ImGui::PopID();
|
||||
//ImGui::Text("Hello");
|
||||
}
|
||||
|
||||
static void DrawVec2(const std::string label, glm::vec2* values, float resetValue = 0.0f, float columnWidth = 100.0, float rate = 0.1f, float min = 0.0f)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
auto boldFont = io.Fonts->Fonts[0];
|
||||
|
||||
ImGui::PushID(label.c_str());
|
||||
|
||||
float availWidth = (ImGui::GetContentRegionAvail().x / 3.0f) - 9.0f;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 });
|
||||
|
||||
float lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
|
||||
ImVec2 buttonSize = { 3.0f, lineHeight };
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.8f, 0.1f, 0.15f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.9f, 0.2f, 0.2f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.8f, 0.1f, 0.15f, 1.0f });
|
||||
ImGui::PushFont(boldFont);
|
||||
if (ImGui::Button("###X", buttonSize))
|
||||
values->x = resetValue;
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(availWidth);
|
||||
ImGui::DragFloat("##X", &values->x, rate, min, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.2f, 0.7f, 0.2f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.3f, 0.8f, 0.3f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.2f, 0.7f, 0.2f, 1.0f });
|
||||
ImGui::PushFont(boldFont);
|
||||
if (ImGui::Button("Y", buttonSize))
|
||||
values->y = resetValue;
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor(3);
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(availWidth);
|
||||
ImGui::DragFloat("##Y", &values->y, rate, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::PopID();
|
||||
//ImGui::Text("Hello");
|
||||
}
|
||||
};
|
||||
@@ -198,7 +198,7 @@ namespace Nuake
|
||||
exposedVar.Name = f.GetName();
|
||||
|
||||
auto typeName = f.GetType().GetFullName();
|
||||
ExposedVarTypes varType = ExposedVarTypes::Float;
|
||||
ExposedVarTypes varType = ExposedVarTypes::Unsupported;
|
||||
if (typeName == "System.Single")
|
||||
{
|
||||
varType = ExposedVarTypes::Float;
|
||||
@@ -215,10 +215,21 @@ namespace Nuake
|
||||
{
|
||||
varType = ExposedVarTypes::Bool;
|
||||
}
|
||||
else if (typeName == "System.Numerics.Vector2")
|
||||
{
|
||||
varType = ExposedVarTypes::Vector2;
|
||||
}
|
||||
else if (typeName == "System.Numerics.Vector3")
|
||||
{
|
||||
varType = ExposedVarTypes::Vector3;
|
||||
}
|
||||
|
||||
exposedVar.Type = varType;
|
||||
if (varType != ExposedVarTypes::Unsupported)
|
||||
{
|
||||
exposedVar.Type = varType;
|
||||
gameScriptObject.exposedVars.push_back(exposedVar);
|
||||
}
|
||||
|
||||
gameScriptObject.exposedVars.push_back(exposedVar);
|
||||
Logger::Log("Exposed field detected: " + std::string(f.GetName()) + " of type " + std::string(f.GetType().GetFullName()) );
|
||||
}
|
||||
}
|
||||
@@ -300,6 +311,16 @@ namespace Nuake
|
||||
exposedVar.Value = (bool)classInstance.GetFieldValue<int>(varName);
|
||||
break;
|
||||
}
|
||||
case ExposedVarTypes::Vector2:
|
||||
{
|
||||
exposedVar.Value = (Vector2)classInstance.GetFieldValue<Vector2>(varName);
|
||||
break;
|
||||
}
|
||||
case ExposedVarTypes::Vector3:
|
||||
{
|
||||
exposedVar.Value = (Vector3)classInstance.GetFieldValue<Vector3>(varName);
|
||||
break;
|
||||
}
|
||||
case ExposedVarTypes::Entity:
|
||||
{
|
||||
exposedVar.Value = classInstance.GetFieldValue<int>(varName);
|
||||
|
||||
@@ -26,7 +26,8 @@ namespace Nuake {
|
||||
Entity,
|
||||
Vector2,
|
||||
Vector3,
|
||||
Vector4
|
||||
Vector4,
|
||||
Unsupported
|
||||
};
|
||||
|
||||
struct ExposedVar
|
||||
|
||||
Reference in New Issue
Block a user