mirror of
https://github.com/minetest/minetest.git
synced 2024-11-30 03:23:45 +01:00
Formspec: Add options to set background color and opacity (fullscreen mode + default mode) (#5493)
* Formspec: Add options to set background color and opacity (fullscreen mode) * Enhance previous comment: Set formspec background when regenerate UI. * This permit to do the calcul only at regen and override it with bgcolor tag * Add a setting for default background color into formspec, separated from fullscreen * Add a little performance gain on formspecs using a const ref instead of copying formspec string
This commit is contained in:
parent
72c09f524b
commit
1b3e4e1736
@ -606,6 +606,18 @@ console_color (Console color) string (0,0,0)
|
|||||||
# In-game chat console background alpha (opaqueness, between 0 and 255).
|
# In-game chat console background alpha (opaqueness, between 0 and 255).
|
||||||
console_alpha (Console alpha) int 200 0 255
|
console_alpha (Console alpha) int 200 0 255
|
||||||
|
|
||||||
|
# Formspec full-screen background opacity (between 0 and 255).
|
||||||
|
formspec_fullscreen_bg_opacity (Formspec Full-Screen Background Opacity) int 140 0 255
|
||||||
|
|
||||||
|
# Formspec full-screen background color (R,G,B).
|
||||||
|
formspec_fullscreen_bg_color (Formspec Full-Screen Background Color) string (0,0,0)
|
||||||
|
|
||||||
|
# Formspec default background opacity (between 0 and 255).
|
||||||
|
formspec_default_bg_opacity (Formspec Default Background Opacity) int 140 0 255
|
||||||
|
|
||||||
|
# Formspec default background color (R,G,B).
|
||||||
|
formspec_default_bg_color (Formspec Default Background Color) string (0,0,0)
|
||||||
|
|
||||||
# Selection box border color (R,G,B).
|
# Selection box border color (R,G,B).
|
||||||
selectionbox_color (Selection box color) string (0,0,0)
|
selectionbox_color (Selection box color) string (0,0,0)
|
||||||
|
|
||||||
|
@ -762,6 +762,22 @@
|
|||||||
# type: int min: 0 max: 255
|
# type: int min: 0 max: 255
|
||||||
# console_alpha = 200
|
# console_alpha = 200
|
||||||
|
|
||||||
|
# Formspec full-screen background opacity (between 0 and 255).
|
||||||
|
# type: int
|
||||||
|
# formspec_fullscreen_bg_opacity = 140
|
||||||
|
|
||||||
|
# Formspec full-screen background color (R,G,B).
|
||||||
|
# type: string
|
||||||
|
# formspec_fullscreen_bg_color = (0,0,0)
|
||||||
|
|
||||||
|
# Formspec default background opacity (between 0 and 255).
|
||||||
|
# type: int
|
||||||
|
# formspec_default_bg_opacity = 140
|
||||||
|
|
||||||
|
# Formspec default background color (R,G,B).
|
||||||
|
# type: string
|
||||||
|
# formspec_default_bg_color = (0,0,0)
|
||||||
|
|
||||||
# Selection box border color (R,G,B).
|
# Selection box border color (R,G,B).
|
||||||
# type: string
|
# type: string
|
||||||
# selectionbox_color = (0,0,0)
|
# selectionbox_color = (0,0,0)
|
||||||
|
@ -187,6 +187,10 @@ void set_default_settings(Settings *settings)
|
|||||||
settings->setDefault("console_height", "1.0");
|
settings->setDefault("console_height", "1.0");
|
||||||
settings->setDefault("console_color", "(0,0,0)");
|
settings->setDefault("console_color", "(0,0,0)");
|
||||||
settings->setDefault("console_alpha", "200");
|
settings->setDefault("console_alpha", "200");
|
||||||
|
settings->setDefault("formspec_fullscreen_bg_color", "(0,0,0)");
|
||||||
|
settings->setDefault("formspec_fullscreen_bg_opacity", "140");
|
||||||
|
settings->setDefault("formspec_default_bg_color", "(0,0,0)");
|
||||||
|
settings->setDefault("formspec_default_bg_opacity", "140");
|
||||||
settings->setDefault("selectionbox_color", "(0,0,0)");
|
settings->setDefault("selectionbox_color", "(0,0,0)");
|
||||||
settings->setDefault("selectionbox_width", "2");
|
settings->setDefault("selectionbox_width", "2");
|
||||||
settings->setDefault("node_highlighting", "box");
|
settings->setDefault("node_highlighting", "box");
|
||||||
|
@ -185,6 +185,7 @@ struct LocalFormspecHandler : public TextDest
|
|||||||
|
|
||||||
/* Form update callback */
|
/* Form update callback */
|
||||||
|
|
||||||
|
static const std::string empty_string = "";
|
||||||
class NodeMetadataFormSource: public IFormSource
|
class NodeMetadataFormSource: public IFormSource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -193,12 +194,12 @@ public:
|
|||||||
m_p(p)
|
m_p(p)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
std::string getForm()
|
const std::string &getForm() const
|
||||||
{
|
{
|
||||||
NodeMetadata *meta = m_map->getNodeMetadata(m_p);
|
NodeMetadata *meta = m_map->getNodeMetadata(m_p);
|
||||||
|
|
||||||
if (!meta)
|
if (!meta)
|
||||||
return "";
|
return empty_string;
|
||||||
|
|
||||||
return meta->getString("formspec");
|
return meta->getString("formspec");
|
||||||
}
|
}
|
||||||
@ -224,7 +225,8 @@ public:
|
|||||||
m_client(client)
|
m_client(client)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
std::string getForm()
|
|
||||||
|
const std::string &getForm() const
|
||||||
{
|
{
|
||||||
LocalPlayer *player = m_client->getEnv().getLocalPlayer();
|
LocalPlayer *player = m_client->getEnv().getLocalPlayer();
|
||||||
return player->inventory_formspec;
|
return player->inventory_formspec;
|
||||||
|
@ -79,6 +79,11 @@ static unsigned int font_line_height(gui::IGUIFont *font)
|
|||||||
return font->getDimension(L"Ay").Height + font->getKerningHeight();
|
return font->getDimension(L"Ay").Height + font->getKerningHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline u32 clamp_u8(s32 value)
|
||||||
|
{
|
||||||
|
return (u32) MYMIN(MYMAX(value, 0), 255);
|
||||||
|
}
|
||||||
|
|
||||||
GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
|
GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
|
||||||
gui::IGUIElement *parent, s32 id, IMenuManager *menumgr,
|
gui::IGUIElement *parent, s32 id, IMenuManager *menumgr,
|
||||||
Client *client, ISimpleTextureSource *tsrc, IFormSource *fsrc, TextDest *tdst,
|
Client *client, ISimpleTextureSource *tsrc, IFormSource *fsrc, TextDest *tdst,
|
||||||
@ -1567,17 +1572,19 @@ void GUIFormSpecMenu::parseBackgroundColor(parserData* data, const std::string &
|
|||||||
std::vector<std::string> parts = split(element,';');
|
std::vector<std::string> parts = split(element,';');
|
||||||
|
|
||||||
if (((parts.size() == 1) || (parts.size() == 2)) ||
|
if (((parts.size() == 1) || (parts.size() == 2)) ||
|
||||||
((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION)))
|
((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION))) {
|
||||||
{
|
|
||||||
parseColorString(parts[0], m_bgcolor, false);
|
parseColorString(parts[0], m_bgcolor, false);
|
||||||
|
|
||||||
if (parts.size() == 2) {
|
if (parts.size() == 2) {
|
||||||
std::string fullscreen = parts[1];
|
std::string fullscreen = parts[1];
|
||||||
m_bgfullscreen = is_yes(fullscreen);
|
m_bgfullscreen = is_yes(fullscreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
errorstream<< "Invalid bgcolor element(" << parts.size() << "): '" << element << "'" << std::endl;
|
|
||||||
|
errorstream << "Invalid bgcolor element(" << parts.size() << "): '" << element << "'"
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIFormSpecMenu::parseListColors(parserData* data, const std::string &element)
|
void GUIFormSpecMenu::parseListColors(parserData* data, const std::string &element)
|
||||||
@ -1908,8 +1915,7 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ignore others
|
// Ignore others
|
||||||
infostream
|
infostream << "Unknown DrawSpec: type=" << type << ", data=\"" << description << "\""
|
||||||
<< "Unknown DrawSpec: type="<<type<<", data=\""<<description<<"\""
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1978,10 +1984,29 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
|||||||
m_static_texts.clear();
|
m_static_texts.clear();
|
||||||
m_dropdowns.clear();
|
m_dropdowns.clear();
|
||||||
|
|
||||||
// Set default values (fits old formspec values)
|
|
||||||
m_bgcolor = video::SColor(140,0,0,0);
|
|
||||||
m_bgfullscreen = false;
|
m_bgfullscreen = false;
|
||||||
|
|
||||||
|
{
|
||||||
|
v3f formspec_bgcolor = g_settings->getV3F("formspec_default_bg_color");
|
||||||
|
m_bgcolor = video::SColor(
|
||||||
|
(u8) clamp_u8(g_settings->getS32("formspec_default_bg_opacity")),
|
||||||
|
clamp_u8(myround(formspec_bgcolor.X)),
|
||||||
|
clamp_u8(myround(formspec_bgcolor.Y)),
|
||||||
|
clamp_u8(myround(formspec_bgcolor.Z))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
v3f formspec_bgcolor = g_settings->getV3F("formspec_fullscreen_bg_color");
|
||||||
|
m_fullscreen_bgcolor = video::SColor(
|
||||||
|
(u8) clamp_u8(g_settings->getS32("formspec_fullscreen_bg_opacity")),
|
||||||
|
clamp_u8(myround(formspec_bgcolor.X)),
|
||||||
|
clamp_u8(myround(formspec_bgcolor.Y)),
|
||||||
|
clamp_u8(myround(formspec_bgcolor.Z))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
m_slotbg_n = video::SColor(255,128,128,128);
|
m_slotbg_n = video::SColor(255,128,128,128);
|
||||||
m_slotbg_h = video::SColor(255,192,192,192);
|
m_slotbg_h = video::SColor(255,192,192,192);
|
||||||
|
|
||||||
@ -2402,7 +2427,7 @@ void GUIFormSpecMenu::drawSelectedItem()
|
|||||||
void GUIFormSpecMenu::drawMenu()
|
void GUIFormSpecMenu::drawMenu()
|
||||||
{
|
{
|
||||||
if (m_form_src) {
|
if (m_form_src) {
|
||||||
std::string newform = m_form_src->getForm();
|
const std::string &newform = m_form_src->getForm();
|
||||||
if (newform != m_formspec_string) {
|
if (newform != m_formspec_string) {
|
||||||
m_formspec_string = newform;
|
m_formspec_string = newform;
|
||||||
regenerateGui(m_screensize_old);
|
regenerateGui(m_screensize_old);
|
||||||
@ -2420,8 +2445,9 @@ void GUIFormSpecMenu::drawMenu()
|
|||||||
|
|
||||||
v2u32 screenSize = driver->getScreenSize();
|
v2u32 screenSize = driver->getScreenSize();
|
||||||
core::rect<s32> allbg(0, 0, screenSize.X, screenSize.Y);
|
core::rect<s32> allbg(0, 0, screenSize.X, screenSize.Y);
|
||||||
|
|
||||||
if (m_bgfullscreen)
|
if (m_bgfullscreen)
|
||||||
driver->draw2DRectangle(m_bgcolor, allbg, &allbg);
|
driver->draw2DRectangle(m_fullscreen_bgcolor, allbg, &allbg);
|
||||||
else
|
else
|
||||||
driver->draw2DRectangle(m_bgcolor, AbsoluteRect, &AbsoluteClippingRect);
|
driver->draw2DRectangle(m_bgcolor, AbsoluteRect, &AbsoluteClippingRect);
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ class IFormSource
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IFormSource() = default;
|
virtual ~IFormSource() = default;
|
||||||
virtual std::string getForm() = 0;
|
virtual const std::string &getForm() const = 0;
|
||||||
// Fill in variables in field text
|
// Fill in variables in field text
|
||||||
virtual std::string resolveText(const std::string &str) { return str; }
|
virtual std::string resolveText(const std::string &str) { return str; }
|
||||||
};
|
};
|
||||||
@ -419,6 +419,7 @@ protected:
|
|||||||
bool m_bgfullscreen;
|
bool m_bgfullscreen;
|
||||||
bool m_slotborder;
|
bool m_slotborder;
|
||||||
video::SColor m_bgcolor;
|
video::SColor m_bgcolor;
|
||||||
|
video::SColor m_fullscreen_bgcolor;
|
||||||
video::SColor m_slotbg_n;
|
video::SColor m_slotbg_n;
|
||||||
video::SColor m_slotbg_h;
|
video::SColor m_slotbg_h;
|
||||||
video::SColor m_slotbordercolor;
|
video::SColor m_slotbordercolor;
|
||||||
@ -554,7 +555,10 @@ public:
|
|||||||
m_formspec = FORMSPEC_VERSION_STRING + formspec;
|
m_formspec = FORMSPEC_VERSION_STRING + formspec;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getForm() { return m_formspec; }
|
const std::string &getForm() const
|
||||||
|
{
|
||||||
|
return m_formspec;
|
||||||
|
}
|
||||||
|
|
||||||
std::string m_formspec;
|
std::string m_formspec;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user