2010-12-22 02:34:21 +01:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2010-12-22 02:34:21 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2010-12-22 02:34:21 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-06-05 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2010-12-22 02:34:21 +01:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2010-12-22 02:34:21 +01:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
#include <cstdlib>
|
2021-02-02 20:55:13 +01:00
|
|
|
#include <cmath>
|
2013-06-23 18:30:21 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
|
|
|
#include <limits>
|
2019-11-20 19:39:10 +01:00
|
|
|
#include <sstream>
|
2012-07-15 18:19:38 +02:00
|
|
|
#include "guiFormSpecMenu.h"
|
2010-12-22 02:34:21 +01:00
|
|
|
#include "constants.h"
|
2012-01-12 06:10:39 +01:00
|
|
|
#include "gamedef.h"
|
2018-11-28 20:01:49 +01:00
|
|
|
#include "client/keycode.h"
|
2016-03-19 17:08:24 +01:00
|
|
|
#include "util/strfnd.h"
|
2019-11-07 20:11:01 +01:00
|
|
|
#include <IGUIButton.h>
|
2011-10-12 12:53:38 +02:00
|
|
|
#include <IGUICheckBox.h>
|
2019-11-07 20:11:01 +01:00
|
|
|
#include <IGUIComboBox.h>
|
2011-10-12 12:53:38 +02:00
|
|
|
#include <IGUIEditBox.h>
|
|
|
|
#include <IGUIStaticText.h>
|
|
|
|
#include <IGUIFont.h>
|
2013-06-23 18:30:21 +02:00
|
|
|
#include <IGUITabControl.h>
|
2017-06-26 20:11:17 +02:00
|
|
|
#include "client/renderingengine.h"
|
2011-10-17 00:03:45 +02:00
|
|
|
#include "log.h"
|
2015-03-05 11:52:57 +01:00
|
|
|
#include "client/tile.h" // ITextureSource
|
2018-01-20 14:09:58 +01:00
|
|
|
#include "client/hud.h" // drawItemStack
|
2013-06-23 18:30:21 +02:00
|
|
|
#include "filesys.h"
|
2013-08-15 21:46:55 +02:00
|
|
|
#include "gettime.h"
|
2012-07-15 18:19:38 +02:00
|
|
|
#include "gettext.h"
|
2017-04-25 19:38:08 +02:00
|
|
|
#include "scripting_server.h"
|
2018-01-13 10:54:18 +01:00
|
|
|
#include "mainmenumanager.h"
|
2014-05-30 03:07:48 +02:00
|
|
|
#include "porting.h"
|
2014-06-14 11:22:09 +02:00
|
|
|
#include "settings.h"
|
2018-11-28 20:01:49 +01:00
|
|
|
#include "client/client.h"
|
|
|
|
#include "client/fontengine.h"
|
2020-09-16 17:10:17 +02:00
|
|
|
#include "client/sound.h"
|
2015-02-21 14:17:36 +01:00
|
|
|
#include "util/hex.h"
|
|
|
|
#include "util/numeric.h"
|
|
|
|
#include "util/string.h" // for parseColorString()
|
2016-05-31 17:30:11 +02:00
|
|
|
#include "irrlicht_changes/static_text.h"
|
2018-11-28 20:01:49 +01:00
|
|
|
#include "client/guiscalingfilter.h"
|
2020-02-15 16:33:18 +01:00
|
|
|
#include "guiAnimatedImage.h"
|
2019-11-07 20:11:01 +01:00
|
|
|
#include "guiBackgroundImage.h"
|
|
|
|
#include "guiBox.h"
|
|
|
|
#include "guiButton.h"
|
2019-12-09 21:06:51 +01:00
|
|
|
#include "guiButtonImage.h"
|
|
|
|
#include "guiButtonItemImage.h"
|
2017-02-18 20:40:37 +01:00
|
|
|
#include "guiEditBoxWithScrollbar.h"
|
2020-02-01 13:55:13 +01:00
|
|
|
#include "guiInventoryList.h"
|
2019-11-07 20:11:01 +01:00
|
|
|
#include "guiItemImage.h"
|
2020-04-13 10:50:07 +02:00
|
|
|
#include "guiScrollContainer.h"
|
2019-09-10 15:11:26 +02:00
|
|
|
#include "guiHyperText.h"
|
2020-11-04 21:46:18 +01:00
|
|
|
#include "guiScene.h"
|
2015-06-10 01:54:33 +02:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
#define MY_CHECKPOS(a,b) \
|
|
|
|
if (v_pos.size() != 2) { \
|
2020-12-15 19:06:36 +01:00
|
|
|
errorstream<< "Invalid pos for element " << a << " specified: \"" \
|
2013-06-23 18:30:21 +02:00
|
|
|
<< parts[b] << "\"" << std::endl; \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MY_CHECKGEOM(a,b) \
|
|
|
|
if (v_geom.size() != 2) { \
|
2019-06-27 14:40:49 +02:00
|
|
|
errorstream<< "Invalid geometry for element " << a << \
|
2020-12-15 19:06:36 +01:00
|
|
|
" specified: \"" << parts[b] << "\"" << std::endl; \
|
2013-06-23 18:30:21 +02:00
|
|
|
return; \
|
|
|
|
}
|
2021-12-29 23:58:26 +01:00
|
|
|
|
|
|
|
#define MY_CHECKCLIENT(a) \
|
|
|
|
if (!m_client) { \
|
|
|
|
errorstream << "Attempted to use element " << a << " with m_client == nullptr." << std::endl; \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
|
2010-12-22 02:34:21 +01:00
|
|
|
/*
|
2012-07-15 18:19:38 +02:00
|
|
|
GUIFormSpecMenu
|
2010-12-22 02:34:21 +01:00
|
|
|
*/
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
static unsigned int font_line_height(gui::IGUIFont *font)
|
|
|
|
{
|
|
|
|
return font->getDimension(L"Ay").Height + font->getKerningHeight();
|
|
|
|
}
|
|
|
|
|
2017-08-29 19:25:16 +02:00
|
|
|
inline u32 clamp_u8(s32 value)
|
|
|
|
{
|
|
|
|
return (u32) MYMIN(MYMAX(value, 0), 255);
|
|
|
|
}
|
|
|
|
|
2017-06-26 20:11:17 +02:00
|
|
|
GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
|
|
|
|
gui::IGUIElement *parent, s32 id, IMenuManager *menumgr,
|
2021-04-29 20:38:35 +02:00
|
|
|
Client *client, gui::IGUIEnvironment *guienv, ISimpleTextureSource *tsrc,
|
|
|
|
ISoundManager *sound_manager, IFormSource *fsrc, TextDest *tdst,
|
2020-07-14 22:37:28 +02:00
|
|
|
const std::string &formspecPrepend, bool remap_dbl_click):
|
2021-04-29 20:38:35 +02:00
|
|
|
GUIModalMenu(guienv, parent, id, menumgr, remap_dbl_click),
|
2017-01-09 20:39:22 +01:00
|
|
|
m_invmgr(client),
|
2013-08-20 22:38:14 +02:00
|
|
|
m_tsrc(tsrc),
|
2020-09-16 17:10:17 +02:00
|
|
|
m_sound_manager(sound_manager),
|
2014-09-21 21:18:43 +02:00
|
|
|
m_client(client),
|
2018-03-28 17:04:41 +02:00
|
|
|
m_formspec_prepend(formspecPrepend),
|
2014-04-20 02:40:25 +02:00
|
|
|
m_form_src(fsrc),
|
|
|
|
m_text_dst(tdst),
|
2020-07-14 22:37:28 +02:00
|
|
|
m_joystick(joystick)
|
2010-12-22 02:34:21 +01:00
|
|
|
{
|
2013-07-07 21:53:40 +02:00
|
|
|
current_keys_pending.key_down = false;
|
|
|
|
current_keys_pending.key_up = false;
|
|
|
|
current_keys_pending.key_enter = false;
|
2013-08-07 19:48:31 +02:00
|
|
|
current_keys_pending.key_escape = false;
|
2013-07-07 21:53:40 +02:00
|
|
|
|
2014-06-25 11:52:09 +02:00
|
|
|
m_tooltip_show_delay = (u32)g_settings->getS32("tooltip_show_delay");
|
2017-09-16 18:42:17 +02:00
|
|
|
m_tooltip_append_itemname = g_settings->getBool("tooltip_append_itemname");
|
2010-12-22 02:34:21 +01:00
|
|
|
}
|
|
|
|
|
2012-07-15 18:19:38 +02:00
|
|
|
GUIFormSpecMenu::~GUIFormSpecMenu()
|
2010-12-22 02:34:21 +01:00
|
|
|
{
|
2022-05-22 00:11:59 +02:00
|
|
|
removeAllChildren();
|
|
|
|
removeTooltip();
|
2014-06-14 11:22:09 +02:00
|
|
|
|
2019-12-06 21:51:10 +01:00
|
|
|
for (auto &table_it : m_tables)
|
2017-08-20 19:37:29 +02:00
|
|
|
table_it.second->drop();
|
2019-12-06 21:51:10 +01:00
|
|
|
for (auto &inventorylist_it : m_inventorylists)
|
2020-02-01 13:55:13 +01:00
|
|
|
inventorylist_it->drop();
|
2019-12-06 21:51:10 +01:00
|
|
|
for (auto &checkbox_it : m_checkboxes)
|
2019-11-07 20:11:01 +01:00
|
|
|
checkbox_it.second->drop();
|
2019-12-06 21:51:10 +01:00
|
|
|
for (auto &scrollbar_it : m_scrollbars)
|
2019-11-07 20:11:01 +01:00
|
|
|
scrollbar_it.second->drop();
|
2019-12-06 21:51:10 +01:00
|
|
|
for (auto &tooltip_rect_it : m_tooltip_rects)
|
2019-11-07 20:11:01 +01:00
|
|
|
tooltip_rect_it.first->drop();
|
2020-03-31 19:34:42 +02:00
|
|
|
for (auto &clickthrough_it : m_clickthrough_elements)
|
|
|
|
clickthrough_it->drop();
|
2020-04-13 10:50:07 +02:00
|
|
|
for (auto &scroll_container_it : m_scroll_containers)
|
|
|
|
scroll_container_it.second->drop();
|
2010-12-25 15:04:51 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
delete m_selected_item;
|
2017-06-05 01:52:55 +02:00
|
|
|
delete m_form_src;
|
|
|
|
delete m_text_dst;
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2018-01-13 10:54:18 +01:00
|
|
|
void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client,
|
2021-04-29 20:38:35 +02:00
|
|
|
gui::IGUIEnvironment *guienv, JoystickController *joystick, IFormSource *fs_src,
|
|
|
|
TextDest *txt_dest, const std::string &formspecPrepend, ISoundManager *sound_manager)
|
2018-01-13 10:34:56 +01:00
|
|
|
{
|
2018-01-13 10:54:18 +01:00
|
|
|
if (cur_formspec == nullptr) {
|
|
|
|
cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
|
2021-04-29 20:38:35 +02:00
|
|
|
client, guienv, client->getTextureSource(), sound_manager, fs_src,
|
2020-09-16 17:10:17 +02:00
|
|
|
txt_dest, formspecPrepend);
|
2018-01-13 10:54:18 +01:00
|
|
|
cur_formspec->doPause = false;
|
2018-01-13 10:34:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Caution: do not call (*cur_formspec)->drop() here --
|
|
|
|
the reference might outlive the menu, so we will
|
|
|
|
periodically check if *cur_formspec is the only
|
|
|
|
remaining reference (i.e. the menu was removed)
|
|
|
|
and delete it in that case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
} else {
|
2018-03-28 17:04:41 +02:00
|
|
|
cur_formspec->setFormspecPrepend(formspecPrepend);
|
2018-01-13 10:54:18 +01:00
|
|
|
cur_formspec->setFormSource(fs_src);
|
|
|
|
cur_formspec->setTextDest(txt_dest);
|
2018-01-13 10:34:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-22 00:11:59 +02:00
|
|
|
void GUIFormSpecMenu::removeTooltip()
|
2013-06-23 18:30:21 +02:00
|
|
|
{
|
2019-09-10 15:11:26 +02:00
|
|
|
if (m_tooltip_element) {
|
2013-06-23 18:30:21 +02:00
|
|
|
m_tooltip_element->remove();
|
2013-08-25 10:48:29 +02:00
|
|
|
m_tooltip_element->drop();
|
2019-09-10 15:11:26 +02:00
|
|
|
m_tooltip_element = nullptr;
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-19 11:26:51 +02:00
|
|
|
void GUIFormSpecMenu::setInitialFocus()
|
|
|
|
{
|
|
|
|
// Set initial focus according to following order of precedence:
|
|
|
|
// 1. first empty editbox
|
|
|
|
// 2. first editbox
|
2013-08-23 12:24:11 +02:00
|
|
|
// 3. first table
|
2013-08-19 11:26:51 +02:00
|
|
|
// 4. last button
|
|
|
|
// 5. first focusable (not statictext, not tabheader)
|
|
|
|
// 6. first child element
|
|
|
|
|
2022-05-22 00:11:59 +02:00
|
|
|
const auto& children = getChildren();
|
2013-08-19 11:26:51 +02:00
|
|
|
|
|
|
|
// 1. first empty editbox
|
2017-08-20 19:37:29 +02:00
|
|
|
for (gui::IGUIElement *it : children) {
|
|
|
|
if (it->getType() == gui::EGUIET_EDIT_BOX
|
|
|
|
&& it->getText()[0] == 0) {
|
|
|
|
Environment->setFocus(it);
|
2013-08-19 11:26:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. first editbox
|
2017-08-20 19:37:29 +02:00
|
|
|
for (gui::IGUIElement *it : children) {
|
|
|
|
if (it->getType() == gui::EGUIET_EDIT_BOX) {
|
|
|
|
Environment->setFocus(it);
|
2013-08-19 11:26:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-23 12:24:11 +02:00
|
|
|
// 3. first table
|
2017-08-20 19:37:29 +02:00
|
|
|
for (gui::IGUIElement *it : children) {
|
|
|
|
if (it->getTypeName() == std::string("GUITable")) {
|
|
|
|
Environment->setFocus(it);
|
2013-08-19 11:26:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 4. last button
|
2022-05-22 00:11:59 +02:00
|
|
|
for (auto it = children.rbegin(); it != children.rend(); ++it) {
|
2013-08-19 11:26:51 +02:00
|
|
|
if ((*it)->getType() == gui::EGUIET_BUTTON) {
|
|
|
|
Environment->setFocus(*it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 5. first focusable (not statictext, not tabheader)
|
2017-08-20 19:37:29 +02:00
|
|
|
for (gui::IGUIElement *it : children) {
|
|
|
|
if (it->getType() != gui::EGUIET_STATIC_TEXT &&
|
|
|
|
it->getType() != gui::EGUIET_TAB_CONTROL) {
|
|
|
|
Environment->setFocus(it);
|
2013-08-19 11:26:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 6. first child element
|
|
|
|
if (children.empty())
|
|
|
|
Environment->setFocus(this);
|
|
|
|
else
|
2022-05-22 00:11:59 +02:00
|
|
|
Environment->setFocus(children.front());
|
2013-08-19 11:26:51 +02:00
|
|
|
}
|
|
|
|
|
2015-06-10 01:54:33 +02:00
|
|
|
GUITable* GUIFormSpecMenu::getTable(const std::string &tablename)
|
2013-08-15 21:46:55 +02:00
|
|
|
{
|
2017-08-20 19:37:29 +02:00
|
|
|
for (auto &table : m_tables) {
|
|
|
|
if (tablename == table.first.fname)
|
|
|
|
return table.second;
|
2013-08-16 00:54:38 +02:00
|
|
|
}
|
2013-08-23 12:24:11 +02:00
|
|
|
return 0;
|
2013-08-16 00:54:38 +02:00
|
|
|
}
|
|
|
|
|
2016-05-05 18:50:02 +02:00
|
|
|
std::vector<std::string>* GUIFormSpecMenu::getDropDownValues(const std::string &name)
|
|
|
|
{
|
2017-08-20 19:37:29 +02:00
|
|
|
for (auto &dropdown : m_dropdowns) {
|
|
|
|
if (name == dropdown.first.fname)
|
|
|
|
return &dropdown.second;
|
2016-05-05 18:50:02 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
v2s32 GUIFormSpecMenu::getElementBasePos(const std::vector<std::string> *v_pos)
|
2018-08-04 18:55:54 +02:00
|
|
|
{
|
2019-11-07 20:11:01 +01:00
|
|
|
v2f32 pos_f = v2f32(padding.X, padding.Y) + pos_offset * spacing;
|
2018-08-04 18:55:54 +02:00
|
|
|
if (v_pos) {
|
|
|
|
pos_f.X += stof((*v_pos)[0]) * spacing.X;
|
|
|
|
pos_f.Y += stof((*v_pos)[1]) * spacing.Y;
|
|
|
|
}
|
|
|
|
return v2s32(pos_f.X, pos_f.Y);
|
|
|
|
}
|
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
v2s32 GUIFormSpecMenu::getRealCoordinateBasePos(const std::vector<std::string> &v_pos)
|
2019-06-27 14:40:49 +02:00
|
|
|
{
|
2019-11-07 20:11:01 +01:00
|
|
|
return v2s32((stof(v_pos[0]) + pos_offset.X) * imgsize.X,
|
|
|
|
(stof(v_pos[1]) + pos_offset.Y) * imgsize.Y);
|
2019-06-27 14:40:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
v2s32 GUIFormSpecMenu::getRealCoordinateGeometry(const std::vector<std::string> &v_geom)
|
|
|
|
{
|
|
|
|
return v2s32(stof(v_geom[0]) * imgsize.X, stof(v_geom[1]) * imgsize.Y);
|
|
|
|
}
|
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
bool GUIFormSpecMenu::precheckElement(const std::string &name, const std::string &element,
|
|
|
|
size_t args_min, size_t args_max, std::vector<std::string> &parts)
|
|
|
|
{
|
|
|
|
parts = split(element, ';');
|
|
|
|
if (parts.size() >= args_min && (parts.size() <= args_max || m_formspec_version > FORMSPEC_API_VERSION))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
errorstream << "Invalid " << name << " element(" << parts.size() << "): '" << element << "'" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseSize(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
// Note: do not use precheckElement due to "," separator.
|
2013-06-23 18:30:21 +02:00
|
|
|
std::vector<std::string> parts = split(element,',');
|
|
|
|
|
2014-06-25 19:04:47 +02:00
|
|
|
if (((parts.size() == 2) || parts.size() == 3) ||
|
|
|
|
((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION)))
|
|
|
|
{
|
2013-06-23 18:30:21 +02:00
|
|
|
if (parts[1].find(';') != std::string::npos)
|
|
|
|
parts[1] = parts[1].substr(0,parts[1].find(';'));
|
|
|
|
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
data->invsize.X = MYMAX(0, stof(parts[0]));
|
|
|
|
data->invsize.Y = MYMAX(0, stof(parts[1]));
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2014-03-04 19:57:39 +01:00
|
|
|
lockSize(false);
|
2021-09-26 18:04:09 +02:00
|
|
|
#ifndef HAVE_TOUCHSCREENGUI
|
2014-03-04 19:57:39 +01:00
|
|
|
if (parts.size() == 3) {
|
|
|
|
if (parts[2] == "true") {
|
|
|
|
lockSize(true,v2u32(800,600));
|
|
|
|
}
|
|
|
|
}
|
2018-11-18 11:31:19 +01:00
|
|
|
#endif
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
data->explicit_size = true;
|
2013-06-23 18:30:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
errorstream<< "Invalid size element (" << parts.size() << "): '" << element << "'" << std::endl;
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseContainer(parserData* data, const std::string &element)
|
2016-07-07 22:10:15 +02:00
|
|
|
{
|
|
|
|
std::vector<std::string> parts = split(element, ',');
|
|
|
|
|
|
|
|
if (parts.size() >= 2) {
|
|
|
|
if (parts[1].find(';') != std::string::npos)
|
|
|
|
parts[1] = parts[1].substr(0, parts[1].find(';'));
|
|
|
|
|
|
|
|
container_stack.push(pos_offset);
|
2019-08-03 17:20:15 +02:00
|
|
|
pos_offset.X += stof(parts[0]);
|
|
|
|
pos_offset.Y += stof(parts[1]);
|
2016-07-07 22:10:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
errorstream<< "Invalid container start element (" << parts.size() << "): '" << element << "'" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIFormSpecMenu::parseContainerEnd(parserData* data)
|
|
|
|
{
|
|
|
|
if (container_stack.empty()) {
|
|
|
|
errorstream<< "Invalid container end element, no matching container start element" << std::endl;
|
|
|
|
} else {
|
|
|
|
pos_offset = container_stack.top();
|
|
|
|
container_stack.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:50:07 +02:00
|
|
|
void GUIFormSpecMenu::parseScrollContainer(parserData *data, const std::string &element)
|
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("scroll_container start", element, 4, 5, parts))
|
2020-04-13 10:50:07 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector<std::string> v_pos = split(parts[0], ',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1], ',');
|
|
|
|
std::string scrollbar_name = parts[2];
|
|
|
|
std::string orientation = parts[3];
|
|
|
|
f32 scroll_factor = 0.1f;
|
|
|
|
if (parts.size() >= 5 && !parts[4].empty())
|
|
|
|
scroll_factor = stof(parts[4]);
|
|
|
|
|
|
|
|
MY_CHECKPOS("scroll_container", 0);
|
|
|
|
MY_CHECKGEOM("scroll_container", 1);
|
|
|
|
|
|
|
|
v2s32 pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
v2s32 geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
|
|
|
|
if (orientation == "vertical")
|
|
|
|
scroll_factor *= -imgsize.Y;
|
|
|
|
else if (orientation == "horizontal")
|
|
|
|
scroll_factor *= -imgsize.X;
|
|
|
|
else
|
|
|
|
warningstream << "GUIFormSpecMenu::parseScrollContainer(): "
|
|
|
|
<< "Invalid scroll_container orientation: " << orientation
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
// old parent (at first: this)
|
|
|
|
// ^ is parent of clipper
|
|
|
|
// ^ is parent of mover
|
|
|
|
// ^ is parent of other elements
|
|
|
|
|
|
|
|
// make clipper
|
|
|
|
core::rect<s32> rect_clipper = core::rect<s32>(pos, pos + geom);
|
|
|
|
|
|
|
|
gui::IGUIElement *clipper = new gui::IGUIElement(EGUIET_ELEMENT, Environment,
|
|
|
|
data->current_parent, 0, rect_clipper);
|
|
|
|
|
|
|
|
// make mover
|
|
|
|
FieldSpec spec_mover(
|
|
|
|
"",
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
|
|
|
|
|
|
|
core::rect<s32> rect_mover = core::rect<s32>(0, 0, geom.X, geom.Y);
|
|
|
|
|
|
|
|
GUIScrollContainer *mover = new GUIScrollContainer(Environment,
|
|
|
|
clipper, spec_mover.fid, rect_mover, orientation, scroll_factor);
|
|
|
|
|
|
|
|
data->current_parent = mover;
|
|
|
|
|
|
|
|
m_scroll_containers.emplace_back(scrollbar_name, mover);
|
|
|
|
|
|
|
|
m_fields.push_back(spec_mover);
|
|
|
|
|
|
|
|
clipper->drop();
|
|
|
|
|
|
|
|
// remove interferring offset of normal containers
|
|
|
|
container_stack.push(pos_offset);
|
|
|
|
pos_offset.X = 0.0f;
|
|
|
|
pos_offset.Y = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIFormSpecMenu::parseScrollContainerEnd(parserData *data)
|
|
|
|
{
|
|
|
|
if (data->current_parent == this || data->current_parent->getParent() == this ||
|
|
|
|
container_stack.empty()) {
|
|
|
|
errorstream << "Invalid scroll_container end element, "
|
|
|
|
<< "no matching scroll_container start element" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos_offset.getLengthSQ() != 0.0f) {
|
|
|
|
// pos_offset is only set by containers and scroll_containers.
|
|
|
|
// scroll_containers always set it to 0,0 which means that if it is
|
|
|
|
// not 0,0, it is a normal container that was opened last, not a
|
|
|
|
// scroll_container
|
|
|
|
errorstream << "Invalid scroll_container end element, "
|
|
|
|
<< "an inner container was left open" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->current_parent = data->current_parent->getParent()->getParent();
|
|
|
|
pos_offset = container_stack.top();
|
|
|
|
container_stack.pop();
|
|
|
|
}
|
|
|
|
|
2020-02-01 13:55:13 +01:00
|
|
|
void GUIFormSpecMenu::parseList(parserData *data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKCLIENT("list");
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("list", element, 4, 5, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::string location = parts[0];
|
|
|
|
std::string listname = parts[1];
|
|
|
|
std::vector<std::string> v_pos = split(parts[2],',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[3],',');
|
|
|
|
std::string startindex;
|
|
|
|
if (parts.size() == 5)
|
|
|
|
startindex = parts[4];
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("list",2);
|
|
|
|
MY_CHECKGEOM("list",3);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
InventoryLocation loc;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (location == "context" || location == "current_name")
|
|
|
|
loc = m_current_inventory_location;
|
|
|
|
else
|
|
|
|
loc.deSerialize(location);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 geom;
|
|
|
|
geom.X = stoi(v_geom[0]);
|
|
|
|
geom.Y = stoi(v_geom[1]);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
s32 start_i = 0;
|
|
|
|
if (!startindex.empty())
|
|
|
|
start_i = stoi(startindex);
|
2013-12-09 22:39:24 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (geom.X < 0 || geom.Y < 0 || start_i < 0) {
|
|
|
|
errorstream << "Invalid list element: '" << element << "'" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2013-12-09 22:39:24 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (!data->explicit_size)
|
|
|
|
warningstream << "invalid use of list without a size[] element" << std::endl;
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
"",
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size(),
|
|
|
|
3
|
|
|
|
);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("list", spec.fname);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2f32 slot_scale = style.getVector2f(StyleSpec::SIZE, v2f32(0, 0));
|
|
|
|
v2f32 slot_size(
|
|
|
|
slot_scale.X <= 0 ? imgsize.X : std::max<f32>(slot_scale.X * imgsize.X, 1),
|
|
|
|
slot_scale.Y <= 0 ? imgsize.Y : std::max<f32>(slot_scale.Y * imgsize.Y, 1)
|
|
|
|
);
|
2021-01-23 21:46:19 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2f32 slot_spacing = style.getVector2f(StyleSpec::SPACING, v2f32(-1, -1));
|
|
|
|
v2f32 default_spacing = data->real_coordinates ?
|
|
|
|
v2f32(imgsize.X * 0.25f, imgsize.Y * 0.25f) :
|
|
|
|
v2f32(spacing.X - imgsize.X, spacing.Y - imgsize.Y);
|
2021-02-02 20:55:13 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
slot_spacing.X = slot_spacing.X < 0 ? default_spacing.X :
|
|
|
|
imgsize.X * slot_spacing.X;
|
|
|
|
slot_spacing.Y = slot_spacing.Y < 0 ? default_spacing.Y :
|
|
|
|
imgsize.Y * slot_spacing.Y;
|
2021-02-02 20:55:13 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
slot_spacing += slot_size;
|
2021-01-23 21:46:19 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos = data->real_coordinates ? getRealCoordinateBasePos(v_pos) :
|
|
|
|
getElementBasePos(&v_pos);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y,
|
|
|
|
pos.X + (geom.X - 1) * slot_spacing.X + slot_size.X,
|
|
|
|
pos.Y + (geom.Y - 1) * slot_spacing.Y + slot_size.Y);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
GUIInventoryList *e = new GUIInventoryList(Environment, data->current_parent,
|
|
|
|
spec.fid, rect, m_invmgr, loc, listname, geom, start_i,
|
|
|
|
v2s32(slot_size.X, slot_size.Y), slot_spacing, this,
|
|
|
|
data->inventorylist_options, m_font);
|
2020-01-04 15:45:22 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
2021-01-23 21:46:19 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
m_inventorylists.push_back(e);
|
|
|
|
m_fields.push_back(spec);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2020-02-01 13:55:13 +01:00
|
|
|
void GUIFormSpecMenu::parseListRing(parserData *data, const std::string &element)
|
2015-06-16 10:48:54 +02:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKCLIENT("listring");
|
2015-06-16 10:48:54 +02:00
|
|
|
|
|
|
|
std::vector<std::string> parts = split(element, ';');
|
|
|
|
|
|
|
|
if (parts.size() == 2) {
|
|
|
|
std::string location = parts[0];
|
|
|
|
std::string listname = parts[1];
|
|
|
|
|
|
|
|
InventoryLocation loc;
|
|
|
|
|
|
|
|
if (location == "context" || location == "current_name")
|
|
|
|
loc = m_current_inventory_location;
|
|
|
|
else
|
|
|
|
loc.deSerialize(location);
|
|
|
|
|
2017-08-20 19:37:29 +02:00
|
|
|
m_inventory_rings.emplace_back(loc, listname);
|
2015-06-16 10:48:54 +02:00
|
|
|
return;
|
2017-08-20 19:37:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (element.empty() && m_inventorylists.size() > 1) {
|
2015-06-16 10:48:54 +02:00
|
|
|
size_t siz = m_inventorylists.size();
|
|
|
|
// insert the last two inv list elements into the list ring
|
2020-02-01 13:55:13 +01:00
|
|
|
const GUIInventoryList *spa = m_inventorylists[siz - 2];
|
|
|
|
const GUIInventoryList *spb = m_inventorylists[siz - 1];
|
|
|
|
m_inventory_rings.emplace_back(spa->getInventoryloc(), spa->getListname());
|
|
|
|
m_inventory_rings.emplace_back(spb->getInventoryloc(), spb->getListname());
|
2015-06-18 04:25:11 +02:00
|
|
|
return;
|
2015-06-16 10:48:54 +02:00
|
|
|
}
|
2017-08-20 19:37:29 +02:00
|
|
|
|
2015-06-16 10:48:54 +02:00
|
|
|
errorstream<< "Invalid list ring element(" << parts.size() << ", "
|
|
|
|
<< m_inventorylists.size() << "): '" << element << "'" << std::endl;
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("checkbox", element, 3, 4, parts))
|
|
|
|
return;
|
2014-06-14 11:22:09 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::string name = parts[1];
|
|
|
|
std::string label = parts[2];
|
|
|
|
std::string selected;
|
2014-06-14 11:22:09 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts.size() >= 4)
|
|
|
|
selected = parts[3];
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("checkbox",0);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
bool fselected = false;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (selected == "true")
|
|
|
|
fselected = true;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label)));
|
|
|
|
const core::dimension2d<u32> label_size = m_font->getDimension(wlabel.c_str());
|
|
|
|
s32 cb_size = Environment->getSkin()->getSize(gui::EGDS_CHECK_BOX_WIDTH);
|
|
|
|
s32 y_center = (std::max(label_size.Height, (u32)cb_size) + 1) / 2;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
core::rect<s32> rect;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
2014-06-18 22:38:29 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
rect = core::rect<s32>(
|
|
|
|
pos.X,
|
|
|
|
pos.Y - y_center,
|
|
|
|
pos.X + label_size.Width + cb_size + 7,
|
|
|
|
pos.Y + y_center
|
2013-06-23 18:30:21 +02:00
|
|
|
);
|
2021-12-29 23:58:26 +01:00
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
rect = core::rect<s32>(
|
|
|
|
pos.X,
|
|
|
|
pos.Y + imgsize.Y / 2 - y_center,
|
|
|
|
pos.X + label_size.Width + cb_size + 7,
|
|
|
|
pos.Y + imgsize.Y / 2 + y_center
|
|
|
|
);
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
wlabel, //Needed for displaying text on MSVC
|
|
|
|
wlabel,
|
|
|
|
258+m_fields.size()
|
|
|
|
);
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.ftype = f_CheckBox;
|
2013-08-19 11:26:51 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
gui::IGUICheckBox *e = Environment->addCheckBox(fselected, rect,
|
|
|
|
data->current_parent, spec.fid, spec.flabel.c_str());
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("checkbox", name);
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.sound = style.get(StyleSpec::Property::SOUND, "");
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
2014-06-24 12:28:24 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (spec.fname == m_focused_element) {
|
|
|
|
Environment->setFocus(e);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
2021-12-29 23:58:26 +01:00
|
|
|
|
|
|
|
e->grab();
|
|
|
|
m_checkboxes.emplace_back(spec, e);
|
|
|
|
m_fields.push_back(spec);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &element)
|
2014-06-19 18:17:35 +02:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("scrollbar", element, 5, 5, parts))
|
|
|
|
return;
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1],',');
|
|
|
|
std::string name = parts[3];
|
|
|
|
std::string value = parts[4];
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("scrollbar",0);
|
|
|
|
MY_CHECKGEOM("scrollbar",1);
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 dim;
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
dim = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
dim.X = stof(v_geom[0]) * spacing.X;
|
|
|
|
dim.Y = stof(v_geom[1]) * spacing.Y;
|
|
|
|
}
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> rect =
|
|
|
|
core::rect<s32>(pos.X, pos.Y, pos.X + dim.X, pos.Y + dim.Y);
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258+m_fields.size()
|
|
|
|
);
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
bool is_horizontal = true;
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts[2] == "vertical")
|
|
|
|
is_horizontal = false;
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.ftype = f_ScrollBar;
|
|
|
|
spec.send = true;
|
|
|
|
GUIScrollBar *e = new GUIScrollBar(Environment, data->current_parent,
|
|
|
|
spec.fid, rect, is_horizontal, true);
|
2019-12-06 21:51:10 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("scrollbar", name);
|
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
|
|
|
e->setArrowsVisible(data->scrollbar_options.arrow_visiblity);
|
2019-12-06 21:51:10 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
s32 max = data->scrollbar_options.max;
|
|
|
|
s32 min = data->scrollbar_options.min;
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setMax(max);
|
|
|
|
e->setMin(min);
|
2019-12-06 21:51:10 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setPos(stoi(parts[4]));
|
2019-12-06 21:51:10 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setSmallStep(data->scrollbar_options.small_step);
|
|
|
|
e->setLargeStep(data->scrollbar_options.large_step);
|
2019-12-06 21:51:10 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
s32 scrollbar_size = is_horizontal ? dim.X : dim.Y;
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setPageSize(scrollbar_size * (max - min + 1) / data->scrollbar_options.thumb_size);
|
2020-07-12 09:47:05 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (spec.fname == m_focused_element) {
|
|
|
|
Environment->setFocus(e);
|
2014-06-19 18:17:35 +02:00
|
|
|
}
|
2021-12-29 23:58:26 +01:00
|
|
|
|
|
|
|
m_scrollbars.emplace_back(spec,e);
|
|
|
|
m_fields.push_back(spec);
|
2019-12-06 21:51:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GUIFormSpecMenu::parseScrollBarOptions(parserData* data, const std::string &element)
|
|
|
|
{
|
|
|
|
std::vector<std::string> parts = split(element, ';');
|
|
|
|
|
|
|
|
if (parts.size() == 0) {
|
|
|
|
warningstream << "Invalid scrollbaroptions element(" << parts.size() << "): '" <<
|
|
|
|
element << "'" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const std::string &i : parts) {
|
|
|
|
std::vector<std::string> options = split(i, '=');
|
|
|
|
|
|
|
|
if (options.size() != 2) {
|
|
|
|
warningstream << "Invalid scrollbaroptions option syntax: '" <<
|
|
|
|
element << "'" << std::endl;
|
|
|
|
continue; // Go to next option
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options[0] == "max") {
|
|
|
|
data->scrollbar_options.max = stoi(options[1]);
|
|
|
|
continue;
|
|
|
|
} else if (options[0] == "min") {
|
|
|
|
data->scrollbar_options.min = stoi(options[1]);
|
|
|
|
continue;
|
|
|
|
} else if (options[0] == "smallstep") {
|
|
|
|
int value = stoi(options[1]);
|
|
|
|
data->scrollbar_options.small_step = value < 0 ? 10 : value;
|
|
|
|
continue;
|
|
|
|
} else if (options[0] == "largestep") {
|
|
|
|
int value = stoi(options[1]);
|
|
|
|
data->scrollbar_options.large_step = value < 0 ? 100 : value;
|
|
|
|
continue;
|
|
|
|
} else if (options[0] == "thumbsize") {
|
|
|
|
int value = stoi(options[1]);
|
|
|
|
data->scrollbar_options.thumb_size = value <= 0 ? 1 : value;
|
|
|
|
continue;
|
|
|
|
} else if (options[0] == "arrows") {
|
|
|
|
std::string value = trim(options[1]);
|
|
|
|
if (value == "hide")
|
|
|
|
data->scrollbar_options.arrow_visiblity = GUIScrollBar::HIDE;
|
|
|
|
else if (value == "show")
|
|
|
|
data->scrollbar_options.arrow_visiblity = GUIScrollBar::SHOW;
|
|
|
|
else // Auto hide/show
|
|
|
|
data->scrollbar_options.arrow_visiblity = GUIScrollBar::DEFAULT;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
warningstream << "Invalid scrollbaroptions option(" << options[0] <<
|
|
|
|
"): '" << element << "'" << std::endl;
|
|
|
|
}
|
2014-06-19 18:17:35 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
2022-07-03 14:52:26 +02:00
|
|
|
if (!precheckElement("image", element, 2, 4, parts))
|
2021-12-29 23:58:26 +01:00
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2022-07-03 14:52:26 +02:00
|
|
|
size_t offset = parts.size() >= 3;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2022-07-03 14:52:26 +02:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
MY_CHECKPOS("image", 0);
|
|
|
|
|
|
|
|
std::vector<std::string> v_geom;
|
|
|
|
if (parts.size() >= 3) {
|
|
|
|
v_geom = split(parts[1],',');
|
2016-07-07 22:10:15 +02:00
|
|
|
MY_CHECKGEOM("image", 1);
|
2022-07-03 14:52:26 +02:00
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2022-07-03 14:52:26 +02:00
|
|
|
std::string name = unescape_string(parts[1 + offset]);
|
|
|
|
video::ITexture *texture = m_tsrc->getTexture(name);
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2022-07-03 14:52:26 +02:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
|
|
|
|
|
|
|
if (parts.size() < 3) {
|
|
|
|
if (texture != nullptr) {
|
|
|
|
core::dimension2du dim = texture->getOriginalSize();
|
|
|
|
geom.X = dim.Width;
|
|
|
|
geom.Y = dim.Height;
|
2019-06-27 14:40:49 +02:00
|
|
|
} else {
|
2022-07-03 14:52:26 +02:00
|
|
|
geom = v2s32(0);
|
2019-06-27 14:40:49 +02:00
|
|
|
}
|
2022-07-03 14:52:26 +02:00
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2022-07-03 14:52:26 +02:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
if (parts.size() >= 3)
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
if (parts.size() >= 3) {
|
|
|
|
geom.X = stof(v_geom[0]) * (float)imgsize.X;
|
|
|
|
geom.Y = stof(v_geom[1]) * (float)imgsize.Y;
|
2019-11-07 20:11:01 +01:00
|
|
|
}
|
2017-08-20 19:37:29 +02:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (!data->explicit_size)
|
2022-07-03 14:52:26 +02:00
|
|
|
warningstream << "Invalid use of image without a size[] element" << std::endl;
|
2021-12-29 23:58:26 +01:00
|
|
|
|
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
L"",
|
|
|
|
L"",
|
2022-07-03 14:52:26 +02:00
|
|
|
258 + m_fields.size(),
|
|
|
|
1
|
2021-12-29 23:58:26 +01:00
|
|
|
);
|
2022-07-03 14:52:26 +02:00
|
|
|
|
|
|
|
core::rect<s32> rect = core::rect<s32>(pos, pos + geom);
|
|
|
|
|
|
|
|
core::rect<s32> middle;
|
|
|
|
if (parts.size() >= 4)
|
|
|
|
parseMiddleRect(parts[3], &middle);
|
|
|
|
|
|
|
|
GUIAnimatedImage *e = new GUIAnimatedImage(Environment, data->current_parent,
|
|
|
|
spec.fid, rect);
|
|
|
|
|
|
|
|
e->setTexture(texture);
|
|
|
|
e->setMiddleRect(middle);
|
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("image", spec.fname);
|
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3));
|
|
|
|
|
2022-07-03 14:52:26 +02:00
|
|
|
// Animated images should let events through
|
2021-12-29 23:58:26 +01:00
|
|
|
m_clickthrough_elements.push_back(e);
|
2022-07-03 14:52:26 +02:00
|
|
|
|
|
|
|
m_fields.push_back(spec);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2020-02-15 16:33:18 +01:00
|
|
|
void GUIFormSpecMenu::parseAnimatedImage(parserData *data, const std::string &element)
|
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
2022-07-03 14:52:26 +02:00
|
|
|
if (!precheckElement("animated_image", element, 6, 8, parts))
|
2020-02-15 16:33:18 +01:00
|
|
|
return;
|
|
|
|
|
2020-03-16 22:56:48 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0], ',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1], ',');
|
|
|
|
std::string name = parts[2];
|
|
|
|
std::string texture_name = unescape_string(parts[3]);
|
|
|
|
s32 frame_count = stoi(parts[4]);
|
|
|
|
s32 frame_duration = stoi(parts[5]);
|
2020-02-15 16:33:18 +01:00
|
|
|
|
|
|
|
MY_CHECKPOS("animated_image", 0);
|
|
|
|
MY_CHECKGEOM("animated_image", 1);
|
|
|
|
|
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
|
|
|
|
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
geom.X = stof(v_geom[0]) * (float)imgsize.X;
|
|
|
|
geom.Y = stof(v_geom[1]) * (float)imgsize.Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!data->explicit_size)
|
2022-07-03 14:52:26 +02:00
|
|
|
warningstream << "Invalid use of animated_image without a size[] element"
|
|
|
|
<< std::endl;
|
2020-02-15 16:33:18 +01:00
|
|
|
|
|
|
|
FieldSpec spec(
|
2020-03-16 22:56:48 +01:00
|
|
|
name,
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
2020-02-15 16:33:18 +01:00
|
|
|
);
|
2020-03-16 22:56:48 +01:00
|
|
|
spec.ftype = f_AnimatedImage;
|
|
|
|
spec.send = true;
|
2020-02-15 16:33:18 +01:00
|
|
|
|
|
|
|
core::rect<s32> rect = core::rect<s32>(pos, pos + geom);
|
|
|
|
|
2022-07-03 14:52:26 +02:00
|
|
|
core::rect<s32> middle;
|
|
|
|
if (parts.size() >= 8)
|
|
|
|
parseMiddleRect(parts[7], &middle);
|
2020-02-15 16:33:18 +01:00
|
|
|
|
2022-07-03 14:52:26 +02:00
|
|
|
GUIAnimatedImage *e = new GUIAnimatedImage(Environment, data->current_parent,
|
|
|
|
spec.fid, rect);
|
|
|
|
|
|
|
|
e->setTexture(m_tsrc->getTexture(texture_name));
|
|
|
|
e->setMiddleRect(middle);
|
|
|
|
e->setFrameDuration(frame_duration);
|
|
|
|
e->setFrameCount(frame_count);
|
2020-03-16 22:56:48 +01:00
|
|
|
if (parts.size() >= 7)
|
|
|
|
e->setFrameIndex(stoi(parts[6]) - 1);
|
|
|
|
|
2020-04-11 22:39:30 +02:00
|
|
|
auto style = getDefaultStyleForElement("animated_image", spec.fname, "image");
|
2020-02-15 16:33:18 +01:00
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
2020-04-25 16:55:21 +02:00
|
|
|
|
|
|
|
// Animated images should let events through
|
|
|
|
m_clickthrough_elements.push_back(e);
|
2020-02-15 16:33:18 +01:00
|
|
|
|
|
|
|
m_fields.push_back(spec);
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("item_image", element, 3, 3, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1],',');
|
|
|
|
std::string name = parts[2];
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("item_image",0);
|
|
|
|
MY_CHECKGEOM("item_image",1);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
geom.X = stof(v_geom[0]) * (float)imgsize.X;
|
|
|
|
geom.Y = stof(v_geom[1]) * (float)imgsize.Y;
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if(!data->explicit_size)
|
|
|
|
warningstream<<"invalid use of item_image without a size[] element"<<std::endl;
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
"",
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size(),
|
|
|
|
2
|
|
|
|
);
|
|
|
|
spec.ftype = f_ItemImage;
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
GUIItemImage *e = new GUIItemImage(Environment, data->current_parent, spec.fid,
|
|
|
|
core::rect<s32>(pos, pos + geom), name, m_font, m_client);
|
|
|
|
auto style = getDefaultStyleForElement("item_image", spec.fname);
|
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
2020-03-31 19:34:42 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
// item images should let events through
|
|
|
|
m_clickthrough_elements.push_back(e);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
m_fields.push_back(spec);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element,
|
|
|
|
const std::string &type)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("button", element, 4, 4, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1],',');
|
|
|
|
std::string name = parts[2];
|
|
|
|
std::string label = parts[3];
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("button",0);
|
|
|
|
MY_CHECKGEOM("button",1);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
|
|
|
core::rect<s32> rect;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X,
|
|
|
|
pos.Y+geom.Y);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
|
|
|
|
pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
rect = core::rect<s32>(pos.X, pos.Y - m_btn_height,
|
|
|
|
pos.X + geom.X, pos.Y + m_btn_height);
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if(!data->explicit_size)
|
|
|
|
warningstream<<"invalid use of button without a size[] element"<<std::endl;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label)));
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
wlabel,
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
|
|
|
spec.ftype = f_Button;
|
|
|
|
if(type == "button_exit")
|
|
|
|
spec.is_exit = true;
|
2013-08-19 11:26:51 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
GUIButton *e = GUIButton::addButton(Environment, rect, m_tsrc,
|
|
|
|
data->current_parent, spec.fid, spec.flabel.c_str());
|
2019-03-15 20:03:12 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getStyleForElement(type, name, (type != "button") ? "button" : "");
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.sound = style[StyleSpec::STATE_DEFAULT].get(StyleSpec::Property::SOUND, "");
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setStyles(style);
|
2019-03-15 20:03:12 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (spec.fname == m_focused_element) {
|
|
|
|
Environment->setFocus(e);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
2021-12-29 23:58:26 +01:00
|
|
|
|
|
|
|
m_fields.push_back(spec);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2022-07-03 14:52:26 +02:00
|
|
|
bool GUIFormSpecMenu::parseMiddleRect(const std::string &value, core::rect<s32> *parsed_rect)
|
|
|
|
{
|
|
|
|
core::rect<s32> rect;
|
|
|
|
std::vector<std::string> v_rect = split(value, ',');
|
|
|
|
|
|
|
|
if (v_rect.size() == 1) {
|
|
|
|
s32 x = stoi(v_rect[0]);
|
|
|
|
rect.UpperLeftCorner = core::vector2di(x, x);
|
|
|
|
rect.LowerRightCorner = core::vector2di(-x, -x);
|
|
|
|
} else if (v_rect.size() == 2) {
|
|
|
|
s32 x = stoi(v_rect[0]);
|
|
|
|
s32 y = stoi(v_rect[1]);
|
|
|
|
rect.UpperLeftCorner = core::vector2di(x, y);
|
|
|
|
rect.LowerRightCorner = core::vector2di(-x, -y);
|
|
|
|
// `-x` is interpreted as `w - x`
|
|
|
|
} else if (v_rect.size() == 4) {
|
|
|
|
rect.UpperLeftCorner = core::vector2di(stoi(v_rect[0]), stoi(v_rect[1]));
|
|
|
|
rect.LowerRightCorner = core::vector2di(stoi(v_rect[2]), stoi(v_rect[3]));
|
|
|
|
} else {
|
|
|
|
warningstream << "Invalid rectangle string format: \"" << value
|
|
|
|
<< "\"" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*parsed_rect = rect;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseBackground(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("background", element, 3, 5, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1],',');
|
|
|
|
std::string name = unescape_string(parts[2]);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("background",0);
|
|
|
|
MY_CHECKGEOM("background",1);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
pos.X -= (spacing.X - (float)imgsize.X) / 2;
|
|
|
|
pos.Y -= (spacing.Y - (float)imgsize.Y) / 2;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
geom.X = stof(v_geom[0]) * spacing.X;
|
|
|
|
geom.Y = stof(v_geom[1]) * spacing.Y;
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
bool clip = false;
|
|
|
|
if (parts.size() >= 4 && is_yes(parts[3])) {
|
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos) * -1;
|
|
|
|
geom = v2s32(0, 0);
|
|
|
|
} else {
|
|
|
|
pos.X = stoi(v_pos[0]); //acts as offset
|
|
|
|
pos.Y = stoi(v_pos[1]);
|
2013-11-02 04:26:44 +01:00
|
|
|
}
|
2021-12-29 23:58:26 +01:00
|
|
|
clip = true;
|
|
|
|
}
|
2018-11-28 20:01:49 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> middle;
|
2022-07-03 14:52:26 +02:00
|
|
|
if (parts.size() >= 5)
|
|
|
|
parseMiddleRect(parts[4], &middle);
|
2019-06-22 16:03:54 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (!data->explicit_size && !clip)
|
|
|
|
warningstream << "invalid use of unclipped background without a size[] element" << std::endl;
|
2018-11-28 20:01:49 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> rect;
|
|
|
|
if (!clip) {
|
|
|
|
// no auto_clip => position like normal image
|
|
|
|
rect = core::rect<s32>(pos, pos + geom);
|
|
|
|
} else {
|
|
|
|
// it will be auto-clipped when drawing
|
|
|
|
rect = core::rect<s32>(-pos, pos);
|
|
|
|
}
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2022-02-22 19:17:53 +01:00
|
|
|
GUIBackgroundImage *e = new GUIBackgroundImage(Environment, data->background_parent.get(),
|
|
|
|
spec.fid, rect, name, middle, m_tsrc, clip);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FATAL_ERROR_IF(!e, "Failed to create background formspec element");
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setNotClipped(true);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
m_fields.push_back(spec);
|
2022-02-22 19:17:53 +01:00
|
|
|
e->drop();
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseTableOptions(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2013-08-23 12:24:11 +02:00
|
|
|
std::vector<std::string> parts = split(element,';');
|
|
|
|
|
|
|
|
data->table_options.clear();
|
2017-08-20 19:37:29 +02:00
|
|
|
for (const std::string &part : parts) {
|
2013-08-23 12:24:11 +02:00
|
|
|
// Parse table option
|
2017-08-20 19:37:29 +02:00
|
|
|
std::string opt = unescape_string(part);
|
2013-08-23 12:24:11 +02:00
|
|
|
data->table_options.push_back(GUITable::splitOption(opt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseTableColumns(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2013-06-23 18:30:21 +02:00
|
|
|
std::vector<std::string> parts = split(element,';');
|
|
|
|
|
2013-08-23 12:24:11 +02:00
|
|
|
data->table_columns.clear();
|
2017-08-20 19:37:29 +02:00
|
|
|
for (const std::string &part : parts) {
|
|
|
|
std::vector<std::string> col_parts = split(part,',');
|
2013-08-23 12:24:11 +02:00
|
|
|
GUITable::TableColumn column;
|
|
|
|
// Parse column type
|
|
|
|
if (!col_parts.empty())
|
|
|
|
column.type = col_parts[0];
|
|
|
|
// Parse column options
|
|
|
|
for (size_t j = 1; j < col_parts.size(); ++j) {
|
|
|
|
std::string opt = unescape_string(col_parts[j]);
|
|
|
|
column.options.push_back(GUITable::splitOption(opt));
|
|
|
|
}
|
|
|
|
data->table_columns.push_back(column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseTable(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("table", element, 4, 5, parts))
|
|
|
|
return;
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1],',');
|
|
|
|
std::string name = parts[2];
|
|
|
|
std::vector<std::string> items = split(parts[3],',');
|
|
|
|
std::string str_initial_selection;
|
|
|
|
std::string str_transparent = "false";
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts.size() >= 5)
|
|
|
|
str_initial_selection = parts[4];
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("table",0);
|
|
|
|
MY_CHECKGEOM("table",1);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
geom.X = stof(v_geom[0]) * spacing.X;
|
|
|
|
geom.Y = stof(v_geom[1]) * spacing.Y;
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.ftype = f_Table;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
for (std::string &item : items) {
|
|
|
|
item = wide_to_utf8(unescape_translate(utf8_to_wide(unescape_string(item))));
|
|
|
|
}
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
//now really show table
|
|
|
|
GUITable *e = new GUITable(Environment, data->current_parent, spec.fid,
|
|
|
|
rect, m_tsrc);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (spec.fname == m_focused_element) {
|
|
|
|
Environment->setFocus(e);
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setTable(data->table_options, data->table_columns, items);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->table_dyndata.find(name) != data->table_dyndata.end()) {
|
|
|
|
e->setDynamicData(data->table_dyndata[name]);
|
|
|
|
}
|
2013-07-07 21:53:40 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (!str_initial_selection.empty() && str_initial_selection != "0")
|
|
|
|
e->setSelected(stoi(str_initial_selection));
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("table", name);
|
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
|
|
|
e->setOverrideFont(style.getFont());
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
m_tables.emplace_back(spec, e);
|
|
|
|
m_fields.push_back(spec);
|
2013-08-23 12:24:11 +02:00
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("textlist", element, 4, 6, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1],',');
|
|
|
|
std::string name = parts[2];
|
|
|
|
std::vector<std::string> items = split(parts[3],',');
|
|
|
|
std::string str_initial_selection;
|
|
|
|
std::string str_transparent = "false";
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts.size() >= 5)
|
|
|
|
str_initial_selection = parts[4];
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts.size() >= 6)
|
|
|
|
str_transparent = parts[5];
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("textlist",0);
|
|
|
|
MY_CHECKGEOM("textlist",1);
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
geom.X = stof(v_geom[0]) * spacing.X;
|
|
|
|
geom.Y = stof(v_geom[1]) * spacing.Y;
|
|
|
|
}
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.ftype = f_Table;
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
for (std::string &item : items) {
|
|
|
|
item = wide_to_utf8(unescape_translate(utf8_to_wide(unescape_string(item))));
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
//now really show list
|
|
|
|
GUITable *e = new GUITable(Environment, data->current_parent, spec.fid,
|
|
|
|
rect, m_tsrc);
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (spec.fname == m_focused_element) {
|
|
|
|
Environment->setFocus(e);
|
|
|
|
}
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setTextList(items, is_yes(str_transparent));
|
2013-08-23 12:24:11 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->table_dyndata.find(name) != data->table_dyndata.end()) {
|
|
|
|
e->setDynamicData(data->table_dyndata[name]);
|
|
|
|
}
|
2013-08-16 00:54:38 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (!str_initial_selection.empty() && str_initial_selection != "0")
|
|
|
|
e->setSelected(stoi(str_initial_selection));
|
2013-07-07 21:53:40 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("textlist", name);
|
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
|
|
|
e->setOverrideFont(style.getFont());
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
m_tables.emplace_back(spec, e);
|
|
|
|
m_fields.push_back(spec);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("dropdown", element, 5, 6, parts))
|
|
|
|
return;
|
2020-07-10 12:11:26 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0], ',');
|
|
|
|
std::string name = parts[2];
|
|
|
|
std::vector<std::string> items = split(parts[3], ',');
|
|
|
|
std::string str_initial_selection = parts[4];
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts.size() >= 6 && is_yes(parts[5]))
|
|
|
|
m_dropdown_index_event[name] = true;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("dropdown",0);
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
|
|
|
core::rect<s32> rect;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
std::vector<std::string> v_geom = split(parts[1],',');
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (v_geom.size() == 1)
|
|
|
|
v_geom.emplace_back("1");
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKGEOM("dropdown",1);
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
s32 width = stof(parts[1]) * spacing.Y;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
rect = core::rect<s32>(pos.X, pos.Y,
|
|
|
|
pos.X + width, pos.Y + (m_btn_height * 2));
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.ftype = f_DropDown;
|
|
|
|
spec.send = true;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
//now really show list
|
|
|
|
gui::IGUIComboBox *e = Environment->addComboBox(rect, data->current_parent,
|
|
|
|
spec.fid);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (spec.fname == m_focused_element) {
|
|
|
|
Environment->setFocus(e);
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
for (const std::string &item : items) {
|
|
|
|
e->addItem(unescape_translate(unescape_string(
|
|
|
|
utf8_to_wide(item))).c_str());
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (!str_initial_selection.empty())
|
|
|
|
e->setSelected(stoi(str_initial_selection)-1);
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("dropdown", name);
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.sound = style.get(StyleSpec::Property::SOUND, "");
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
2016-05-05 18:50:02 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
m_fields.push_back(spec);
|
2016-05-05 18:50:02 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
m_dropdowns.emplace_back(spec, std::vector<std::string>());
|
|
|
|
std::vector<std::string> &values = m_dropdowns.back().second;
|
|
|
|
for (const std::string &item : items) {
|
|
|
|
values.push_back(unescape_string(item));
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseFieldCloseOnEnter(parserData *data, const std::string &element)
|
2016-10-03 01:30:33 +02:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("field_close_on_enter", element, 2, 2, parts))
|
|
|
|
return;
|
|
|
|
|
|
|
|
field_close_on_enter[parts[0]] = is_yes(parts[1]);
|
2016-10-03 01:30:33 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("pwdfield", element, 4, 4, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1],',');
|
|
|
|
std::string name = parts[2];
|
|
|
|
std::string label = parts[3];
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("pwdfield",0);
|
|
|
|
MY_CHECKGEOM("pwdfield",1);
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
pos -= padding;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
|
|
|
|
pos.Y -= m_btn_height;
|
|
|
|
geom.Y = m_btn_height*2;
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label)));
|
2013-08-19 11:26:51 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
wlabel,
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size(),
|
|
|
|
0,
|
|
|
|
ECI_IBEAM
|
|
|
|
);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.send = true;
|
|
|
|
gui::IGUIEditBox *e = Environment->addEditBox(0, rect, true,
|
|
|
|
data->current_parent, spec.fid);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (spec.fname == m_focused_element) {
|
|
|
|
Environment->setFocus(e);
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (label.length() >= 1) {
|
|
|
|
int font_height = g_fontengine->getTextHeight();
|
|
|
|
rect.UpperLeftCorner.Y -= font_height;
|
|
|
|
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
|
|
|
|
gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true,
|
|
|
|
data->current_parent, 0);
|
|
|
|
}
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setPasswordBox(true,L'*');
|
2016-08-07 17:22:50 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("pwdfield", name, "field");
|
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
|
|
|
e->setDrawBorder(style.getBool(StyleSpec::BORDER, true));
|
|
|
|
e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
|
|
|
|
e->setOverrideFont(style.getFont());
|
|
|
|
|
|
|
|
irr::SEvent evt;
|
|
|
|
evt.EventType = EET_KEY_INPUT_EVENT;
|
|
|
|
evt.KeyInput.Key = KEY_END;
|
|
|
|
evt.KeyInput.Char = 0;
|
|
|
|
evt.KeyInput.Control = false;
|
|
|
|
evt.KeyInput.Shift = false;
|
|
|
|
evt.KeyInput.PressedDown = true;
|
|
|
|
e->OnEvent(evt);
|
|
|
|
|
|
|
|
// Note: Before 5.2.0 "parts.size() >= 5" resulted in a
|
|
|
|
// warning referring to field_close_on_enter[]!
|
2016-08-07 17:22:50 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
m_fields.push_back(spec);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2018-03-10 00:24:57 +01:00
|
|
|
void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec,
|
|
|
|
core::rect<s32> &rect, bool is_multiline)
|
|
|
|
{
|
|
|
|
bool is_editable = !spec.fname.empty();
|
|
|
|
if (!is_editable && !is_multiline) {
|
|
|
|
// spec field id to 0, this stops submit searching for a value that isn't there
|
|
|
|
gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true,
|
2020-04-13 10:50:07 +02:00
|
|
|
data->current_parent, 0);
|
2018-03-10 00:24:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_editable) {
|
|
|
|
spec.send = true;
|
|
|
|
} else if (is_multiline &&
|
|
|
|
spec.fdefault.empty() && !spec.flabel.empty()) {
|
|
|
|
// Multiline textareas: swap default and label for backwards compat
|
|
|
|
spec.flabel.swap(spec.fdefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
gui::IGUIEditBox *e = nullptr;
|
2021-03-19 18:44:32 +01:00
|
|
|
if (is_multiline) {
|
|
|
|
e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true, Environment,
|
|
|
|
data->current_parent, spec.fid, rect, is_editable, true);
|
|
|
|
} else if (is_editable) {
|
|
|
|
e = Environment->addEditBox(spec.fdefault.c_str(), rect, true,
|
|
|
|
data->current_parent, spec.fid);
|
|
|
|
e->grab();
|
2018-03-10 00:24:57 +01:00
|
|
|
}
|
|
|
|
|
2020-04-11 22:39:30 +02:00
|
|
|
auto style = getDefaultStyleForElement(is_multiline ? "textarea" : "field", spec.fname);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2018-03-10 00:24:57 +01:00
|
|
|
if (e) {
|
2020-07-12 09:47:05 +02:00
|
|
|
if (is_editable && spec.fname == m_focused_element)
|
2018-03-10 00:24:57 +01:00
|
|
|
Environment->setFocus(e);
|
|
|
|
|
|
|
|
if (is_multiline) {
|
|
|
|
e->setMultiLine(true);
|
|
|
|
e->setWordWrap(true);
|
|
|
|
e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT);
|
|
|
|
} else {
|
|
|
|
irr::SEvent evt;
|
|
|
|
evt.EventType = EET_KEY_INPUT_EVENT;
|
|
|
|
evt.KeyInput.Key = KEY_END;
|
|
|
|
evt.KeyInput.Char = 0;
|
|
|
|
evt.KeyInput.Control = 0;
|
|
|
|
evt.KeyInput.Shift = 0;
|
|
|
|
evt.KeyInput.PressedDown = true;
|
|
|
|
e->OnEvent(evt);
|
|
|
|
}
|
2019-03-16 22:38:36 +01:00
|
|
|
|
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
|
|
|
e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
|
2021-05-25 21:03:51 +02:00
|
|
|
bool border = style.getBool(StyleSpec::BORDER, true);
|
|
|
|
e->setDrawBorder(border);
|
|
|
|
e->setDrawBackground(border);
|
2020-07-12 09:48:50 +02:00
|
|
|
e->setOverrideFont(style.getFont());
|
2019-11-07 20:11:01 +01:00
|
|
|
|
|
|
|
e->drop();
|
2018-03-10 00:24:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!spec.flabel.empty()) {
|
|
|
|
int font_height = g_fontengine->getTextHeight();
|
|
|
|
rect.UpperLeftCorner.Y -= font_height;
|
|
|
|
rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
|
2019-11-07 20:11:01 +01:00
|
|
|
IGUIElement *t = gui::StaticText::add(Environment, spec.flabel.c_str(),
|
2020-04-13 10:50:07 +02:00
|
|
|
rect, false, true, data->current_parent, 0);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
|
|
|
if (t)
|
|
|
|
t->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
2018-03-10 00:24:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
void GUIFormSpecMenu::parseSimpleField(parserData *data,
|
|
|
|
std::vector<std::string> &parts)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2013-06-23 18:30:21 +02:00
|
|
|
std::string name = parts[0];
|
|
|
|
std::string label = parts[1];
|
|
|
|
std::string default_val = parts[2];
|
|
|
|
|
|
|
|
core::rect<s32> rect;
|
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
if (data->explicit_size)
|
|
|
|
warningstream << "invalid use of unpositioned \"field\" in inventory" << std::endl;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
v2s32 pos = getElementBasePos(nullptr);
|
|
|
|
pos.Y = (data->simple_field_count + 2) * 60;
|
2013-06-23 18:30:21 +02:00
|
|
|
v2s32 size = DesiredRect.getSize();
|
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
rect = core::rect<s32>(
|
|
|
|
size.X / 2 - 150, pos.Y,
|
|
|
|
size.X / 2 - 150 + 300, pos.Y + m_btn_height * 2
|
|
|
|
);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
if (m_form_src)
|
2013-06-23 18:30:21 +02:00
|
|
|
default_val = m_form_src->resolveText(default_val);
|
|
|
|
|
|
|
|
|
2017-01-31 18:05:03 +01:00
|
|
|
std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label)));
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2014-05-30 03:04:10 +02:00
|
|
|
FieldSpec spec(
|
2015-06-10 01:54:33 +02:00
|
|
|
name,
|
2013-06-23 18:30:21 +02:00
|
|
|
wlabel,
|
2016-05-05 19:08:45 +02:00
|
|
|
utf8_to_wide(unescape_string(default_val)),
|
2020-01-11 20:17:11 +01:00
|
|
|
258 + m_fields.size(),
|
|
|
|
0,
|
|
|
|
ECI_IBEAM
|
2013-06-23 18:30:21 +02:00
|
|
|
);
|
|
|
|
|
2018-03-10 00:24:57 +01:00
|
|
|
createTextField(data, spec, rect, false);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
|
|
|
m_fields.push_back(spec);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
|
|
|
data->simple_field_count++;
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>& parts,
|
|
|
|
const std::string &type)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2013-06-23 18:30:21 +02:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1],',');
|
|
|
|
std::string name = parts[2];
|
|
|
|
std::string label = parts[3];
|
|
|
|
std::string default_val = parts[4];
|
|
|
|
|
|
|
|
MY_CHECKPOS(type,0);
|
|
|
|
MY_CHECKGEOM(type,1);
|
|
|
|
|
2019-06-27 14:40:49 +02:00
|
|
|
v2s32 pos;
|
2013-06-23 18:30:21 +02:00
|
|
|
v2s32 geom;
|
|
|
|
|
2019-06-27 14:40:49 +02:00
|
|
|
if (data->real_coordinates) {
|
2019-11-07 20:11:01 +01:00
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
2019-06-27 14:40:49 +02:00
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
2019-11-07 20:11:01 +01:00
|
|
|
pos = getElementBasePos(&v_pos);
|
2019-06-27 14:40:49 +02:00
|
|
|
pos -= padding;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2019-06-27 14:40:49 +02:00
|
|
|
geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
|
|
|
|
|
|
|
|
if (type == "textarea")
|
|
|
|
{
|
|
|
|
geom.Y = (stof(v_geom[1]) * (float)imgsize.Y) - (spacing.Y-imgsize.Y);
|
|
|
|
pos.Y += m_btn_height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
|
|
|
|
pos.Y -= m_btn_height;
|
|
|
|
geom.Y = m_btn_height*2;
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
|
|
|
|
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
if(!data->explicit_size)
|
2015-10-14 07:26:03 +02:00
|
|
|
warningstream<<"invalid use of positioned "<<type<<" without a size[] element"<<std::endl;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
|
|
|
if(m_form_src)
|
|
|
|
default_val = m_form_src->resolveText(default_val);
|
|
|
|
|
|
|
|
|
2017-01-31 18:05:03 +01:00
|
|
|
std::wstring wlabel = translate_string(utf8_to_wide(unescape_string(label)));
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2014-05-30 03:04:10 +02:00
|
|
|
FieldSpec spec(
|
2015-06-10 01:54:33 +02:00
|
|
|
name,
|
2013-06-23 18:30:21 +02:00
|
|
|
wlabel,
|
2016-05-05 19:08:45 +02:00
|
|
|
utf8_to_wide(unescape_string(default_val)),
|
2020-01-11 20:17:11 +01:00
|
|
|
258 + m_fields.size(),
|
|
|
|
0,
|
|
|
|
ECI_IBEAM
|
2013-06-23 18:30:21 +02:00
|
|
|
);
|
|
|
|
|
2018-03-10 00:24:57 +01:00
|
|
|
createTextField(data, spec, rect, type == "textarea");
|
2016-08-07 17:22:50 +02:00
|
|
|
|
2020-03-10 20:30:55 +01:00
|
|
|
// Note: Before 5.2.0 "parts.size() >= 6" resulted in a
|
|
|
|
// warning referring to field_close_on_enter[]!
|
2016-08-07 17:22:50 +02:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
m_fields.push_back(spec);
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseField(parserData* data, const std::string &element,
|
|
|
|
const std::string &type)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement(type, element, 3, 5, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2014-06-19 00:22:03 +02:00
|
|
|
if (parts.size() == 3 || parts.size() == 4) {
|
2021-12-29 23:58:26 +01:00
|
|
|
parseSimpleField(data, parts);
|
2013-06-23 18:30:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
// Else: >= 5 arguments in "parts"
|
|
|
|
parseTextArea(data, parts, type);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2019-09-10 15:11:26 +02:00
|
|
|
void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &element)
|
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKCLIENT("list");
|
2019-09-10 15:11:26 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("hypertext", element, 4, 4, parts))
|
2019-09-10 15:11:26 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector<std::string> v_pos = split(parts[0], ',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1], ',');
|
|
|
|
std::string name = parts[2];
|
|
|
|
std::string text = parts[3];
|
|
|
|
|
|
|
|
MY_CHECKPOS("hypertext", 0);
|
|
|
|
MY_CHECKGEOM("hypertext", 1);
|
|
|
|
|
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
|
|
|
|
|
|
|
if (data->real_coordinates) {
|
2019-11-07 20:11:01 +01:00
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
2019-09-10 15:11:26 +02:00
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
2019-11-07 20:11:01 +01:00
|
|
|
pos = getElementBasePos(&v_pos);
|
2019-09-10 15:11:26 +02:00
|
|
|
pos -= padding;
|
|
|
|
|
|
|
|
geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
|
2020-02-11 19:53:09 +01:00
|
|
|
geom.Y = (stof(v_geom[1]) * (float)imgsize.Y) - (spacing.Y - imgsize.Y);
|
|
|
|
pos.Y += m_btn_height;
|
2019-09-10 15:11:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X + geom.X, pos.Y + geom.Y);
|
|
|
|
|
|
|
|
if(m_form_src)
|
|
|
|
text = m_form_src->resolveText(text);
|
|
|
|
|
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
2020-08-20 12:25:02 +02:00
|
|
|
translate_string(utf8_to_wide(unescape_string(text))),
|
2019-09-10 15:11:26 +02:00
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
|
|
|
|
2020-02-11 19:53:09 +01:00
|
|
|
spec.ftype = f_HyperText;
|
2020-09-16 17:10:17 +02:00
|
|
|
|
|
|
|
auto style = getDefaultStyleForElement("hypertext", spec.fname);
|
|
|
|
spec.sound = style.get(StyleSpec::Property::SOUND, "");
|
|
|
|
|
2020-04-13 10:50:07 +02:00
|
|
|
GUIHyperText *e = new GUIHyperText(spec.flabel.c_str(), Environment,
|
|
|
|
data->current_parent, spec.fid, rect, m_client, m_tsrc);
|
2020-03-10 20:32:38 +01:00
|
|
|
e->drop();
|
2019-09-10 15:11:26 +02:00
|
|
|
|
|
|
|
m_fields.push_back(spec);
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("label", element, 2, 2, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("label",0);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if(!data->explicit_size)
|
|
|
|
warningstream<<"invalid use of label without a size[] element"<<std::endl;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("label", "");
|
|
|
|
gui::IGUIFont *font = style.getFont();
|
|
|
|
if (!font)
|
|
|
|
font = m_font;
|
2020-07-12 09:48:50 +02:00
|
|
|
|
2022-07-14 20:51:01 +02:00
|
|
|
EnrichedString str(unescape_string(utf8_to_wide(parts[1])));
|
|
|
|
size_t str_pos = 0;
|
|
|
|
|
|
|
|
for (size_t i = 0; str_pos < str.size(); ++i) {
|
|
|
|
// Split per line
|
|
|
|
size_t str_nl = str.getString().find(L'\n', str_pos);
|
|
|
|
if (str_nl == std::wstring::npos)
|
|
|
|
str_nl = str.getString().size();
|
|
|
|
EnrichedString line = str.substr(str_pos, str_nl - str_pos);
|
|
|
|
str_pos += line.size() + 1;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> rect;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
// Lines are spaced at the distance of 1/2 imgsize.
|
|
|
|
// This alows lines that line up with the new elements
|
|
|
|
// easily without sacrificing good line distance. If
|
|
|
|
// it was one whole imgsize, it would have too much
|
|
|
|
// spacing.
|
|
|
|
v2s32 pos = getRealCoordinateBasePos(v_pos);
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
// Labels are positioned by their center, not their top.
|
|
|
|
pos.Y += (((float) imgsize.Y) / -2) + (((float) imgsize.Y) * i / 2);
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
rect = core::rect<s32>(
|
|
|
|
pos.X, pos.Y,
|
2022-07-14 20:51:01 +02:00
|
|
|
pos.X + font->getDimension(line.c_str()).Width,
|
2021-12-29 23:58:26 +01:00
|
|
|
pos.Y + imgsize.Y);
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
} else {
|
|
|
|
// Lines are spaced at the nominal distance of
|
|
|
|
// 2/5 inventory slot, even if the font doesn't
|
|
|
|
// quite match that. This provides consistent
|
|
|
|
// form layout, at the expense of sometimes
|
|
|
|
// having sub-optimal spacing for the font.
|
|
|
|
// We multiply by 2 and then divide by 5, rather
|
|
|
|
// than multiply by 0.4, to get exact results
|
|
|
|
// in the integer cases: 0.4 is not exactly
|
|
|
|
// representable in binary floating point.
|
|
|
|
|
|
|
|
v2s32 pos = getElementBasePos(nullptr);
|
|
|
|
pos.X += stof(v_pos[0]) * spacing.X;
|
|
|
|
pos.Y += (stof(v_pos[1]) + 7.0f / 30.0f) * spacing.Y;
|
|
|
|
|
|
|
|
pos.Y += ((float) i) * spacing.Y * 2.0 / 5.0;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
rect = core::rect<s32>(
|
|
|
|
pos.X, pos.Y - m_btn_height,
|
2022-07-14 20:51:01 +02:00
|
|
|
pos.X + font->getDimension(line.c_str()).Width,
|
2021-12-29 23:58:26 +01:00
|
|
|
pos.Y + m_btn_height);
|
|
|
|
}
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
"",
|
2022-07-14 20:51:01 +02:00
|
|
|
L"",
|
2021-12-29 23:58:26 +01:00
|
|
|
L"",
|
|
|
|
258 + m_fields.size(),
|
|
|
|
4
|
|
|
|
);
|
|
|
|
gui::IGUIStaticText *e = gui::StaticText::add(Environment,
|
2022-07-14 20:51:01 +02:00
|
|
|
line, rect, false, false, data->current_parent,
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.fid);
|
|
|
|
e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER);
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
|
|
|
e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
|
|
|
|
e->setOverrideFont(font);
|
2020-03-31 19:34:42 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
m_fields.push_back(spec);
|
2014-06-18 22:38:29 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
// labels should let events through
|
|
|
|
e->grab();
|
|
|
|
m_clickthrough_elements.push_back(e);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("vertlabel", element, 2, 2, parts))
|
|
|
|
return;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::wstring text = unescape_translate(
|
|
|
|
unescape_string(utf8_to_wide(parts[1])));
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("vertlabel",1);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("vertlabel", "", "label");
|
|
|
|
gui::IGUIFont *font = style.getFont();
|
|
|
|
if (!font)
|
|
|
|
font = m_font;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
core::rect<s32> rect;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
// Vertlabels are positioned by center, not left.
|
|
|
|
pos.X -= imgsize.X / 2;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
// We use text.length + 1 because without it, the rect
|
|
|
|
// isn't quite tall enough and cuts off the text.
|
|
|
|
rect = core::rect<s32>(pos.X, pos.Y,
|
|
|
|
pos.X + imgsize.X,
|
|
|
|
pos.Y + font_line_height(font) *
|
|
|
|
(text.length() + 1));
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
// As above, the length must be one longer. The width of
|
|
|
|
// the rect (15 pixels) seems rather arbitrary, but
|
|
|
|
// changing it might break something.
|
|
|
|
rect = core::rect<s32>(
|
|
|
|
pos.X, pos.Y+((imgsize.Y/2) - m_btn_height),
|
|
|
|
pos.X+15, pos.Y +
|
|
|
|
font_line_height(font) *
|
|
|
|
(text.length() + 1) +
|
|
|
|
((imgsize.Y/2) - m_btn_height));
|
|
|
|
}
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if(!data->explicit_size)
|
|
|
|
warningstream<<"invalid use of label without a size[] element"<<std::endl;
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::wstring label;
|
2020-03-31 19:34:42 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
for (wchar_t i : text) {
|
|
|
|
label += i;
|
|
|
|
label += L"\n";
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
2021-12-29 23:58:26 +01:00
|
|
|
|
|
|
|
FieldSpec spec(
|
|
|
|
"",
|
|
|
|
label,
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
|
|
|
gui::IGUIStaticText *e = gui::StaticText::add(Environment, spec.flabel.c_str(),
|
|
|
|
rect, false, false, data->current_parent, spec.fid);
|
|
|
|
e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
|
|
|
|
|
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
|
|
|
e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
|
|
|
|
e->setOverrideFont(font);
|
|
|
|
|
|
|
|
m_fields.push_back(spec);
|
|
|
|
|
|
|
|
// vertlabels should let events through
|
|
|
|
e->grab();
|
|
|
|
m_clickthrough_elements.push_back(e);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &element,
|
|
|
|
const std::string &type)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("image_button", element, 5, 8, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts.size() == 6) {
|
|
|
|
// Invalid argument count.
|
|
|
|
errorstream << "Invalid image_button element(" << parts.size() << "): '" << element << "'" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1],',');
|
|
|
|
std::string image_name = parts[2];
|
|
|
|
std::string name = parts[3];
|
|
|
|
std::string label = parts[4];
|
2014-06-14 11:22:09 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("image_button",0);
|
|
|
|
MY_CHECKGEOM("image_button",1);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::string pressed_image_name;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts.size() >= 8) {
|
|
|
|
pressed_image_name = parts[7];
|
|
|
|
}
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
|
|
|
|
geom.Y = (stof(v_geom[1]) * spacing.Y) - (spacing.Y - imgsize.Y);
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X,
|
|
|
|
pos.Y+geom.Y);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (!data->explicit_size)
|
|
|
|
warningstream<<"invalid use of image_button without a size[] element"<<std::endl;
|
2013-07-17 21:18:24 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
image_name = unescape_string(image_name);
|
|
|
|
pressed_image_name = unescape_string(pressed_image_name);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::wstring wlabel = utf8_to_wide(unescape_string(label));
|
2013-08-19 11:26:51 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
wlabel,
|
|
|
|
utf8_to_wide(image_name),
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
|
|
|
spec.ftype = f_Button;
|
|
|
|
if (type == "image_button_exit")
|
|
|
|
spec.is_exit = true;
|
2014-07-06 16:17:46 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
GUIButtonImage *e = GUIButtonImage::addButton(Environment, rect, m_tsrc,
|
|
|
|
data->current_parent, spec.fid, spec.flabel.c_str());
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (spec.fname == m_focused_element) {
|
|
|
|
Environment->setFocus(e);
|
|
|
|
}
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getStyleForElement("image_button", spec.fname);
|
2020-04-11 22:39:30 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.sound = style[StyleSpec::STATE_DEFAULT].get(StyleSpec::Property::SOUND, "");
|
2019-12-09 21:06:51 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
// Override style properties with values specified directly in the element
|
|
|
|
if (!image_name.empty())
|
|
|
|
style[StyleSpec::STATE_DEFAULT].set(StyleSpec::FGIMG, image_name);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (!pressed_image_name.empty())
|
|
|
|
style[StyleSpec::STATE_PRESSED].set(StyleSpec::FGIMG, pressed_image_name);
|
2020-04-11 22:39:30 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts.size() >= 7) {
|
|
|
|
style[StyleSpec::STATE_DEFAULT].set(StyleSpec::NOCLIP, parts[5]);
|
|
|
|
style[StyleSpec::STATE_DEFAULT].set(StyleSpec::BORDER, parts[6]);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setStyles(style);
|
|
|
|
e->setScaleImage(true);
|
|
|
|
|
|
|
|
m_fields.push_back(spec);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("tabheader", element, 4, 7, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
// Length 7: Additional "height" parameter after "pos". Only valid with real_coordinates.
|
|
|
|
// Note: New arguments for the "height" syntax cannot be added without breaking older clients.
|
|
|
|
if (parts.size() == 5 || (parts.size() == 7 && !data->real_coordinates)) {
|
|
|
|
errorstream << "Invalid tabheader element(" << parts.size() << "): '"
|
|
|
|
<< element << "'" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
// If we're using real coordinates, add an extra field for height.
|
|
|
|
// Width is not here because tabs are the width of the text, and
|
|
|
|
// there's no reason to change that.
|
|
|
|
unsigned int i = 0;
|
|
|
|
std::vector<std::string> v_geom = {"1", "1"}; // Dummy width and height
|
|
|
|
bool auto_width = true;
|
|
|
|
if (parts.size() == 7) {
|
|
|
|
i++;
|
|
|
|
|
|
|
|
v_geom = split(parts[1], ',');
|
|
|
|
if (v_geom.size() == 1)
|
|
|
|
v_geom.insert(v_geom.begin(), "1"); // Dummy value
|
|
|
|
else
|
|
|
|
auto_width = false;
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::string name = parts[i+1];
|
|
|
|
std::vector<std::string> buttons = split(parts[i+2], ',');
|
|
|
|
std::string str_index = parts[i+3];
|
|
|
|
bool show_background = true;
|
|
|
|
bool show_border = true;
|
|
|
|
int tab_index = stoi(str_index) - 1;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("tabheader", 0);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts.size() == 6 + i) {
|
|
|
|
if (parts[4+i] == "true")
|
|
|
|
show_background = false;
|
|
|
|
if (parts[5+i] == "false")
|
|
|
|
show_border = false;
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.ftype = f_TabHeader;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
// Set default height
|
|
|
|
if (parts.size() <= 6)
|
2019-06-27 14:40:49 +02:00
|
|
|
geom.Y = m_btn_height * 2;
|
2021-12-29 23:58:26 +01:00
|
|
|
pos.Y -= geom.Y; // TabHeader base pos is the bottom, not the top.
|
|
|
|
if (auto_width)
|
|
|
|
geom.X = DesiredRect.getWidth(); // Set automatic width
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKGEOM("tabheader", 1);
|
|
|
|
} else {
|
|
|
|
v2f32 pos_f = pos_offset * spacing;
|
|
|
|
pos_f.X += stof(v_pos[0]) * spacing.X;
|
|
|
|
pos_f.Y += stof(v_pos[1]) * spacing.Y - m_btn_height * 2;
|
|
|
|
pos = v2s32(pos_f.X, pos_f.Y);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
geom.Y = m_btn_height * 2;
|
|
|
|
geom.X = DesiredRect.getWidth();
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X,
|
|
|
|
pos.Y+geom.Y);
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
gui::IGUITabControl *e = Environment->addTabControl(rect,
|
|
|
|
data->current_parent, show_background, show_border, spec.fid);
|
|
|
|
e->setAlignment(irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_UPPERLEFT,
|
|
|
|
irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_LOWERRIGHT);
|
|
|
|
e->setTabHeight(geom.Y);
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("tabheader", name);
|
2019-03-15 20:03:12 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec.sound = style.get(StyleSpec::Property::SOUND, "");
|
2019-03-15 20:03:12 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, true));
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
for (const std::string &button : buttons) {
|
|
|
|
auto tab = e->addTab(unescape_translate(unescape_string(
|
|
|
|
utf8_to_wide(button))).c_str(), -1);
|
|
|
|
if (style.isNotDefault(StyleSpec::BGCOLOR))
|
|
|
|
tab->setBackgroundColor(style.getColor(StyleSpec::BGCOLOR));
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
tab->setTextColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
2021-12-29 23:58:26 +01:00
|
|
|
|
|
|
|
if ((tab_index >= 0) &&
|
|
|
|
(buttons.size() < INT_MAX) &&
|
|
|
|
(tab_index < (int) buttons.size()))
|
|
|
|
e->setActiveTab(tab_index);
|
|
|
|
|
|
|
|
m_fields.push_back(spec);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKCLIENT("item_image_button");
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("item_image_button", element, 5, 5, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0],',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1],',');
|
|
|
|
std::string item_name = parts[2];
|
|
|
|
std::string name = parts[3];
|
|
|
|
std::string label = parts[4];
|
2016-05-05 19:08:45 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
label = unescape_string(label);
|
|
|
|
item_name = unescape_string(item_name);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("item_image_button",0);
|
|
|
|
MY_CHECKGEOM("item_image_button",1);
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
|
|
|
|
geom.Y = (stof(v_geom[1]) * spacing.Y) - (spacing.Y - imgsize.Y);
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if(!data->explicit_size)
|
|
|
|
warningstream<<"invalid use of item_image_button without a size[] element"<<std::endl;
|
2014-06-24 12:28:24 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
IItemDefManager *idef = m_client->idef();
|
|
|
|
ItemStack item;
|
|
|
|
item.deSerialize(item_name, idef);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
m_tooltips[name] =
|
|
|
|
TooltipSpec(utf8_to_wide(item.getDefinition(idef).description),
|
|
|
|
m_default_tooltip_bgcolor,
|
|
|
|
m_default_tooltip_color);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
// the spec for the button
|
|
|
|
FieldSpec spec_btn(
|
|
|
|
name,
|
|
|
|
utf8_to_wide(label),
|
|
|
|
utf8_to_wide(item_name),
|
|
|
|
258 + m_fields.size(),
|
|
|
|
2
|
|
|
|
);
|
2013-08-19 11:26:51 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
GUIButtonItemImage *e_btn = GUIButtonItemImage::addButton(Environment,
|
|
|
|
rect, m_tsrc, data->current_parent, spec_btn.fid, spec_btn.flabel.c_str(),
|
|
|
|
item_name, m_client);
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getStyleForElement("item_image_button", spec_btn.fname, "image_button");
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
spec_btn.sound = style[StyleSpec::STATE_DEFAULT].get(StyleSpec::Property::SOUND, "");
|
2019-03-16 22:38:36 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
e_btn->setStyles(style);
|
2013-08-19 11:26:51 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (spec_btn.fname == m_focused_element) {
|
|
|
|
Environment->setFocus(e_btn);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
2021-12-29 23:58:26 +01:00
|
|
|
|
|
|
|
spec_btn.ftype = f_Button;
|
|
|
|
rect += data->basepos-padding;
|
|
|
|
spec_btn.rect = rect;
|
|
|
|
m_fields.push_back(spec_btn);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseBox(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("box", element, 3, 3, parts))
|
|
|
|
return;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> v_pos = split(parts[0], ',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1], ',');
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKPOS("box", 0);
|
|
|
|
MY_CHECKGEOM("box", 1);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
geom.X = stof(v_geom[0]) * spacing.X;
|
|
|
|
geom.Y = stof(v_geom[1]) * spacing.Y;
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
FieldSpec spec(
|
|
|
|
"",
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size(),
|
|
|
|
-2
|
|
|
|
);
|
|
|
|
spec.ftype = f_Box;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
auto style = getDefaultStyleForElement("box", spec.fname);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
video::SColor tmp_color;
|
|
|
|
std::array<video::SColor, 4> colors;
|
|
|
|
std::array<video::SColor, 4> bordercolors = {0x0, 0x0, 0x0, 0x0};
|
|
|
|
std::array<s32, 4> borderwidths = {0, 0, 0, 0};
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parseColorString(parts[2], tmp_color, true, 0x8C)) {
|
|
|
|
colors = {tmp_color, tmp_color, tmp_color, tmp_color};
|
|
|
|
} else {
|
|
|
|
colors = style.getColorArray(StyleSpec::COLORS, {0x0, 0x0, 0x0, 0x0});
|
|
|
|
bordercolors = style.getColorArray(StyleSpec::BORDERCOLORS,
|
|
|
|
{0x0, 0x0, 0x0, 0x0});
|
|
|
|
borderwidths = style.getIntArray(StyleSpec::BORDERWIDTHS, {0, 0, 0, 0});
|
|
|
|
}
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
core::rect<s32> rect(pos, pos + geom);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
GUIBox *e = new GUIBox(Environment, data->current_parent, spec.fid, rect,
|
|
|
|
colors, bordercolors, borderwidths);
|
|
|
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3));
|
|
|
|
e->drop();
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
m_fields.push_back(spec);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 14:50:45 +02:00
|
|
|
void GUIFormSpecMenu::parseBackgroundColor(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
2022-01-09 18:33:37 +01:00
|
|
|
if (!precheckElement("bgcolor", element, 1, 3, parts))
|
2021-12-29 23:58:26 +01:00
|
|
|
return;
|
|
|
|
|
2019-12-08 18:59:30 +01:00
|
|
|
const u32 parameter_count = parts.size();
|
2013-11-02 04:26:44 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parameter_count > 2 && m_formspec_version < 3) {
|
2019-12-08 18:59:30 +01:00
|
|
|
errorstream << "Invalid bgcolor element(" << parameter_count << "): '"
|
|
|
|
<< element << "'" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// bgcolor
|
|
|
|
if (parameter_count >= 1 && parts[0] != "")
|
2019-10-06 14:50:45 +02:00
|
|
|
parseColorString(parts[0], m_bgcolor, false);
|
|
|
|
|
2019-12-08 18:59:30 +01:00
|
|
|
// fullscreen
|
|
|
|
if (parameter_count >= 2) {
|
|
|
|
if (parts[1] == "both") {
|
|
|
|
m_bgnonfullscreen = true;
|
|
|
|
m_bgfullscreen = true;
|
|
|
|
} else if (parts[1] == "neither") {
|
|
|
|
m_bgnonfullscreen = false;
|
|
|
|
m_bgfullscreen = false;
|
|
|
|
} else if (parts[1] != "" || m_formspec_version < 3) {
|
|
|
|
m_bgfullscreen = is_yes(parts[1]);
|
|
|
|
m_bgnonfullscreen = !m_bgfullscreen;
|
2013-11-02 04:26:44 +01:00
|
|
|
}
|
|
|
|
}
|
2017-08-29 19:25:16 +02:00
|
|
|
|
2019-12-08 18:59:30 +01:00
|
|
|
// fbgcolor
|
|
|
|
if (parameter_count >= 3 && parts[2] != "")
|
|
|
|
parseColorString(parts[2], m_fullscreen_bgcolor, false);
|
2013-11-02 04:26:44 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseListColors(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
// Legacy Note: If clients older than 5.5.0-dev are supplied with additional arguments,
|
|
|
|
// the tooltip colors will be ignored.
|
|
|
|
if (!precheckElement("listcolors", element, 2, 5, parts))
|
|
|
|
return;
|
2013-11-02 04:26:44 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts.size() == 4) {
|
|
|
|
// Invalid argument combination
|
|
|
|
errorstream << "Invalid listcolors element(" << parts.size() << "): '"
|
|
|
|
<< element << "'" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2014-05-30 03:07:48 +02:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
parseColorString(parts[0], data->inventorylist_options.slotbg_n, false);
|
|
|
|
parseColorString(parts[1], data->inventorylist_options.slotbg_h, false);
|
2013-11-02 04:26:44 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parts.size() >= 3) {
|
|
|
|
if (parseColorString(parts[2], data->inventorylist_options.slotbordercolor,
|
|
|
|
false)) {
|
|
|
|
data->inventorylist_options.slotborder = true;
|
2013-11-02 04:26:44 +01:00
|
|
|
}
|
2021-12-29 23:58:26 +01:00
|
|
|
}
|
|
|
|
if (parts.size() >= 5) {
|
|
|
|
video::SColor tmp_color;
|
2020-02-01 13:55:13 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (parseColorString(parts[3], tmp_color, false))
|
|
|
|
m_default_tooltip_bgcolor = tmp_color;
|
|
|
|
if (parseColorString(parts[4], tmp_color, false))
|
|
|
|
m_default_tooltip_color = tmp_color;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update all already parsed inventorylists
|
|
|
|
for (GUIInventoryList *e : m_inventorylists) {
|
|
|
|
e->setSlotBGColors(data->inventorylist_options.slotbg_n,
|
|
|
|
data->inventorylist_options.slotbg_h);
|
|
|
|
e->setSlotBorders(data->inventorylist_options.slotborder,
|
|
|
|
data->inventorylist_options.slotbordercolor);
|
2013-11-02 04:26:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void GUIFormSpecMenu::parseTooltip(parserData* data, const std::string &element)
|
2014-06-24 12:28:24 +02:00
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("tooltip", element, 2, 5, parts))
|
2014-06-24 12:28:24 +02:00
|
|
|
return;
|
2017-08-20 19:37:29 +02:00
|
|
|
|
2018-06-20 22:55:39 +02:00
|
|
|
// Get mode and check size
|
|
|
|
bool rect_mode = parts[0].find(',') != std::string::npos;
|
|
|
|
size_t base_size = rect_mode ? 3 : 2;
|
|
|
|
if (parts.size() != base_size && parts.size() != base_size + 2) {
|
|
|
|
errorstream << "Invalid tooltip element(" << parts.size() << "): '"
|
|
|
|
<< element << "'" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read colors
|
|
|
|
video::SColor bgcolor = m_default_tooltip_bgcolor;
|
|
|
|
video::SColor color = m_default_tooltip_color;
|
|
|
|
if (parts.size() == base_size + 2 &&
|
|
|
|
(!parseColorString(parts[base_size], bgcolor, false) ||
|
|
|
|
!parseColorString(parts[base_size + 1], color, false))) {
|
|
|
|
errorstream << "Invalid color in tooltip element(" << parts.size()
|
|
|
|
<< "): '" << element << "'" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make tooltip spec
|
|
|
|
std::string text = unescape_string(parts[rect_mode ? 2 : 1]);
|
|
|
|
TooltipSpec spec(utf8_to_wide(text), bgcolor, color);
|
|
|
|
|
|
|
|
// Add tooltip
|
|
|
|
if (rect_mode) {
|
|
|
|
std::vector<std::string> v_pos = split(parts[0], ',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1], ',');
|
|
|
|
|
2019-06-27 14:40:49 +02:00
|
|
|
MY_CHECKPOS("tooltip", 0);
|
2018-06-20 22:55:39 +02:00
|
|
|
MY_CHECKGEOM("tooltip", 1);
|
|
|
|
|
2019-06-27 14:40:49 +02:00
|
|
|
v2s32 pos;
|
2018-06-20 22:55:39 +02:00
|
|
|
v2s32 geom;
|
2019-06-27 14:40:49 +02:00
|
|
|
|
|
|
|
if (data->real_coordinates) {
|
2019-11-07 20:11:01 +01:00
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
2019-06-27 14:40:49 +02:00
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
2019-11-07 20:11:01 +01:00
|
|
|
pos = getElementBasePos(&v_pos);
|
2019-06-27 14:40:49 +02:00
|
|
|
geom.X = stof(v_geom[0]) * spacing.X;
|
|
|
|
geom.Y = stof(v_geom[1]) * spacing.Y;
|
|
|
|
}
|
2018-06-20 22:55:39 +02:00
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
FieldSpec fieldspec(
|
|
|
|
"",
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
|
|
|
|
|
|
|
core::rect<s32> rect(pos, pos + geom);
|
|
|
|
|
|
|
|
gui::IGUIElement *e = new gui::IGUIElement(EGUIET_ELEMENT, Environment,
|
2020-04-13 10:50:07 +02:00
|
|
|
data->current_parent, fieldspec.fid, rect);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2020-01-04 15:45:22 +01:00
|
|
|
// the element the rect tooltip is bound to should not block mouse-clicks
|
|
|
|
e->setVisible(false);
|
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
m_fields.push_back(fieldspec);
|
|
|
|
m_tooltip_rects.emplace_back(e, spec);
|
|
|
|
|
2018-06-20 22:55:39 +02:00
|
|
|
} else {
|
|
|
|
m_tooltips[parts[0]] = spec;
|
2014-06-24 12:28:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
bool GUIFormSpecMenu::parseVersionDirect(const std::string &data)
|
2014-06-25 19:04:47 +02:00
|
|
|
{
|
|
|
|
//some prechecks
|
2017-08-20 19:37:29 +02:00
|
|
|
if (data.empty())
|
2014-06-25 19:04:47 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<std::string> parts = split(data,'[');
|
|
|
|
|
|
|
|
if (parts.size() < 2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-09 22:05:07 +01:00
|
|
|
if (trim(parts[0]) != "formspec_version") {
|
2014-06-25 19:04:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_number(parts[1])) {
|
|
|
|
m_formspec_version = mystoi(parts[1]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
bool GUIFormSpecMenu::parseSizeDirect(parserData* data, const std::string &element)
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
{
|
2017-08-20 19:37:29 +02:00
|
|
|
if (element.empty())
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<std::string> parts = split(element,'[');
|
|
|
|
|
|
|
|
if (parts.size() < 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::string type = trim(parts[0]);
|
|
|
|
std::string description = trim(parts[1]);
|
|
|
|
|
|
|
|
if (type != "size" && type != "invsize")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (type == "invsize")
|
2020-02-12 19:17:04 +01:00
|
|
|
warningstream << "Deprecated formspec element \"invsize\" is used" << std::endl;
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
|
|
|
|
parseSize(data, description);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-04 10:46:55 +01:00
|
|
|
bool GUIFormSpecMenu::parsePositionDirect(parserData *data, const std::string &element)
|
|
|
|
{
|
|
|
|
if (element.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<std::string> parts = split(element, '[');
|
|
|
|
|
|
|
|
if (parts.size() != 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::string type = trim(parts[0]);
|
|
|
|
std::string description = trim(parts[1]);
|
|
|
|
|
|
|
|
if (type != "position")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
parsePosition(data, description);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIFormSpecMenu::parsePosition(parserData *data, const std::string &element)
|
|
|
|
{
|
2021-12-30 21:54:47 +01:00
|
|
|
std::vector<std::string> parts = split(element, ';');
|
2017-03-04 10:46:55 +01:00
|
|
|
|
2021-12-30 21:54:47 +01:00
|
|
|
if (parts.size() == 1 ||
|
|
|
|
(parts.size() > 1 && m_formspec_version > FORMSPEC_API_VERSION)) {
|
|
|
|
std::vector<std::string> v_geom = split(parts[0], ',');
|
|
|
|
|
|
|
|
MY_CHECKGEOM("position", 0);
|
|
|
|
|
|
|
|
data->offset.X = stof(v_geom[0]);
|
|
|
|
data->offset.Y = stof(v_geom[1]);
|
2017-03-04 10:46:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errorstream << "Invalid position element (" << parts.size() << "): '" << element << "'" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GUIFormSpecMenu::parseAnchorDirect(parserData *data, const std::string &element)
|
|
|
|
{
|
|
|
|
if (element.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<std::string> parts = split(element, '[');
|
|
|
|
|
|
|
|
if (parts.size() != 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::string type = trim(parts[0]);
|
|
|
|
std::string description = trim(parts[1]);
|
|
|
|
|
|
|
|
if (type != "anchor")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
parseAnchor(data, description);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIFormSpecMenu::parseAnchor(parserData *data, const std::string &element)
|
|
|
|
{
|
2021-12-30 21:54:47 +01:00
|
|
|
std::vector<std::string> parts = split(element, ';');
|
2017-03-04 10:46:55 +01:00
|
|
|
|
2021-12-30 21:54:47 +01:00
|
|
|
if (parts.size() == 1 ||
|
|
|
|
(parts.size() > 1 && m_formspec_version > FORMSPEC_API_VERSION)) {
|
|
|
|
std::vector<std::string> v_geom = split(parts[0], ',');
|
|
|
|
|
|
|
|
MY_CHECKGEOM("anchor", 0);
|
|
|
|
|
|
|
|
data->anchor.X = stof(v_geom[0]);
|
|
|
|
data->anchor.Y = stof(v_geom[1]);
|
2017-03-04 10:46:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-21 23:40:48 +02:00
|
|
|
errorstream << "Invalid anchor element (" << parts.size() << "): '" << element
|
|
|
|
<< "'" << std::endl;
|
2017-03-04 10:46:55 +01:00
|
|
|
}
|
|
|
|
|
2021-12-30 21:54:47 +01:00
|
|
|
bool GUIFormSpecMenu::parsePaddingDirect(parserData *data, const std::string &element)
|
|
|
|
{
|
|
|
|
if (element.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<std::string> parts = split(element, '[');
|
|
|
|
|
|
|
|
if (parts.size() != 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::string type = trim(parts[0]);
|
|
|
|
std::string description = trim(parts[1]);
|
|
|
|
|
|
|
|
if (type != "padding")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
parsePadding(data, description);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIFormSpecMenu::parsePadding(parserData *data, const std::string &element)
|
|
|
|
{
|
|
|
|
std::vector<std::string> parts = split(element, ';');
|
|
|
|
|
|
|
|
if (parts.size() == 1 ||
|
|
|
|
(parts.size() > 1 && m_formspec_version > FORMSPEC_API_VERSION)) {
|
|
|
|
std::vector<std::string> v_geom = split(parts[0], ',');
|
|
|
|
|
|
|
|
MY_CHECKGEOM("padding", 0);
|
|
|
|
|
|
|
|
data->padding.X = stof(v_geom[0]);
|
|
|
|
data->padding.Y = stof(v_geom[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
errorstream << "Invalid padding element (" << parts.size() << "): '" << element
|
|
|
|
<< "'" << std::endl;
|
|
|
|
}
|
|
|
|
|
2019-03-15 20:03:12 +01:00
|
|
|
bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, bool style_type)
|
|
|
|
{
|
|
|
|
std::vector<std::string> parts = split(element, ';');
|
|
|
|
|
2019-03-16 22:38:36 +01:00
|
|
|
if (parts.size() < 2) {
|
2019-03-15 20:03:12 +01:00
|
|
|
errorstream << "Invalid style element (" << parts.size() << "): '" << element
|
|
|
|
<< "'" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
StyleSpec spec;
|
|
|
|
|
2020-04-11 22:39:30 +02:00
|
|
|
// Parse properties
|
2019-03-16 22:38:36 +01:00
|
|
|
for (size_t i = 1; i < parts.size(); i++) {
|
|
|
|
size_t equal_pos = parts[i].find('=');
|
|
|
|
if (equal_pos == std::string::npos) {
|
|
|
|
errorstream << "Invalid style element (Property missing value): '" << element
|
|
|
|
<< "'" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string propname = trim(parts[i].substr(0, equal_pos));
|
|
|
|
std::string value = trim(unescape_string(parts[i].substr(equal_pos + 1)));
|
|
|
|
|
|
|
|
std::transform(propname.begin(), propname.end(), propname.begin(), ::tolower);
|
|
|
|
|
|
|
|
StyleSpec::Property prop = StyleSpec::GetPropertyByName(propname);
|
|
|
|
if (prop == StyleSpec::NONE) {
|
|
|
|
if (property_warned.find(propname) != property_warned.end()) {
|
|
|
|
warningstream << "Invalid style element (Unknown property " << propname << "): '"
|
|
|
|
<< element
|
|
|
|
<< "'" << std::endl;
|
|
|
|
property_warned.insert(propname);
|
|
|
|
}
|
2020-07-03 18:33:23 +02:00
|
|
|
continue;
|
2019-03-16 22:38:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
spec.set(prop, value);
|
2019-03-15 20:03:12 +01:00
|
|
|
}
|
|
|
|
|
2020-03-01 15:39:57 +01:00
|
|
|
std::vector<std::string> selectors = split(parts[0], ',');
|
|
|
|
for (size_t sel = 0; sel < selectors.size(); sel++) {
|
|
|
|
std::string selector = trim(selectors[sel]);
|
|
|
|
|
2020-04-11 22:39:30 +02:00
|
|
|
// Copy the style properties to a new StyleSpec
|
|
|
|
// This allows a separate state mask per-selector
|
|
|
|
StyleSpec selector_spec = spec;
|
|
|
|
|
|
|
|
// Parse state information, if it exists
|
|
|
|
bool state_valid = true;
|
|
|
|
size_t state_pos = selector.find(':');
|
|
|
|
if (state_pos != std::string::npos) {
|
|
|
|
std::string state_str = selector.substr(state_pos + 1);
|
|
|
|
selector = selector.substr(0, state_pos);
|
|
|
|
|
|
|
|
if (state_str.empty()) {
|
|
|
|
errorstream << "Invalid style element (Invalid state): '" << element
|
|
|
|
<< "'" << std::endl;
|
|
|
|
state_valid = false;
|
|
|
|
} else {
|
|
|
|
std::vector<std::string> states = split(state_str, '+');
|
|
|
|
for (std::string &state : states) {
|
|
|
|
StyleSpec::State converted = StyleSpec::getStateByName(state);
|
|
|
|
if (converted == StyleSpec::STATE_INVALID) {
|
|
|
|
infostream << "Unknown style state " << state <<
|
|
|
|
" in element '" << element << "'" << std::endl;
|
|
|
|
state_valid = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
selector_spec.addState(converted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 18:33:23 +02:00
|
|
|
if (!state_valid) {
|
2020-04-11 22:39:30 +02:00
|
|
|
// Skip this selector
|
2020-03-01 15:39:57 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style_type) {
|
2020-04-11 22:39:30 +02:00
|
|
|
theme_by_type[selector].push_back(selector_spec);
|
2020-03-01 15:39:57 +01:00
|
|
|
} else {
|
2020-04-11 22:39:30 +02:00
|
|
|
theme_by_name[selector].push_back(selector_spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Backwards-compatibility for existing _hovered/_pressed properties
|
|
|
|
if (selector_spec.hasProperty(StyleSpec::BGCOLOR_HOVERED)
|
|
|
|
|| selector_spec.hasProperty(StyleSpec::BGIMG_HOVERED)
|
|
|
|
|| selector_spec.hasProperty(StyleSpec::FGIMG_HOVERED)) {
|
|
|
|
StyleSpec hover_spec;
|
|
|
|
hover_spec.addState(StyleSpec::STATE_HOVERED);
|
|
|
|
|
|
|
|
if (selector_spec.hasProperty(StyleSpec::BGCOLOR_HOVERED)) {
|
|
|
|
hover_spec.set(StyleSpec::BGCOLOR, selector_spec.get(StyleSpec::BGCOLOR_HOVERED, ""));
|
|
|
|
}
|
|
|
|
if (selector_spec.hasProperty(StyleSpec::BGIMG_HOVERED)) {
|
|
|
|
hover_spec.set(StyleSpec::BGIMG, selector_spec.get(StyleSpec::BGIMG_HOVERED, ""));
|
|
|
|
}
|
|
|
|
if (selector_spec.hasProperty(StyleSpec::FGIMG_HOVERED)) {
|
|
|
|
hover_spec.set(StyleSpec::FGIMG, selector_spec.get(StyleSpec::FGIMG_HOVERED, ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style_type) {
|
|
|
|
theme_by_type[selector].push_back(hover_spec);
|
|
|
|
} else {
|
|
|
|
theme_by_name[selector].push_back(hover_spec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (selector_spec.hasProperty(StyleSpec::BGCOLOR_PRESSED)
|
|
|
|
|| selector_spec.hasProperty(StyleSpec::BGIMG_PRESSED)
|
|
|
|
|| selector_spec.hasProperty(StyleSpec::FGIMG_PRESSED)) {
|
|
|
|
StyleSpec press_spec;
|
|
|
|
press_spec.addState(StyleSpec::STATE_PRESSED);
|
|
|
|
|
|
|
|
if (selector_spec.hasProperty(StyleSpec::BGCOLOR_PRESSED)) {
|
|
|
|
press_spec.set(StyleSpec::BGCOLOR, selector_spec.get(StyleSpec::BGCOLOR_PRESSED, ""));
|
|
|
|
}
|
|
|
|
if (selector_spec.hasProperty(StyleSpec::BGIMG_PRESSED)) {
|
|
|
|
press_spec.set(StyleSpec::BGIMG, selector_spec.get(StyleSpec::BGIMG_PRESSED, ""));
|
|
|
|
}
|
|
|
|
if (selector_spec.hasProperty(StyleSpec::FGIMG_PRESSED)) {
|
|
|
|
press_spec.set(StyleSpec::FGIMG, selector_spec.get(StyleSpec::FGIMG_PRESSED, ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style_type) {
|
|
|
|
theme_by_type[selector].push_back(press_spec);
|
|
|
|
} else {
|
|
|
|
theme_by_name[selector].push_back(press_spec);
|
|
|
|
}
|
2020-03-01 15:39:57 +01:00
|
|
|
}
|
2019-03-15 20:03:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-12 09:47:05 +02:00
|
|
|
void GUIFormSpecMenu::parseSetFocus(const std::string &element)
|
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
2022-01-09 18:33:37 +01:00
|
|
|
if (!precheckElement("set_focus", element, 1, 2, parts))
|
2020-07-12 09:47:05 +02:00
|
|
|
return;
|
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
if (m_is_form_regenerated)
|
|
|
|
return; // Never focus on resizing
|
|
|
|
|
|
|
|
bool force_focus = parts.size() >= 2 && is_yes(parts[1]);
|
|
|
|
if (force_focus || m_text_dst->m_formname != m_last_formname)
|
|
|
|
setFocus(parts[0]);
|
2020-07-12 09:47:05 +02:00
|
|
|
}
|
|
|
|
|
2020-11-04 21:46:18 +01:00
|
|
|
void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element)
|
|
|
|
{
|
2021-12-29 23:58:26 +01:00
|
|
|
MY_CHECKCLIENT("model");
|
2020-11-04 21:46:18 +01:00
|
|
|
|
2021-12-29 23:58:26 +01:00
|
|
|
std::vector<std::string> parts;
|
|
|
|
if (!precheckElement("model", element, 5, 10, parts))
|
2020-11-04 21:46:18 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Avoid length checks by resizing
|
2021-03-21 23:23:30 +01:00
|
|
|
if (parts.size() < 10)
|
|
|
|
parts.resize(10);
|
2020-11-04 21:46:18 +01:00
|
|
|
|
|
|
|
std::vector<std::string> v_pos = split(parts[0], ',');
|
|
|
|
std::vector<std::string> v_geom = split(parts[1], ',');
|
|
|
|
std::string name = unescape_string(parts[2]);
|
|
|
|
std::string meshstr = unescape_string(parts[3]);
|
|
|
|
std::vector<std::string> textures = split(parts[4], ',');
|
|
|
|
std::vector<std::string> vec_rot = split(parts[5], ',');
|
|
|
|
bool inf_rotation = is_yes(parts[6]);
|
|
|
|
bool mousectrl = is_yes(parts[7]) || parts[7].empty(); // default true
|
2020-12-15 19:06:36 +01:00
|
|
|
std::vector<std::string> frame_loop = split(parts[8], ',');
|
2021-03-16 23:28:16 +01:00
|
|
|
std::string speed = unescape_string(parts[9]);
|
2020-11-04 21:46:18 +01:00
|
|
|
|
|
|
|
MY_CHECKPOS("model", 0);
|
|
|
|
MY_CHECKGEOM("model", 1);
|
|
|
|
|
|
|
|
v2s32 pos;
|
|
|
|
v2s32 geom;
|
|
|
|
|
|
|
|
if (data->real_coordinates) {
|
|
|
|
pos = getRealCoordinateBasePos(v_pos);
|
|
|
|
geom = getRealCoordinateGeometry(v_geom);
|
|
|
|
} else {
|
|
|
|
pos = getElementBasePos(&v_pos);
|
|
|
|
geom.X = stof(v_geom[0]) * (float)imgsize.X;
|
|
|
|
geom.Y = stof(v_geom[1]) * (float)imgsize.Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!data->explicit_size)
|
|
|
|
warningstream << "invalid use of model without a size[] element" << std::endl;
|
|
|
|
|
|
|
|
scene::IAnimatedMesh *mesh = m_client->getMesh(meshstr);
|
|
|
|
|
|
|
|
if (!mesh) {
|
|
|
|
errorstream << "Invalid model element: Unable to load mesh:"
|
|
|
|
<< std::endl << "\t" << meshstr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FieldSpec spec(
|
|
|
|
name,
|
|
|
|
L"",
|
|
|
|
L"",
|
|
|
|
258 + m_fields.size()
|
|
|
|
);
|
|
|
|
|
|
|
|
core::rect<s32> rect(pos, pos + geom);
|
|
|
|
|
2021-04-29 09:40:56 +02:00
|
|
|
GUIScene *e = new GUIScene(Environment, m_client->getSceneManager(),
|
2020-11-04 21:46:18 +01:00
|
|
|
data->current_parent, rect, spec.fid);
|
|
|
|
|
|
|
|
auto meshnode = e->setMesh(mesh);
|
|
|
|
|
|
|
|
for (u32 i = 0; i < textures.size() && i < meshnode->getMaterialCount(); ++i)
|
2021-01-01 17:03:34 +01:00
|
|
|
e->setTexture(i, m_tsrc->getTexture(unescape_string(textures[i])));
|
2020-11-04 21:46:18 +01:00
|
|
|
|
|
|
|
if (vec_rot.size() >= 2)
|
|
|
|
e->setRotation(v2f(stof(vec_rot[0]), stof(vec_rot[1])));
|
|
|
|
|
|
|
|
e->enableContinuousRotation(inf_rotation);
|
|
|
|
e->enableMouseControl(mousectrl);
|
|
|
|
|
2020-12-15 19:06:36 +01:00
|
|
|
s32 frame_loop_begin = 0;
|
|
|
|
s32 frame_loop_end = 0x7FFFFFFF;
|
|
|
|
|
|
|
|
if (frame_loop.size() == 2) {
|
|
|
|
frame_loop_begin = stoi(frame_loop[0]);
|
|
|
|
frame_loop_end = stoi(frame_loop[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
e->setFrameLoop(frame_loop_begin, frame_loop_end);
|
2021-03-16 23:28:16 +01:00
|
|
|
e->setAnimationSpeed(stof(speed));
|
2020-12-15 19:06:36 +01:00
|
|
|
|
2020-11-04 21:46:18 +01:00
|
|
|
auto style = getStyleForElement("model", spec.fname);
|
|
|
|
e->setStyles(style);
|
|
|
|
e->drop();
|
|
|
|
|
|
|
|
m_fields.push_back(spec);
|
|
|
|
}
|
|
|
|
|
2017-04-21 23:40:48 +02:00
|
|
|
void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element)
|
2014-03-04 19:57:39 +01:00
|
|
|
{
|
2013-06-23 18:30:21 +02:00
|
|
|
//some prechecks
|
2017-08-20 19:37:29 +02:00
|
|
|
if (element.empty())
|
2013-06-23 18:30:21 +02:00
|
|
|
return;
|
|
|
|
|
2019-09-10 21:18:42 +02:00
|
|
|
if (parseVersionDirect(element))
|
|
|
|
return;
|
|
|
|
|
2020-04-25 07:48:04 +02:00
|
|
|
size_t pos = element.find('[');
|
|
|
|
if (pos == std::string::npos)
|
2013-06-23 18:30:21 +02:00
|
|
|
return;
|
|
|
|
|
2020-04-25 07:48:04 +02:00
|
|
|
std::string type = trim(element.substr(0, pos));
|
|
|
|
std::string description = element.substr(pos+1);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2016-07-07 22:10:15 +02:00
|
|
|
if (type == "container") {
|
|
|
|
parseContainer(data, description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "container_end") {
|
|
|
|
parseContainerEnd(data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if (type == "list") {
|
2016-07-07 22:10:15 +02:00
|
|
|
parseList(data, description);
|
2013-06-23 18:30:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:48:54 +02:00
|
|
|
if (type == "listring") {
|
|
|
|
parseListRing(data, description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if (type == "checkbox") {
|
2016-07-07 22:10:15 +02:00
|
|
|
parseCheckbox(data, description);
|
2013-06-23 18:30:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "image") {
|
2016-07-07 22:10:15 +02:00
|
|
|
parseImage(data, description);
|
2013-06-23 18:30:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-15 16:33:18 +01:00
|
|
|
if (type == "animated_image") {
|
|
|
|
parseAnimatedImage(data, description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if (type == "item_image") {
|
2016-07-07 22:10:15 +02:00
|
|
|
parseItemImage(data, description);
|
2013-06-23 18:30:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-07 22:10:15 +02:00
|
|
|
if (type == "button" || type == "button_exit") {
|
|
|
|
parseButton(data, description, type);
|
2013-06-23 18:30:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-29 13:40:59 +02:00
|
|
|
if (type == "background" || type == "background9") {
|
|
|
|
parseBackground(data, description);
|
2013-06-23 18:30:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-23 12:24:11 +02:00
|
|
|
if (type == "tableoptions"){
|
|
|
|
parseTableOptions(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "tablecolumns"){
|
|
|
|
parseTableColumns(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "table"){
|
|
|
|
parseTable(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if (type == "textlist"){
|
|
|
|
parseTextList(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "dropdown"){
|
|
|
|
parseDropDown(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-03 01:30:33 +02:00
|
|
|
if (type == "field_close_on_enter") {
|
|
|
|
parseFieldCloseOnEnter(data, description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if (type == "pwdfield") {
|
|
|
|
parsePwdField(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((type == "field") || (type == "textarea")){
|
|
|
|
parseField(data,description,type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-10 15:11:26 +02:00
|
|
|
if (type == "hypertext") {
|
|
|
|
parseHyperText(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if (type == "label") {
|
|
|
|
parseLabel(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "vertlabel") {
|
|
|
|
parseVertLabel(data,description);
|
|
|
|
return;
|
|
|
|
}
|
2010-12-22 02:34:21 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if (type == "item_image_button") {
|
|
|
|
parseItemImageButton(data,description);
|
|
|
|
return;
|
2011-04-04 14:13:19 +02:00
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
|
|
|
if ((type == "image_button") || (type == "image_button_exit")) {
|
|
|
|
parseImageButton(data,description,type);
|
|
|
|
return;
|
2011-04-04 23:24:47 +02:00
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
|
|
|
if (type == "tabheader") {
|
|
|
|
parseTabHeader(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "box") {
|
|
|
|
parseBox(data,description);
|
|
|
|
return;
|
2012-01-13 12:35:55 +01:00
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2013-11-02 04:26:44 +01:00
|
|
|
if (type == "bgcolor") {
|
|
|
|
parseBackgroundColor(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "listcolors") {
|
|
|
|
parseListColors(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-24 12:28:24 +02:00
|
|
|
if (type == "tooltip") {
|
|
|
|
parseTooltip(data,description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-19 18:17:35 +02:00
|
|
|
if (type == "scrollbar") {
|
|
|
|
parseScrollBar(data, description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-27 14:40:49 +02:00
|
|
|
if (type == "real_coordinates") {
|
|
|
|
data->real_coordinates = is_yes(description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-15 20:03:12 +01:00
|
|
|
if (type == "style") {
|
|
|
|
parseStyle(data, description, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "style_type") {
|
|
|
|
parseStyle(data, description, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-06 21:51:10 +01:00
|
|
|
if (type == "scrollbaroptions") {
|
|
|
|
parseScrollBarOptions(data, description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:50:07 +02:00
|
|
|
if (type == "scroll_container") {
|
|
|
|
parseScrollContainer(data, description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == "scroll_container_end") {
|
|
|
|
parseScrollContainerEnd(data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-12 09:47:05 +02:00
|
|
|
if (type == "set_focus") {
|
|
|
|
parseSetFocus(description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-04 21:46:18 +01:00
|
|
|
if (type == "model") {
|
|
|
|
parseModel(data, description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
// Ignore others
|
2017-08-29 19:25:16 +02:00
|
|
|
infostream << "Unknown DrawSpec: type=" << type << ", data=\"" << description << "\""
|
|
|
|
<< std::endl;
|
2010-12-25 15:04:51 +01:00
|
|
|
}
|
|
|
|
|
2012-07-15 18:19:38 +02:00
|
|
|
void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
|
2010-12-22 02:34:21 +01:00
|
|
|
{
|
2020-07-12 09:47:05 +02:00
|
|
|
// Useless to regenerate without a screensize
|
2014-06-14 11:22:09 +02:00
|
|
|
if ((screensize.X <= 0) || (screensize.Y <= 0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
parserData mydata;
|
|
|
|
|
2020-07-12 09:47:05 +02:00
|
|
|
// Preserve stuff only on same form, not on a new form.
|
|
|
|
if (m_text_dst->m_formname == m_last_formname) {
|
|
|
|
// Preserve tables/textlists
|
|
|
|
for (auto &m_table : m_tables) {
|
|
|
|
std::string tablename = m_table.first.fname;
|
|
|
|
GUITable *table = m_table.second;
|
|
|
|
mydata.table_dyndata[tablename] = table->getDynamicData();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preserve focus
|
|
|
|
gui::IGUIElement *focused_element = Environment->getFocus();
|
|
|
|
if (focused_element && focused_element->getParent() == this) {
|
|
|
|
s32 focused_id = focused_element->getID();
|
|
|
|
if (focused_id > 257) {
|
|
|
|
for (const GUIFormSpecMenu::FieldSpec &field : m_fields) {
|
|
|
|
if (field.fid == focused_id) {
|
|
|
|
m_focused_element = field.fname;
|
|
|
|
break;
|
|
|
|
}
|
2013-08-19 11:26:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-12 09:47:05 +02:00
|
|
|
} else {
|
|
|
|
// Don't keep old focus value
|
|
|
|
m_focused_element = "";
|
2013-08-19 11:26:51 +02:00
|
|
|
}
|
|
|
|
|
2010-12-25 15:04:51 +01:00
|
|
|
// Remove children
|
2022-05-22 00:11:59 +02:00
|
|
|
removeAllChildren();
|
|
|
|
removeTooltip();
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2019-12-06 21:51:10 +01:00
|
|
|
for (auto &table_it : m_tables)
|
2017-08-20 19:37:29 +02:00
|
|
|
table_it.second->drop();
|
2019-12-06 21:51:10 +01:00
|
|
|
for (auto &inventorylist_it : m_inventorylists)
|
2020-02-01 13:55:13 +01:00
|
|
|
inventorylist_it->drop();
|
2019-12-06 21:51:10 +01:00
|
|
|
for (auto &checkbox_it : m_checkboxes)
|
2019-11-07 20:11:01 +01:00
|
|
|
checkbox_it.second->drop();
|
2019-12-06 21:51:10 +01:00
|
|
|
for (auto &scrollbar_it : m_scrollbars)
|
2019-11-07 20:11:01 +01:00
|
|
|
scrollbar_it.second->drop();
|
2019-12-06 21:51:10 +01:00
|
|
|
for (auto &tooltip_rect_it : m_tooltip_rects)
|
2019-11-07 20:11:01 +01:00
|
|
|
tooltip_rect_it.first->drop();
|
2020-03-31 19:34:42 +02:00
|
|
|
for (auto &clickthrough_it : m_clickthrough_elements)
|
|
|
|
clickthrough_it->drop();
|
2020-04-13 10:50:07 +02:00
|
|
|
for (auto &scroll_container_it : m_scroll_containers)
|
|
|
|
scroll_container_it.second->drop();
|
2014-05-30 03:04:10 +02:00
|
|
|
|
2020-04-13 10:50:07 +02:00
|
|
|
mydata.size = v2s32(100, 100);
|
2013-06-23 18:30:21 +02:00
|
|
|
mydata.screensize = screensize;
|
2017-03-04 10:46:55 +01:00
|
|
|
mydata.offset = v2f32(0.5f, 0.5f);
|
|
|
|
mydata.anchor = v2f32(0.5f, 0.5f);
|
2021-12-30 21:54:47 +01:00
|
|
|
mydata.padding = v2f32(0.05f, 0.05f);
|
2019-11-07 20:11:01 +01:00
|
|
|
mydata.simple_field_count = 0;
|
2012-07-15 18:19:38 +02:00
|
|
|
|
|
|
|
// Base position of contents of form
|
2013-06-23 18:30:21 +02:00
|
|
|
mydata.basepos = getBasePos();
|
|
|
|
|
2020-04-13 10:50:07 +02:00
|
|
|
// the parent for the parsed elements
|
|
|
|
mydata.current_parent = this;
|
|
|
|
|
2012-06-03 16:18:08 +02:00
|
|
|
m_inventorylists.clear();
|
2013-08-23 12:24:11 +02:00
|
|
|
m_tables.clear();
|
2013-06-23 18:30:21 +02:00
|
|
|
m_checkboxes.clear();
|
2014-06-19 18:17:35 +02:00
|
|
|
m_scrollbars.clear();
|
2012-07-15 18:19:38 +02:00
|
|
|
m_fields.clear();
|
2014-06-24 12:28:24 +02:00
|
|
|
m_tooltips.clear();
|
2018-06-20 22:55:39 +02:00
|
|
|
m_tooltip_rects.clear();
|
2015-10-10 17:07:53 +02:00
|
|
|
m_inventory_rings.clear();
|
2017-06-01 08:00:26 +02:00
|
|
|
m_dropdowns.clear();
|
2020-04-13 10:50:07 +02:00
|
|
|
m_scroll_containers.clear();
|
2019-03-15 20:03:12 +01:00
|
|
|
theme_by_name.clear();
|
|
|
|
theme_by_type.clear();
|
2020-03-31 19:34:42 +02:00
|
|
|
m_clickthrough_elements.clear();
|
2020-07-10 12:11:26 +02:00
|
|
|
field_close_on_enter.clear();
|
|
|
|
m_dropdown_index_event.clear();
|
2014-07-06 16:17:46 +02:00
|
|
|
|
2019-12-08 18:59:30 +01:00
|
|
|
m_bgnonfullscreen = true;
|
2013-11-02 04:26:44 +01:00
|
|
|
m_bgfullscreen = false;
|
|
|
|
|
2019-10-20 12:44:52 +02:00
|
|
|
m_formspec_version = 1;
|
|
|
|
|
2017-08-29 19:25:16 +02:00
|
|
|
{
|
|
|
|
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))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-06-24 12:28:24 +02:00
|
|
|
m_default_tooltip_bgcolor = video::SColor(255,110,130,60);
|
|
|
|
m_default_tooltip_color = video::SColor(255,255,255,255);
|
2014-07-06 16:17:46 +02:00
|
|
|
|
2013-11-02 04:26:44 +01:00
|
|
|
// Add tooltip
|
|
|
|
{
|
2017-06-17 19:11:28 +02:00
|
|
|
assert(!m_tooltip_element);
|
2013-11-02 04:26:44 +01:00
|
|
|
// Note: parent != this so that the tooltip isn't clipped by the menu rectangle
|
2018-01-03 17:28:57 +01:00
|
|
|
m_tooltip_element = gui::StaticText::add(Environment, L"",
|
2018-01-05 19:39:06 +01:00
|
|
|
core::rect<s32>(0, 0, 110, 18));
|
2013-11-02 04:26:44 +01:00
|
|
|
m_tooltip_element->enableOverrideColor(true);
|
2014-06-24 12:28:24 +02:00
|
|
|
m_tooltip_element->setBackgroundColor(m_default_tooltip_bgcolor);
|
2013-11-02 04:26:44 +01:00
|
|
|
m_tooltip_element->setDrawBackground(true);
|
|
|
|
m_tooltip_element->setDrawBorder(true);
|
2014-06-24 12:28:24 +02:00
|
|
|
m_tooltip_element->setOverrideColor(m_default_tooltip_color);
|
2013-11-02 04:26:44 +01:00
|
|
|
m_tooltip_element->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
|
|
|
|
m_tooltip_element->setWordWrap(false);
|
|
|
|
//we're not parent so no autograb for this one!
|
|
|
|
m_tooltip_element->grab();
|
|
|
|
}
|
|
|
|
|
2013-08-14 20:21:39 +02:00
|
|
|
std::vector<std::string> elements = split(m_formspec_string,']');
|
2014-06-25 19:04:47 +02:00
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
/* try to read version from first element only */
|
2017-08-20 19:37:29 +02:00
|
|
|
if (!elements.empty()) {
|
2018-03-28 17:04:41 +02:00
|
|
|
if (parseVersionDirect(elements[0])) {
|
2014-06-25 19:04:47 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
/* we need size first in order to calculate image scale */
|
|
|
|
mydata.explicit_size = false;
|
|
|
|
for (; i< elements.size(); i++) {
|
|
|
|
if (!parseSizeDirect(&mydata, elements[i])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 10:46:55 +01:00
|
|
|
/* "position" element is always after "size" element if it used */
|
|
|
|
for (; i< elements.size(); i++) {
|
|
|
|
if (!parsePositionDirect(&mydata, elements[i])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "anchor" element is always after "position" (or "size" element) if it used */
|
|
|
|
for (; i< elements.size(); i++) {
|
|
|
|
if (!parseAnchorDirect(&mydata, elements[i])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-30 21:54:47 +01:00
|
|
|
/* "padding" element is always after "anchor" and previous if it is used */
|
|
|
|
for (; i < elements.size(); i++) {
|
|
|
|
if (!parsePaddingDirect(&mydata, elements[i])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "no_prepend" element is always after "padding" and previous if it used */
|
2018-03-28 17:04:41 +02:00
|
|
|
bool enable_prepends = true;
|
|
|
|
for (; i < elements.size(); i++) {
|
|
|
|
if (elements[i].empty())
|
|
|
|
break;
|
|
|
|
|
|
|
|
std::vector<std::string> parts = split(elements[i], '[');
|
2018-08-15 21:06:09 +02:00
|
|
|
if (trim(parts[0]) == "no_prepend")
|
2018-03-28 17:04:41 +02:00
|
|
|
enable_prepends = false;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2017-03-04 10:46:55 +01:00
|
|
|
|
2019-06-27 14:40:49 +02:00
|
|
|
/* Copy of the "real_coordinates" element for after the form size. */
|
2019-09-10 21:18:42 +02:00
|
|
|
mydata.real_coordinates = m_formspec_version >= 2;
|
2019-06-27 14:40:49 +02:00
|
|
|
for (; i < elements.size(); i++) {
|
|
|
|
std::vector<std::string> parts = split(elements[i], '[');
|
|
|
|
std::string name = trim(parts[0]);
|
|
|
|
if (name != "real_coordinates" || parts.size() != 2)
|
|
|
|
break; // Invalid format
|
|
|
|
|
|
|
|
mydata.real_coordinates = is_yes(trim(parts[1]));
|
|
|
|
}
|
|
|
|
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
if (mydata.explicit_size) {
|
|
|
|
// compute scaling for specified form size
|
|
|
|
if (m_lock) {
|
2017-06-26 20:11:17 +02:00
|
|
|
v2u32 current_screensize = RenderingEngine::get_video_driver()->getScreenSize();
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
v2u32 delta = current_screensize - m_lockscreensize;
|
|
|
|
|
|
|
|
if (current_screensize.Y > m_lockscreensize.Y)
|
|
|
|
delta.Y /= 2;
|
|
|
|
else
|
|
|
|
delta.Y = 0;
|
|
|
|
|
|
|
|
if (current_screensize.X > m_lockscreensize.X)
|
|
|
|
delta.X /= 2;
|
|
|
|
else
|
|
|
|
delta.X = 0;
|
|
|
|
|
|
|
|
offset = v2s32(delta.X,delta.Y);
|
|
|
|
|
|
|
|
mydata.screensize = m_lockscreensize;
|
|
|
|
} else {
|
|
|
|
offset = v2s32(0,0);
|
|
|
|
}
|
|
|
|
|
2022-07-09 22:32:08 +02:00
|
|
|
const double gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 42.0f);
|
|
|
|
const double screen_dpi = RenderingEngine::getDisplayDensity() * 96;
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
|
|
|
|
double use_imgsize;
|
|
|
|
if (m_lock) {
|
|
|
|
// In fixed-size mode, inventory image size
|
|
|
|
// is 0.53 inch multiplied by the gui_scaling
|
|
|
|
// config parameter. This magic size is chosen
|
|
|
|
// to make the main menu (15.5 inventory images
|
|
|
|
// wide, including border) just fit into the
|
|
|
|
// default window (800 pixels wide) at 96 DPI
|
|
|
|
// and default scaling (1.00).
|
2015-01-02 16:52:02 +01:00
|
|
|
use_imgsize = 0.5555 * screen_dpi * gui_scaling;
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
} else {
|
2020-08-20 01:13:29 +02:00
|
|
|
// Variables for the maximum imgsize that can fit in the screen.
|
|
|
|
double fitx_imgsize;
|
|
|
|
double fity_imgsize;
|
|
|
|
|
|
|
|
v2f padded_screensize(
|
2021-12-30 21:54:47 +01:00
|
|
|
mydata.screensize.X * (1.0f - mydata.padding.X * 2.0f),
|
|
|
|
mydata.screensize.Y * (1.0f - mydata.padding.Y * 2.0f)
|
2020-08-20 01:13:29 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if (mydata.real_coordinates) {
|
|
|
|
fitx_imgsize = padded_screensize.X / mydata.invsize.X;
|
|
|
|
fity_imgsize = padded_screensize.Y / mydata.invsize.Y;
|
|
|
|
} else {
|
|
|
|
// The maximum imgsize in the old coordinate system also needs to
|
|
|
|
// factor in padding and spacing along with 0.1 inventory slot spare
|
|
|
|
// and help text space, hence the magic numbers.
|
|
|
|
fitx_imgsize = padded_screensize.X /
|
|
|
|
((5.0 / 4.0) * (0.5 + mydata.invsize.X));
|
|
|
|
fity_imgsize = padded_screensize.Y /
|
|
|
|
((15.0 / 13.0) * (0.85 + mydata.invsize.Y));
|
|
|
|
}
|
|
|
|
|
2022-01-05 02:47:32 +01:00
|
|
|
s32 min_screen_dim = std::min(padded_screensize.X, padded_screensize.Y);
|
2021-12-30 21:54:47 +01:00
|
|
|
|
2021-09-26 18:04:09 +02:00
|
|
|
#ifdef HAVE_TOUCHSCREENGUI
|
2020-08-20 01:13:29 +02:00
|
|
|
// In Android, the preferred imgsize should be larger to accommodate the
|
|
|
|
// smaller screensize.
|
2021-12-30 21:54:47 +01:00
|
|
|
double prefer_imgsize = min_screen_dim / 10 * gui_scaling;
|
2018-11-18 11:31:19 +01:00
|
|
|
#else
|
2020-08-20 01:13:29 +02:00
|
|
|
// Desktop computers have more space, so try to fit 15 coordinates.
|
2021-12-30 21:54:47 +01:00
|
|
|
double prefer_imgsize = min_screen_dim / 15 * gui_scaling;
|
2018-11-18 11:31:19 +01:00
|
|
|
#endif
|
2020-08-20 01:13:29 +02:00
|
|
|
// Try to use the preferred imgsize, but if that's bigger than the maximum
|
|
|
|
// size, use the maximum size.
|
|
|
|
use_imgsize = std::min(prefer_imgsize,
|
|
|
|
std::min(fitx_imgsize, fity_imgsize));
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Everything else is scaled in proportion to the
|
|
|
|
// inventory image size. The inventory slot spacing
|
|
|
|
// is 5/4 image size horizontally and 15/13 image size
|
|
|
|
// vertically. The padding around the form (incorporating
|
|
|
|
// the border of the outer inventory slots) is 3/8
|
|
|
|
// image size. Font height (baseline to baseline)
|
|
|
|
// is 2/5 vertical inventory slot spacing, and button
|
|
|
|
// half-height is 7/8 of font height.
|
|
|
|
imgsize = v2s32(use_imgsize, use_imgsize);
|
2018-08-04 18:55:54 +02:00
|
|
|
spacing = v2f32(use_imgsize*5.0/4, use_imgsize*15.0/13);
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
padding = v2s32(use_imgsize*3.0/8, use_imgsize*3.0/8);
|
|
|
|
m_btn_height = use_imgsize*15.0/13 * 0.35;
|
|
|
|
|
2015-01-09 18:01:59 +01:00
|
|
|
m_font = g_fontengine->getFont();
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
|
2019-06-27 14:40:49 +02:00
|
|
|
if (mydata.real_coordinates) {
|
|
|
|
mydata.size = v2s32(
|
|
|
|
mydata.invsize.X*imgsize.X,
|
|
|
|
mydata.invsize.Y*imgsize.Y
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
mydata.size = v2s32(
|
|
|
|
padding.X*2+spacing.X*(mydata.invsize.X-1.0)+imgsize.X,
|
|
|
|
padding.Y*2+spacing.Y*(mydata.invsize.Y-1.0)+imgsize.Y + m_btn_height*2.0/3.0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
DesiredRect = mydata.rect = core::rect<s32>(
|
2017-03-04 10:46:55 +01:00
|
|
|
(s32)((f32)mydata.screensize.X * mydata.offset.X) - (s32)(mydata.anchor.X * (f32)mydata.size.X) + offset.X,
|
|
|
|
(s32)((f32)mydata.screensize.Y * mydata.offset.Y) - (s32)(mydata.anchor.Y * (f32)mydata.size.Y) + offset.Y,
|
|
|
|
(s32)((f32)mydata.screensize.X * mydata.offset.X) + (s32)((1.0 - mydata.anchor.X) * (f32)mydata.size.X) + offset.X,
|
|
|
|
(s32)((f32)mydata.screensize.Y * mydata.offset.Y) + (s32)((1.0 - mydata.anchor.Y) * (f32)mydata.size.Y) + offset.Y
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// Non-size[] form must consist only of text fields and
|
|
|
|
// implicit "Proceed" button. Use default font, and
|
|
|
|
// temporary form size which will be recalculated below.
|
2014-11-28 20:06:34 +01:00
|
|
|
m_font = g_fontengine->getFont();
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
m_btn_height = font_line_height(m_font) * 0.875;
|
|
|
|
DesiredRect = core::rect<s32>(
|
2017-03-04 10:46:55 +01:00
|
|
|
(s32)((f32)mydata.screensize.X * mydata.offset.X) - (s32)(mydata.anchor.X * 580.0),
|
|
|
|
(s32)((f32)mydata.screensize.Y * mydata.offset.Y) - (s32)(mydata.anchor.Y * 300.0),
|
|
|
|
(s32)((f32)mydata.screensize.X * mydata.offset.X) + (s32)((1.0 - mydata.anchor.X) * 580.0),
|
|
|
|
(s32)((f32)mydata.screensize.Y * mydata.offset.Y) + (s32)((1.0 - mydata.anchor.Y) * 300.0)
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
recalculateAbsolutePosition(false);
|
|
|
|
mydata.basepos = getBasePos();
|
|
|
|
m_tooltip_element->setOverrideFont(m_font);
|
|
|
|
|
2018-03-28 17:04:41 +02:00
|
|
|
gui::IGUISkin *skin = Environment->getSkin();
|
2017-06-17 19:11:28 +02:00
|
|
|
sanity_check(skin);
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
gui::IGUIFont *old_font = skin->getFont();
|
|
|
|
skin->setFont(m_font);
|
|
|
|
|
2022-02-22 19:17:53 +01:00
|
|
|
// Add a new element that will hold all the background elements as its children.
|
|
|
|
// Because it is the first added element, all backgrounds will be behind all
|
|
|
|
// the other elements.
|
|
|
|
// (We use an arbitrarily big rect. The actual size is determined later by
|
|
|
|
// clipping to `this`.)
|
|
|
|
core::rect<s32> background_parent_rect(0, 0, 100000, 100000);
|
|
|
|
mydata.background_parent.reset(new gui::IGUIElement(EGUIET_ELEMENT, Environment,
|
|
|
|
this, -1, background_parent_rect));
|
|
|
|
|
2018-08-04 18:55:54 +02:00
|
|
|
pos_offset = v2f32();
|
2018-03-28 17:04:41 +02:00
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
// used for formspec versions < 3
|
2022-05-22 00:11:59 +02:00
|
|
|
std::list<IGUIElement *>::iterator legacy_sort_start = std::prev(Children.end()); // last element
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2018-03-28 17:04:41 +02:00
|
|
|
if (enable_prepends) {
|
2019-06-27 14:40:49 +02:00
|
|
|
// Backup the coordinates so that prepends can use the coordinates of choice.
|
|
|
|
bool rc_backup = mydata.real_coordinates;
|
2019-09-15 17:56:11 +02:00
|
|
|
u16 version_backup = m_formspec_version;
|
2019-06-27 14:40:49 +02:00
|
|
|
mydata.real_coordinates = false; // Old coordinates by default.
|
2019-09-10 21:18:42 +02:00
|
|
|
|
2018-03-28 17:04:41 +02:00
|
|
|
std::vector<std::string> prepend_elements = split(m_formspec_prepend, ']');
|
|
|
|
for (const auto &element : prepend_elements)
|
|
|
|
parseElement(&mydata, element);
|
2019-09-10 21:18:42 +02:00
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
// legacy sorting for formspec versions < 3
|
|
|
|
if (m_formspec_version >= 3)
|
|
|
|
// prepends do not need to be reordered
|
2022-05-22 00:11:59 +02:00
|
|
|
legacy_sort_start = std::prev(Children.end()); // last element
|
2019-11-07 20:11:01 +01:00
|
|
|
else if (version_backup >= 3)
|
|
|
|
// only prepends elements have to be reordered
|
|
|
|
legacySortElements(legacy_sort_start);
|
|
|
|
|
2019-09-10 21:18:42 +02:00
|
|
|
m_formspec_version = version_backup;
|
2019-06-27 14:40:49 +02:00
|
|
|
mydata.real_coordinates = rc_backup; // Restore coordinates
|
2018-03-28 17:04:41 +02:00
|
|
|
}
|
|
|
|
|
2014-06-25 19:04:47 +02:00
|
|
|
for (; i< elements.size(); i++) {
|
|
|
|
parseElement(&mydata, elements[i]);
|
2011-04-04 14:13:19 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 10:50:07 +02:00
|
|
|
if (mydata.current_parent != this) {
|
|
|
|
errorstream << "Invalid formspec string: scroll_container was never closed!"
|
|
|
|
<< std::endl;
|
|
|
|
} else if (!container_stack.empty()) {
|
2016-07-07 22:10:15 +02:00
|
|
|
errorstream << "Invalid formspec string: container was never closed!"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:50:07 +02:00
|
|
|
// get the scrollbar elements for scroll_containers
|
|
|
|
for (const std::pair<std::string, GUIScrollContainer *> &c : m_scroll_containers) {
|
|
|
|
for (const std::pair<FieldSpec, GUIScrollBar *> &b : m_scrollbars) {
|
|
|
|
if (c.first == b.first.fname) {
|
|
|
|
c.second->setScrollBar(b.second);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
// If there are fields without explicit size[], add a "Proceed"
|
|
|
|
// button and adjust size to fit all the fields.
|
2019-11-07 20:11:01 +01:00
|
|
|
if (mydata.simple_field_count > 0 && !mydata.explicit_size) {
|
2013-06-23 18:30:21 +02:00
|
|
|
mydata.rect = core::rect<s32>(
|
2019-11-07 20:11:01 +01:00
|
|
|
mydata.screensize.X / 2 - 580 / 2,
|
|
|
|
mydata.screensize.Y / 2 - 300 / 2,
|
|
|
|
mydata.screensize.X / 2 + 580 / 2,
|
|
|
|
mydata.screensize.Y / 2 + 240 / 2 + mydata.simple_field_count * 60
|
2012-07-15 18:19:38 +02:00
|
|
|
);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
DesiredRect = mydata.rect;
|
2012-07-15 18:19:38 +02:00
|
|
|
recalculateAbsolutePosition(false);
|
2013-06-23 18:30:21 +02:00
|
|
|
mydata.basepos = getBasePos();
|
2012-01-13 12:35:55 +01:00
|
|
|
|
2012-07-15 18:19:38 +02:00
|
|
|
{
|
2013-06-23 18:30:21 +02:00
|
|
|
v2s32 pos = mydata.basepos;
|
2019-11-07 20:11:01 +01:00
|
|
|
pos.Y = (mydata.simple_field_count + 2) * 60;
|
2012-07-15 18:19:38 +02:00
|
|
|
|
|
|
|
v2s32 size = DesiredRect.getSize();
|
2019-11-07 20:11:01 +01:00
|
|
|
mydata.rect = core::rect<s32>(
|
|
|
|
size.X / 2 - 70, pos.Y,
|
|
|
|
size.X / 2 - 70 + 140, pos.Y + m_btn_height * 2
|
|
|
|
);
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext("Proceed");
|
2020-04-11 22:39:30 +02:00
|
|
|
GUIButton::addButton(Environment, mydata.rect, m_tsrc, this, 257, text);
|
2013-04-07 19:15:17 +02:00
|
|
|
delete[] text;
|
2012-07-15 18:19:38 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-19 11:26:51 +02:00
|
|
|
|
2020-07-12 09:47:05 +02:00
|
|
|
// Set initial focus if parser didn't set it
|
|
|
|
gui::IGUIElement *focused_element = Environment->getFocus();
|
2013-08-19 11:26:51 +02:00
|
|
|
if (!focused_element
|
|
|
|
|| !isMyChild(focused_element)
|
|
|
|
|| focused_element->getType() == gui::EGUIET_TAB_CONTROL)
|
|
|
|
setInitialFocus();
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
|
|
|
|
skin->setFont(old_font);
|
2019-11-07 20:11:01 +01:00
|
|
|
|
|
|
|
// legacy sorting
|
|
|
|
if (m_formspec_version < 3)
|
|
|
|
legacySortElements(legacy_sort_start);
|
2020-07-12 09:47:05 +02:00
|
|
|
|
|
|
|
// Formname and regeneration setting
|
|
|
|
if (!m_is_form_regenerated) {
|
|
|
|
// Only set previous form name if we purposefully showed a new formspec
|
|
|
|
m_last_formname = m_text_dst->m_formname;
|
|
|
|
m_is_form_regenerated = true;
|
|
|
|
}
|
2019-11-07 20:11:01 +01:00
|
|
|
}
|
|
|
|
|
2022-05-22 00:11:59 +02:00
|
|
|
void GUIFormSpecMenu::legacySortElements(std::list<IGUIElement *>::iterator from)
|
2019-11-07 20:11:01 +01:00
|
|
|
{
|
|
|
|
/*
|
2019-11-20 19:39:10 +01:00
|
|
|
Draw order for formspec_version <= 2:
|
|
|
|
-3 bgcolor
|
|
|
|
-2 background
|
|
|
|
-1 box
|
|
|
|
0 All other elements
|
|
|
|
1 image
|
|
|
|
2 item_image, item_image_button
|
|
|
|
3 list
|
|
|
|
4 label
|
|
|
|
*/
|
2019-11-07 20:11:01 +01:00
|
|
|
|
|
|
|
if (from == Children.end())
|
|
|
|
from = Children.begin();
|
|
|
|
else
|
2022-05-22 00:11:59 +02:00
|
|
|
++from;
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2022-05-22 00:11:59 +02:00
|
|
|
std::list<IGUIElement *>::iterator to = Children.end();
|
2019-11-20 19:39:10 +01:00
|
|
|
// 1: Copy into a sortable container
|
2022-05-22 00:11:59 +02:00
|
|
|
std::vector<IGUIElement *> elements(from, to);
|
2019-11-20 19:39:10 +01:00
|
|
|
|
|
|
|
// 2: Sort the container
|
2019-12-14 21:28:07 +01:00
|
|
|
std::stable_sort(elements.begin(), elements.end(),
|
2019-11-20 19:39:10 +01:00
|
|
|
[this] (const IGUIElement *a, const IGUIElement *b) -> bool {
|
2022-05-22 00:11:59 +02:00
|
|
|
// TODO: getSpecByID is a linear search. It should made O(1), or cached here.
|
2019-11-20 19:39:10 +01:00
|
|
|
const FieldSpec *spec_a = getSpecByID(a->getID());
|
|
|
|
const FieldSpec *spec_b = getSpecByID(b->getID());
|
|
|
|
return spec_a && spec_b &&
|
|
|
|
spec_a->priority < spec_b->priority;
|
|
|
|
});
|
|
|
|
|
|
|
|
// 3: Re-assign the pointers
|
2022-05-22 00:11:59 +02:00
|
|
|
reorderChildren(from, to, elements);
|
2010-12-22 15:30:23 +01:00
|
|
|
}
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
bool GUIFormSpecMenu::getAndroidUIInput()
|
|
|
|
{
|
2018-06-24 21:50:57 +02:00
|
|
|
if (!hasAndroidUIInput())
|
2014-04-21 14:10:59 +02:00
|
|
|
return false;
|
|
|
|
|
2020-04-16 19:19:47 +02:00
|
|
|
// still waiting
|
|
|
|
if (porting::getInputDialogState() == -1)
|
|
|
|
return true;
|
|
|
|
|
2018-06-24 21:50:57 +02:00
|
|
|
std::string fieldname = m_jni_field_name;
|
|
|
|
m_jni_field_name.clear();
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2020-04-16 19:19:47 +02:00
|
|
|
for (const FieldSpec &field : m_fields) {
|
|
|
|
if (field.fname != fieldname)
|
2014-04-21 14:10:59 +02:00
|
|
|
continue;
|
|
|
|
|
2020-04-16 19:19:47 +02:00
|
|
|
IGUIElement *element = getElementFromId(field.fid, true);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2020-04-16 19:19:47 +02:00
|
|
|
if (!element || element->getType() != irr::gui::EGUIET_EDIT_BOX)
|
2014-04-21 14:10:59 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
std::string text = porting::getInputDialogValue();
|
2020-04-16 19:19:47 +02:00
|
|
|
((gui::IGUIEditBox *)element)->setText(utf8_to_wide(text).c_str());
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-02-01 13:55:13 +01:00
|
|
|
GUIInventoryList::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const
|
2010-12-22 15:30:23 +01:00
|
|
|
{
|
2020-02-01 13:55:13 +01:00
|
|
|
for (const GUIInventoryList *e : m_inventorylists) {
|
|
|
|
s32 item_index = e->getItemIndexAtPos(p);
|
|
|
|
if (item_index != -1)
|
|
|
|
return GUIInventoryList::ItemSpec(e->getInventoryloc(), e->getListname(),
|
|
|
|
item_index);
|
2012-06-02 14:28:12 +02:00
|
|
|
}
|
2012-01-13 12:35:55 +01:00
|
|
|
|
2020-02-01 13:55:13 +01:00
|
|
|
return GUIInventoryList::ItemSpec(InventoryLocation(), "", -1);
|
2010-12-22 02:34:21 +01:00
|
|
|
}
|
|
|
|
|
2012-07-15 18:19:38 +02:00
|
|
|
void GUIFormSpecMenu::drawSelectedItem()
|
2012-01-21 21:21:41 +01:00
|
|
|
{
|
|
|
|
video::IVideoDriver* driver = Environment->getVideoDriver();
|
|
|
|
|
2016-01-24 14:19:17 +01:00
|
|
|
if (!m_selected_item) {
|
2019-11-07 20:11:01 +01:00
|
|
|
// reset rotation time
|
2016-01-24 14:19:17 +01:00
|
|
|
drawItemStack(driver, m_font, ItemStack(),
|
2019-09-10 15:11:26 +02:00
|
|
|
core::rect<s32>(v2s32(0, 0), v2s32(0, 0)), NULL,
|
|
|
|
m_client, IT_ROT_DRAGGED);
|
2016-01-24 14:19:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-21 21:21:41 +01:00
|
|
|
Inventory *inv = m_invmgr->getInventory(m_selected_item->inventoryloc);
|
2015-03-06 11:21:51 +01:00
|
|
|
sanity_check(inv);
|
2012-01-21 21:21:41 +01:00
|
|
|
InventoryList *list = inv->getList(m_selected_item->listname);
|
2015-03-06 11:21:51 +01:00
|
|
|
sanity_check(list);
|
2012-01-21 21:21:41 +01:00
|
|
|
ItemStack stack = list->getItem(m_selected_item->i);
|
|
|
|
stack.count = m_selected_amount;
|
|
|
|
|
|
|
|
core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
|
|
|
|
core::rect<s32> rect = imgrect + (m_pointer - imgrect.getCenter());
|
2016-12-20 14:27:14 +01:00
|
|
|
rect.constrainTo(driver->getViewPort());
|
2017-01-09 20:39:22 +01:00
|
|
|
drawItemStack(driver, m_font, stack, rect, NULL, m_client, IT_ROT_DRAGGED);
|
2012-01-21 21:21:41 +01:00
|
|
|
}
|
|
|
|
|
2012-07-15 18:19:38 +02:00
|
|
|
void GUIFormSpecMenu::drawMenu()
|
2010-12-22 02:34:21 +01:00
|
|
|
{
|
2017-08-29 19:25:16 +02:00
|
|
|
if (m_form_src) {
|
|
|
|
const std::string &newform = m_form_src->getForm();
|
|
|
|
if (newform != m_formspec_string) {
|
2012-06-03 17:30:34 +02:00
|
|
|
m_formspec_string = newform;
|
2020-07-12 09:47:05 +02:00
|
|
|
m_is_form_regenerated = false;
|
2012-06-03 17:30:34 +02:00
|
|
|
regenerateGui(m_screensize_old);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
gui::IGUISkin* skin = Environment->getSkin();
|
2015-03-06 11:21:51 +01:00
|
|
|
sanity_check(skin != NULL);
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
gui::IGUIFont *old_font = skin->getFont();
|
|
|
|
skin->setFont(m_font);
|
|
|
|
|
2020-02-01 13:55:13 +01:00
|
|
|
m_hovered_item_tooltips.clear();
|
|
|
|
|
2012-01-21 21:21:41 +01:00
|
|
|
updateSelectedItem();
|
|
|
|
|
2010-12-22 02:34:21 +01:00
|
|
|
video::IVideoDriver* driver = Environment->getVideoDriver();
|
2014-05-30 03:07:48 +02:00
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
/*
|
|
|
|
Draw background color
|
|
|
|
*/
|
2013-11-02 04:26:44 +01:00
|
|
|
v2u32 screenSize = driver->getScreenSize();
|
2017-08-29 19:25:16 +02:00
|
|
|
core::rect<s32> allbg(0, 0, screenSize.X, screenSize.Y);
|
|
|
|
|
2013-12-11 23:07:38 +01:00
|
|
|
if (m_bgfullscreen)
|
2017-08-29 19:25:16 +02:00
|
|
|
driver->draw2DRectangle(m_fullscreen_bgcolor, allbg, &allbg);
|
2019-12-08 18:59:30 +01:00
|
|
|
if (m_bgnonfullscreen)
|
2019-10-06 14:50:45 +02:00
|
|
|
driver->draw2DRectangle(m_bgcolor, AbsoluteRect, &AbsoluteClippingRect);
|
2010-12-22 02:34:21 +01:00
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
/*
|
|
|
|
Draw rect_mode tooltip
|
|
|
|
*/
|
2012-01-13 12:35:55 +01:00
|
|
|
m_tooltip_element->setVisible(false);
|
|
|
|
|
2018-06-20 22:55:39 +02:00
|
|
|
for (const auto &pair : m_tooltip_rects) {
|
2019-11-07 20:11:01 +01:00
|
|
|
const core::rect<s32> &rect = pair.first->getAbsoluteClippingRect();
|
|
|
|
if (rect.getArea() > 0 && rect.isPointInside(m_pointer)) {
|
2018-06-20 22:55:39 +02:00
|
|
|
const std::wstring &text = pair.second.tooltip;
|
|
|
|
if (!text.empty()) {
|
|
|
|
showTooltip(text, pair.second.color, pair.second.bgcolor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:34:42 +02:00
|
|
|
// Some elements are only visible while being drawn
|
|
|
|
for (gui::IGUIElement *e : m_clickthrough_elements)
|
|
|
|
e->setVisible(true);
|
|
|
|
|
2016-01-24 14:19:17 +01:00
|
|
|
/*
|
2020-08-23 22:50:14 +02:00
|
|
|
This is where all the drawing happens.
|
2016-01-24 14:19:17 +01:00
|
|
|
*/
|
2022-05-22 00:11:59 +02:00
|
|
|
for (auto child : Children)
|
|
|
|
if (child->isNotClipped() ||
|
2020-08-23 22:50:14 +02:00
|
|
|
AbsoluteClippingRect.isRectCollided(
|
2022-05-22 00:11:59 +02:00
|
|
|
child->getAbsolutePosition()))
|
|
|
|
child->draw();
|
2016-01-24 14:19:17 +01:00
|
|
|
|
2020-03-31 19:34:42 +02:00
|
|
|
for (gui::IGUIElement *e : m_clickthrough_elements)
|
|
|
|
e->setVisible(false);
|
|
|
|
|
2020-02-01 13:55:13 +01:00
|
|
|
// Draw hovered item tooltips
|
|
|
|
for (const std::string &tooltip : m_hovered_item_tooltips) {
|
|
|
|
showTooltip(utf8_to_wide(tooltip), m_default_tooltip_color,
|
|
|
|
m_default_tooltip_bgcolor);
|
2016-01-24 14:19:17 +01:00
|
|
|
}
|
2020-02-01 13:55:13 +01:00
|
|
|
|
|
|
|
if (m_hovered_item_tooltips.empty()) {
|
2019-11-07 20:11:01 +01:00
|
|
|
// reset rotation time
|
2016-01-24 14:19:17 +01:00
|
|
|
drawItemStack(driver, m_font, ItemStack(),
|
|
|
|
core::rect<s32>(v2s32(0, 0), v2s32(0, 0)),
|
2017-01-09 20:39:22 +01:00
|
|
|
NULL, m_client, IT_ROT_HOVERED);
|
2012-11-04 21:18:28 +01:00
|
|
|
}
|
2014-05-30 03:07:48 +02:00
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
/* TODO find way to show tooltips on touchscreen */
|
|
|
|
#ifndef HAVE_TOUCHSCREENGUI
|
2017-06-26 20:11:17 +02:00
|
|
|
m_pointer = RenderingEngine::get_raw_device()->getCursorControl()->getPosition();
|
2014-04-21 14:10:59 +02:00
|
|
|
#endif
|
|
|
|
|
2012-12-01 18:36:42 +01:00
|
|
|
/*
|
2020-01-11 20:17:11 +01:00
|
|
|
Draw fields/buttons tooltips and update the mouse cursor
|
2012-12-01 18:36:42 +01:00
|
|
|
*/
|
2014-06-19 00:22:03 +02:00
|
|
|
gui::IGUIElement *hovered =
|
|
|
|
Environment->getRootGUIElement()->getElementFromPoint(m_pointer);
|
2014-06-14 11:22:09 +02:00
|
|
|
|
2020-01-11 20:17:11 +01:00
|
|
|
#ifndef HAVE_TOUCHSCREENGUI
|
|
|
|
gui::ICursorControl *cursor_control = RenderingEngine::get_raw_device()->
|
|
|
|
getCursorControl();
|
|
|
|
gui::ECURSOR_ICON current_cursor_icon = cursor_control->getActiveIcon();
|
|
|
|
#endif
|
|
|
|
bool hovered_element_found = false;
|
|
|
|
|
2014-06-19 00:22:03 +02:00
|
|
|
if (hovered != NULL) {
|
2020-04-12 12:02:32 +02:00
|
|
|
if (m_show_debug) {
|
|
|
|
core::rect<s32> rect = hovered->getAbsoluteClippingRect();
|
|
|
|
driver->draw2DRectangle(0x22FFFF00, rect, &rect);
|
|
|
|
}
|
2014-10-30 07:53:20 +01:00
|
|
|
|
2020-04-12 12:02:32 +02:00
|
|
|
s32 id = hovered->getID();
|
2017-05-26 14:03:36 +02:00
|
|
|
u64 delta = 0;
|
2014-06-24 12:28:24 +02:00
|
|
|
if (id == -1) {
|
|
|
|
m_old_tooltip_id = id;
|
2014-10-30 07:53:20 +01:00
|
|
|
} else {
|
|
|
|
if (id == m_old_tooltip_id) {
|
2016-03-06 20:31:16 +01:00
|
|
|
delta = porting::getDeltaMs(m_hovered_time, porting::getTimeMs());
|
2014-10-30 07:53:20 +01:00
|
|
|
} else {
|
2016-03-06 20:31:16 +01:00
|
|
|
m_hovered_time = porting::getTimeMs();
|
2014-10-30 07:53:20 +01:00
|
|
|
m_old_tooltip_id = id;
|
|
|
|
}
|
2014-07-02 15:32:54 +02:00
|
|
|
}
|
2014-10-30 07:53:20 +01:00
|
|
|
|
2020-01-11 20:17:11 +01:00
|
|
|
// Find and update the current tooltip and cursor icon
|
|
|
|
if (id != -1) {
|
2017-08-20 19:37:29 +02:00
|
|
|
for (const FieldSpec &field : m_fields) {
|
2017-06-03 08:55:26 +02:00
|
|
|
|
2017-08-20 19:37:29 +02:00
|
|
|
if (field.fid != id)
|
2017-06-03 08:55:26 +02:00
|
|
|
continue;
|
|
|
|
|
2020-01-11 20:17:11 +01:00
|
|
|
if (delta >= m_tooltip_show_delay) {
|
|
|
|
const std::wstring &text = m_tooltips[field.fname].tooltip;
|
|
|
|
if (!text.empty())
|
|
|
|
showTooltip(text, m_tooltips[field.fname].color,
|
|
|
|
m_tooltips[field.fname].bgcolor);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HAVE_TOUCHSCREENGUI
|
2020-02-11 19:53:09 +01:00
|
|
|
if (field.ftype != f_HyperText && // Handled directly in guiHyperText
|
|
|
|
current_cursor_icon != field.fcursor_icon)
|
2020-01-11 20:17:11 +01:00
|
|
|
cursor_control->setActiveIcon(field.fcursor_icon);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
hovered_element_found = true;
|
2017-06-03 08:55:26 +02:00
|
|
|
|
|
|
|
break;
|
2012-12-01 18:36:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 03:07:48 +02:00
|
|
|
|
2020-01-11 20:17:11 +01:00
|
|
|
if (!hovered_element_found) {
|
|
|
|
// no element is hovered
|
|
|
|
#ifndef HAVE_TOUCHSCREENGUI
|
|
|
|
if (current_cursor_icon != ECI_NORMAL)
|
|
|
|
cursor_control->setActiveIcon(ECI_NORMAL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-05-31 17:30:11 +02:00
|
|
|
m_tooltip_element->draw();
|
|
|
|
|
2012-12-01 18:36:42 +01:00
|
|
|
/*
|
|
|
|
Draw dragged item stack
|
|
|
|
*/
|
|
|
|
drawSelectedItem();
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
|
|
|
|
skin->setFont(old_font);
|
2010-12-22 02:34:21 +01:00
|
|
|
}
|
|
|
|
|
2017-06-03 08:55:26 +02:00
|
|
|
|
|
|
|
void GUIFormSpecMenu::showTooltip(const std::wstring &text,
|
|
|
|
const irr::video::SColor &color, const irr::video::SColor &bgcolor)
|
|
|
|
{
|
2020-01-22 19:09:11 +01:00
|
|
|
EnrichedString ntext(text);
|
|
|
|
ntext.setDefaultColor(color);
|
2020-12-24 14:26:42 +01:00
|
|
|
if (!ntext.hasBackground())
|
|
|
|
ntext.setBackground(bgcolor);
|
2020-01-22 19:09:11 +01:00
|
|
|
|
|
|
|
setStaticText(m_tooltip_element, ntext);
|
2017-06-03 08:55:26 +02:00
|
|
|
|
|
|
|
// Tooltip size and offset
|
|
|
|
s32 tooltip_width = m_tooltip_element->getTextWidth() + m_btn_height;
|
|
|
|
s32 tooltip_height = m_tooltip_element->getTextHeight() + 5;
|
2020-01-22 19:09:11 +01:00
|
|
|
|
2017-06-03 08:55:26 +02:00
|
|
|
v2u32 screenSize = Environment->getVideoDriver()->getScreenSize();
|
|
|
|
int tooltip_offset_x = m_btn_height;
|
|
|
|
int tooltip_offset_y = m_btn_height;
|
2021-09-26 18:04:09 +02:00
|
|
|
#ifdef HAVE_TOUCHSCREENGUI
|
2017-06-03 08:55:26 +02:00
|
|
|
tooltip_offset_x *= 3;
|
|
|
|
tooltip_offset_y = 0;
|
|
|
|
if (m_pointer.X > (s32)screenSize.X / 2)
|
|
|
|
tooltip_offset_x = -(tooltip_offset_x + tooltip_width);
|
2020-04-16 18:49:30 +02:00
|
|
|
|
|
|
|
// Hide tooltip after ETIE_LEFT_UP
|
|
|
|
if (m_pointer.X == 0)
|
|
|
|
return;
|
2017-06-03 08:55:26 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Calculate and set the tooltip position
|
|
|
|
s32 tooltip_x = m_pointer.X + tooltip_offset_x;
|
|
|
|
s32 tooltip_y = m_pointer.Y + tooltip_offset_y;
|
|
|
|
if (tooltip_x + tooltip_width > (s32)screenSize.X)
|
|
|
|
tooltip_x = (s32)screenSize.X - tooltip_width - m_btn_height;
|
|
|
|
if (tooltip_y + tooltip_height > (s32)screenSize.Y)
|
|
|
|
tooltip_y = (s32)screenSize.Y - tooltip_height - m_btn_height;
|
|
|
|
|
|
|
|
m_tooltip_element->setRelativePosition(
|
|
|
|
core::rect<s32>(
|
|
|
|
core::position2d<s32>(tooltip_x, tooltip_y),
|
|
|
|
core::dimension2d<s32>(tooltip_width, tooltip_height)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Display the tooltip
|
|
|
|
m_tooltip_element->setVisible(true);
|
|
|
|
bringToFront(m_tooltip_element);
|
|
|
|
}
|
|
|
|
|
2012-07-15 18:19:38 +02:00
|
|
|
void GUIFormSpecMenu::updateSelectedItem()
|
2012-01-21 21:21:41 +01:00
|
|
|
{
|
2018-04-03 11:15:58 +02:00
|
|
|
verifySelectedItem();
|
|
|
|
|
|
|
|
// If craftresult is nonempty and nothing else is selected, select it now.
|
|
|
|
if (!m_selected_item) {
|
2020-02-01 13:55:13 +01:00
|
|
|
for (const GUIInventoryList *e : m_inventorylists) {
|
|
|
|
if (e->getListname() != "craftpreview")
|
2018-04-03 11:15:58 +02:00
|
|
|
continue;
|
|
|
|
|
2020-02-01 13:55:13 +01:00
|
|
|
Inventory *inv = m_invmgr->getInventory(e->getInventoryloc());
|
2018-04-03 11:15:58 +02:00
|
|
|
if (!inv)
|
2012-09-02 21:51:38 +02:00
|
|
|
continue;
|
2018-04-03 11:15:58 +02:00
|
|
|
|
|
|
|
InventoryList *list = inv->getList("craftresult");
|
|
|
|
|
|
|
|
if (!list || list->getSize() == 0)
|
2012-09-02 21:51:38 +02:00
|
|
|
continue;
|
2012-01-21 21:21:41 +01:00
|
|
|
|
2018-04-03 11:15:58 +02:00
|
|
|
const ItemStack &item = list->getItem(0);
|
|
|
|
if (item.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Grab selected item from the crafting result list
|
2020-02-01 13:55:13 +01:00
|
|
|
m_selected_item = new GUIInventoryList::ItemSpec;
|
|
|
|
m_selected_item->inventoryloc = e->getInventoryloc();
|
2018-04-03 11:15:58 +02:00
|
|
|
m_selected_item->listname = "craftresult";
|
|
|
|
m_selected_item->i = 0;
|
|
|
|
m_selected_amount = item.count;
|
|
|
|
m_selected_dragging = false;
|
|
|
|
break;
|
2012-01-21 21:21:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If craftresult is selected, keep the whole stack selected
|
2018-04-03 11:15:58 +02:00
|
|
|
if (m_selected_item && m_selected_item->listname == "craftresult")
|
2013-06-18 01:32:11 +02:00
|
|
|
m_selected_amount = verifySelectedItem().count;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack GUIFormSpecMenu::verifySelectedItem()
|
|
|
|
{
|
|
|
|
// If the selected stack has become empty for some reason, deselect it.
|
|
|
|
// If the selected stack has become inaccessible, deselect it.
|
|
|
|
// If the selected stack has become smaller, adjust m_selected_amount.
|
|
|
|
// Return the selected stack.
|
|
|
|
|
2020-02-01 13:55:13 +01:00
|
|
|
if (m_selected_item) {
|
|
|
|
if (m_selected_item->isValid()) {
|
2013-06-18 01:32:11 +02:00
|
|
|
Inventory *inv = m_invmgr->getInventory(m_selected_item->inventoryloc);
|
2020-02-01 13:55:13 +01:00
|
|
|
if (inv) {
|
2013-06-18 01:32:11 +02:00
|
|
|
InventoryList *list = inv->getList(m_selected_item->listname);
|
2020-02-01 13:55:13 +01:00
|
|
|
if (list && (u32) m_selected_item->i < list->getSize()) {
|
2013-06-18 01:32:11 +02:00
|
|
|
ItemStack stack = list->getItem(m_selected_item->i);
|
2018-04-03 11:15:58 +02:00
|
|
|
if (!m_selected_swap.empty()) {
|
|
|
|
if (m_selected_swap.name == stack.name &&
|
|
|
|
m_selected_swap.count == stack.count)
|
|
|
|
m_selected_swap.clear();
|
|
|
|
} else {
|
|
|
|
m_selected_amount = std::min(m_selected_amount, stack.count);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stack.empty())
|
2013-06-18 01:32:11 +02:00
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// selection was not valid
|
|
|
|
delete m_selected_item;
|
2020-02-01 13:55:13 +01:00
|
|
|
m_selected_item = nullptr;
|
2013-06-18 01:32:11 +02:00
|
|
|
m_selected_amount = 0;
|
|
|
|
m_selected_dragging = false;
|
2012-01-21 21:21:41 +01:00
|
|
|
}
|
2013-06-18 01:32:11 +02:00
|
|
|
return ItemStack();
|
2012-01-21 21:21:41 +01:00
|
|
|
}
|
|
|
|
|
2021-01-22 16:09:26 +01:00
|
|
|
void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode)
|
2012-07-15 18:19:38 +02:00
|
|
|
{
|
|
|
|
if(m_text_dst)
|
|
|
|
{
|
2015-05-19 08:24:14 +02:00
|
|
|
StringMap fields;
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2014-03-04 19:57:39 +01:00
|
|
|
if (quitmode == quit_mode_accept) {
|
2013-10-26 09:56:38 +02:00
|
|
|
fields["quit"] = "true";
|
|
|
|
}
|
|
|
|
|
2014-03-04 19:57:39 +01:00
|
|
|
if (quitmode == quit_mode_cancel) {
|
|
|
|
fields["quit"] = "true";
|
|
|
|
m_text_dst->gotText(fields);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-07 21:53:40 +02:00
|
|
|
if (current_keys_pending.key_down) {
|
|
|
|
fields["key_down"] = "true";
|
|
|
|
current_keys_pending.key_down = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_keys_pending.key_up) {
|
|
|
|
fields["key_up"] = "true";
|
|
|
|
current_keys_pending.key_up = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_keys_pending.key_enter) {
|
|
|
|
fields["key_enter"] = "true";
|
|
|
|
current_keys_pending.key_enter = false;
|
|
|
|
}
|
|
|
|
|
2016-08-07 17:01:00 +02:00
|
|
|
if (!current_field_enter_pending.empty()) {
|
|
|
|
fields["key_enter_field"] = current_field_enter_pending;
|
2016-08-07 17:22:50 +02:00
|
|
|
current_field_enter_pending = "";
|
2016-08-07 17:01:00 +02:00
|
|
|
}
|
|
|
|
|
2013-07-07 21:53:40 +02:00
|
|
|
if (current_keys_pending.key_escape) {
|
|
|
|
fields["key_escape"] = "true";
|
|
|
|
current_keys_pending.key_escape = false;
|
|
|
|
}
|
|
|
|
|
2017-08-20 19:37:29 +02:00
|
|
|
for (const GUIFormSpecMenu::FieldSpec &s : m_fields) {
|
2020-03-16 22:56:48 +01:00
|
|
|
if (s.send) {
|
2015-06-10 01:54:33 +02:00
|
|
|
std::string name = s.fname;
|
|
|
|
if (s.ftype == f_Button) {
|
|
|
|
fields[name] = wide_to_utf8(s.flabel);
|
|
|
|
} else if (s.ftype == f_Table) {
|
2013-08-23 12:24:11 +02:00
|
|
|
GUITable *table = getTable(s.fname);
|
|
|
|
if (table) {
|
2014-05-30 03:04:10 +02:00
|
|
|
fields[name] = table->checkEvent();
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
2020-03-16 22:56:48 +01:00
|
|
|
} else if (s.ftype == f_DropDown) {
|
|
|
|
// No dynamic cast possible due to some distributions shipped
|
|
|
|
// without rtti support in Irrlicht
|
2019-11-07 20:11:01 +01:00
|
|
|
IGUIElement *element = getElementFromId(s.fid, true);
|
2013-06-23 18:30:21 +02:00
|
|
|
gui::IGUIComboBox *e = NULL;
|
|
|
|
if ((element) && (element->getType() == gui::EGUIET_COMBO_BOX)) {
|
2020-03-16 22:56:48 +01:00
|
|
|
e = static_cast<gui::IGUIComboBox *>(element);
|
2019-11-07 20:11:01 +01:00
|
|
|
} else {
|
|
|
|
warningstream << "GUIFormSpecMenu::acceptInput: dropdown "
|
|
|
|
<< "field without dropdown element" << std::endl;
|
|
|
|
continue;
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
2013-12-11 23:07:38 +01:00
|
|
|
s32 selected = e->getSelected();
|
|
|
|
if (selected >= 0) {
|
2020-07-10 12:11:26 +02:00
|
|
|
if (m_dropdown_index_event.find(s.fname) !=
|
|
|
|
m_dropdown_index_event.end()) {
|
|
|
|
fields[name] = std::to_string(selected + 1);
|
|
|
|
} else {
|
|
|
|
std::vector<std::string> *dropdown_values =
|
|
|
|
getDropDownValues(s.fname);
|
|
|
|
if (dropdown_values && selected < (s32)dropdown_values->size())
|
|
|
|
fields[name] = (*dropdown_values)[selected];
|
2016-05-05 18:50:02 +02:00
|
|
|
}
|
2013-12-11 23:07:38 +01:00
|
|
|
}
|
2020-03-16 22:56:48 +01:00
|
|
|
} else if (s.ftype == f_TabHeader) {
|
|
|
|
// No dynamic cast possible due to some distributions shipped
|
|
|
|
// without rtti support in Irrlicht
|
2019-11-07 20:11:01 +01:00
|
|
|
IGUIElement *element = getElementFromId(s.fid, true);
|
|
|
|
gui::IGUITabControl *e = nullptr;
|
2013-06-23 18:30:21 +02:00
|
|
|
if ((element) && (element->getType() == gui::EGUIET_TAB_CONTROL)) {
|
2017-08-20 20:24:26 +02:00
|
|
|
e = static_cast<gui::IGUITabControl *>(element);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (e != 0) {
|
2021-09-11 21:06:57 +02:00
|
|
|
fields[name] = itos(e->getActiveTab() + 1);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
2020-03-16 22:56:48 +01:00
|
|
|
} else if (s.ftype == f_CheckBox) {
|
|
|
|
// No dynamic cast possible due to some distributions shipped
|
|
|
|
// without rtti support in Irrlicht
|
2019-11-07 20:11:01 +01:00
|
|
|
IGUIElement *element = getElementFromId(s.fid, true);
|
|
|
|
gui::IGUICheckBox *e = nullptr;
|
2013-06-23 18:30:21 +02:00
|
|
|
if ((element) && (element->getType() == gui::EGUIET_CHECK_BOX)) {
|
2017-08-20 20:24:26 +02:00
|
|
|
e = static_cast<gui::IGUICheckBox*>(element);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (e != 0) {
|
|
|
|
if (e->isChecked())
|
2014-05-30 03:04:10 +02:00
|
|
|
fields[name] = "true";
|
2013-06-23 18:30:21 +02:00
|
|
|
else
|
2014-05-30 03:04:10 +02:00
|
|
|
fields[name] = "false";
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
2020-03-16 22:56:48 +01:00
|
|
|
} else if (s.ftype == f_ScrollBar) {
|
|
|
|
// No dynamic cast possible due to some distributions shipped
|
|
|
|
// without rtti support in Irrlicht
|
2019-11-07 20:11:01 +01:00
|
|
|
IGUIElement *element = getElementFromId(s.fid, true);
|
|
|
|
GUIScrollBar *e = nullptr;
|
|
|
|
if (element && element->getType() == gui::EGUIET_ELEMENT)
|
|
|
|
e = static_cast<GUIScrollBar *>(element);
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
if (e) {
|
2014-06-19 18:17:35 +02:00
|
|
|
if (s.fdefault == L"Changed")
|
2021-09-11 21:06:57 +02:00
|
|
|
fields[name] = "CHG:" + itos(e->getPos());
|
2014-06-19 18:17:35 +02:00
|
|
|
else
|
2021-09-11 21:06:57 +02:00
|
|
|
fields[name] = "VAL:" + itos(e->getPos());
|
2014-06-19 18:17:35 +02:00
|
|
|
}
|
2020-03-16 22:56:48 +01:00
|
|
|
} else if (s.ftype == f_AnimatedImage) {
|
|
|
|
// No dynamic cast possible due to some distributions shipped
|
|
|
|
// without rtti support in Irrlicht
|
|
|
|
IGUIElement *element = getElementFromId(s.fid, true);
|
|
|
|
GUIAnimatedImage *e = nullptr;
|
|
|
|
if (element && element->getType() == gui::EGUIET_ELEMENT)
|
|
|
|
e = static_cast<GUIAnimatedImage *>(element);
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
fields[name] = std::to_string(e->getFrameIndex() + 1);
|
|
|
|
} else {
|
2019-11-07 20:11:01 +01:00
|
|
|
IGUIElement *e = getElementFromId(s.fid, true);
|
|
|
|
if (e)
|
2015-06-10 01:54:33 +02:00
|
|
|
fields[name] = wide_to_utf8(e->getText());
|
2012-07-15 18:19:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2012-07-15 18:19:38 +02:00
|
|
|
m_text_dst->gotText(fields);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-19 11:26:51 +02:00
|
|
|
bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
|
|
|
|
{
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
// The IGUITabControl renders visually using the skin's selected
|
|
|
|
// font, which we override for the duration of form drawing,
|
|
|
|
// but computes tab hotspots based on how it would have rendered
|
|
|
|
// using the font that is selected at the time of button release.
|
|
|
|
// To make these two consistent, temporarily override the skin's
|
|
|
|
// font while the IGUITabControl is processing the event.
|
|
|
|
if (event.EventType == EET_MOUSE_INPUT_EVENT &&
|
|
|
|
event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
|
|
|
|
s32 x = event.MouseInput.X;
|
|
|
|
s32 y = event.MouseInput.Y;
|
|
|
|
gui::IGUIElement *hovered =
|
|
|
|
Environment->getRootGUIElement()->getElementFromPoint(
|
|
|
|
core::position2d<s32>(x, y));
|
2014-12-13 00:39:07 +01:00
|
|
|
if (hovered && isMyChild(hovered) &&
|
|
|
|
hovered->getType() == gui::EGUIET_TAB_CONTROL) {
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
gui::IGUISkin* skin = Environment->getSkin();
|
2015-03-06 11:21:51 +01:00
|
|
|
sanity_check(skin != NULL);
|
Scale form elements consistently
The ratios between the sizes of form elements, including text, is now
fixed, aside from variations caused by rounding. This makes form layout
almost fully predictable, and particularly independent of player's
screen size. The proportions of non-text elements are the traditional
proportions.
For compatibility, the way in which element positions and sizes are
specified remains unchanged, in all its baroqueness, with one exception.
The exception is that the position of a label[] element is now defined
in terms of the vertically center of the first line of the label,
rather than the bottom of the first line of the label. This change
allows a label to be precisely aligned with button text or an edit box,
which are positioned in a centering manner. Label positioning remains
consistent with the previous system, just more precisely defined.
Make multi-line label[] elements work properly. Previously the code set
a bounding rectangle assuming that there would be only a single line,
and as a result a multi-line label would be cut somewhere in the middle
of the second line. Now multi-line labels not only work, but have
guaranteed line spacing relative to inventory slots, to aid alignment.
Incidentally fix tabheader[] elements which were being constrained to
the wrong width.
Given an unusually large form, in variable-size mode, the form rendering
system now chooses a scale that will fit the entire form on the screen,
if that doesn't make elements too small. Fixed-size forms, including the
main menu, are have their sizes fixed in inch terms. The fixed size for
fixed-size forms and the preferred and minimum sizes for variable-size
forms all scale according to the gui_scaling parameter.
2014-08-21 00:42:27 +02:00
|
|
|
gui::IGUIFont *old_font = skin->getFont();
|
|
|
|
skin->setFont(m_font);
|
|
|
|
bool retval = hovered->OnEvent(event);
|
|
|
|
skin->setFont(old_font);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-23 12:24:11 +02:00
|
|
|
// Fix Esc/Return key being eaten by checkboxen and tables
|
2020-02-01 13:55:13 +01:00
|
|
|
if (event.EventType == EET_KEY_INPUT_EVENT) {
|
|
|
|
KeyPress kp(event.KeyInput);
|
2014-04-21 14:10:59 +02:00
|
|
|
if (kp == EscapeKey || kp == CancelKey
|
|
|
|
|| kp == getKeySetting("keymap_inventory")
|
2014-05-30 03:04:10 +02:00
|
|
|
|| event.KeyInput.Key==KEY_RETURN) {
|
2013-08-19 11:26:51 +02:00
|
|
|
gui::IGUIElement *focused = Environment->getFocus();
|
|
|
|
if (focused && isMyChild(focused) &&
|
|
|
|
(focused->getType() == gui::EGUIET_LIST_BOX ||
|
2018-07-28 12:58:16 +02:00
|
|
|
focused->getType() == gui::EGUIET_CHECK_BOX) &&
|
|
|
|
(focused->getParent()->getType() != gui::EGUIET_COMBO_BOX ||
|
|
|
|
event.KeyInput.Key != KEY_RETURN)) {
|
2013-08-19 11:26:51 +02:00
|
|
|
OnEvent(event);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-10 15:11:26 +02:00
|
|
|
// Mouse wheel and move events: send to hovered element instead of focused
|
|
|
|
if (event.EventType == EET_MOUSE_INPUT_EVENT &&
|
|
|
|
(event.MouseInput.Event == EMIE_MOUSE_WHEEL ||
|
2020-03-15 20:34:49 +01:00
|
|
|
(event.MouseInput.Event == EMIE_MOUSE_MOVED &&
|
|
|
|
event.MouseInput.ButtonStates == 0))) {
|
2013-08-19 11:26:51 +02:00
|
|
|
s32 x = event.MouseInput.X;
|
|
|
|
s32 y = event.MouseInput.Y;
|
|
|
|
gui::IGUIElement *hovered =
|
|
|
|
Environment->getRootGUIElement()->getElementFromPoint(
|
|
|
|
core::position2d<s32>(x, y));
|
|
|
|
if (hovered && isMyChild(hovered)) {
|
|
|
|
hovered->OnEvent(event);
|
2019-09-10 15:11:26 +02:00
|
|
|
return event.MouseInput.Event == EMIE_MOUSE_WHEEL;
|
2013-08-19 11:26:51 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-30 03:04:10 +02:00
|
|
|
|
2016-05-27 08:35:07 +02:00
|
|
|
if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
|
|
|
|
/* TODO add a check like:
|
|
|
|
if (event.JoystickEvent != joystick_we_listen_for)
|
|
|
|
return false;
|
|
|
|
*/
|
|
|
|
bool handled = m_joystick->handleEvent(event.JoystickEvent);
|
|
|
|
if (handled) {
|
|
|
|
if (m_joystick->wasKeyDown(KeyType::ESC)) {
|
|
|
|
tryClose();
|
|
|
|
} else if (m_joystick->wasKeyDown(KeyType::JUMP)) {
|
|
|
|
if (m_allowclose) {
|
|
|
|
acceptInput(quit_mode_accept);
|
|
|
|
quitMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
2018-06-24 21:50:57 +02:00
|
|
|
return GUIModalMenu::preprocessEvent(event);
|
2014-05-30 03:07:48 +02:00
|
|
|
}
|
|
|
|
|
2016-05-27 08:35:07 +02:00
|
|
|
void GUIFormSpecMenu::tryClose()
|
|
|
|
{
|
|
|
|
if (m_allowclose) {
|
|
|
|
doPause = false;
|
|
|
|
acceptInput(quit_mode_cancel);
|
|
|
|
quitMenu();
|
|
|
|
} else {
|
|
|
|
m_text_dst->gotText(L"MenuQuit");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 11:15:58 +02:00
|
|
|
enum ButtonEventType : u8
|
|
|
|
{
|
|
|
|
BET_LEFT,
|
|
|
|
BET_RIGHT,
|
|
|
|
BET_MIDDLE,
|
|
|
|
BET_WHEEL_UP,
|
|
|
|
BET_WHEEL_DOWN,
|
|
|
|
BET_UP,
|
|
|
|
BET_DOWN,
|
|
|
|
BET_MOVE,
|
|
|
|
BET_OTHER
|
|
|
|
};
|
|
|
|
|
2012-07-15 18:19:38 +02:00
|
|
|
bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
2010-12-22 02:34:21 +01:00
|
|
|
{
|
2015-06-16 20:33:07 +02:00
|
|
|
if (event.EventType==EET_KEY_INPUT_EVENT) {
|
2011-08-13 22:44:31 +02:00
|
|
|
KeyPress kp(event.KeyInput);
|
2017-04-15 07:16:57 +02:00
|
|
|
if (event.KeyInput.PressedDown && (
|
|
|
|
(kp == EscapeKey) || (kp == CancelKey) ||
|
|
|
|
((m_client != NULL) && (kp == getKeySetting("keymap_inventory"))))) {
|
2016-05-27 08:35:07 +02:00
|
|
|
tryClose();
|
2010-12-22 02:34:21 +01:00
|
|
|
return true;
|
2017-08-20 19:37:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_client != NULL && event.KeyInput.PressedDown &&
|
2015-06-16 20:33:07 +02:00
|
|
|
(kp == getKeySetting("keymap_screenshot"))) {
|
2017-06-19 00:00:55 +02:00
|
|
|
m_client->makeScreenshot();
|
2010-12-22 02:34:21 +01:00
|
|
|
}
|
2020-04-12 12:02:32 +02:00
|
|
|
|
|
|
|
if (event.KeyInput.PressedDown && kp == getKeySetting("keymap_toggle_debug"))
|
|
|
|
m_show_debug = !m_show_debug;
|
|
|
|
|
2013-07-07 21:53:40 +02:00
|
|
|
if (event.KeyInput.PressedDown &&
|
|
|
|
(event.KeyInput.Key==KEY_RETURN ||
|
|
|
|
event.KeyInput.Key==KEY_UP ||
|
|
|
|
event.KeyInput.Key==KEY_DOWN)
|
|
|
|
) {
|
|
|
|
switch (event.KeyInput.Key) {
|
|
|
|
case KEY_RETURN:
|
2013-11-23 00:30:16 +01:00
|
|
|
current_keys_pending.key_enter = true;
|
2013-07-07 21:53:40 +02:00
|
|
|
break;
|
|
|
|
case KEY_UP:
|
|
|
|
current_keys_pending.key_up = true;
|
|
|
|
break;
|
|
|
|
case KEY_DOWN:
|
|
|
|
current_keys_pending.key_down = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//can't happen at all!
|
2015-03-06 11:21:51 +01:00
|
|
|
FATAL_ERROR("Reached a source line that can't ever been reached");
|
2013-07-07 21:53:40 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-11-23 00:30:16 +01:00
|
|
|
if (current_keys_pending.key_enter && m_allowclose) {
|
2014-03-04 19:57:39 +01:00
|
|
|
acceptInput(quit_mode_accept);
|
2013-11-23 00:30:16 +01:00
|
|
|
quitMenu();
|
2014-05-30 03:04:10 +02:00
|
|
|
} else {
|
2013-11-23 00:30:16 +01:00
|
|
|
acceptInput();
|
|
|
|
}
|
2012-07-15 18:19:38 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-07-07 21:53:40 +02:00
|
|
|
|
2010-12-22 02:34:21 +01:00
|
|
|
}
|
2014-07-06 16:17:46 +02:00
|
|
|
|
2014-10-08 04:40:14 +02:00
|
|
|
/* Mouse event other than movement, or crossing the border of inventory
|
|
|
|
field while holding right mouse button
|
|
|
|
*/
|
|
|
|
if (event.EventType == EET_MOUSE_INPUT_EVENT &&
|
|
|
|
(event.MouseInput.Event != EMIE_MOUSE_MOVED ||
|
|
|
|
(event.MouseInput.Event == EMIE_MOUSE_MOVED &&
|
|
|
|
event.MouseInput.isRightPressed() &&
|
|
|
|
getItemAtPos(m_pointer).i != getItemAtPos(m_old_pointer).i))) {
|
2011-12-01 10:25:55 +01:00
|
|
|
|
2012-01-21 21:21:41 +01:00
|
|
|
// Get selected item and hovered/clicked item (s)
|
|
|
|
|
2014-06-24 12:28:24 +02:00
|
|
|
m_old_tooltip_id = -1;
|
2012-01-21 21:21:41 +01:00
|
|
|
updateSelectedItem();
|
2020-02-01 13:55:13 +01:00
|
|
|
GUIInventoryList::ItemSpec s = getItemAtPos(m_pointer);
|
2011-12-01 10:32:51 +01:00
|
|
|
|
2012-01-13 12:35:55 +01:00
|
|
|
Inventory *inv_selected = NULL;
|
|
|
|
Inventory *inv_s = NULL;
|
2015-06-16 20:33:07 +02:00
|
|
|
InventoryList *list_s = NULL;
|
2012-01-21 21:21:41 +01:00
|
|
|
|
2015-06-16 20:33:07 +02:00
|
|
|
if (m_selected_item) {
|
2012-01-13 12:35:55 +01:00
|
|
|
inv_selected = m_invmgr->getInventory(m_selected_item->inventoryloc);
|
2015-03-06 11:21:51 +01:00
|
|
|
sanity_check(inv_selected);
|
|
|
|
sanity_check(inv_selected->getList(m_selected_item->listname) != NULL);
|
2012-01-13 12:35:55 +01:00
|
|
|
}
|
2012-01-21 21:21:41 +01:00
|
|
|
|
|
|
|
u32 s_count = 0;
|
|
|
|
|
2015-06-16 20:33:07 +02:00
|
|
|
if (s.isValid())
|
2014-05-30 03:04:10 +02:00
|
|
|
do { // breakable
|
2012-01-13 12:35:55 +01:00
|
|
|
inv_s = m_invmgr->getInventory(s.inventoryloc);
|
2012-06-01 23:33:51 +02:00
|
|
|
|
2015-06-16 20:33:07 +02:00
|
|
|
if (!inv_s) {
|
|
|
|
errorstream << "InventoryMenu: The selected inventory location "
|
|
|
|
<< "\"" << s.inventoryloc.dump() << "\" doesn't exist"
|
|
|
|
<< std::endl;
|
2012-06-01 23:33:51 +02:00
|
|
|
s.i = -1; // make it invalid again
|
|
|
|
break;
|
|
|
|
}
|
2012-01-21 21:21:41 +01:00
|
|
|
|
2015-06-16 20:33:07 +02:00
|
|
|
list_s = inv_s->getList(s.listname);
|
|
|
|
if (list_s == NULL) {
|
|
|
|
verbosestream << "InventoryMenu: The selected inventory list \""
|
|
|
|
<< s.listname << "\" does not exist" << std::endl;
|
2012-06-01 18:33:20 +02:00
|
|
|
s.i = -1; // make it invalid again
|
2012-06-01 23:33:51 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-16 20:33:07 +02:00
|
|
|
if ((u32)s.i >= list_s->getSize()) {
|
|
|
|
infostream << "InventoryMenu: The selected inventory list \""
|
|
|
|
<< s.listname << "\" is too small (i=" << s.i << ", size="
|
|
|
|
<< list_s->getSize() << ")" << std::endl;
|
2012-01-21 21:21:41 +01:00
|
|
|
s.i = -1; // make it invalid again
|
2012-06-01 23:33:51 +02:00
|
|
|
break;
|
2012-06-01 18:33:20 +02:00
|
|
|
}
|
2012-06-01 23:33:51 +02:00
|
|
|
|
2015-06-16 20:33:07 +02:00
|
|
|
s_count = list_s->getItem(s.i).count;
|
2014-05-30 03:04:10 +02:00
|
|
|
} while(0);
|
2012-01-13 12:35:55 +01:00
|
|
|
|
2018-04-03 11:15:58 +02:00
|
|
|
bool identical = m_selected_item && s.isValid() &&
|
2012-01-22 00:49:02 +01:00
|
|
|
(inv_selected == inv_s) &&
|
|
|
|
(m_selected_item->listname == s.listname) &&
|
|
|
|
(m_selected_item->i == s.i);
|
|
|
|
|
2018-04-03 11:15:58 +02:00
|
|
|
ButtonEventType button = BET_LEFT;
|
|
|
|
ButtonEventType updown = BET_OTHER;
|
2018-04-02 16:52:07 +02:00
|
|
|
switch (event.MouseInput.Event) {
|
|
|
|
case EMIE_LMOUSE_PRESSED_DOWN:
|
2018-04-03 11:15:58 +02:00
|
|
|
button = BET_LEFT; updown = BET_DOWN;
|
2018-04-02 16:52:07 +02:00
|
|
|
break;
|
|
|
|
case EMIE_RMOUSE_PRESSED_DOWN:
|
2018-04-03 11:15:58 +02:00
|
|
|
button = BET_RIGHT; updown = BET_DOWN;
|
2018-04-02 16:52:07 +02:00
|
|
|
break;
|
|
|
|
case EMIE_MMOUSE_PRESSED_DOWN:
|
2018-04-03 11:15:58 +02:00
|
|
|
button = BET_MIDDLE; updown = BET_DOWN;
|
2018-04-02 16:52:07 +02:00
|
|
|
break;
|
|
|
|
case EMIE_MOUSE_WHEEL:
|
2018-04-03 11:15:58 +02:00
|
|
|
button = (event.MouseInput.Wheel > 0) ?
|
|
|
|
BET_WHEEL_UP : BET_WHEEL_DOWN;
|
|
|
|
updown = BET_DOWN;
|
2018-04-02 16:52:07 +02:00
|
|
|
break;
|
|
|
|
case EMIE_LMOUSE_LEFT_UP:
|
2018-04-03 11:15:58 +02:00
|
|
|
button = BET_LEFT; updown = BET_UP;
|
2018-04-02 16:52:07 +02:00
|
|
|
break;
|
|
|
|
case EMIE_RMOUSE_LEFT_UP:
|
2018-04-03 11:15:58 +02:00
|
|
|
button = BET_RIGHT; updown = BET_UP;
|
2018-04-02 16:52:07 +02:00
|
|
|
break;
|
|
|
|
case EMIE_MMOUSE_LEFT_UP:
|
2018-04-03 11:15:58 +02:00
|
|
|
button = BET_MIDDLE; updown = BET_UP;
|
2018-04-02 16:52:07 +02:00
|
|
|
break;
|
|
|
|
case EMIE_MOUSE_MOVED:
|
2018-04-03 11:15:58 +02:00
|
|
|
updown = BET_MOVE;
|
2018-04-02 16:52:07 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-01-21 21:21:41 +01:00
|
|
|
|
|
|
|
// Set this number to a positive value to generate a move action
|
|
|
|
// from m_selected_item to s.
|
|
|
|
u32 move_amount = 0;
|
|
|
|
|
2015-06-16 10:48:54 +02:00
|
|
|
// Set this number to a positive value to generate a move action
|
|
|
|
// from s to the next inventory ring.
|
|
|
|
u32 shift_move_amount = 0;
|
|
|
|
|
2012-01-21 21:21:41 +01:00
|
|
|
// Set this number to a positive value to generate a drop action
|
|
|
|
// from m_selected_item.
|
|
|
|
u32 drop_amount = 0;
|
|
|
|
|
|
|
|
// Set this number to a positive value to generate a craft action at s.
|
|
|
|
u32 craft_amount = 0;
|
|
|
|
|
2018-04-03 11:15:58 +02:00
|
|
|
switch (updown) {
|
|
|
|
case BET_DOWN:
|
2012-01-21 21:21:41 +01:00
|
|
|
// Some mouse button has been pressed
|
2012-01-13 12:35:55 +01:00
|
|
|
|
2020-02-01 13:55:13 +01:00
|
|
|
//infostream << "Mouse button " << button << " pressed at p=("
|
|
|
|
// << event.MouseInput.X << "," << event.MouseInput.Y << ")"
|
|
|
|
// << std::endl;
|
2012-01-21 21:21:41 +01:00
|
|
|
|
|
|
|
m_selected_dragging = false;
|
|
|
|
|
2015-06-16 20:33:07 +02:00
|
|
|
if (s.isValid() && s.listname == "craftpreview") {
|
2012-01-21 21:21:41 +01:00
|
|
|
// Craft preview has been clicked: craft
|
2018-04-03 11:15:58 +02:00
|
|
|
craft_amount = (button == BET_MIDDLE ? 10 : 1);
|
|
|
|
} else if (!m_selected_item) {
|
|
|
|
if (s_count && button != BET_WHEEL_UP) {
|
2015-06-16 10:48:54 +02:00
|
|
|
// Non-empty stack has been clicked: select or shift-move it
|
2020-02-01 13:55:13 +01:00
|
|
|
m_selected_item = new GUIInventoryList::ItemSpec(s);
|
2012-01-21 21:21:41 +01:00
|
|
|
|
2015-06-16 10:48:54 +02:00
|
|
|
u32 count;
|
2018-04-03 11:15:58 +02:00
|
|
|
if (button == BET_RIGHT)
|
2015-06-16 10:48:54 +02:00
|
|
|
count = (s_count + 1) / 2;
|
2018-04-03 11:15:58 +02:00
|
|
|
else if (button == BET_MIDDLE)
|
2015-06-16 10:48:54 +02:00
|
|
|
count = MYMIN(s_count, 10);
|
2018-06-20 22:55:39 +02:00
|
|
|
else if (button == BET_WHEEL_DOWN)
|
2018-04-02 16:52:07 +02:00
|
|
|
count = 1;
|
2012-01-21 21:21:41 +01:00
|
|
|
else // left
|
2015-06-16 10:48:54 +02:00
|
|
|
count = s_count;
|
|
|
|
|
2020-12-13 18:25:13 +01:00
|
|
|
if (!event.MouseInput.Shift) {
|
2015-06-16 10:48:54 +02:00
|
|
|
// no shift: select item
|
|
|
|
m_selected_amount = count;
|
2018-04-03 11:15:58 +02:00
|
|
|
m_selected_dragging = button != BET_WHEEL_DOWN;
|
2017-10-17 21:50:58 +02:00
|
|
|
m_auto_place = false;
|
2015-06-16 10:48:54 +02:00
|
|
|
} else {
|
2018-04-02 16:52:07 +02:00
|
|
|
// shift pressed: move item, right click moves 1
|
2018-04-03 11:15:58 +02:00
|
|
|
shift_move_amount = button == BET_RIGHT ? 1 : count;
|
2015-06-16 10:48:54 +02:00
|
|
|
}
|
2010-12-22 15:30:23 +01:00
|
|
|
}
|
2015-06-16 20:33:07 +02:00
|
|
|
} else { // m_selected_item != NULL
|
2012-01-21 21:21:41 +01:00
|
|
|
assert(m_selected_amount >= 1);
|
|
|
|
|
2015-06-16 20:33:07 +02:00
|
|
|
if (s.isValid()) {
|
2012-01-22 00:49:02 +01:00
|
|
|
// Clicked a slot: move
|
2018-04-03 11:15:58 +02:00
|
|
|
if (button == BET_RIGHT || button == BET_WHEEL_UP)
|
2012-01-21 21:21:41 +01:00
|
|
|
move_amount = 1;
|
2018-04-03 11:15:58 +02:00
|
|
|
else if (button == BET_MIDDLE)
|
2012-01-21 21:21:41 +01:00
|
|
|
move_amount = MYMIN(m_selected_amount, 10);
|
2018-04-03 11:15:58 +02:00
|
|
|
else if (button == BET_LEFT)
|
2012-01-21 21:21:41 +01:00
|
|
|
move_amount = m_selected_amount;
|
2018-04-02 16:52:07 +02:00
|
|
|
// else wheeldown
|
2012-01-22 00:49:02 +01:00
|
|
|
|
2015-06-16 20:33:07 +02:00
|
|
|
if (identical) {
|
2018-04-03 11:15:58 +02:00
|
|
|
if (button == BET_WHEEL_DOWN) {
|
2018-04-02 16:52:07 +02:00
|
|
|
if (m_selected_amount < s_count)
|
|
|
|
++m_selected_amount;
|
|
|
|
} else {
|
|
|
|
if (move_amount >= m_selected_amount)
|
|
|
|
m_selected_amount = 0;
|
|
|
|
else
|
|
|
|
m_selected_amount -= move_amount;
|
|
|
|
move_amount = 0;
|
|
|
|
}
|
2012-01-22 00:49:02 +01:00
|
|
|
}
|
2018-04-03 11:15:58 +02:00
|
|
|
} else if (!getAbsoluteClippingRect().isPointInside(m_pointer)
|
|
|
|
&& button != BET_WHEEL_DOWN) {
|
2012-01-21 21:21:41 +01:00
|
|
|
// Clicked outside of the window: drop
|
2018-04-03 11:15:58 +02:00
|
|
|
if (button == BET_RIGHT || button == BET_WHEEL_UP)
|
2012-01-21 21:21:41 +01:00
|
|
|
drop_amount = 1;
|
2018-04-03 11:15:58 +02:00
|
|
|
else if (button == BET_MIDDLE)
|
2012-01-21 21:21:41 +01:00
|
|
|
drop_amount = MYMIN(m_selected_amount, 10);
|
|
|
|
else // left
|
|
|
|
drop_amount = m_selected_amount;
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 11:15:58 +02:00
|
|
|
break;
|
|
|
|
case BET_UP:
|
2012-01-21 21:21:41 +01:00
|
|
|
// Some mouse button has been released
|
|
|
|
|
|
|
|
//infostream<<"Mouse button "<<button<<" released at p=("
|
|
|
|
// <<p.X<<","<<p.Y<<")"<<std::endl;
|
|
|
|
|
2018-04-03 11:15:58 +02:00
|
|
|
if (m_selected_dragging && m_selected_item) {
|
2018-04-02 16:52:07 +02:00
|
|
|
if (s.isValid()) {
|
|
|
|
if (!identical) {
|
|
|
|
// Dragged to different slot: move all selected
|
|
|
|
move_amount = m_selected_amount;
|
|
|
|
}
|
|
|
|
} else if (!getAbsoluteClippingRect().isPointInside(m_pointer)) {
|
|
|
|
// Dragged outside of window: drop all selected
|
|
|
|
drop_amount = m_selected_amount;
|
2010-12-22 15:30:23 +01:00
|
|
|
}
|
2012-01-21 21:21:41 +01:00
|
|
|
}
|
2012-01-13 12:35:55 +01:00
|
|
|
|
2012-01-21 21:21:41 +01:00
|
|
|
m_selected_dragging = false;
|
2017-10-17 21:50:58 +02:00
|
|
|
// Keep track of whether the mouse button be released
|
|
|
|
// One click is drag without dropping. Click + release
|
|
|
|
// + click changes to drop item when moved mode
|
|
|
|
if (m_selected_item)
|
|
|
|
m_auto_place = true;
|
2018-04-03 11:15:58 +02:00
|
|
|
break;
|
|
|
|
case BET_MOVE:
|
2014-09-19 15:27:48 +02:00
|
|
|
// Mouse has been moved and rmb is down and mouse pointer just
|
|
|
|
// entered a new inventory field (checked in the entry-if, this
|
|
|
|
// is the only action here that is generated by mouse movement)
|
2019-05-25 17:37:54 +02:00
|
|
|
if (m_selected_item && s.isValid() && s.listname != "craftpreview") {
|
2014-09-19 15:27:48 +02:00
|
|
|
// Move 1 item
|
|
|
|
// TODO: middle mouse to move 10 items might be handy
|
2017-10-17 21:50:58 +02:00
|
|
|
if (m_auto_place) {
|
2014-10-09 09:53:20 +02:00
|
|
|
// Only move an item if the destination slot is empty
|
|
|
|
// or contains the same item type as what is going to be
|
|
|
|
// moved
|
|
|
|
InventoryList *list_from = inv_selected->getList(m_selected_item->listname);
|
2015-06-16 20:33:07 +02:00
|
|
|
InventoryList *list_to = list_s;
|
2014-10-09 09:53:20 +02:00
|
|
|
assert(list_from && list_to);
|
|
|
|
ItemStack stack_from = list_from->getItem(m_selected_item->i);
|
|
|
|
ItemStack stack_to = list_to->getItem(s.i);
|
|
|
|
if (stack_to.empty() || stack_to.name == stack_from.name)
|
|
|
|
move_amount = 1;
|
|
|
|
}
|
2014-09-19 15:27:48 +02:00
|
|
|
}
|
2018-04-03 11:15:58 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2014-09-19 15:27:48 +02:00
|
|
|
}
|
2012-01-21 21:21:41 +01:00
|
|
|
|
|
|
|
// Possibly send inventory action to server
|
2015-06-16 10:48:54 +02:00
|
|
|
if (move_amount > 0) {
|
2017-07-01 14:07:40 +02:00
|
|
|
// Send IAction::Move
|
2012-01-21 21:21:41 +01:00
|
|
|
|
|
|
|
assert(m_selected_item && m_selected_item->isValid());
|
|
|
|
assert(s.isValid());
|
|
|
|
|
|
|
|
assert(inv_selected && inv_s);
|
|
|
|
InventoryList *list_from = inv_selected->getList(m_selected_item->listname);
|
2015-06-16 20:33:07 +02:00
|
|
|
InventoryList *list_to = list_s;
|
2012-01-21 21:21:41 +01:00
|
|
|
assert(list_from && list_to);
|
|
|
|
ItemStack stack_from = list_from->getItem(m_selected_item->i);
|
|
|
|
ItemStack stack_to = list_to->getItem(s.i);
|
|
|
|
|
|
|
|
// Check how many items can be moved
|
|
|
|
move_amount = stack_from.count = MYMIN(move_amount, stack_from.count);
|
2017-01-09 20:39:22 +01:00
|
|
|
ItemStack leftover = stack_to.addItem(stack_from, m_client->idef());
|
2018-04-03 11:15:58 +02:00
|
|
|
bool move = true;
|
2012-09-02 21:51:38 +02:00
|
|
|
// If source stack cannot be added to destination stack at all,
|
|
|
|
// they are swapped
|
2018-04-03 11:15:58 +02:00
|
|
|
if (leftover.count == stack_from.count &&
|
|
|
|
leftover.name == stack_from.name) {
|
|
|
|
|
|
|
|
if (m_selected_swap.empty()) {
|
|
|
|
m_selected_amount = stack_to.count;
|
|
|
|
m_selected_dragging = false;
|
|
|
|
|
|
|
|
// WARNING: BLACK MAGIC, BUT IN A REDUCED SET
|
|
|
|
// Skip next validation checks due async inventory calls
|
|
|
|
m_selected_swap = stack_to;
|
|
|
|
} else {
|
|
|
|
move = false;
|
|
|
|
}
|
2012-01-21 21:21:41 +01:00
|
|
|
}
|
2012-09-02 21:51:38 +02:00
|
|
|
// Source stack goes fully into destination stack
|
2015-06-16 20:33:07 +02:00
|
|
|
else if (leftover.empty()) {
|
2012-01-22 00:49:02 +01:00
|
|
|
m_selected_amount -= move_amount;
|
2012-01-21 21:21:41 +01:00
|
|
|
}
|
2012-09-02 21:51:38 +02:00
|
|
|
// Source stack goes partly into destination stack
|
2014-05-30 03:04:10 +02:00
|
|
|
else {
|
2012-01-21 21:21:41 +01:00
|
|
|
move_amount -= leftover.count;
|
2012-01-22 00:49:02 +01:00
|
|
|
m_selected_amount -= move_amount;
|
2012-01-13 12:35:55 +01:00
|
|
|
}
|
2012-01-21 21:21:41 +01:00
|
|
|
|
2018-04-03 11:15:58 +02:00
|
|
|
if (move) {
|
|
|
|
infostream << "Handing IAction::Move to manager" << std::endl;
|
|
|
|
IMoveAction *a = new IMoveAction();
|
|
|
|
a->count = move_amount;
|
|
|
|
a->from_inv = m_selected_item->inventoryloc;
|
|
|
|
a->from_list = m_selected_item->listname;
|
|
|
|
a->from_i = m_selected_item->i;
|
|
|
|
a->to_inv = s.inventoryloc;
|
|
|
|
a->to_list = s.listname;
|
|
|
|
a->to_i = s.i;
|
|
|
|
m_invmgr->inventoryAction(a);
|
|
|
|
}
|
2015-06-16 10:48:54 +02:00
|
|
|
} else if (shift_move_amount > 0) {
|
|
|
|
u32 mis = m_inventory_rings.size();
|
|
|
|
u32 i = 0;
|
|
|
|
for (; i < mis; i++) {
|
|
|
|
const ListRingSpec &sp = m_inventory_rings[i];
|
|
|
|
if (sp.inventoryloc == s.inventoryloc
|
|
|
|
&& sp.listname == s.listname)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
if (i >= mis) // if not found
|
|
|
|
break;
|
|
|
|
u32 to_inv_ind = (i + 1) % mis;
|
|
|
|
const ListRingSpec &to_inv_sp = m_inventory_rings[to_inv_ind];
|
2015-06-16 20:33:07 +02:00
|
|
|
InventoryList *list_from = list_s;
|
|
|
|
if (!s.isValid())
|
2015-06-16 10:48:54 +02:00
|
|
|
break;
|
|
|
|
Inventory *inv_to = m_invmgr->getInventory(to_inv_sp.inventoryloc);
|
|
|
|
if (!inv_to)
|
|
|
|
break;
|
|
|
|
InventoryList *list_to = inv_to->getList(to_inv_sp.listname);
|
|
|
|
if (!list_to)
|
|
|
|
break;
|
|
|
|
ItemStack stack_from = list_from->getItem(s.i);
|
|
|
|
assert(shift_move_amount <= stack_from.count);
|
2018-04-03 11:15:58 +02:00
|
|
|
|
|
|
|
infostream << "Handing IAction::Move to manager" << std::endl;
|
|
|
|
IMoveAction *a = new IMoveAction();
|
|
|
|
a->count = shift_move_amount;
|
|
|
|
a->from_inv = s.inventoryloc;
|
|
|
|
a->from_list = s.listname;
|
|
|
|
a->from_i = s.i;
|
|
|
|
a->to_inv = to_inv_sp.inventoryloc;
|
|
|
|
a->to_list = to_inv_sp.listname;
|
|
|
|
a->move_somewhere = true;
|
|
|
|
m_invmgr->inventoryAction(a);
|
2015-06-16 10:48:54 +02:00
|
|
|
} while (0);
|
|
|
|
} else if (drop_amount > 0) {
|
2017-07-01 14:07:40 +02:00
|
|
|
// Send IAction::Drop
|
2012-01-21 21:21:41 +01:00
|
|
|
|
|
|
|
assert(m_selected_item && m_selected_item->isValid());
|
|
|
|
assert(inv_selected);
|
|
|
|
InventoryList *list_from = inv_selected->getList(m_selected_item->listname);
|
|
|
|
assert(list_from);
|
|
|
|
ItemStack stack_from = list_from->getItem(m_selected_item->i);
|
|
|
|
|
|
|
|
// Check how many items can be dropped
|
|
|
|
drop_amount = stack_from.count = MYMIN(drop_amount, stack_from.count);
|
|
|
|
assert(drop_amount > 0 && drop_amount <= m_selected_amount);
|
|
|
|
m_selected_amount -= drop_amount;
|
|
|
|
|
2017-07-01 14:07:40 +02:00
|
|
|
infostream << "Handing IAction::Drop to manager" << std::endl;
|
2012-01-21 21:21:41 +01:00
|
|
|
IDropAction *a = new IDropAction();
|
|
|
|
a->count = drop_amount;
|
|
|
|
a->from_inv = m_selected_item->inventoryloc;
|
|
|
|
a->from_list = m_selected_item->listname;
|
|
|
|
a->from_i = m_selected_item->i;
|
|
|
|
m_invmgr->inventoryAction(a);
|
2015-06-16 20:33:07 +02:00
|
|
|
} else if (craft_amount > 0) {
|
2012-01-21 21:21:41 +01:00
|
|
|
assert(s.isValid());
|
2018-01-03 17:28:57 +01:00
|
|
|
|
2017-12-06 17:32:05 +01:00
|
|
|
// if there are no items selected or the selected item
|
|
|
|
// belongs to craftresult list, proceed with crafting
|
2020-02-01 13:55:13 +01:00
|
|
|
if (!m_selected_item ||
|
2017-12-06 17:32:05 +01:00
|
|
|
!m_selected_item->isValid() || m_selected_item->listname == "craftresult") {
|
2018-01-03 17:28:57 +01:00
|
|
|
|
2017-12-06 17:32:05 +01:00
|
|
|
assert(inv_s);
|
|
|
|
|
|
|
|
// Send IACTION_CRAFT
|
|
|
|
infostream << "Handing IACTION_CRAFT to manager" << std::endl;
|
|
|
|
ICraftAction *a = new ICraftAction();
|
|
|
|
a->count = craft_amount;
|
|
|
|
a->craft_inv = s.inventoryloc;
|
|
|
|
m_invmgr->inventoryAction(a);
|
|
|
|
}
|
2012-01-21 21:21:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// If m_selected_amount has been decreased to zero, deselect
|
2015-06-16 20:33:07 +02:00
|
|
|
if (m_selected_amount == 0) {
|
2018-04-03 11:15:58 +02:00
|
|
|
m_selected_swap.clear();
|
2012-01-21 21:21:41 +01:00
|
|
|
delete m_selected_item;
|
2020-02-01 13:55:13 +01:00
|
|
|
m_selected_item = nullptr;
|
2012-01-22 00:49:02 +01:00
|
|
|
m_selected_amount = 0;
|
2012-01-21 21:21:41 +01:00
|
|
|
m_selected_dragging = false;
|
2010-12-22 02:34:21 +01:00
|
|
|
}
|
2014-09-19 15:27:48 +02:00
|
|
|
m_old_pointer = m_pointer;
|
2010-12-22 02:34:21 +01:00
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2019-09-10 15:11:26 +02:00
|
|
|
if (event.EventType == EET_GUI_EVENT) {
|
2015-06-16 20:33:07 +02:00
|
|
|
if (event.GUIEvent.EventType == gui::EGET_TAB_CHANGED
|
2014-05-30 03:04:10 +02:00
|
|
|
&& isVisible()) {
|
2013-06-23 18:30:21 +02:00
|
|
|
// find the element that was clicked
|
2017-08-20 19:37:29 +02:00
|
|
|
for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
|
2014-05-30 03:04:10 +02:00
|
|
|
if ((s.ftype == f_TabHeader) &&
|
|
|
|
(s.fid == event.GUIEvent.Caller->getID())) {
|
2020-09-16 17:10:17 +02:00
|
|
|
if (!s.sound.empty() && m_sound_manager)
|
2022-07-10 15:34:53 +02:00
|
|
|
m_sound_manager->playSound(SimpleSoundSpec(s.sound, 1.0f));
|
2013-06-23 18:30:21 +02:00
|
|
|
s.send = true;
|
|
|
|
acceptInput();
|
|
|
|
s.send = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-16 20:33:07 +02:00
|
|
|
if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST
|
2014-05-30 03:04:10 +02:00
|
|
|
&& isVisible()) {
|
2015-06-16 20:33:07 +02:00
|
|
|
if (!canTakeFocus(event.GUIEvent.Element)) {
|
2012-07-15 18:19:38 +02:00
|
|
|
infostream<<"GUIFormSpecMenu: Not allowing focus change."
|
2010-12-22 02:34:21 +01:00
|
|
|
<<std::endl;
|
|
|
|
// Returning true disables focus change
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-06-16 20:33:07 +02:00
|
|
|
if ((event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) ||
|
2014-06-14 12:27:56 +02:00
|
|
|
(event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED) ||
|
2014-06-19 18:17:35 +02:00
|
|
|
(event.GUIEvent.EventType == gui::EGET_COMBO_BOX_CHANGED) ||
|
|
|
|
(event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED)) {
|
2020-02-11 19:53:09 +01:00
|
|
|
s32 caller_id = event.GUIEvent.Caller->getID();
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2020-02-11 19:53:09 +01:00
|
|
|
if (caller_id == 257) {
|
2013-10-26 09:56:38 +02:00
|
|
|
if (m_allowclose) {
|
2014-03-04 19:57:39 +01:00
|
|
|
acceptInput(quit_mode_accept);
|
2013-06-23 18:30:21 +02:00
|
|
|
quitMenu();
|
2013-10-26 09:56:38 +02:00
|
|
|
} else {
|
|
|
|
acceptInput();
|
2015-06-10 01:54:33 +02:00
|
|
|
m_text_dst->gotText(L"ExitButton");
|
2013-10-26 09:56:38 +02:00
|
|
|
}
|
2012-07-15 18:19:38 +02:00
|
|
|
// quitMenu deallocates menu
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2012-07-15 18:19:38 +02:00
|
|
|
// find the element that was clicked
|
2017-08-20 19:37:29 +02:00
|
|
|
for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
|
2013-12-11 23:07:38 +01:00
|
|
|
// if its a button, set the send field so
|
2012-07-15 18:19:38 +02:00
|
|
|
// lua knows which button was pressed
|
2020-02-11 19:53:09 +01:00
|
|
|
|
|
|
|
if (caller_id != s.fid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (s.ftype == f_Button || s.ftype == f_CheckBox) {
|
2020-09-16 17:10:17 +02:00
|
|
|
if (!s.sound.empty() && m_sound_manager)
|
2022-07-10 15:34:53 +02:00
|
|
|
m_sound_manager->playSound(SimpleSoundSpec(s.sound, 1.0f));
|
2020-09-16 17:10:17 +02:00
|
|
|
|
2012-07-15 18:19:38 +02:00
|
|
|
s.send = true;
|
2015-06-16 20:33:07 +02:00
|
|
|
if (s.is_exit) {
|
2013-10-26 09:56:38 +02:00
|
|
|
if (m_allowclose) {
|
2014-03-04 19:57:39 +01:00
|
|
|
acceptInput(quit_mode_accept);
|
2013-06-23 18:30:21 +02:00
|
|
|
quitMenu();
|
2013-10-26 09:56:38 +02:00
|
|
|
} else {
|
2015-06-10 01:54:33 +02:00
|
|
|
m_text_dst->gotText(L"ExitButton");
|
2013-10-26 09:56:38 +02:00
|
|
|
}
|
2012-07-22 16:28:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
2017-08-20 19:37:29 +02:00
|
|
|
|
|
|
|
acceptInput(quit_mode_no);
|
|
|
|
s.send = false;
|
|
|
|
return true;
|
|
|
|
|
2020-02-11 19:53:09 +01:00
|
|
|
} else if (s.ftype == f_DropDown) {
|
2014-06-14 12:27:56 +02:00
|
|
|
// only send the changed dropdown
|
2017-08-20 19:37:29 +02:00
|
|
|
for (GUIFormSpecMenu::FieldSpec &s2 : m_fields) {
|
2014-06-14 12:27:56 +02:00
|
|
|
if (s2.ftype == f_DropDown) {
|
|
|
|
s2.send = false;
|
|
|
|
}
|
|
|
|
}
|
2020-09-16 17:10:17 +02:00
|
|
|
if (!s.sound.empty() && m_sound_manager)
|
2022-07-10 15:34:53 +02:00
|
|
|
m_sound_manager->playSound(SimpleSoundSpec(s.sound, 1.0f));
|
2014-06-14 12:27:56 +02:00
|
|
|
s.send = true;
|
|
|
|
acceptInput(quit_mode_no);
|
|
|
|
|
|
|
|
// revert configuration to make sure dropdowns are sent on
|
|
|
|
// regular button click
|
2017-08-20 19:37:29 +02:00
|
|
|
for (GUIFormSpecMenu::FieldSpec &s2 : m_fields) {
|
2014-06-14 12:27:56 +02:00
|
|
|
if (s2.ftype == f_DropDown) {
|
|
|
|
s2.send = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2020-02-11 19:53:09 +01:00
|
|
|
} else if (s.ftype == f_ScrollBar) {
|
2014-06-19 18:17:35 +02:00
|
|
|
s.fdefault = L"Changed";
|
|
|
|
acceptInput(quit_mode_no);
|
|
|
|
s.fdefault = L"";
|
2020-02-11 19:53:09 +01:00
|
|
|
} else if (s.ftype == f_Unknown || s.ftype == f_HyperText) {
|
2020-09-16 17:10:17 +02:00
|
|
|
if (!s.sound.empty() && m_sound_manager)
|
2022-07-10 15:34:53 +02:00
|
|
|
m_sound_manager->playSound(SimpleSoundSpec(s.sound, 1.0f));
|
2019-09-10 15:11:26 +02:00
|
|
|
s.send = true;
|
|
|
|
acceptInput();
|
|
|
|
s.send = false;
|
2014-06-19 18:17:35 +02:00
|
|
|
}
|
2012-07-15 18:19:38 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-19 18:17:35 +02:00
|
|
|
|
2020-04-13 10:50:07 +02:00
|
|
|
if (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED) {
|
|
|
|
// move scroll_containers
|
|
|
|
for (const std::pair<std::string, GUIScrollContainer *> &c : m_scroll_containers)
|
|
|
|
c.second->onScrollEvent(event.GUIEvent.Caller);
|
|
|
|
}
|
|
|
|
|
2015-06-16 20:33:07 +02:00
|
|
|
if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
|
|
|
|
if (event.GUIEvent.Caller->getID() > 257) {
|
2016-08-07 17:22:50 +02:00
|
|
|
bool close_on_enter = true;
|
2017-08-20 19:37:29 +02:00
|
|
|
for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
|
2016-08-07 17:01:00 +02:00
|
|
|
if (s.ftype == f_Unknown &&
|
|
|
|
s.fid == event.GUIEvent.Caller->getID()) {
|
|
|
|
current_field_enter_pending = s.fname;
|
2017-06-04 21:00:04 +02:00
|
|
|
std::unordered_map<std::string, bool>::const_iterator it =
|
2016-10-03 01:30:33 +02:00
|
|
|
field_close_on_enter.find(s.fname);
|
|
|
|
if (it != field_close_on_enter.end())
|
|
|
|
close_on_enter = (*it).second;
|
|
|
|
|
2016-08-07 17:22:50 +02:00
|
|
|
break;
|
2016-08-07 17:01:00 +02:00
|
|
|
}
|
|
|
|
}
|
2013-07-07 21:53:40 +02:00
|
|
|
|
2016-08-07 17:22:50 +02:00
|
|
|
if (m_allowclose && close_on_enter) {
|
2016-08-07 17:01:00 +02:00
|
|
|
current_keys_pending.key_enter = true;
|
2014-03-04 19:57:39 +01:00
|
|
|
acceptInput(quit_mode_accept);
|
2013-06-23 18:30:21 +02:00
|
|
|
quitMenu();
|
2014-05-30 03:04:10 +02:00
|
|
|
} else {
|
2013-07-07 21:53:40 +02:00
|
|
|
current_keys_pending.key_enter = true;
|
|
|
|
acceptInput();
|
|
|
|
}
|
2012-07-15 18:19:38 +02:00
|
|
|
// quitMenu deallocates menu
|
|
|
|
return true;
|
|
|
|
}
|
2010-12-22 02:34:21 +01:00
|
|
|
}
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2015-06-16 20:33:07 +02:00
|
|
|
if (event.GUIEvent.EventType == gui::EGET_TABLE_CHANGED) {
|
2013-06-23 18:30:21 +02:00
|
|
|
int current_id = event.GUIEvent.Caller->getID();
|
2015-06-16 20:33:07 +02:00
|
|
|
if (current_id > 257) {
|
2013-06-23 18:30:21 +02:00
|
|
|
// find the element that was clicked
|
2017-08-20 19:37:29 +02:00
|
|
|
for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
|
2013-08-23 12:24:11 +02:00
|
|
|
// if it's a table, set the send field
|
|
|
|
// so lua knows which table was changed
|
2014-05-30 03:04:10 +02:00
|
|
|
if ((s.ftype == f_Table) && (s.fid == current_id)) {
|
2013-06-23 18:30:21 +02:00
|
|
|
s.send = true;
|
2013-08-15 21:46:55 +02:00
|
|
|
acceptInput();
|
2013-06-23 18:30:21 +02:00
|
|
|
s.send=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-12-22 02:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Parent ? Parent->OnEvent(event) : false;
|
|
|
|
}
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
/**
|
|
|
|
* get name of element by element id
|
|
|
|
* @param id of element
|
|
|
|
* @return name string or empty string
|
|
|
|
*/
|
2015-06-10 01:54:33 +02:00
|
|
|
std::string GUIFormSpecMenu::getNameByID(s32 id)
|
2014-04-21 14:10:59 +02:00
|
|
|
{
|
2017-08-20 19:37:29 +02:00
|
|
|
for (FieldSpec &spec : m_fields) {
|
2019-11-07 20:11:01 +01:00
|
|
|
if (spec.fid == id)
|
2017-08-20 19:37:29 +02:00
|
|
|
return spec.fname;
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
2015-06-10 01:54:33 +02:00
|
|
|
return "";
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
|
2019-11-07 20:11:01 +01:00
|
|
|
|
2019-11-20 19:39:10 +01:00
|
|
|
const GUIFormSpecMenu::FieldSpec *GUIFormSpecMenu::getSpecByID(s32 id)
|
2019-11-07 20:11:01 +01:00
|
|
|
{
|
|
|
|
for (FieldSpec &spec : m_fields) {
|
|
|
|
if (spec.fid == id)
|
2019-11-20 19:39:10 +01:00
|
|
|
return &spec;
|
2019-11-07 20:11:01 +01:00
|
|
|
}
|
2019-11-20 19:39:10 +01:00
|
|
|
return nullptr;
|
2019-11-07 20:11:01 +01:00
|
|
|
}
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
/**
|
|
|
|
* get label of element by id
|
|
|
|
* @param id of element
|
|
|
|
* @return label string or empty string
|
|
|
|
*/
|
|
|
|
std::wstring GUIFormSpecMenu::getLabelByID(s32 id)
|
|
|
|
{
|
2017-08-20 19:37:29 +02:00
|
|
|
for (FieldSpec &spec : m_fields) {
|
2019-11-07 20:11:01 +01:00
|
|
|
if (spec.fid == id)
|
2017-08-20 19:37:29 +02:00
|
|
|
return spec.flabel;
|
2014-04-21 14:10:59 +02:00
|
|
|
}
|
|
|
|
return L"";
|
|
|
|
}
|
2019-03-15 20:03:12 +01:00
|
|
|
|
2020-04-11 22:39:30 +02:00
|
|
|
StyleSpec GUIFormSpecMenu::getDefaultStyleForElement(const std::string &type,
|
2019-03-16 22:38:36 +01:00
|
|
|
const std::string &name, const std::string &parent_type) {
|
2020-04-11 22:39:30 +02:00
|
|
|
return getStyleForElement(type, name, parent_type)[StyleSpec::STATE_DEFAULT];
|
|
|
|
}
|
|
|
|
|
2020-05-06 19:36:02 +02:00
|
|
|
std::array<StyleSpec, StyleSpec::NUM_STATES> GUIFormSpecMenu::getStyleForElement(
|
|
|
|
const std::string &type, const std::string &name, const std::string &parent_type)
|
2020-04-11 22:39:30 +02:00
|
|
|
{
|
|
|
|
std::array<StyleSpec, StyleSpec::NUM_STATES> ret;
|
2019-03-15 20:03:12 +01:00
|
|
|
|
2020-05-06 19:36:02 +02:00
|
|
|
auto it = theme_by_type.find("*");
|
|
|
|
if (it != theme_by_type.end()) {
|
|
|
|
for (const StyleSpec &spec : it->second)
|
|
|
|
ret[(u32)spec.getState()] |= spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
it = theme_by_name.find("*");
|
|
|
|
if (it != theme_by_name.end()) {
|
|
|
|
for (const StyleSpec &spec : it->second)
|
|
|
|
ret[(u32)spec.getState()] |= spec;
|
|
|
|
}
|
|
|
|
|
2019-03-16 22:38:36 +01:00
|
|
|
if (!parent_type.empty()) {
|
2020-05-06 19:36:02 +02:00
|
|
|
it = theme_by_type.find(parent_type);
|
2019-03-16 22:38:36 +01:00
|
|
|
if (it != theme_by_type.end()) {
|
2020-04-11 22:39:30 +02:00
|
|
|
for (const StyleSpec &spec : it->second)
|
|
|
|
ret[(u32)spec.getState()] |= spec;
|
2019-03-16 22:38:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 19:36:02 +02:00
|
|
|
it = theme_by_type.find(type);
|
2019-03-15 20:03:12 +01:00
|
|
|
if (it != theme_by_type.end()) {
|
2020-04-11 22:39:30 +02:00
|
|
|
for (const StyleSpec &spec : it->second)
|
|
|
|
ret[(u32)spec.getState()] |= spec;
|
2019-03-15 20:03:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
it = theme_by_name.find(name);
|
|
|
|
if (it != theme_by_name.end()) {
|
2020-04-11 22:39:30 +02:00
|
|
|
for (const StyleSpec &spec : it->second)
|
|
|
|
ret[(u32)spec.getState()] |= spec;
|
2019-03-15 20:03:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|