-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWidgetManager.h
163 lines (126 loc) · 4.24 KB
/
WidgetManager.h
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
151
152
153
154
155
156
157
158
159
160
161
162
163
#pragma once
#include "EntityComponentSystemManager.h"
#include "System.h"
#include "Vector2D.h"
#include "HUDWidget.h"
#include <iostream>
#include "RectangleWidget.h"
#include "TextWidget.h"
#include "Button.h"
//extern EntityComponentSystemManager m_EntityComponentSystemManager;
class RectangleWidget;
class WidgetManager : public System
{
public:
WidgetManager()
{
}
~WidgetManager()
{
}
void Tick(float DeltaTime)
{
for (auto widgets : m_Widgets)
{
widgets->Tick(DeltaTime);
}
}
void BeginPlay()
{
for (auto widgets : m_Widgets)
{
widgets->BeginPlay();
}
}
void setECS(EntityComponentSystemManager* ECS)
{
m_EntityComponentSystemManager = ECS;
}
void CheckButtonHoverAndPress(const Point cursor_position,bool L_button_pressed )
{
for (auto button : m_Buttons)
{
auto& transform = m_EntityComponentSystemManager->GetComponent<TransformComponent2D>(button->GetEntityID());
button->CheckHoverAndPress(cursor_position, L_button_pressed, transform);
}
}
void RegisterRect(RectangleWidget* widget, const char Name[32], Point position, Point scale, WidgetPositionOffset offset, Vector3D color,
ShapeType rect_type = ShapeType::Filled,float border_width = 1, Vector3D border_color = Vector3D(0,0,0))
{
widget->SetEntityID(m_EntityComponentSystemManager->CreateEntity() );
widget->SetName(Name);
widget->SetOffset(offset);
widget->SetRectType(rect_type);
widget->CreateColor(color, border_color);
widget->SetBorderWidth(border_width);
widget->setECS(m_EntityComponentSystemManager);
TransformComponent2D tr;
tr.position = position;
tr.scale = scale;
m_EntityComponentSystemManager->AddComponent(widget->GetEntityID(), tr);
m_Max_Widgets++;
int index = m_Max_Widgets - 1;
m_Widgets.resize(m_Max_Widgets);
if (m_Max_Widgets != 0)
{
m_Widgets[index] = widget;
// m_Entity_Index[widget->GetEntityID()] = index;
}
// std::cout << m_Max_Widgets;
}
void RegisterText(TextWidget* widget, const char Name[32], const wchar_t* text, Point position, Point scale, Vector3D color, float font_size)
{
widget->SetEntityID(m_EntityComponentSystemManager->CreateEntity());
widget->SetName(Name);
//widget->SetHUDRS(HUDSystem);
widget->CreateColor(color);
widget->SetText(text);
widget->SetFontSize(font_size);
widget->setECS(m_EntityComponentSystemManager);
TransformComponent2D tr;
tr.position = position;
tr.scale = scale;
m_EntityComponentSystemManager->AddComponent(widget->GetEntityID(), tr);
m_Max_Widgets++;
int index = m_Max_Widgets - 1;
m_Widgets.resize(m_Max_Widgets);
if (m_Max_Widgets != 0)
{
m_Widgets[index] = widget;
//m_Entity_Index[widget->GetEntityID()] = index;
}
widget->CreateTextFont();
}
void RegisterButton(Button* button, const char Name[32], void(*fnc)(),Point button_position, Point button_scale,
const wchar_t* text, float font_size, Vector3D text_color,Vector3D rect_color, ShapeType shape_type = ShapeType::Filled,
float border_width = 1, Vector3D rect_border_color = Vector3D(0,0,0))
{
button->SetEntityID(m_EntityComponentSystemManager->CreateEntity());
button->SetName(Name);
//button->SetHUDRS(HUDSystem);
button->SetDefaultRectColor(rect_color);
button->setECS(m_EntityComponentSystemManager);
button->SetFnc(fnc);
RegisterRect(button->GetButtonRectangle(),Name, button_position, button_scale,
WidgetPositionOffset::Center, rect_color, shape_type, border_width, rect_border_color
);
RegisterText(button->GetButtonTextWidget(), Name,text, button_position, button_scale, text_color, font_size);
TransformComponent2D tr;
tr.position = button_position;
tr.scale = button_scale;
m_EntityComponentSystemManager->AddComponent(button->GetEntityID(), tr);
m_Max_Buttons++;
int index = m_Max_Buttons - 1;
m_Buttons.resize(m_Max_Buttons);
if (m_Max_Buttons != 0)
{
m_Buttons[index] = button;
}
}
private:
int m_Max_Widgets = 0;
int m_Max_Buttons = 0;
std::vector<HUDWidget*> m_Widgets{};
std::vector<Button*>m_Buttons{};
EntityComponentSystemManager* m_EntityComponentSystemManager = nullptr;
};