Skip to content

Commit 88d43af

Browse files
sapierkwolekr
sapier
authored andcommittedJul 7, 2013
Fix many formspec menu bugs
1 parent 7e73b7c commit 88d43af

13 files changed

+374
-113
lines changed
 

Diff for: ‎builtin/mainmenu.lua

+218-52
Large diffs are not rendered by default.

Diff for: ‎builtin/mainmenu_helper.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ function fs_escape_string(text)
7777
text = newtext
7878
end
7979

80-
text = text:gsub("%[","%[%[")
81-
text = text:gsub("]","]]")
82-
text = text:gsub(";"," ")
80+
text = text:gsub("%[","\\%[")
81+
text = text:gsub("]","\\]")
82+
text = text:gsub(";","\\;")
8383
end
8484
return text
8585
end

Diff for: ‎builtin/modmgr.lua

+12-7
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,20 @@ function modmgr.dialog_configure_world()
399399
local worldmodidx = modmgr.get_worldmod_idx()
400400
modname = modmgr.global_mods[worldmodidx]
401401

402-
if modname:find("<MODPACK>") ~= nil then
403-
modname = modname:sub(0,modname:find("<") -2)
404-
modpack_selected = true
405-
end
402+
if modname ~= nil then
403+
404+
if modname:find("<MODPACK>") ~= nil then
405+
modname = modname:sub(0,modname:find("<") -2)
406+
modpack_selected = true
407+
end
406408

407-
local parts = modmgr.global_mods[worldmodidx]:split(DIR_DELIM)
408-
shortname = parts[#parts]
409+
local parts = modmgr.global_mods[worldmodidx]:split(DIR_DELIM)
410+
shortname = parts[#parts]
409411

410-
modfolder = engine.get_modpath() .. DIR_DELIM .. modname
412+
modfolder = engine.get_modpath() .. DIR_DELIM .. modname
413+
else
414+
modname = ""
415+
end
411416
end
412417

413418
local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]

Diff for: ‎builtin/modstore.lua

+1
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,4 @@ function modstore.get_details(modid)
273273
modstore.details_cache[modid] = retval
274274
return retval
275275
end
276+

Diff for: ‎doc/lua_api.txt

+23-2
Original file line numberDiff line numberDiff line change
@@ -960,11 +960,21 @@ textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>]
960960
^Scrollabel itemlist showing arbitrary text elements
961961
^ x and y position the itemlist relative to the top left of the menu
962962
^ w and h are the size of the itemlist
963-
^ listelements can be prepended by #RRGGBB in hexadecimal format
963+
^ name fieldname sent to server on doubleclick value is current selected element
964+
^ listelements can be prepended by #colorkey (see colorkeys),
964965
^ if you want a listelement to start with # write ##
966+
967+
textlist[<X>,<Y>;<W>,<H>;<name>;<listelem 1>,<listelem 2>,...,<listelem n>;<selected idx>;<transparent>]
968+
^Scrollabel itemlist showing arbitrary text elements
969+
^ x and y position the itemlist relative to the top left of the menu
970+
^ w and h are the size of the itemlist
965971
^ name fieldname sent to server on doubleclick value is current selected element
972+
^ listelements can be prepended by #RRGGBB in hexadecimal format
973+
^ if you want a listelement to start with # write ##
974+
^ index to be selected within textlist
975+
^ true/false draw transparent background
966976

967-
tabheader[<X>,<Y>;<name>;<caption 1>,<caption 2>;<current_tab>;<transparent>;<draw_border>]
977+
tabheader[<X>,<Y>;<name>;<caption 1>,<caption 2>,...,<caption n>;<current_tab>;<transparent>;<draw_border>]
968978
^ show a tabHEADER at specific position (ignores formsize)
969979
^ x and y position the itemlist relative to the top left of the menu
970980
^ name fieldname data is transfered to lua
@@ -977,8 +987,19 @@ box[<X>,<Y>;<W>,<H>;<color>]
977987
^ simple colored semitransparent box
978988
^ x and y position the box relative to the top left of the menu
979989
^ w and h are the size of box
990+
^ colorkey (see colorkeys)
991+
992+
dropdown[<X>,<Y>;<W>;<name>;<item 1>,<item 2>, ...,<item n>;<selected idx>]
993+
^ show a dropdown field
994+
^ x and y position of dropdown
995+
^ width of dropdown
996+
^ fieldname data is transfered to lua
997+
^ items to be shown in dropdown
998+
^ index of currently selected dropdown item
980999
^ color in hexadecimal format RRGGBB
9811000

1001+
Note: do NOT use a element name starting with "key_" those names are reserved to
1002+
pass key press events to formspec!
9821003

9831004
Inventory location:
9841005

Diff for: ‎src/defaultsettings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ void set_default_settings(Settings *settings)
126126
settings->setDefault("bilinear_filter", "false");
127127
settings->setDefault("trilinear_filter", "false");
128128
settings->setDefault("preload_item_visuals", "true");
129-
settings->setDefault("enable_shaders", "2");
130129
settings->setDefault("enable_bumpmapping", "false");
130+
settings->setDefault("enable_shaders", "true");
131131
settings->setDefault("repeat_rightclick_time", "0.25");
132132
settings->setDefault("enable_particles", "true");
133133

Diff for: ‎src/environment.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void Environment::printPlayers(std::ostream &o)
204204

205205
u32 Environment::getDayNightRatio()
206206
{
207-
bool smooth = (g_settings->getS32("enable_shaders") != 0);
207+
bool smooth = g_settings->getBool("enable_shaders");
208208
return time_to_daynight_ratio(m_time_of_day_f*24000, smooth);
209209
}
210210

Diff for: ‎src/guiEngine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
182182
errorstream
183183
<< "GUIEngine::GUIEngine unable to load builtin menu"
184184
<< std::endl;
185-
return;
185+
assert("no future without mainmenu" == 0);
186186
}
187187
}
188188

Diff for: ‎src/guiFormSpecMenu.cpp

+96-36
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
171171
m_use_gettext(false),
172172
m_lock(false)
173173
{
174+
current_keys_pending.key_down = false;
175+
current_keys_pending.key_up = false;
176+
current_keys_pending.key_enter = false;
177+
174178
}
175179

176180
GUIFormSpecMenu::~GUIFormSpecMenu()
@@ -243,28 +247,25 @@ std::vector<std::string> split(const std::string &s, char delim, bool escape=fal
243247
else {
244248
std::string current = "";
245249
current += s.c_str()[0];
246-
bool last_was_delim = false;
250+
bool last_was_escape = false;
247251
for(unsigned int i=1; i < s.size(); i++) {
248-
if (last_was_delim) {
252+
if (last_was_escape) {
253+
current += '\\';
254+
current += s.c_str()[i];
255+
last_was_escape = false;
256+
}
257+
else {
249258
if (s.c_str()[i] == delim) {
250-
current += s.c_str()[i];
251-
last_was_delim = false;
252-
}
253-
else {
254259
tokens.push_back(current);
255-
256260
current = "";
257-
current += s.c_str()[i];
258-
last_was_delim = false;
261+
last_was_escape = false;
259262
}
260-
}
261-
else {
262-
if (s.c_str()[i] == delim) {
263-
last_was_delim = true;
263+
else if (s.c_str()[i] == '\\'){
264+
last_was_escape = true;
264265
}
265266
else {
266-
last_was_delim = false;
267267
current += s.c_str()[i];
268+
last_was_escape = false;
268269
}
269270
}
270271
}
@@ -659,32 +660,34 @@ void GUIFormSpecMenu::parseTextList(parserData* data,std::string element) {
659660
for (unsigned int i=0; i < items.size(); i++) {
660661
if (items[i].c_str()[0] == '#') {
661662
if (items[i].c_str()[1] == '#') {
662-
e->addItem(narrow_to_wide(items[i]).c_str() +1);
663+
e->addItem(narrow_to_wide(unescape_string(items[i])).c_str() +1);
663664
}
664665
else {
665-
std::wstring toadd = narrow_to_wide(items[i].c_str() + 7);
666666
std::string color = items[i].substr(1,6);
667+
std::wstring toadd =
668+
narrow_to_wide(unescape_string(items[i]).c_str() + 7);
669+
667670

668671
e->addItem(toadd.c_str());
669672

670673
irr::video::SColor toset;
671674

672-
if (parseColor(color,toset))
675+
if (parseColor(color, toset))
673676
e->setItemOverrideColor(i,toset);
674677
}
675678
}
676679
else {
677-
e->addItem(narrow_to_wide(items[i]).c_str());
680+
e->addItem(narrow_to_wide(unescape_string(items[i])).c_str());
678681
}
679682
}
680683

681-
if (str_initial_selection != "")
682-
e->setSelected(stoi(str_initial_selection.c_str())-1);
683-
684684
if (data->listbox_selections.find(fname_w) != data->listbox_selections.end()) {
685685
e->setSelected(data->listbox_selections[fname_w]);
686686
}
687687

688+
if (str_initial_selection != "")
689+
e->setSelected(stoi(str_initial_selection.c_str())-1);
690+
688691
m_listboxes.push_back(std::pair<FieldSpec,gui::IGUIListBox*>(spec,e));
689692
m_fields.push_back(spec);
690693
return;
@@ -1335,7 +1338,7 @@ void GUIFormSpecMenu::parseBox(parserData* data,std::string element) {
13351338

13361339
irr::video::SColor color;
13371340

1338-
if (parseColor(color_str,color)) {
1341+
if (parseColor(color_str, color)) {
13391342
BoxDrawSpec spec(pos,geom,color);
13401343

13411344
m_boxes.push_back(spec);
@@ -1355,8 +1358,19 @@ void GUIFormSpecMenu::parseElement(parserData* data,std::string element) {
13551358

13561359
std::vector<std::string> parts = split(element,'[', true);
13571360

1358-
if (parts.size() != 2)
1361+
// ugly workaround to keep compatibility
1362+
if (parts.size() > 2) {
1363+
if (trim(parts[0]) == "image") {
1364+
for (unsigned int i=2;i< parts.size(); i++) {
1365+
parts[1] += "[" + parts[i];
1366+
}
1367+
}
1368+
else { return; }
1369+
}
1370+
1371+
if (parts.size() < 2) {
13591372
return;
1373+
}
13601374

13611375
std::string type = trim(parts[0]);
13621376
std::string description = trim(parts[1]);
@@ -2010,6 +2024,26 @@ void GUIFormSpecMenu::acceptInput(int eventtype)
20102024
{
20112025
std::map<std::string, std::string> fields;
20122026

2027+
if (current_keys_pending.key_down) {
2028+
fields["key_down"] = "true";
2029+
current_keys_pending.key_down = false;
2030+
}
2031+
2032+
if (current_keys_pending.key_up) {
2033+
fields["key_up"] = "true";
2034+
current_keys_pending.key_up = false;
2035+
}
2036+
2037+
if (current_keys_pending.key_enter) {
2038+
fields["key_enter"] = "true";
2039+
current_keys_pending.key_enter = false;
2040+
}
2041+
2042+
if (current_keys_pending.key_escape) {
2043+
fields["key_escape"] = "true";
2044+
current_keys_pending.key_escape = false;
2045+
}
2046+
20132047
for(u32 i=0; i<m_fields.size(); i++)
20142048
{
20152049
const FieldSpec &s = m_fields[i];
@@ -2101,16 +2135,38 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
21012135
m_text_dst->gotText(narrow_to_wide("MenuQuit"));
21022136
return true;
21032137
}
2104-
if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
2105-
{
2138+
if (event.KeyInput.PressedDown &&
2139+
(event.KeyInput.Key==KEY_RETURN ||
2140+
event.KeyInput.Key==KEY_UP ||
2141+
event.KeyInput.Key==KEY_DOWN)
2142+
) {
2143+
2144+
2145+
switch (event.KeyInput.Key) {
2146+
case KEY_RETURN:
2147+
if (m_allowclose) {
2148+
acceptInput();
2149+
quitMenu();
2150+
}
2151+
else
2152+
current_keys_pending.key_enter = true;
2153+
break;
2154+
case KEY_UP:
2155+
current_keys_pending.key_up = true;
2156+
break;
2157+
case KEY_DOWN:
2158+
current_keys_pending.key_down = true;
2159+
break;
2160+
break;
2161+
default:
2162+
//can't happen at all!
2163+
assert("reached a source line that can't ever been reached" == 0);
2164+
break;
2165+
}
21062166
acceptInput();
2107-
2108-
if (m_allowclose)
2109-
quitMenu();
2110-
else
2111-
m_text_dst->gotText(narrow_to_wide("KeyEnter"));
21122167
return true;
21132168
}
2169+
21142170
}
21152171
if(event.EventType==EET_MOUSE_INPUT_EVENT
21162172
&& event.MouseInput.Event != EMIE_MOUSE_MOVED)
@@ -2477,11 +2533,15 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
24772533
{
24782534
if(event.GUIEvent.Caller->getID() > 257)
24792535
{
2480-
acceptInput();
2481-
if (m_allowclose)
2536+
2537+
if (m_allowclose) {
2538+
acceptInput();
24822539
quitMenu();
2483-
else
2484-
m_text_dst->gotText(narrow_to_wide("EditBoxEnter"));
2540+
}
2541+
else {
2542+
current_keys_pending.key_enter = true;
2543+
acceptInput();
2544+
}
24852545
// quitMenu deallocates menu
24862546
return true;
24872547
}
@@ -2519,15 +2579,15 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
25192579
bool GUIFormSpecMenu::parseColor(std::string color, irr::video::SColor& outcolor) {
25202580
outcolor = irr::video::SColor(0,0,0,0);
25212581

2522-
if(!string_allowed(color, "0123456789abcdefABCDEF"))
2582+
if (!string_allowed(color, "0123456789abcdefABCDEF"))
25232583
return false;
25242584

25252585
u32 color_value;
25262586
std::istringstream iss(color);
25272587
iss >> std::hex >> color_value;
2588+
25282589
outcolor = irr::video::SColor(color_value);
25292590

25302591
outcolor.setAlpha(255);
25312592
return true;
25322593
}
2533-

Diff for: ‎src/guiFormSpecMenu.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,17 @@ class GUIFormSpecMenu : public GUIModalMenu
297297
std::map<std::wstring,int> listbox_selections;
298298
} parserData;
299299

300+
typedef struct {
301+
bool key_up;
302+
bool key_down;
303+
bool key_enter;
304+
bool key_escape;
305+
} fs_key_pendig;
306+
300307
std::vector<video::ITexture *> m_Textures;
301308

309+
fs_key_pendig current_keys_pending;
310+
302311
void parseElement(parserData* data,std::string element);
303312

304313
void parseSize(parserData* data,std::string element);
@@ -321,7 +330,7 @@ class GUIFormSpecMenu : public GUIModalMenu
321330
void parseTabHeader(parserData* data,std::string element);
322331
void parseBox(parserData* data,std::string element);
323332

324-
bool parseColor(std::string color, irr::video::SColor& outcolor);
333+
bool parseColor(std::string color, irr::video::SColor& outcolor);
325334
};
326335

327336
class FormspecFormSource: public IFormSource

Diff for: ‎src/itemdef.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class CItemDefManager: public IWritableItemDefManager
389389
scene::IMesh *node_mesh = mapblock_mesh.getMesh();
390390
assert(node_mesh);
391391
video::SColor c(255, 255, 255, 255);
392-
if(g_settings->getS32("enable_shaders") != 0)
392+
if(g_settings->getBool("enable_shaders"))
393393
c = MapBlock_LightColor(255, 0xffff, decode_light(f.light_source));
394394
setMeshColor(node_mesh, c);
395395

Diff for: ‎src/mapblock_mesh.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1069,10 +1069,9 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
10691069

10701070
/*
10711071
Convert MeshCollector to SMesh
1072-
Also store animation info
10731072
*/
1074-
bool enable_shaders = (g_settings->getS32("enable_shaders") > 0);
10751073
bool enable_bumpmapping = g_settings->getBool("enable_bumpmapping");
1074+
bool enable_shaders = g_settings->getBool("enable_shaders");
10761075
video::E_MATERIAL_TYPE shadermat1 = m_gamedef->getShaderSource()->
10771076
getShader("test_shader_1").material;
10781077
video::E_MATERIAL_TYPE shadermat2 = m_gamedef->getShaderSource()->

0 commit comments

Comments
 (0)
Please sign in to comment.