aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/defaultsettings.cpp4
-rw-r--r--src/game.cpp8
-rw-r--r--src/guiFormSpecMenu.cpp54
-rw-r--r--src/guiFormSpecMenu.h8
4 files changed, 55 insertions, 19 deletions
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index 502223fcd..2a3003f76 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -187,6 +187,10 @@ void set_default_settings(Settings *settings)
settings->setDefault("console_height", "1.0");
settings->setDefault("console_color", "(0,0,0)");
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_width", "2");
settings->setDefault("node_highlighting", "box");
diff --git a/src/game.cpp b/src/game.cpp
index 17ab68e7c..8a2ca00a2 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -185,6 +185,7 @@ struct LocalFormspecHandler : public TextDest
/* Form update callback */
+static const std::string empty_string = "";
class NodeMetadataFormSource: public IFormSource
{
public:
@@ -193,12 +194,12 @@ public:
m_p(p)
{
}
- std::string getForm()
+ const std::string &getForm() const
{
NodeMetadata *meta = m_map->getNodeMetadata(m_p);
if (!meta)
- return "";
+ return empty_string;
return meta->getString("formspec");
}
@@ -224,7 +225,8 @@ public:
m_client(client)
{
}
- std::string getForm()
+
+ const std::string &getForm() const
{
LocalPlayer *player = m_client->getEnv().getLocalPlayer();
return player->inventory_formspec;
diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp
index 5ae652601..7b7bd7c29 100644
--- a/src/guiFormSpecMenu.cpp
+++ b/src/guiFormSpecMenu.cpp
@@ -79,6 +79,11 @@ static unsigned int font_line_height(gui::IGUIFont *font)
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,
gui::IGUIElement *parent, s32 id, IMenuManager *menumgr,
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,';');
if (((parts.size() == 1) || (parts.size() == 2)) ||
- ((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION)))
- {
- parseColorString(parts[0],m_bgcolor,false);
+ ((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION))) {
+ parseColorString(parts[0], m_bgcolor, false);
if (parts.size() == 2) {
std::string fullscreen = parts[1];
m_bgfullscreen = is_yes(fullscreen);
}
+
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)
@@ -1908,9 +1915,8 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element)
}
// Ignore others
- infostream
- << "Unknown DrawSpec: type="<<type<<", data=\""<<description<<"\""
- <<std::endl;
+ infostream << "Unknown DrawSpec: type=" << type << ", data=\"" << description << "\""
+ << std::endl;
}
void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
@@ -1978,10 +1984,29 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
m_static_texts.clear();
m_dropdowns.clear();
- // Set default values (fits old formspec values)
- m_bgcolor = video::SColor(140,0,0,0);
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_h = video::SColor(255,192,192,192);
@@ -2401,9 +2426,9 @@ void GUIFormSpecMenu::drawSelectedItem()
void GUIFormSpecMenu::drawMenu()
{
- if(m_form_src){
- std::string newform = m_form_src->getForm();
- if(newform != m_formspec_string){
+ if (m_form_src) {
+ const std::string &newform = m_form_src->getForm();
+ if (newform != m_formspec_string) {
m_formspec_string = newform;
regenerateGui(m_screensize_old);
}
@@ -2419,9 +2444,10 @@ void GUIFormSpecMenu::drawMenu()
video::IVideoDriver* driver = Environment->getVideoDriver();
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)
- driver->draw2DRectangle(m_bgcolor, allbg, &allbg);
+ driver->draw2DRectangle(m_fullscreen_bgcolor, allbg, &allbg);
else
driver->draw2DRectangle(m_bgcolor, AbsoluteRect, &AbsoluteClippingRect);
diff --git a/src/guiFormSpecMenu.h b/src/guiFormSpecMenu.h
index 02f367fbf..c86d596b7 100644
--- a/src/guiFormSpecMenu.h
+++ b/src/guiFormSpecMenu.h
@@ -66,7 +66,7 @@ class IFormSource
{
public:
virtual ~IFormSource() = default;
- virtual std::string getForm() = 0;
+ virtual const std::string &getForm() const = 0;
// Fill in variables in field text
virtual std::string resolveText(const std::string &str) { return str; }
};
@@ -419,6 +419,7 @@ protected:
bool m_bgfullscreen;
bool m_slotborder;
video::SColor m_bgcolor;
+ video::SColor m_fullscreen_bgcolor;
video::SColor m_slotbg_n;
video::SColor m_slotbg_h;
video::SColor m_slotbordercolor;
@@ -554,7 +555,10 @@ public:
m_formspec = FORMSPEC_VERSION_STRING + formspec;
}
- std::string getForm() { return m_formspec; }
+ const std::string &getForm() const
+ {
+ return m_formspec;
+ }
std::string m_formspec;
};