diff --git a/CMakeLists.txt b/CMakeLists.txt index 70b06df2a..58cfd11bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ find_package(JPEG REQUIRED) find_package(Vorbis REQUIRED) find_package(OGG REQUIRED) find_package(LibArchive REQUIRED) +find_package(CryptoPP REQUIRED) # All projects use unicode define # this is mainly for windows functions either being defined to call A or W prefixed functions diff --git a/Main/include/Application.hpp b/Main/include/Application.hpp index b8a0c4078..497a898df 100644 --- a/Main/include/Application.hpp +++ b/Main/include/Application.hpp @@ -103,6 +103,7 @@ class Application private: bool m_LoadConfig(); + bool m_LoadSettingsStyleConfig(String skin); void m_SaveConfig(); void m_InitDiscord(); bool m_Init(); diff --git a/Main/include/GameConfig.hpp b/Main/include/GameConfig.hpp index d75163b98..ffabaf4ac 100644 --- a/Main/include/GameConfig.hpp +++ b/Main/include/GameConfig.hpp @@ -123,7 +123,12 @@ DefineEnum(GameConfigKeys, MultiplayerUsername, RollIgnoreDuration, - LaserSlamLength + LaserSlamLength, + + // Internet Ranking + IRBaseURL, + IRUsername, + IRPassword ); DefineEnum(SpeedMods, diff --git a/Main/include/SkinConfig.hpp b/Main/include/SkinConfig.hpp index 8e8a28267..419119b4f 100644 --- a/Main/include/SkinConfig.hpp +++ b/Main/include/SkinConfig.hpp @@ -1,4 +1,5 @@ #pragma once +#include "Shared/Config.hpp" #include "stdafx.h" struct SkinSetting @@ -108,3 +109,84 @@ class SkinConfig : ConfigBase return targetType; } }; + +DefineEnum(SettingsStyleConfigKeys, + // Screen settings + BackgroundColor, + BorderColor, + BorderWidth, + TextColor, + + ButtonTextColor, + ButtonTextColorHover, + ButtonBackgroundColor, + ButtonBackgroundColorHover, + ButtonBorderColor, + ButtonBorderWidth, + ButtonPaddingLeftRight, + ButtonPaddingTopBottom, + ButtonRounding, + + NodeTextColor, + NodeArrowColor, + NodeArrowBackgroundColor, + + OptionTextColor, + OptionColor, + OptionColorHover, + OptionColorChecked, + OptionColorCheckedHover, + OptionBorderColor, + OptionBorderWidth, + + CheckTextColor, + CheckColor, + CheckColorHover, + CheckColorChecked, + CheckColorCheckedHover, + CheckBorderColor, + CheckBorderWidth, + + SliderBarEmptyColor, + SliderBarFilledColor, + SliderBallColor, + SliderBallColorHover, + + ComboButtonBackgroundColor, + ComboButtonTextColor, + ComboButtonBackgroundColorHover, + ComboButtonTextColorHover, + ComboButtonArrowColor, + + ComboBoxBackgroundColor, + ComboBoxTextColor, + ComboBoxBackgroundColorHover, + ComboBoxTextColorHover, + + PropertyTextColor, + PropertyBackgroundColor, + PropertyArrowColor, + PropertyEditTextColor, + PropertyEditBackgroundColor, + PropertyEditSelectedTextColor, + PropertyEditSelectedBackgroundColor, + + EditTextColor, + EditBackgroundColor, + EditSelectedTextColor, + EditSelectedBackgroundColor + + + +); + +// Config for game settings +class SettingsStyleConfig : public Config +{ +public: + SettingsStyleConfig(); + virtual void InitDefaults() override; +}; + +// Main config instance +extern class SettingsStyleConfig g_settingsStyleConfig; \ No newline at end of file diff --git a/Main/src/Application.cpp b/Main/src/Application.cpp index 76a1f3b2c..f5f859979 100644 --- a/Main/src/Application.cpp +++ b/Main/src/Application.cpp @@ -38,6 +38,7 @@ #include "archive_entry.h" GameConfig g_gameConfig; +SettingsStyleConfig g_settingsStyleConfig; SkinConfig* g_skinConfig; OpenGL* g_gl = nullptr; Graphics::Window* g_gameWindow = nullptr; @@ -415,6 +416,23 @@ void Application::m_unpackSkins() } } +bool Application::m_LoadSettingsStyleConfig(String skin) +{ + File configFile; + + // Reset to defaults incase skin can't load; + g_settingsStyleConfig.Clear(); + g_settingsStyleConfig.InitDefaults(); + + if (configFile.OpenRead(Path::Absolute("skins/" + skin + "/style.cfg"))) + { + FileReader reader(configFile); + if (g_settingsStyleConfig.Load(reader)) + return true; + } + return false; +} + bool Application::m_LoadConfig() { File configFile; @@ -679,6 +697,9 @@ bool Application::m_Init() } g_skinConfig = new SkinConfig(m_skin); + + m_LoadSettingsStyleConfig(m_skin); + // Window cursor Image cursorImg = ImageRes::Create(Path::Absolute("skins/" + m_skin + "/textures/cursor.png")); g_gameWindow->SetCursor(cursorImg, Vector2i(5, 5)); @@ -1284,6 +1305,9 @@ void Application::ReloadSkin() delete g_skinConfig; } g_skinConfig = new SkinConfig(m_skin); + + m_LoadSettingsStyleConfig(m_skin); + g_guiState.fontCahce.clear(); g_guiState.textCache.clear(); g_guiState.nextTextId.clear(); diff --git a/Main/src/GameConfig.cpp b/Main/src/GameConfig.cpp index 703abec14..169c3bc8a 100644 --- a/Main/src/GameConfig.cpp +++ b/Main/src/GameConfig.cpp @@ -137,4 +137,9 @@ void GameConfig::InitDefaults() Set(GameConfigKeys::RollIgnoreDuration, 100.f); Set(GameConfigKeys::LaserSlamLength, 100.f); + + // Internet Ranking + Set(GameConfigKeys::IRBaseURL, "https://api.orchestra.fm"); + Set(GameConfigKeys::IRUsername, ""); + Set(GameConfigKeys::IRPassword, ""); } diff --git a/Main/src/ScoreScreen.cpp b/Main/src/ScoreScreen.cpp index 3cd230e4b..309b53d51 100644 --- a/Main/src/ScoreScreen.cpp +++ b/Main/src/ScoreScreen.cpp @@ -12,6 +12,13 @@ #include "Shared/Time.hpp" #include "json.hpp" #include "CollectionDialog.hpp" +#include +#include "cryptopp/cryptlib.h" +#include "cryptopp/hex.h" +#include "cryptopp/sha3.h" +#include +#include + class ScoreScreen_Impl : public ScoreScreen { @@ -209,7 +216,49 @@ class ScoreScreen_Impl : public ScoreScreen m_graphTex->SetWrap(Graphics::TextureWrap::Clamp, Graphics::TextureWrap::Clamp); m_numPlayersSeen = m_stats->size(); - m_displayId = static_cast((*m_stats)[m_displayIndex].value("uid","")); + m_displayId = static_cast((*m_stats)[m_displayIndex].value("uid", "")); + + } + + void SubmitScoreToIR(class Game* game) { + Scoring& m_scoring = game->GetScoring(); + + // check if we can login + String url = g_gameConfig.GetString(GameConfigKeys::IRBaseURL); + + // hash the file of the chart we played + CryptoPP::SHA3_512 hash; + String digest; + CryptoPP::FileSource f( + std::istringstream(game->GetDifficultyIndex().path), + true, + new CryptoPP::HashFilter( + hash, + new CryptoPP::HexEncoder( + new CryptoPP::StringSink(digest)))); + + // get the ids from the file hash + auto res = nlohmann::json::parse(cpr::Get(cpr::Url{ url + "/api/v0/board/sha3/" + digest }).text); + + uint64 track_id = res["track_id"]; + uint64 board_id = res["id"]; + + // post the score + nlohmann::json score_info = { + {"track", track_id, }, + {"board", board_id, }, + {"score", m_scoring.CalculateCurrentScore(), }, + {"combo", m_scoring.maxComboCounter, }, + {"rate", m_scoring.currentGauge, }, + {"criticals", m_scoring.categorizedHits[2], }, + {"nears", m_scoring.categorizedHits[1] , }, + {"errors", m_scoring.categorizedHits[0], }, + {"mods", m_flags, }, + //{"replaydata", 0, }, does usc have replays? + }; + cpr::Post(cpr::Url{ url + "/api/v0/score" }, + cpr::Body{ score_info.dump() }, + cpr::Header{ {"Content-Type", "application/json"} }); } @@ -251,6 +300,9 @@ class ScoreScreen_Impl : public ScoreScreen loadScoresFromGame(game); } + // TODO: check if Internet Ranking is enabled + SubmitScoreToIR(game); + for (HitStat* stat : scoring.hitStats) { if (!stat->forReplay) diff --git a/Main/src/SettingsScreen.cpp b/Main/src/SettingsScreen.cpp index 2bcd0685f..1c8239a0f 100644 --- a/Main/src/SettingsScreen.cpp +++ b/Main/src/SettingsScreen.cpp @@ -86,6 +86,17 @@ int nk_propertyi_sdl_text(struct nk_context *ctx, const char *name, int min, int return value; } +struct nk_color nk_rgb(uint32 hex) +{ + return nk_rgb((hex >> 16) & 0xff, (hex >> 8) & 0xff, hex & 0xff); +} + +struct nk_color nk_rgb(const Color& c) +{ + Colori ci = c.ToRGBA8(); + return nk_rgb(ci.x, ci.y, ci.z); +} + float nk_propertyf_sdl_text(struct nk_context *ctx, const char *name, float min, float val, float max, float step, float inc_per_pixel) { @@ -115,6 +126,7 @@ class SettingsScreen_Impl : public SettingsScreen Vector m_aaModes = { "Off", "2x MSAA", "4x MSAA", "8x MSAA", "16x MSAA" }; Vector m_gamePads; Vector m_skins; + String m_loadedSkin; Vector m_keyboardKeys = { GameConfigKeys::Key_BTS, @@ -178,6 +190,12 @@ class SettingsScreen_Impl : public SettingsScreen int m_multiplayerPasswordLen = 0; char m_multiplayerUsername[1024]; int m_multiplayerUsernameLen = 0; + char m_irBaseURL[1024]; + int m_irBaseURLLen = 0; + char m_irUsername[1024]; + int m_irUsernameLen = 0; + char m_irPassword[1024]; + int m_irPasswordLen = 0; Vector* m_activeBTKeys = &m_keyboardKeys; bool m_useBTGamepad = false; bool m_useLaserGamepad = false; @@ -260,6 +278,21 @@ class SettingsScreen_Impl : public SettingsScreen multiplayerUsername.TrimBack(' '); g_gameConfig.Set(GameConfigKeys::MultiplayerUsername, multiplayerUsername); + String irBaseURL = String(m_irBaseURL, m_irBaseURLLen); + irBaseURL.TrimBack('\n'); + irBaseURL.TrimBack(' '); + g_gameConfig.Set(GameConfigKeys::IRBaseURL, irBaseURL); + + String irUsername = String(m_irUsername, m_irUsernameLen); + irUsername.TrimBack('\n'); + irUsername.TrimBack(' '); + g_gameConfig.Set(GameConfigKeys::IRUsername, irUsername); + + String irPassword = String(m_irPassword, m_irPasswordLen); + irPassword.TrimBack('\n'); + irPassword.TrimBack(' '); + g_gameConfig.Set(GameConfigKeys::IRPassword, irPassword); + if (g_gameConfig.GetEnum(GameConfigKeys::ButtonInputDevice) == InputDevice::Mouse) { g_gameConfig.SetEnum(GameConfigKeys::ButtonInputDevice, InputDevice::Keyboard); @@ -426,14 +459,12 @@ class SettingsScreen_Impl : public SettingsScreen //nk_style_load_all_cursors(m_nctx, atlas->cursors); nk_style_set_font(m_nctx, &fallback->handle); } - m_nctx->style.text.color = nk_rgb(255, 255, 255); - m_nctx->style.button.border_color = nk_rgb(0, 128, 255); - m_nctx->style.button.padding = nk_vec2(5,5); - m_nctx->style.button.rounding = 0; - m_nctx->style.window.fixed_background = nk_style_item_color(nk_rgb(40, 40, 40)); - m_nctx->style.slider.bar_normal = nk_rgb(20, 20, 20); - m_nctx->style.slider.bar_hover = nk_rgb(20, 20, 20); - m_nctx->style.slider.bar_active = nk_rgb(20, 20, 20); + + m_loadSkinStyle(); + + + + m_laserColors[0] = g_gameConfig.GetFloat(GameConfigKeys::Laser0Color); @@ -455,9 +486,217 @@ class SettingsScreen_Impl : public SettingsScreen strcpy(m_multiplayerUsername, multiplayerUsername.c_str()); m_multiplayerUsernameLen = multiplayerUsername.length(); + String irBaseURL = g_gameConfig.GetString(GameConfigKeys::IRBaseURL); + strcpy(m_irBaseURL, irBaseURL.c_str()); + m_irBaseURLLen = irBaseURL.length(); + + String irUsername = g_gameConfig.GetString(GameConfigKeys::IRUsername); + strcpy(m_irUsername, irUsername.c_str()); + m_irUsernameLen = irUsername.length(); + + String irPassword = g_gameConfig.GetString(GameConfigKeys::IRPassword); + strcpy(m_irPassword, irPassword.c_str()); + m_irPasswordLen = irPassword.length(); + return true; + } + + void m_loadSkinStyle() + { + m_loadedSkin = g_gameConfig.GetString(GameConfigKeys::Skin); + + // Global Styling + m_nctx->style.text.color = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::TextColor)); + m_nctx->style.window.fixed_background = nk_style_item_color(nk_rgb( + g_settingsStyleConfig.GetColor(SettingsStyleConfigKeys::BackgroundColor))); + m_nctx->style.window.background = (nk_rgb( + g_settingsStyleConfig.GetColor(SettingsStyleConfigKeys::ComboBoxBackgroundColor))); + m_nctx->style.window.border_color = nk_rgb( + g_settingsStyleConfig.GetColor(SettingsStyleConfigKeys::BorderColor)); + m_nctx->style.window.border = g_settingsStyleConfig.GetInt( + SettingsStyleConfigKeys::BorderWidth); + + // Button Text + m_nctx->style.button.text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ButtonTextColor)); + m_nctx->style.button.text_hover = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ButtonTextColorHover)); + + // Button Background + m_nctx->style.button.normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ButtonBackgroundColor))); + m_nctx->style.button.hover = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ButtonBackgroundColorHover))); + + // Button Border + m_nctx->style.button.border_color = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ButtonBorderColor)); + m_nctx->style.button.padding = nk_vec2( + g_settingsStyleConfig.GetInt(SettingsStyleConfigKeys::ButtonPaddingLeftRight), + g_settingsStyleConfig.GetInt(SettingsStyleConfigKeys::ButtonPaddingTopBottom)); + m_nctx->style.button.rounding = g_settingsStyleConfig.GetInt( + SettingsStyleConfigKeys::ButtonRounding); + m_nctx->style.button.border = g_settingsStyleConfig.GetInt( + SettingsStyleConfigKeys::ButtonBorderWidth); + + + // Tree node styling + m_nctx->style.tab.text = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::NodeTextColor)); + m_nctx->style.tab.node_minimize_button.text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::NodeArrowColor)); + m_nctx->style.tab.node_minimize_button.normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::NodeArrowBackgroundColor))); + m_nctx->style.tab.node_maximize_button.text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::NodeArrowColor)); + m_nctx->style.tab.node_maximize_button.normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::NodeArrowBackgroundColor))); + + // Option styling + m_nctx->style.option.text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::OptionTextColor)); + m_nctx->style.option.text_active = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::OptionTextColor)); + m_nctx->style.option.text_hover = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::OptionTextColor)); + m_nctx->style.option.border_color = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::OptionBorderColor)); + m_nctx->style.option.normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::OptionColor))); + m_nctx->style.option.cursor_normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::OptionColorChecked))); + m_nctx->style.option.cursor_hover = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::OptionColorCheckedHover))); + m_nctx->style.option.hover = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::OptionColorHover))); + m_nctx->style.option.border = g_settingsStyleConfig.GetInt( + SettingsStyleConfigKeys::OptionBorderWidth); + + // Check styling + m_nctx->style.checkbox.text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::CheckTextColor)); + m_nctx->style.checkbox.text_active = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::CheckTextColor)); + m_nctx->style.checkbox.text_hover = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::OptionTextColor)); + m_nctx->style.checkbox.border_color = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::CheckBorderColor)); + m_nctx->style.checkbox.normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::CheckColor))); + m_nctx->style.checkbox.cursor_normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::CheckColorChecked))); + m_nctx->style.checkbox.cursor_hover = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::CheckColorCheckedHover))); + m_nctx->style.checkbox.hover = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::CheckColorHover))); + m_nctx->style.checkbox.border = g_settingsStyleConfig.GetInt( + SettingsStyleConfigKeys::CheckBorderWidth); + + // Slider styles + m_nctx->style.slider.bar_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::SliderBarEmptyColor)); + m_nctx->style.slider.bar_hover = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::SliderBarEmptyColor)); + m_nctx->style.slider.bar_filled = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::SliderBarFilledColor)); + m_nctx->style.slider.cursor_normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::SliderBallColor))); + m_nctx->style.slider.cursor_hover = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::SliderBallColorHover))); + + // Combo Button styles + m_nctx->style.combo.label_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ComboButtonTextColor)); + m_nctx->style.combo.button.text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ComboButtonArrowColor)); + m_nctx->style.combo.label_hover = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ComboButtonTextColorHover)); + m_nctx->style.combo.normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ComboButtonBackgroundColor))); + m_nctx->style.combo.button.normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ComboButtonBackgroundColor))); + m_nctx->style.combo.hover = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ComboButtonBackgroundColorHover))); + m_nctx->style.combo.button.hover = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ComboButtonBackgroundColorHover))); + + // Combo Box Styles + m_nctx->style.contextual_button.text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ComboBoxTextColor)); + m_nctx->style.contextual_button.text_hover = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ComboBoxTextColorHover)); + m_nctx->style.contextual_button.normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ComboBoxBackgroundColor))); + m_nctx->style.contextual_button.hover = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::ComboBoxBackgroundColorHover))); + + // Property Styles + m_nctx->style.property.label_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::PropertyTextColor)); + m_nctx->style.property.label_active = m_nctx->style.property.label_normal; + m_nctx->style.property.label_hover = m_nctx->style.property.label_normal; + + m_nctx->style.property.normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::PropertyBackgroundColor))); + m_nctx->style.property.active = m_nctx->style.property.normal; + m_nctx->style.property.hover = m_nctx->style.property.normal; + + m_nctx->style.property.edit.text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::PropertyEditTextColor)); + m_nctx->style.property.edit.text_active = m_nctx->style.property.edit.text_normal; + m_nctx->style.property.edit.text_hover = m_nctx->style.property.edit.text_hover; + + m_nctx->style.property.edit.selected_text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::PropertyEditSelectedTextColor)); + m_nctx->style.property.edit.selected_text_hover = m_nctx->style.property.edit.selected_text_normal; + m_nctx->style.property.edit.cursor_text_normal = m_nctx->style.property.edit.selected_text_normal; + m_nctx->style.property.edit.cursor_text_hover = m_nctx->style.property.edit.selected_text_normal; + + m_nctx->style.property.edit.selected_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::PropertyEditSelectedBackgroundColor)); + m_nctx->style.property.edit.selected_hover = m_nctx->style.property.edit.selected_normal; + m_nctx->style.property.edit.cursor_normal = m_nctx->style.property.edit.selected_normal; + m_nctx->style.property.edit.cursor_hover = m_nctx->style.property.edit.selected_normal; + + m_nctx->style.property.edit.normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::PropertyEditBackgroundColor))); + m_nctx->style.property.edit.active = m_nctx->style.property.edit.normal; + m_nctx->style.property.edit.hover = m_nctx->style.property.edit.normal; + + m_nctx->style.property.inc_button.normal = m_nctx->style.property.normal; + m_nctx->style.property.inc_button.text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::PropertyArrowColor)); + + m_nctx->style.property.dec_button.normal = m_nctx->style.property.normal; + m_nctx->style.property.dec_button.text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::PropertyArrowColor)); + + // Edit styles + m_nctx->style.edit.text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::EditTextColor)); + m_nctx->style.edit.text_active = m_nctx->style.property.edit.text_normal; + m_nctx->style.edit.text_hover = m_nctx->style.property.edit.text_hover; + + m_nctx->style.edit.selected_text_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::EditSelectedTextColor)); + m_nctx->style.edit.selected_text_hover = m_nctx->style.property.edit.selected_text_normal; + m_nctx->style.edit.cursor_text_normal = m_nctx->style.property.edit.selected_text_normal; + m_nctx->style.edit.cursor_text_hover = m_nctx->style.property.edit.selected_text_normal; + + m_nctx->style.edit.selected_normal = nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::EditSelectedBackgroundColor)); + m_nctx->style.edit.selected_hover = m_nctx->style.property.edit.selected_normal; + m_nctx->style.edit.cursor_normal = m_nctx->style.property.edit.selected_normal; + m_nctx->style.edit.cursor_hover = m_nctx->style.property.edit.selected_normal; + + m_nctx->style.edit.normal = nk_style_item_color(nk_rgb(g_settingsStyleConfig.GetColor( + SettingsStyleConfigKeys::EditBackgroundColor))); + m_nctx->style.edit.active = m_nctx->style.property.edit.normal; + m_nctx->style.edit.hover = m_nctx->style.property.edit.normal; } + void Tick(float deltatime) { @@ -646,7 +885,11 @@ class SettingsScreen_Impl : public SettingsScreen if (m_skins.size() > 0) { - StringSelectionSetting(GameConfigKeys::Skin, m_skins, "Selected Skin:"); + String selSkin = StringSelectionSetting(GameConfigKeys::Skin, m_skins, "Selected Skin:"); + if (selSkin != m_loadedSkin) { + g_application->ReloadSkin(); + m_loadSkinStyle(); + } } nk_label(m_nctx, "Laser colors:", nk_text_alignment::NK_TEXT_LEFT); @@ -695,6 +938,15 @@ class SettingsScreen_Impl : public SettingsScreen nk_label(m_nctx, "Multiplayer Server Password:", nk_text_alignment::NK_TEXT_LEFT); nk_sdl_text(nk_edit_string(m_nctx, NK_EDIT_FIELD, m_multiplayerPassword, &m_multiplayerPasswordLen, 1024, nk_filter_default)); + + nk_label(m_nctx, "Internet Ranking URL:", nk_text_alignment::NK_TEXT_LEFT); + nk_sdl_text(nk_edit_string(m_nctx, NK_EDIT_FIELD, m_irBaseURL, &m_irBaseURLLen, 1024, nk_filter_default)); + + nk_label(m_nctx, "Account Username for Internet Ranking:", nk_text_alignment::NK_TEXT_LEFT); + nk_sdl_text(nk_edit_string(m_nctx, NK_EDIT_FIELD, m_irUsername, &m_irUsernameLen, 1024, nk_filter_default)); + + nk_label(m_nctx, "Account Password for Internet Ranking:", nk_text_alignment::NK_TEXT_LEFT); + nk_sdl_text(nk_edit_string(m_nctx, NK_EDIT_FIELD, m_irPassword, &m_irPasswordLen, 1024, nk_filter_default)); nk_tree_pop(m_nctx); } @@ -710,6 +962,8 @@ class SettingsScreen_Impl : public SettingsScreen else { m_skinBeforeSkinSettings = ""; + g_application->ReloadSkin(); + m_loadSkinStyle(); } if (nk_button_label(m_nctx, "Exit")) Exit(); nk_end(m_nctx); diff --git a/Main/src/SkinConfig.cpp b/Main/src/SkinConfig.cpp index 55b4e891f..ae0488190 100644 --- a/Main/src/SkinConfig.cpp +++ b/Main/src/SkinConfig.cpp @@ -322,3 +322,81 @@ void SkinConfig::Set(String key, const String& value) m_dirty = true; } } + + +SettingsStyleConfig::SettingsStyleConfig() +{ + // Default state + Clear(); + InitDefaults(); +} + +void SettingsStyleConfig::InitDefaults() +{ + Set(SettingsStyleConfigKeys::BackgroundColor, Colori(40,40,40)); + Set(SettingsStyleConfigKeys::BorderColor, Colori(0, 0, 0)); + Set(SettingsStyleConfigKeys::BorderWidth, 0); + Set(SettingsStyleConfigKeys::TextColor, Colori(255, 255, 255)); + + Set(SettingsStyleConfigKeys::ButtonBorderColor, Colori(0, 128, 255)); + Set(SettingsStyleConfigKeys::ButtonPaddingLeftRight, 5); + Set(SettingsStyleConfigKeys::ButtonPaddingTopBottom, 5); + Set(SettingsStyleConfigKeys::ButtonRounding, 0); + Set(SettingsStyleConfigKeys::ButtonBorderWidth, 1); + + Set(SettingsStyleConfigKeys::ButtonBackgroundColor, Colori(40,40,40)); + Set(SettingsStyleConfigKeys::ButtonBackgroundColorHover, Colori(50, 50, 50)); + Set(SettingsStyleConfigKeys::ButtonTextColor, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::ButtonTextColorHover, Colori(156, 156, 156)); + + Set(SettingsStyleConfigKeys::NodeTextColor, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::NodeArrowColor, Colori(175, 175, 175)); + Set(SettingsStyleConfigKeys::NodeArrowBackgroundColor, Colori(50, 50, 50)); + + Set(SettingsStyleConfigKeys::OptionTextColor, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::OptionColor, Colori(100,100,100)); + Set(SettingsStyleConfigKeys::OptionColorChecked, Colori(45, 45, 45)); + Set(SettingsStyleConfigKeys::OptionColorCheckedHover, Colori(45, 45, 45)); + Set(SettingsStyleConfigKeys::OptionColorHover, Colori(120, 120, 120)); + Set(SettingsStyleConfigKeys::OptionBorderColor, Colori(0,0,0,0)); + Set(SettingsStyleConfigKeys::OptionBorderWidth, 0); + + Set(SettingsStyleConfigKeys::CheckTextColor, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::CheckColor, Colori(100, 100, 100)); + Set(SettingsStyleConfigKeys::CheckColorChecked, Colori(45, 45, 45)); + Set(SettingsStyleConfigKeys::CheckColorCheckedHover, Colori(45, 45, 45)); + Set(SettingsStyleConfigKeys::CheckColorHover, Colori(120, 120, 120)); + Set(SettingsStyleConfigKeys::CheckBorderColor, Colori(0, 0, 0, 0)); + Set(SettingsStyleConfigKeys::CheckBorderWidth, 0); + + Set(SettingsStyleConfigKeys::SliderBarFilledColor, Colori(120,120,120)); + Set(SettingsStyleConfigKeys::SliderBarEmptyColor, Colori(0,0,0)); + Set(SettingsStyleConfigKeys::SliderBallColor, Colori(120, 120, 120)); + Set(SettingsStyleConfigKeys::SliderBallColorHover, Colori(142, 142, 142)); + + Set(SettingsStyleConfigKeys::ComboButtonTextColor, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::ComboButtonTextColorHover, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::ComboButtonBackgroundColor, Colori(50, 50, 50)); + Set(SettingsStyleConfigKeys::ComboButtonBackgroundColorHover, Colori(50, 50, 50)); + Set(SettingsStyleConfigKeys::ComboButtonArrowColor, Colori(120, 120, 120)); + + Set(SettingsStyleConfigKeys::ComboBoxTextColor, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::ComboBoxTextColorHover, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::ComboBoxBackgroundColor, Colori(50, 50, 50)); + Set(SettingsStyleConfigKeys::ComboBoxBackgroundColorHover, Colori(60, 60, 60)); + + Set(SettingsStyleConfigKeys::PropertyTextColor, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::PropertyBackgroundColor, Colori(40, 40, 40)); + Set(SettingsStyleConfigKeys::PropertyEditTextColor, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::PropertyEditBackgroundColor, Colori(40, 40, 40)); + Set(SettingsStyleConfigKeys::PropertyEditSelectedTextColor, Colori(40,40,40)); + Set(SettingsStyleConfigKeys::PropertyEditSelectedBackgroundColor, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::PropertyArrowColor, Colori(156, 156, 156)); + + Set(SettingsStyleConfigKeys::EditTextColor, Colori(156, 156, 156)); + Set(SettingsStyleConfigKeys::EditBackgroundColor, Colori(40, 40, 40)); + Set(SettingsStyleConfigKeys::EditSelectedTextColor, Colori(40,40,40)); + Set(SettingsStyleConfigKeys::EditSelectedBackgroundColor, Colori(156, 156, 156)); + + +} \ No newline at end of file diff --git a/Shared/CMakeLists.txt b/Shared/CMakeLists.txt index a2e1eee3e..d19c7f48e 100644 --- a/Shared/CMakeLists.txt +++ b/Shared/CMakeLists.txt @@ -45,3 +45,4 @@ target_include_directories(Shared PRIVATE ) target_link_libraries(Shared lua) +target_link_libraries(Shared cryptopp-static) \ No newline at end of file diff --git a/Shared/include/Shared/Config.hpp b/Shared/include/Shared/Config.hpp index b3d75dc16..b0fe4fd14 100644 --- a/Shared/include/Shared/Config.hpp +++ b/Shared/include/Shared/Config.hpp @@ -75,6 +75,10 @@ class Config : public ConfigBase { return GetEnsure(key)->data; } + const Color& GetColor(KeyType key) const + { + return GetEnsure(key)->data; + } template typename EnumClass1::EnumType GetEnum(KeyType key) const { @@ -126,6 +130,25 @@ class Config : public ConfigBase m_dirty = true; } } + void Set(KeyType key, const Color& value) + { + Color& dst = SetEnsure(key)->data; + if (dst != value) + { + dst = value; + m_dirty = true; + } + } + void Set(KeyType key, const Colori& valuei) + { + const Color value = Color(valuei); + Color& dst = SetEnsure(key)->data; + if (dst != value) + { + dst = value; + m_dirty = true; + } + } template void SetEnum(KeyType key, typename EnumClass1::EnumType value) { diff --git a/Shared/src/ConfigEntry.cpp b/Shared/src/ConfigEntry.cpp index 2bc445707..ebddd232e 100644 --- a/Shared/src/ConfigEntry.cpp +++ b/Shared/src/ConfigEntry.cpp @@ -41,14 +41,20 @@ void FloatConfigEntry::FromString(const String& str) String ColorConfigEntry::ToString() const { Colori ci = data.ToRGBA8(); - return Utility::Sprintf("%02X%02X%02X%02X", ci.x, ci.y, ci.z, ci.w); + return Utility::Sprintf("#%02X%02X%02X%02X", ci.x, ci.y, ci.z, ci.w); } void ColorConfigEntry::FromString(const String& str) { int r, g, b, a; - sscanf(str.substr(0, 2).c_str(), "%X", &r); - sscanf(str.substr(2, 2).c_str(), "%X", &g); - sscanf(str.substr(4, 2).c_str(), "%X", &b); - sscanf(str.substr(6, 2).c_str(), "%X", &a); - data = Colori(r,g,b,a); + int start = 0; + if (str[0] == '#') + start = 1; + sscanf(str.substr(start, 2).c_str(), "%X", &r); + sscanf(str.substr(start+2, 2).c_str(), "%X", &g); + sscanf(str.substr(start+4, 2).c_str(), "%X", &b); + + // If ther is no alpha, default to 255 + a = 255; + sscanf(str.substr(start+6, 2).c_str(), "%X", &a); + data = Colori(r, g, b, a); } \ No newline at end of file diff --git a/build.windows b/build.windows index 0b6e73736..b8d3ec008 100644 --- a/build.windows +++ b/build.windows @@ -5,3 +5,4 @@ sdl2:x64-windows libjpeg-turbo:x64-windows libvorbis:x64-windows libarchive[core,bzip2,libxml2,lz4,lzma,lzo]:x64-windows +cryptopp:x64-windows \ No newline at end of file