forked from CHollingworth/Lampray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
224 lines (184 loc) · 11.5 KB
/
main.cpp
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#include "third-party/imgui/imgui.h"
#include "third-party/imgui/imgui_impl_sdl2.h"
#include "third-party/imgui/imgui_impl_sdlrenderer2.h"
#include "Lampray/Lang/lampLang.h"
#include "Lampray/Control/lampControl.h"
#include "Lampray/Menu/lampMenu.h"
#include "Lampray/Menu/lampCustomise .h"
#include <stdio.h>
#include "SDL2/SDL.h"
#include "Lampray/Control/lampNotification.h"
#if !SDL_VERSION_ATLEAST(2,0,17)
#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function
#endif
// Main code
int main(int, char**)
{
// Setup SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
{
printf("Error: %s\n", SDL_GetError());
return -1;
}
// From 2.0.18: Enable native IME.
#ifdef SDL_HINT_IME_SHOW_UI
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
#endif
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
SDL_Window* window = SDL_CreateWindow("Lampray", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
if (renderer == nullptr)
{
SDL_Log("Error creating SDL_Renderer!");
return 0;
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
ImGui_ImplSDL2_InitForSDLRenderer(window, renderer);
ImGui_ImplSDLRenderer2_Init(renderer);
std::filesystem::path fontFolder("Lamp_Font/");
// Check if the "Font" folder exists
if (std::filesystem::is_directory(fontFolder)) {
for (const auto& entry : std::filesystem::directory_iterator(fontFolder)) {
if (entry.is_regular_file() && entry.path().extension() == ".ttf") {
io.Fonts->AddFontFromFileTTF(entry.path().string().c_str(), 16.0f);
break;
}
}
}
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
std::string languageCheck = Lamp::Core::FS::lampIO::loadKeyData("LanguagePath", "LAMP CONFIG");
Lamp::Core::lampLang::getInstance().CurrentLanguage = Lamp::Core::lampLang::LanguageContainer();
if(languageCheck != ""){
if (!std::filesystem::exists(languageCheck)) {
Lamp::Core::Base::lampLog::getInstance().log(Lamp::Core::lampLang::getInstance().CurrentLanguage.build(languageCheck).returnReason);
}else{
if (!std::filesystem::exists("Lamp_Language/English (UK).xml")) {
Lamp::Core::lampLang::getInstance().createEnglishUK();
}
Lamp::Core::Base::lampLog::getInstance().log(Lamp::Core::lampLang::getInstance().CurrentLanguage.build("Lamp_Language/English (UK).xml").returnReason);
}
}else{
if (!std::filesystem::exists("Lamp_Language/English (UK).xml")) {
Lamp::Core::lampLang::getInstance().createEnglishUK();
}
Lamp::Core::Base::lampLog::getInstance().log(Lamp::Core::lampLang::getInstance().CurrentLanguage.build("Lamp_Language/English (UK).xml").returnReason);
}
Lamp::Core::lampControl::getInstance().Colour_SearchHighlight = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[13]);
ImGui::GetStyle().Colors[ImGuiCol_Text] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[0]);
ImGui::GetStyle().Colors[ImGuiCol_WindowBg] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[1]);
ImGui::GetStyle().Colors[ImGuiCol_PopupBg] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[2]);
ImGui::GetStyle().Colors[ImGuiCol_FrameBg] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[3]);
ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[4]);
ImGui::GetStyle().Colors[ImGuiCol_Button] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[5]);
ImGui::GetStyle().Colors[ImGuiCol_ButtonHovered] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[6]);
ImGui::GetStyle().Colors[ImGuiCol_ButtonActive] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[7]);
ImGui::GetStyle().Colors[ImGuiCol_Header] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[8]);
ImGui::GetStyle().Colors[ImGuiCol_HeaderHovered] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[9]);
ImGui::GetStyle().Colors[ImGuiCol_HeaderActive] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[10]);
ImGui::GetStyle().Colors[ImGuiCol_Separator] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[11]);
ImGui::GetStyle().Colors[ImGuiCol_SeparatorHovered] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[12]);
std::string PreviousGame = Lamp::Core::FS::lampIO::loadKeyData("PreviousGame","LAMP CONFIG");
if(PreviousGame != "") {
Lamp::Games::getInstance().currentGameInt = std::stoi(PreviousGame);
Lamp::Games::getInstance().currentGame = Lamp::Games::getInstance().gameList[Lamp::Games::getInstance().currentGameInt];
}
Lamp::Core::Base::lampLog::getInstance().log("Clearing log file.");
const std::string filename = "lamp.log";
std::ofstream file(filename, std::ios::trunc);
if (!file) {
file.close();
Lamp::Core::Base::lampLog::getInstance().log("Couldn't clear the Log.");
}
file.close();
Lamp::Core::Base::lampLog::getInstance().log(Lamp::Core::lampControl::getFormattedTimeAndDate()+" | | Battle Control Online, Welcome Back Commander.", Lamp::Core::Base::lampLog::LOG);
Lamp::Games::getInstance();
std::string loadedCheckUpdates = Lamp::Core::FS::lampIO::loadKeyData("Check_Updates_Startup", "LAMP CONFIG");
bool checkForUpdates = true;
if(loadedCheckUpdates == "0" || loadedCheckUpdates == "false"){
checkForUpdates = false;
}
if(checkForUpdates){
Lamp::Core::FS::lampUpdate::getInstance().checkForUpdates();
}
Lamp::Core::lampConfig::getInstance().lampFlags["showIntroMenu"]=(std::string)Lamp::Core::FS::lampIO::loadKeyData("showIntroMenu","LAMP CONFIG").returnReason;
Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation = (std::string)Lamp::Core::FS::lampIO::loadKeyData("bit7zLibaryLocation","LAMP CONFIG").returnReason;
bool found7z = Lamp::Core::lampConfig::getInstance().init();
if(!found7z){
Lamp::Core::lampNotification::getInstance().pushErrorNotification(Lamp::Core::lampLang::getInstance().LS("LAMPRAY_ERROR_7Z"));
}
Lamp::Core::FS::lampIO::saveKeyData("bit7zLibaryLocation", Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation, "LAMP CONFIG");
Lamp::Core::lampMenu Menus;
// This is a very inefficent way of doing this.
Lamp::Games::getInstance().currentProfile = Lamp::Games::getInstance().currentGame->KeyInfo()["CurrentProfile"];
// Try to load and set the global font scale. I am pretty sure this is not a good way of doing this...
std::string loadedFontScale = Lamp::Core::FS::lampIO::loadKeyData("Font_Scale", "LAMP CONFIG");
if(loadedFontScale != ""){
io.FontGlobalScale = std::stof(loadedFontScale);
}
Lamp::Core::Base::lampLog::getInstance().log("Creating Directories");
try {
std::filesystem::create_directories(Lamp::Core::lampConfig::getInstance().saveDataPath);
std::filesystem::create_directories(Lamp::Core::lampConfig::getInstance().archiveDataPath);
std::filesystem::create_directories(Lamp::Core::lampConfig::getInstance().ConfigDataPath);
std::filesystem::create_directories(Lamp::Core::lampConfig::getInstance().DeploymentDataPath);
std::filesystem::create_directories(Lamp::Core::lampConfig::getInstance().workingPaths);
for (Lamp::Game::gameControl *element: Lamp::Games::getInstance().gameList){
std::filesystem::create_directories(std::filesystem::path(Lamp::Core::lampConfig::getInstance().DeploymentDataPath + element->Ident().ReadableName));
std::filesystem::create_directories(std::filesystem::path(Lamp::Core::lampConfig::getInstance().archiveDataPath + element->Ident().ReadableName + "/GameFiles"));
std::filesystem::create_directories(Lamp::Core::lampConfig::getInstance().workingPaths + element->Ident().ReadableName);
std::filesystem::create_directories(Lamp::Core::lampConfig::getInstance().ConfigDataPath + element->Ident().ReadableName);
}
std::filesystem::create_directories(Lamp::Core::lampConfig::getInstance().workingPaths + Lamp::Games::getInstance().gameList[0]->Ident().ReadableName+"/MODS/");
std::filesystem::create_directories(Lamp::Core::lampConfig::getInstance().workingPaths + Lamp::Games::getInstance().gameList[0]->Ident().ReadableName+"/STEAM/");
std::filesystem::create_directories(Lamp::Core::lampConfig::getInstance().ConfigDataPath + Lamp::Games::getInstance().gameList[0]->Ident().ReadableName+"/MODS/");
std::filesystem::create_directories(Lamp::Core::lampConfig::getInstance().ConfigDataPath + Lamp::Games::getInstance().gameList[0]->Ident().ReadableName+"/STEAM/");
} catch (std::exception ex) {
Lamp::Core::Base::lampLog::getInstance().log("Could not create base directories", Lamp::Core::Base::lampLog::ERROR,
Lamp::Core::Base::lampLog::LMP_NODIRCREATION);
}
Lamp::Core::Base::lampLog::getInstance().log("Directories Created");
Lamp::Core::lampCustomise::getInstance().getConfigColours();
bool done = false;
while (!done)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
ImGui_ImplSDL2_ProcessEvent(&event);
if (event.type == SDL_QUIT)
done = true;
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
done = true;
if (event.type == SDL_DROPFILE) {
// A file has been dropped
char* droppedFile = event.drop.file;
Lamp::Core::FS::lampIO::fileDrop(droppedFile);
SDL_free(droppedFile);
}
}
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
Menus.RunMenus();
ImGui::Render();
SDL_RenderSetScale(renderer, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
SDL_SetRenderDrawColor(renderer, (Uint8)(clear_color.x * 255), (Uint8)(clear_color.y * 255), (Uint8)(clear_color.z * 255), (Uint8)(clear_color.w * 255));
SDL_RenderClear(renderer);
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
SDL_RenderPresent(renderer);
if(Menus.userRequestedQuit){
done = true;
}
}
ImGui_ImplSDLRenderer2_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}