-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathComponentUiButton.cpp
More file actions
150 lines (132 loc) · 3.19 KB
/
ComponentUiButton.cpp
File metadata and controls
150 lines (132 loc) · 3.19 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "ComponentUiButton.h"
#include "Application.h"
#include "Assets.h"
#include "ModuleResourceManager.h"
#include "ModuleGOManager.h"
#include "ModuleInput.h"
#include "ComponentRectTransform.h"
#include "ResourceFileTexture.h"
#include "GameObject.h"
#include "ComponentMaterial.h"
#include "ComponentCanvas.h"
#include "imgui\imgui.h"
// Only for Vertical Slice 3
#include "SDL\include\SDL_scancode.h"
#include "ComponentAudioSource.h"
#include "ModuleAudio.h"
ComponentUiButton::ComponentUiButton(ComponentType type, GameObject * game_object) : Component(type, game_object)
{
UImaterial = new ComponentMaterial(C_MATERIAL, nullptr);
}
ComponentUiButton::~ComponentUiButton()
{
delete UImaterial;
}
void ComponentUiButton::Update()
{
}
void ComponentUiButton::CleanUp()
{
}
void ComponentUiButton::OnInspector(bool debug)
{
std::string str = (std::string("UI Button") + std::string("##") + std::to_string(uuid));
if (ImGui::CollapsingHeader(str.c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
if (ImGui::IsItemClicked(1))
{
ImGui::OpenPopup("delete##uiImage");
}
if (ImGui::BeginPopup("delete##uiImage"))
{
if (ImGui::MenuItem("Delete"))
{
Remove();
}
ImGui::EndPopup();
}
UImaterial->DefaultMaterialInspector();
if (ImGui::Button("Set Size"))
{
string tex_path = (*UImaterial->list_textures_paths.begin());
ResourceFileTexture* rc_tmp = (ResourceFileTexture*)App->resource_manager->LoadResource(tex_path, ResourceFileType::RES_TEXTURE);
ComponentRectTransform* c = (ComponentRectTransform*)game_object->GetComponent(C_RECT_TRANSFORM);
c->SetSize(float2(rc_tmp->GetWidth(), rc_tmp->GetHeight()));
c->OnTransformModified();
}
}
}
void ComponentUiButton::OnFocus()
{
}
void ComponentUiButton::OnPress()
{
if (pressed == false)
{
UImaterial->SetIdToRender(UImaterial->GetIdToRender() + 1);
pressed = true;
}
else
{
UImaterial->SetIdToRender(UImaterial->GetIdToRender() -1);
pressed = false;
}
}
void ComponentUiButton::OnPressId(int i)
{
if (pressed == false)
{
UImaterial->SetIdToRender(i + 1);
pressed = true;
}
else
{
UImaterial->SetIdToRender(0);
pressed = false;
}
}
void ComponentUiButton::ChangeState()
{
pressed = !pressed;
}
void ComponentUiButton::Save(Data & file) const
{
Data data;
data.AppendInt("type", type);
data.AppendUInt("UUID", uuid);
data.AppendBool("active", active);
data.AppendArray("Material");
UImaterial->Save(data);
file.AppendArrayValue(data);
}
void ComponentUiButton::Load(Data & conf)
{
uuid = conf.GetUInt("UUID");
active = conf.GetBool("active");
Data mat_file;
mat_file = conf.GetArray("Material", 0);
UImaterial->Load(mat_file);
}
void ComponentUiButton::Reset()
{
if (UImaterial->texture_ids.size() >= 2)
{
uint tmp = UImaterial->texture_ids.at("0");
UImaterial->texture_ids.at("0") = UImaterial->texture_ids.at("1");
UImaterial->texture_ids.at("1") = tmp;
}
}
void ComponentUiButton::ResetId(int i)
{
if (UImaterial->texture_ids.size() >= i+1)
{
string str = to_string(i+1);
uint tmp = UImaterial->texture_ids.at("0");
UImaterial->texture_ids.at("0") = UImaterial->texture_ids.at(str);
UImaterial->texture_ids.at(str) = tmp;
}
}
bool ComponentUiButton::GetState() const
{
return pressed;
}