-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.hpp
120 lines (97 loc) · 4.49 KB
/
GUI.hpp
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
#include "RaylibAdditions.hpp"
#include <vector>
#include <raylib.h>
#include <variant>
#include <string>
namespace RaylibAdditions {
class FrameClass {
public:
std::vector<Texture2D*> textures;
std::vector<Vector2> texturePos;
std::vector<float> textureScales;
};
class LoadedRoomClass {
public:
std::unordered_map<std::string, Texture2D> textures;
std::vector<FrameClass> frames;
std::vector<RaylibAdditions::LoadedButtonClass> Buttons;
Sound music;
bool isValid = true;
};
class RoomClass {
public:
int ID = 0;
Camera2D camera;
// Loads a .gui room made with RaylibGuiCreator https://github.com/SparklesReal/RaylibGuiCreator also this needs to be rewritten
LoadedRoomClass loadRoom(std::string path, std::string fileName);
// Unloads a LoadedRoomClass
RaylibAdditions::LoadedRoomClass unloadRoom(LoadedRoomClass room);
// Draws a single frameclass
void drawFrameClass(FrameClass* frame);
};
namespace Menu {
class slider {
public:
slider(std::string entryName, int entryProcentage) : name(entryName), procentage(entryProcentage) {};
std::string name;
int procentage = 100;
Rectangle box = {};
Rectangle procentageRect = {};
};
class toggleBox {
public:
toggleBox(std::string entryName, bool entryState) : name(entryName), state(entryState) {};
std::string name;
bool state = false;
};
class stringList {
public:
stringList(std::string entryName, std::vector<std::string> stringList) : name(entryName), items(stringList) {};
std::string name;
std::vector<std::string> items;
bool extended = false;
};
class Menu {
bool centered = false;
float xPos, yPos = 0;
std::vector<std::string> pageTitles;
int selectedPage = 0;
Vector2 menuSize {500, 500};
std::vector<std::vector<std::variant<toggleBox, slider, stringList>>> settings; // Name, type
public:
Menu(bool center, std::vector<std::string> pageNames = {}, Vector2 size = {800, 800}, float x = 0, float y = 0) : centered(center), pageTitles(pageNames), menuSize(size), xPos(x), yPos(y) {
for (int i = 0; i < pageNames.size(); i++) {
this->settings.push_back({});
}
};
void loadSettingsFromFile(std::string path);
void saveSettingsToFile(std::string path);
void addSettingToPage(std::string page, std::variant<toggleBox, slider, stringList> setting);
void removeSettingFromPage(std::string page, std::string name);
void setSettingAtPage(std::string page, std::string name, std::variant<toggleBox, slider, stringList> setting);
std::variant<toggleBox, slider, stringList>* getVariant(std::string page, std::string name);
int titleFontSize = 20;
int entryFontSize = 40;
int outlineThickness = 10;
float titleBoxHeight = 50.0;
Color background = DARKGRAY;
Color outline = BLACK;
Color textColor = BLACK;
void DrawAndUpdate(Vector2 mousePos = GetMousePosition());
};
std::unordered_map<std::string, std::variant<bool, int, std::string>> loadSettingsFromFileToMap(std::string path); // For loading to game not as a menu but applied setting
}
class ScrollingMenu {
private:
float lastGamepadAxis = 0;
int selectedText = 0;
const std::vector<std::string> options;
const Color textColor = BLACK;
const Color selectedColor = BLACK;
const float textSize = 10;
const float selectedTextSize = 15;
public:
ScrollingMenu(std::vector<std::string> texts, Color textColor, Color selectedColor, float textSize, float selectedTextSize) : options(texts), textColor(textColor), selectedColor(selectedColor), textSize(textSize), selectedTextSize(selectedTextSize) {};
int drawAndUpdate(Sound* optionChangeSound = nullptr, int gamepad = -1, bool drawWithoutUpdate = false);
};
}