diff --git a/include/SSVOpenHexagon/Data/StyleData.hpp b/include/SSVOpenHexagon/Data/StyleData.hpp index 646d9aa68..67701c173 100644 --- a/include/SSVOpenHexagon/Data/StyleData.hpp +++ b/include/SSVOpenHexagon/Data/StyleData.hpp @@ -87,12 +87,20 @@ class StyleData float _3dPulseSpeed{}; float _3dPerspectiveMult{}; + sf::Color _mainOverrideColor; + sf::Color _playerOverrideColor; + sf::Color _textOverrideColor; + sf::Color _wallOverrideColor; + sf::Color _capOverrideColor; + sf::Color _3dOverrideColor; + std::vector _overrideColors; + std::vector _3dOverrideColors; + float bgTileRadius{10000.f}; unsigned int BGColorOffset{0}; float BGRotOff{0}; // In degrees private: - sf::Color _3dOverrideColor; ColorData mainColorData; ColorData playerColor; ColorData textColor; @@ -102,6 +110,8 @@ class StyleData std::vector colorDatas; + float last3dDepth{}; + public: explicit StyleData(); explicit StyleData(const ssvuj::Obj& mRoot); diff --git a/src/SSVOpenHexagon/Core/HGGraphics.cpp b/src/SSVOpenHexagon/Core/HGGraphics.cpp index 6098d4815..7607be3b9 100644 --- a/src/SSVOpenHexagon/Core/HGGraphics.cpp +++ b/src/SSVOpenHexagon/Core/HGGraphics.cpp @@ -198,11 +198,15 @@ void HexagonGame::draw() const sf::Vector2f newPos(offset * cosRot, offset * sinRot); sf::Color overrideColor; + bool mustOverride{styleData._3dOverrideColors[i].a != 0}; if(!Config::getBlackAndWhite()) { - overrideColor = Utils::getColorDarkened( - styleData.get3DOverrideColor(), styleData._3dDarkenMult); + overrideColor = mustOverride + ? styleData._3dOverrideColors[i] + : Utils::getColorDarkened( + styleData.get3DOverrideColor(), + styleData._3dDarkenMult); } else { @@ -210,7 +214,10 @@ void HexagonGame::draw() sf::Color(255, 255, 255, styleData.getMainColor().a), styleData._3dDarkenMult); } - adjustAlpha(overrideColor, i); + if(!mustOverride) + { + adjustAlpha(overrideColor, i); + } // Draw pivot layers for(std::size_t k = j * numPivotQuads; k < (j + 1) * numPivotQuads; @@ -220,7 +227,7 @@ void HexagonGame::draw() pivotQuads3D[k].color = overrideColor; } - if(styleData.get3DOverrideColor() == styleData.getMainColor()) + if(styleData.get3DOverrideColor() == styleData.getMainColor() && !mustOverride) { overrideColor = Utils::getColorDarkened( getColorWall(), styleData._3dDarkenMult); @@ -237,7 +244,7 @@ void HexagonGame::draw() } // Apply player color if no 3D override is present. - if(styleData.get3DOverrideColor() == styleData.getMainColor()) + if(styleData.get3DOverrideColor() == styleData.getMainColor() && !mustOverride) { overrideColor = Utils::getColorDarkened( getColorPlayer(), styleData._3dDarkenMult); @@ -596,7 +603,8 @@ void HexagonGame::updateText(ssvu::FT mFT) } } -void HexagonGame::drawText_TimeAndStatus(const sf::Color& offsetColor, const sf::RenderStates& mStates) +void HexagonGame::drawText_TimeAndStatus( + const sf::Color& offsetColor, const sf::RenderStates& mStates) { if(Config::getDrawTextOutlines()) { @@ -701,14 +709,17 @@ static void drawTextMessagePBImpl(sf::Text& text, const sf::Color& offsetColor, fRender(text); } -void HexagonGame::drawText_Message(const sf::Color& offsetColor, const sf::RenderStates& mStates) +void HexagonGame::drawText_Message( + const sf::Color& offsetColor, const sf::RenderStates& mStates) { drawTextMessagePBImpl(messageText, offsetColor, {Config::getWidth() / 2.f, Config::getHeight() / 5.5f}, getColorText(), - 1.f /* outlineThickness */, [this, &mStates](sf::Text& t) { render(t, mStates); }); + 1.f /* outlineThickness */, + [this, &mStates](sf::Text& t) { render(t, mStates); }); } -void HexagonGame::drawText_PersonalBest(const sf::Color& offsetColor, const sf::RenderStates& mStates) +void HexagonGame::drawText_PersonalBest( + const sf::Color& offsetColor, const sf::RenderStates& mStates) { drawTextMessagePBImpl(pbText, offsetColor, {Config::getWidth() / 2.f, diff --git a/src/SSVOpenHexagon/Core/LuaScripting.cpp b/src/SSVOpenHexagon/Core/LuaScripting.cpp index 6e233733b..6323be056 100644 --- a/src/SSVOpenHexagon/Core/LuaScripting.cpp +++ b/src/SSVOpenHexagon/Core/LuaScripting.cpp @@ -1156,16 +1156,42 @@ static void initStyleControl(Lua::LuaContext& lua, StyleData& styleData) " color computed by the level style.")); }; + const auto sdColorSetter = + [&lua, &styleData](const char* name, const char* docName, auto pmd) + { + addLuaFn(lua, name, + [&styleData, pmd](int r, int g, int b, int a) + { (styleData.*pmd) = sf::Color(r, g, b, a); }) + .arg("r") + .arg("g") + .arg("b") + .arg("a") + .doc(Utils::concat( + "Set the ", docName, " color (only used if `$3` is not 0)")); + }; + sdColorGetter("s_getMainColor", "main", &StyleData::getMainColor); sdColorGetter("s_getPlayerColor", "player", &StyleData::getPlayerColor); sdColorGetter("s_getTextColor", "text", &StyleData::getTextColor); - + sdColorGetter("s_getWallColor", "wall", &StyleData::getWallColor); sdColorGetter( "s_get3DOverrideColor", "3D override", &StyleData::get3DOverrideColor); - sdColorGetter("s_getCapColorResult", "cap color result", &StyleData::getCapColorResult); + sdColorSetter("s_setMainOverrideColor", "main override", + &StyleData::_mainOverrideColor); + sdColorSetter("s_setPlayerOverrideColor", "player override", + &StyleData::_playerOverrideColor); + sdColorSetter("s_setTextOverrideColor", "text override", + &StyleData::_textOverrideColor); + sdColorSetter("s_setWallOverrideColor", "wall override", + &StyleData::_wallOverrideColor); + sdColorSetter( + "s_set3DOverrideColor", "3D override", &StyleData::_3dOverrideColor); + sdColorSetter( + "s_setCapOverrideColor", "cap override", &StyleData::_capOverrideColor); + addLuaFn(lua, "s_getColor", [&styleData, &colorToTuple](int mIndex) { @@ -1180,6 +1206,50 @@ static void initStyleControl(Lua::LuaContext& lua, StyleData& styleData) .doc( "Return the current color with index `$0` computed by the level " "style."); + addLuaFn(lua, "s_setOverrideColor", + [&styleData](int mIndex, int r, int g, int b, int a) + { + if(mIndex < styleData._overrideColors.size() && mIndex >= 0) + { + styleData._overrideColors[mIndex] = sf::Color(r, g, b, a); + } + else + { + ssvu::lo("hg::LuaScripting::initStyleControl") + << "`s_setOverrideColor` failed, no color found at index " + << mIndex << "\n"; + } + }) + .arg("index") + .arg("r") + .arg("g") + .arg("b") + .arg("a") + .doc("Set the color with index `$0` (only used if `$4` is not 0)"); + + addLuaFn(lua, "s_set3DLayerOverrideColor", + [&styleData](int mIndex, int r, int g, int b, int a) + { + if(mIndex < styleData._3dOverrideColors.size() && mIndex >= 0) + { + styleData._3dOverrideColors[mIndex] = sf::Color(r, g, b, a); + } + else + { + ssvu::lo("hg::LuaScripting::initStyleControl") + << "`s_set3DLayerOverrideColor` failed, no color found at " + "index " + << mIndex << "\n"; + } + }) + .arg("index") + .arg("r") + .arg("g") + .arg("b") + .arg("a") + .doc( + "Set the 3D layer color with index `$0` (only used if `$4` is not " + "0)"); } static void initExecScript(Lua::LuaContext& lua, HGAssets& assets, diff --git a/src/SSVOpenHexagon/Data/StyleData.cpp b/src/SSVOpenHexagon/Data/StyleData.cpp index 0db0a06e9..41f8f7c6b 100644 --- a/src/SSVOpenHexagon/Data/StyleData.cpp +++ b/src/SSVOpenHexagon/Data/StyleData.cpp @@ -54,6 +54,11 @@ StyleData::StyleData(const ssvuj::Obj& mRoot) _3dPulseSpeed{ssvuj::getExtr(mRoot, "3D_pulse_speed", 0.01f)}, _3dPerspectiveMult{ ssvuj::getExtr(mRoot, "3D_perspective_multiplier", 1.f)}, + _mainOverrideColor{sf::Color::Transparent}, + _playerOverrideColor{sf::Color::Transparent}, + _textOverrideColor{sf::Color::Transparent}, + _wallOverrideColor{sf::Color::Transparent}, + _capOverrideColor{sf::Color::Transparent}, _3dOverrideColor{ssvuj::getExtr( mRoot, "3D_override_color", sf::Color::Transparent)}, mainColorData{ssvuj::getObj(mRoot, "main")}, // @@ -62,7 +67,8 @@ StyleData::StyleData(const ssvuj::Obj& mRoot) textColor{ colorDataFromObjOrDefault(mRoot, "text_color", mainColorData)}, // wallColor{colorDataFromObjOrDefault(mRoot, "wall_color", mainColorData)}, - capColor{parseCapColor(ssvuj::getObj(mRoot, "cap_color"))} + capColor{parseCapColor(ssvuj::getObj(mRoot, "cap_color"))}, + last3dDepth{_3dDepth} { currentHue = hueMin; @@ -70,9 +76,16 @@ StyleData::StyleData(const ssvuj::Obj& mRoot) const auto& colorCount(ssvuj::getObjSize(objColors)); colorDatas.reserve(colorCount); + _overrideColors.reserve(colorCount); for(auto i(0u); i < colorCount; i++) { colorDatas.emplace_back(ssvuj::getObj(objColors, i)); + _overrideColors.emplace_back(sf::Color::Transparent); + } + _3dOverrideColors.reserve(_3dDepth); + for(auto i(0u); i < _3dDepth; i++) + { + _3dOverrideColors.emplace_back(sf::Color::Transparent); } } @@ -167,23 +180,46 @@ void StyleData::update(ssvu::FT mFT, float mMult) pulseIncrement *= -1.f; pulseFactor = pulseMax; } + + if(_3dDepth != last3dDepth) + { + _3dOverrideColors.clear(); + for(auto i(0u); i < _3dDepth; i++) + { + _3dOverrideColors.emplace_back(sf::Color::Transparent); + } + last3dDepth = _3dDepth; + } } void StyleData::computeColors() { - currentMainColor = calculateColor(currentHue, pulseFactor, mainColorData); - currentPlayerColor = calculateColor(currentHue, pulseFactor, playerColor); - currentTextColor = calculateColor(currentHue, pulseFactor, textColor); - currentWallColor = calculateColor(currentHue, pulseFactor, wallColor); + currentMainColor = + _mainOverrideColor.a != 0 + ? _mainOverrideColor + : calculateColor(currentHue, pulseFactor, mainColorData); + currentPlayerColor = + _playerOverrideColor.a != 0 + ? _playerOverrideColor + : calculateColor(currentHue, pulseFactor, playerColor); + currentTextColor = _textOverrideColor.a != 0 + ? _textOverrideColor + : calculateColor(currentHue, pulseFactor, textColor); + currentWallColor = _wallOverrideColor.a != 0 + ? _wallOverrideColor + : calculateColor(currentHue, pulseFactor, wallColor); current3DOverrideColor = _3dOverrideColor.a != 0 ? _3dOverrideColor : getMainColor(); currentColors.clear(); - for(const ColorData& cd : colorDatas) + for(auto i(0u); i < colorDatas.size(); ++i) { - currentColors.emplace_back(calculateColor(currentHue, pulseFactor, cd)); + currentColors.emplace_back( + _overrideColors[i].a != 0 + ? _overrideColors[i] + : calculateColor(currentHue, pulseFactor, colorDatas[i])); } if(currentColors.size() > 1) @@ -341,14 +377,18 @@ StyleData::getColors() const noexcept sf::Color StyleData::getCapColorResult() const noexcept { - return Utils::match( - capColor, // - [this](CapColorMode::Main) { return getMainColor(); }, // - [this](CapColorMode::MainDarkened) - { return Utils::getColorDarkened(getMainColor(), 1.4f); }, // - [this](CapColorMode::ByIndex x) { return getColor(x._index); }, // - [this](const ColorData& data) - { return calculateColor(currentHue, pulseFactor, data); }); + return _capOverrideColor.a != 0 + ? _capOverrideColor + : Utils::match( + capColor, // + [this](CapColorMode::Main) { return getMainColor(); }, // + [this](CapColorMode::MainDarkened) { + return Utils::getColorDarkened(getMainColor(), 1.4f); + }, // + [this](CapColorMode::ByIndex x) + { return getColor(x._index); }, // + [this](const ColorData& data) + { return calculateColor(currentHue, pulseFactor, data); }); } } // namespace hg