blob: 0368231d90787ed0868c57d4645a0900d7c14aff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#include "Properties.h"
#include "port/ui/PortMenu.h"
#include "UIWidgets.h"
#include "libultraship/src/Context.h"
#include <imgui.h>
#include <map>
#include <libultraship/libultraship.h>
#include <spdlog/fmt/fmt.h>
#include "spdlog/formatter.h"
#include <common_structs.h>
#include <defines.h>
#include "engine/editor/Editor.h"
#include "port/Game.h"
#include "src/engine/World.h"
namespace Editor {
PropertiesWindow::~PropertiesWindow() {
SPDLOG_TRACE("destruct properties window");
}
void PropertiesWindow::DrawElement() {
GameObject* selected = gEditor.eObjectPicker.eGizmo._selected;
if (nullptr == selected) {
return;
}
ImGui::Begin("Properties");
if (selected->Pos) {
ImGui::Text("Location");
ImGui::SameLine();
bool positionChanged = ImGui::DragFloat3("##Location", &selected->Pos->x, 0.1f);
ImGui::SameLine();
if (ImGui::Button(ICON_FA_UNDO "##ResetPos")) {
selected->Pos->x = 0.0f;
selected->Pos->y = 0.0f;
selected->Pos->z = 0.0f;
positionChanged = true; // also counts as a change
}
if (positionChanged) {
gEditor.eObjectPicker.eGizmo.Pos = *selected->Pos;
}
}
if (selected->Rot) {
ImGui::Text("Rotation");
ImGui::SameLine();
// Convert to temporary int values (to prevent writing 32bit values to 16bit variables)
int rot[3] = {
selected->Rot->pitch,
selected->Rot->yaw,
selected->Rot->roll
};
if (ImGui::DragInt3("##Rotation", rot, 5.0f)) {
for (int i = 0; i < 3; i++) {
// Wrap around 0–65535
rot[i] = (rot[i] % 65536 + 65536) % 65536;
}
selected->Rot->pitch = static_cast<uint16_t>(rot[0]);
selected->Rot->yaw = static_cast<uint16_t>(rot[1]);
selected->Rot->roll = static_cast<uint16_t>(rot[2]);
}
ImGui::SameLine();
if (ImGui::Button(ICON_FA_UNDO "##ResetRot")) {
selected->Rot->pitch = 0;
selected->Rot->yaw = 0;
selected->Rot->roll = 0;
}
}
if (selected->Scale) {
ImGui::Text("Scale ");
ImGui::SameLine();
ImGui::DragFloat3("##Scale", &selected->Scale->x, 0.1f);
ImGui::SameLine();
if (ImGui::Button(ICON_FA_UNDO "##ResetScale")) {
selected->Scale->x = 1.0f;
selected->Scale->y = 1.0f;
selected->Scale->z = 1.0f;
}
}
if (selected->Collision == GameObject::CollisionType::BOUNDING_BOX) {
ImGui::Separator();
ImGui::Text("Editor Bounding Box Size:");
ImGui::PushID("BoundingBoxSize");
ImGui::DragFloat("##BoundingBoxSize", &selected->BoundingBoxSize, 0.1f);
ImGui::SameLine();
if (ImGui::Button(ICON_FA_UNDO)) { selected->BoundingBoxSize = 2.0f; }
ImGui::PopID();
}
ImGui::End();
}
}
|