mirror of
https://github.com/OpenMW/openmw.git
synced 2025-11-10 07:26:42 +00:00
Merge branch 'mwui' into 'master'
Dehardcode script settings window font and colors See merge request OpenMW/openmw!4798
This commit is contained in:
commit
2e4020a244
7 changed files with 53 additions and 6 deletions
|
|
@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
|
||||||
set(OPENMW_VERSION_MAJOR 0)
|
set(OPENMW_VERSION_MAJOR 0)
|
||||||
set(OPENMW_VERSION_MINOR 51)
|
set(OPENMW_VERSION_MINOR 51)
|
||||||
set(OPENMW_VERSION_RELEASE 0)
|
set(OPENMW_VERSION_RELEASE 0)
|
||||||
set(OPENMW_LUA_API_REVISION 100)
|
set(OPENMW_LUA_API_REVISION 101)
|
||||||
set(OPENMW_POSTPROCESSING_API_REVISION 3)
|
set(OPENMW_POSTPROCESSING_API_REVISION 3)
|
||||||
|
|
||||||
set(OPENMW_VERSION_COMMITHASH "")
|
set(OPENMW_VERSION_COMMITHASH "")
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,13 @@ namespace
|
||||||
EXPECT_EQ(get<std::string>(lua, "darkRed:asHex()"), "a01112");
|
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, "green:asRgba() == util.vector4(0, 1, 0, 1)"));
|
||||||
EXPECT_TRUE(get<bool>(lua, "red:asRgb() == util.vector3(1, 0, 0)"));
|
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)");
|
||||||
|
EXPECT_ERROR(lua.safe_script("white = util.color.commaString('aaa')"), "Invalid comma-separated color");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LuaUtilPackageTest, Transform)
|
TEST_F(LuaUtilPackageTest, Transform)
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ namespace MWLua
|
||||||
luaManager->addAction([state] { MWBase::Environment::get().getWindowManager()->setHudVisibility(state); });
|
luaManager->addAction([state] { MWBase::Environment::get().getWindowManager()->setHudVisibility(state); });
|
||||||
};
|
};
|
||||||
api["_isHudVisible"] = []() -> bool { return MWBase::Environment::get().getWindowManager()->isHudVisible(); };
|
api["_isHudVisible"] = []() -> bool { return MWBase::Environment::get().getWindowManager()->isHudVisible(); };
|
||||||
|
api["_getDefaultFontSize"] = []() -> int { return Settings::gui().mFontSize; };
|
||||||
api["showMessage"]
|
api["showMessage"]
|
||||||
= [luaManager = context.mLuaManager](std::string_view message, const sol::optional<sol::table>& options) {
|
= [luaManager = context.mLuaManager](std::string_view message, const sol::optional<sol::table>& options) {
|
||||||
MWGui::ShowInDialogueMode mode = MWGui::ShowInDialogueMode_IfPossible;
|
MWGui::ShowInDialogueMode mode = MWGui::ShowInDialogueMode_IfPossible;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@
|
||||||
|
|
||||||
#include <components/misc/color.hpp>
|
#include <components/misc/color.hpp>
|
||||||
#include <components/misc/mathutil.hpp>
|
#include <components/misc/mathutil.hpp>
|
||||||
|
#include <components/misc/strings/algorithm.hpp>
|
||||||
|
|
||||||
|
#include <MyGUI_StringUtility.h>
|
||||||
|
|
||||||
#include "luastate.hpp"
|
#include "luastate.hpp"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
|
|
@ -243,6 +246,28 @@ namespace LuaUtil
|
||||||
color["rgba"] = [](float r, float g, float b, float a) { return Misc::Color(r, g, b, a); };
|
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["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["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)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Invalid comma-separated color: " + std::string(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> rgba;
|
||||||
|
Misc::StringUtils::split(str, rgba, ",");
|
||||||
|
if (rgba.size() != 3 && rgba.size() != 4)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Invalid comma-separated color: " + std::string(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
util["color"] = LuaUtil::makeReadOnly(color);
|
||||||
|
|
||||||
// Lua bindings for Transform
|
// Lua bindings for Transform
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
|
local core = require('openmw.core')
|
||||||
local ui = require('openmw.ui')
|
local ui = require('openmw.ui')
|
||||||
local util = require('openmw.util')
|
local util = require('openmw.util')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
textNormalSize = 16,
|
textNormalSize = ui._getDefaultFontSize(),
|
||||||
textHeaderSize = 16,
|
textHeaderSize = ui._getDefaultFontSize(),
|
||||||
headerColor = util.color.rgb(223 / 255, 201 / 255, 159 / 255),
|
headerColor = util.color.commaString(core.getGMST("FontColor_color_header")),
|
||||||
normalColor = util.color.rgb(202 / 255, 165 / 255, 96 / 255),
|
normalColor = util.color.commaString(core.getGMST("FontColor_color_normal")),
|
||||||
border = 2,
|
border = 2,
|
||||||
thickBorder = 4,
|
thickBorder = 4,
|
||||||
padding = 2,
|
padding = 2,
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,13 @@
|
||||||
-- @return #number
|
-- @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
|
-- @function [parent=#core] getGMST
|
||||||
-- @param #string setting Setting name
|
-- @param #string setting Setting name
|
||||||
-- @return #any
|
-- @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.
|
-- The game's difficulty setting.
|
||||||
|
|
|
||||||
|
|
@ -477,6 +477,16 @@
|
||||||
-- @param #number a
|
-- @param #number a
|
||||||
-- @return #Color
|
-- @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.
|
-- Creates a Color from RGB format. Equivalent to calling util.rgba with a = 1.
|
||||||
-- @function [parent=#COLOR] rgb
|
-- @function [parent=#COLOR] rgb
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue