Skip to content

Commit

Permalink
feat: window icon and colouring
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMcAvoy committed Dec 31, 2024
1 parent 02120ba commit 30d6bd3
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 113 deletions.
Binary file added CarbonLauncher/CarbonLauncher.aps
Binary file not shown.
Binary file added CarbonLauncher/CarbonLauncher.ico
Binary file not shown.
Binary file added CarbonLauncher/CarbonLauncher.rc
Binary file not shown.
18 changes: 14 additions & 4 deletions CarbonLauncher/CarbonLauncher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>include;.</AdditionalIncludeDirectories>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
Expand All @@ -97,7 +97,7 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>include;.</AdditionalIncludeDirectories>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
Expand All @@ -114,7 +114,7 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>include;.</AdditionalIncludeDirectories>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
Expand All @@ -131,7 +131,7 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalIncludeDirectories>include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>include;.</AdditionalIncludeDirectories>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
Expand Down Expand Up @@ -159,6 +159,16 @@
<ClInclude Include="include\repomanager.h" />
<ClInclude Include="include\state.h" />
<ClInclude Include="include\utils.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="CarbonLauncher.rc" />
</ItemGroup>
<ItemGroup>
<None Include="CarbonLauncher.aps" />
</ItemGroup>
<ItemGroup>
<Image Include="..\..\..\Users\Ben\Nextcloud2\CarbonLauncher.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
4 changes: 2 additions & 2 deletions CarbonLauncher/include/repomanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace Carbon {
std::string description;

// The link to the mods GitHub page
std::string user;
std::string repoName;
std::string ghUser;
std::string ghRepo;

bool installed = false;
bool wantsUpdate = false;
Expand Down
16 changes: 16 additions & 0 deletions CarbonLauncher/resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by CarbonLauncher.rc
//
#define IDI_ICON1 102

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
133 changes: 84 additions & 49 deletions CarbonLauncher/src/guimanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#define GLFW_EXPOSE_NATIVE_WIN32
#define WIN32_LEAN_AND_MEAN

#include "resource.h"

#include "guimanager.h"
#include "utils.h"
#include "state.h"
Expand All @@ -22,6 +24,7 @@
#include <fmt/ranges.h>

#include <imgui.h>
#include <imgui_internal.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>

Expand Down Expand Up @@ -75,19 +78,38 @@ GUIManager::GUIManager() : renderCallback(nullptr), window(nullptr) {
// Round everything, disable some frames
ImGuiStyle& style = ImGui::GetStyle();
style.WindowRounding = 4.0f;
style.FramePadding = ImVec2(8, 4);
style.TabBarBorderSize = 2;
style.ScrollbarSize = 10;
style.FrameRounding = 4.0f;
style.GrabRounding = 4.0f;
style.TabRounding = 4.0f;
style.ChildRounding = 4.0f;
style.TabRounding = 6.0f;
style.ChildRounding = 6.0f;
style.PopupRounding = 4.0f;
style.ScrollbarRounding = 4.0f;
style.ScrollbarRounding = 12.0f;
style.FrameBorderSize = 0.0f;
style.WindowBorderSize = 0.0f;
style.PopupBorderSize = 0.0f;
style.TabBorderSize = 0.0f;

io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\seguisb.ttf", 18.0f);

// Go through every colour and get hsv values, if it's 151 then change it to 0 and then set the colour
for (int i = 0; i < ImGuiCol_COUNT; i++) {
ImVec4* col = &style.Colors[i];
float h, s, v;
ImGui::ColorConvertRGBtoHSV(col->x, col->y, col->z, h, s, v);
if (h > 0.59 && h < 0.61) {
h = 0.0f;
s = 0.5f;
spdlog::info("Modified colour {}", i);
}
else {
spdlog::info("Colour {} is {}", i, h);
}
ImGui::ColorConvertHSVtoRGB(h, s, v, col->x, col->y, col->z);
}

ImGui_ImplGlfw_InitForOpenGL(this->window, true);
ImGui_ImplOpenGL3_Init("#version 460");
glfwSwapInterval(1);
Expand Down Expand Up @@ -160,6 +182,7 @@ void _GUI() {
if (!C.repoManager.hasLoaded) {
ImGui::TextWrapped("Loading mods...");
ImGui::EndTabItem();
ImGui::EndTabBar();
ImGui::End();
return;
}
Expand Down Expand Up @@ -230,72 +253,84 @@ void _GUI() {
if (ImGui::BeginTabItem("Public mods")) {
ImGui::Columns(3, "modColumns", false);
for (auto& mod : C.repoManager.GetMods()) {
ImGui::ItemSize(ImVec2(0, 8), 0);
// Layout:
// | mod | mod | mod |
// | mod |

ImGui::BeginChild(mod.name.c_str(), ImVec2(0, 300), true);

ImGui::TextWrapped(mod.name.c_str());
ImGui::Separator();
ImGui::TextWrapped(mod.description.c_str());

ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 8);

if (mod.authors.size() > 1) {
ImGui::TextWrapped("Authors: ");
ImGui::SameLine();
ImGui::BeginChild(mod.name.c_str(), ImVec2(0, 200), true);

for (auto& author : mod.authors) {
std::string link = "https://github.com/" + author;
std::string text = "@" + author + " ";
ImGui::TextWrapped(mod.name.c_str());
ImGui::Separator();
ImGui::TextWrapped(mod.description.c_str());

if (ImGui::Button(text.c_str())) {
ShellExecute(NULL, L"open", std::wstring(link.begin(), link.end()).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 8);

ImGui::PopStyleColor();

if (author != mod.authors.back()) {
ImGui::SameLine();
}
}
}
else {
ImGui::TextWrapped("Author: ");
ImGui::SameLine();
if (mod.authors.size() > 1) {
ImGui::TextWrapped("Authors: ");
ImGui::SameLine();

std::string link = "https://github.com/" + mod.authors[0];
std::string text = "@" + mod.authors[0] + " ";
for (auto& author : mod.authors) {
std::string link = "https://github.com/" + author;
std::string text = "@" + author + " ";

if (ImGui::Button(text.c_str())) {
ShellExecute(NULL, L"open", std::wstring(link.begin(), link.end()).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
}

// Set ImGui cursor y pos to bottom of child window
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().ItemSpacing.y);

if (ImGui::Button(mod.installed ? "Uninstall" : "Install")) {
if (mod.installed) {
mod.Uninstall();
}
else {
mod.Install();
if (author != mod.authors.back()) {
ImGui::SameLine();
}
}
}
else {
ImGui::TextWrapped("Author: ");
ImGui::SameLine();

if (mod.wantsUpdate) {
ImGui::SameLine();
if (ImGui::Button("Update")) {
mod.Update();
}
std::string link = "https://github.com/" + mod.authors[0];
std::string text = "@" + mod.authors[0] + " ";

if (ImGui::Button(text.c_str())) {
ShellExecute(NULL, L"open", std::wstring(link.begin(), link.end()).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
}

ImGui::EndChild();
ImGui::TextWrapped("Source: ");
ImGui::SameLine();
if (ImGui::Button("GitHub")) {
std::string link = fmt::format("https://github.com/{}/{}", mod.ghUser, mod.ghRepo);
ShellExecute(NULL, L"open", std::wstring(link.begin(), link.end()).c_str(), NULL, NULL, SW_SHOWNORMAL);
}

ImGui::NextColumn();
// Set ImGui cursor y pos to bottom of child window
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().ItemSpacing.y);

if (ImGui::Button(mod.installed ? "Uninstall" : "Install")) {
if (mod.installed) {
mod.Uninstall();
}
else {
mod.Install();
}
}

ImGui::SameLine();
if (!mod.wantsUpdate) {
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
}
if (ImGui::Button(mod.wantsUpdate ? "Update" : "Up to date")) {
mod.Update();
}
if (!mod.wantsUpdate) {
ImGui::PopItemFlag();
ImGui::PopStyleVar();
}

ImGui::EndChild();

ImGui::NextColumn();
}

ImGui::Columns(1);

Expand Down
4 changes: 3 additions & 1 deletion CarbonLauncher/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using namespace Carbon;
* @return The exit code of the application
*/
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
#ifndef NDEBUG
// Tell winapi to show a console window
AllocConsole();
FILE* file;
Expand All @@ -26,8 +27,9 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
spdlog::set_default_logger(console); // Set the default logger to the console logger
console->set_level(spdlog::level::trace); // Set the log level to info
spdlog::set_pattern("%^[ %H:%M:%S | %-8l] %n: %v%$"); // Nice log format
#endif

// Tell windows this program isn't important, so other processes can use more resources
// Tell windows this program isn't important, so other processes (i.e. like the game) can have more resources
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);

C.guiManager.RenderCallback(_GUI);
Expand Down
Loading

0 comments on commit 30d6bd3

Please sign in to comment.