Merge branch 'mwui' into 'master'

Dehardcode script settings window font and colors

See merge request OpenMW/openmw!4798
This commit is contained in:
Andrei Kortunov 2025-09-21 02:00:16 +00:00
commit a1bda752e4
7 changed files with 63 additions and 5 deletions

View File

@ -158,6 +158,14 @@ namespace
EXPECT_EQ(get<std::string>(lua, "darkRed:asHex()"), "a01112");
EXPECT_TRUE(get<bool>(lua, "green:asRgba() == util.vector4(0, 1, 0, 1)"));
EXPECT_TRUE(get<bool>(lua, "red:asRgb() == util.vector3(1, 0, 0)"));
lua.safe_script("green = util.color.commaString('0,255,0')");
EXPECT_EQ(get<std::string>(lua, "tostring(green)"), "(0, 1, 0, 1)");
lua.safe_script("red = util.color.commaString('255, 0, 0, 255')");
EXPECT_EQ(get<std::string>(lua, "tostring(red)"), "(1, 0, 0, 1)");
lua.safe_script("blue = util.color.commaString('0, 0, 1000, 255')");
EXPECT_EQ(get<std::string>(lua, "tostring(blue)"), "(0, 0, 1, 1)");
lua.safe_script("white = util.color.commaString('aaa')");
EXPECT_EQ(get<std::string>(lua, "tostring(white)"), "(1, 1, 1, 1)");
}
TEST_F(LuaUtilPackageTest, Transform)

View File

@ -92,6 +92,7 @@ namespace MWLua
luaManager->addAction([state] { MWBase::Environment::get().getWindowManager()->setHudVisibility(state); });
};
api["_isHudVisible"] = []() -> bool { return MWBase::Environment::get().getWindowManager()->isHudVisible(); };
api["getDefaultFontSize"] = []() -> int { return Settings::gui().mFontSize; };
api["showMessage"]
= [luaManager = context.mLuaManager](std::string_view message, const sol::optional<sol::table>& options) {
MWGui::ShowInDialogueMode mode = MWGui::ShowInDialogueMode_IfPossible;

View File

@ -6,8 +6,13 @@
#include <limits>
#include <sstream>
#include <components/debug/debuglog.hpp>
#include <components/misc/color.hpp>
#include <components/misc/mathutil.hpp>
#include <components/misc/strings/algorithm.hpp>
#include <MyGUI_StringUtility.h>
#include "luastate.hpp"
#include "util.hpp"
@ -243,6 +248,30 @@ namespace LuaUtil
color["rgba"] = [](float r, float g, float b, float a) { return Misc::Color(r, g, b, a); };
color["rgb"] = [](float r, float g, float b) { return Misc::Color(r, g, b, 1); };
color["hex"] = [](std::string_view hex) { return Misc::Color::fromHex(hex); };
color["commaString"] = [](std::string_view str) {
int wrongChars = std::count_if(
str.begin(), str.end(), [](unsigned char c) { return !std::isdigit(c) && c != ' ' && c != ','; });
if (wrongChars != 0)
{
Log(Debug::Warning) << "Invalid comma-separated color: " << str;
return Misc::Color(1, 1, 1, 1);
}
std::vector<std::string> rgba;
Misc::StringUtils::split(str, rgba, ",");
if (rgba.size() != 3 && rgba.size() != 4)
{
Log(Debug::Warning) << "Invalid comma-separated color: " << str;
return Misc::Color(1, 1, 1, 1);
}
if (rgba.size() == 3)
rgba.push_back("255");
return Misc::Color(MyGUI::utility::parseInt(rgba[0]) / 255.f, MyGUI::utility::parseInt(rgba[1]) / 255.f,
MyGUI::utility::parseInt(rgba[2]) / 255.f, MyGUI::utility::parseInt(rgba[3]) / 255.f);
};
util["color"] = LuaUtil::makeReadOnly(color);
// Lua bindings for Transform

View File

@ -1,11 +1,12 @@
local core = require('openmw.core')
local ui = require('openmw.ui')
local util = require('openmw.util')
return {
textNormalSize = 16,
textHeaderSize = 16,
headerColor = util.color.rgb(223 / 255, 201 / 255, 159 / 255),
normalColor = util.color.rgb(202 / 255, 165 / 255, 96 / 255),
textNormalSize = ui.getDefaultFontSize(),
textHeaderSize = ui.getDefaultFontSize(),
headerColor = util.color.commaString(core.getGMST("FontColor_color_header")),
normalColor = util.color.commaString(core.getGMST("FontColor_color_normal")),
border = 2,
thickBorder = 4,
padding = 2,

View File

@ -57,10 +57,13 @@
-- @return #number
---
-- Get a GMST setting from content files.
-- Get a game setting with given name (from GMST ESM records or from openmw.cfg).
-- @function [parent=#core] getGMST
-- @param #string setting Setting name
-- @return #any
-- @usage local skillBonus = core.getGMST('fMinorSkillBonus') -- get a numeric GMST from ESM data
-- @usage local jailFormatString = core.getGMST('sNotifyMessage42') -- get a string GMST from ESM data
-- @usage local bloodTextureName = core.getGMST('Blood_Texture_1') -- get a "fallback" parameter value from openmw.cfg (always a string)
---
-- The game's difficulty setting.

View File

@ -48,6 +48,12 @@
-- };
-- ui.showMessage("Hello world", params)
---
-- Returns a default font size from engine settings
-- @function [parent=#ui] getDefaultFontSize
-- @return #number
-- @usage local fontSize = ui.getDefaultFontSize();
---
-- Predefined colors for console output
-- @field [parent=#ui] #CONSOLE_COLOR CONSOLE_COLOR

View File

@ -477,6 +477,16 @@
-- @param #number a
-- @return #Color
---
-- Creates a Color from comma-separated string (in RGB or RGBA order, spaces are ignored)
-- @function [parent=#COLOR] commaString
-- @param #string str
-- @return #Color
-- @usage local color = util.color.commaString('255,0,0') -- red color
-- @usage local color = util.color.commaString('10000,0,0') -- red color (values are still capped at 255)
-- @usage local color = util.color.commaString('0, 0, 255, 255') -- blue color, with explicit alpha
-- @usage local color = util.color.commaString('0,255,0,128') -- green color, semi-transparent
---
-- Creates a Color from RGB format. Equivalent to calling util.rgba with a = 1.
-- @function [parent=#COLOR] rgb