-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimationDataInspector.cpp
More file actions
92 lines (79 loc) · 2.25 KB
/
Copy pathAnimationDataInspector.cpp
File metadata and controls
92 lines (79 loc) · 2.25 KB
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
#include "AnimationDataInspector.h"
#include "Editor/DragDropHelper.hpp"
#include <limits>
namespace sh::editor
{
SH_EDIT_API void AnimationDataInspector::RenderUI(const std::vector<core::SObject*>& objs, int idx)
{
CustomInspector::RenderUI(objs, idx);
game::AnimationData& anim = *reinterpret_cast<game::AnimationData*>(objs.back());
if (anim.IsPendingKill())
return;
bool bChanged = false;
ImGui::Text("frames/delay/x/y/a0/a1");
for (int i = 0; i < anim.frames.size(); ++i)
{
auto& frame = anim.frames[i];
auto& texPtr = frame.texture;
int delay = frame.delayMs;
float pos[2] = { frame.pos.x, frame.pos.y };
int alpha[2] = { frame.a0, frame.a1 };
std::string name = core::IsValid(texPtr) ? texPtr->GetName().ToString() : "None";
if (ImGui::Button(fmt::format("{}##tex{}", name, i).c_str()))
{
}
if (ImGui::BeginDragDropTarget())
{
if (render::Texture* payloadTexPtr = editor::dragdrop::AcceptAsset<render::Texture>())
{
texPtr = payloadTexPtr;
bChanged = true;
}
}
ImGui::SameLine();
ImGui::SetNextItemWidth(40);
if (ImGui::InputInt(fmt::format("##delay{}", i).c_str(), &delay, 0))
{
frame.delayMs = std::clamp(delay, 10, std::numeric_limits<int>::max());
bChanged = true;
}
ImGui::SameLine();
ImGui::SetNextItemWidth(130);
if (ImGui::InputFloat2(fmt::format("##pos{}", i).c_str(), pos))
{
frame.pos.x = pos[0];
frame.pos.y = pos[1];
bChanged = true;
}
ImGui::SameLine();
ImGui::SetNextItemWidth(130);
if (ImGui::InputInt2(fmt::format("##alpha{}", i).c_str(), alpha))
{
frame.a0 = std::clamp(alpha[0], 0, 255);
frame.a1 = std::clamp(alpha[1], 0, 255);
bChanged = true;
}
ImGui::SameLine();
if (ImGui::Button(fmt::format("-##{}", i).c_str()))
{
anim.frames.erase(anim.frames.begin() + i);
AssetDatabase::GetInstance()->SetDirty(&anim);
AssetDatabase::GetInstance()->SaveAllAssets();
break;
}
}
ImGui::Separator();
if (ImGui::Button("Add"))
{
anim.frames.push_back({});
bChanged = true;
}
if (ImGui::Checkbox("Loop", &anim.bLoop))
bChanged = true;
if (bChanged)
{
AssetDatabase::GetInstance()->SetDirty(&anim);
AssetDatabase::GetInstance()->SaveAllAssets();
}
}
}//namespace