details = details .. " "
end
- text = text .. ":" .. spec.port:trim()
+ if spec.port ~= nil then
+ text = text .. ":" .. spec.port:trim()
+ else
+ text = text .. ":??"
+ end
return text
end
return temppath
end
+function menu.set_texture(identifier,gamedetails)
+ local texture_set = false
+ if menu.texturepack ~= nil then
+ local path = menu.basetexturedir ..
+ gamedetails.id .. "_menu_" .. identifier .. ".png"
+
+ if engine.set_background(identifier,path) then
+ texture_set = true
+ end
+ end
+
+ if not texture_set then
+ local path = gamedetails.path .. DIR_DELIM .."menu" ..
+ DIR_DELIM .. identifier .. ".png"
+ if engine.set_background(identifier,path) then
+ texture_set = true
+ end
+ end
+
+ if not texture_set then
+ local path = menu.basetexturedir .. DIR_DELIM .."menu_" ..
+ identifier .. ".png"
+ if engine.set_background(identifier,path) then
+ texture_set = true
+ end
+ end
+
+ if not texture_set then
+ local path = menu.defaulttexturedir .. DIR_DELIM .."menu_" ..
+ identifier .. ".png"
+ engine.set_background(identifier,path)
+ end
+end
+
--------------------------------------------------------------------------------
function menu.update_gametype()
if (menu.game_last_check == nil or
engine.set_topleft_text(gamedetails.name)
--background
- local path_background_texture = gamedetails.path .. DIR_DELIM .."menu" ..
- DIR_DELIM .. "background.png"
- if engine.set_background("background",path_background_texture) then
- engine.set_clouds(false)
- else
- engine.set_clouds(true)
+ local background_set = false
+ if menu.texturepack ~= nil then
+ local path_background_texture = menu.basetexturedir ..
+ gamedetails.id .. "_menu_background.png"
+
+ if engine.set_background("background",path_background_texture) then
+ background_set = true
+ engine.set_clouds(false)
+ end
end
- --overlay
- local path_overlay_texture = gamedetails.path .. DIR_DELIM .."menu" ..
- DIR_DELIM .. "overlay.png"
- engine.set_background("overlay",path_overlay_texture)
+ if not background_set then
+ local path_background_texture = gamedetails.path .. DIR_DELIM .."menu" ..
+ DIR_DELIM .. "background.png"
+ if engine.set_background("background",path_background_texture) then
+ background_set = true
+ engine.set_clouds(false)
+ end
+ end
- --header
- local path_overlay_texture = gamedetails.path .. DIR_DELIM .."menu" ..
- DIR_DELIM .. "header.png"
- engine.set_background("header",path_overlay_texture)
+ if not background_set then
+ engine.set_clouds(true)
+ end
- --footer
- local path_overlay_texture = gamedetails.path .. DIR_DELIM .."menu" ..
- DIR_DELIM .. "footer.png"
- engine.set_background("footer",path_overlay_texture)
+ menu.set_texture("overlay",gamedetails)
+ menu.set_texture("header",gamedetails)
+ menu.set_texture("footer",gamedetails)
menu.game_last_check = menu.last_game
else
end
retval = retval .. menu.worldlist[i].name ..
- " [[" .. menu.worldlist[i].gameid .. "]]"
+ " \\[" .. menu.worldlist[i].gameid .. "\\]"
end
end
end
- menu.basetexturedir = engine.get_gamepath() .. DIR_DELIM .. ".." ..
+ menu.defaulttexturedir = engine.get_gamepath() .. DIR_DELIM .. ".." ..
DIR_DELIM .. "textures" .. DIR_DELIM .. "base" ..
DIR_DELIM .. "pack" .. DIR_DELIM
+ menu.basetexturedir = menu.defaulttexturedir
+
+ menu.texturepack = engine.setting_get("texture_path")
+
+ if menu.texturepack ~= nil then
+ menu.basetexturedir = menu.texturepack .. DIR_DELIM
+ end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function menubar.refresh()
- menubar.formspec = "box[-2,7.625;15.75,1.75;000000]"
+ menubar.formspec = "box[-0.3,5.625;12.4,1.3;000000]" ..
+ "box[-0.3,5.6;12.4,0.05;FFFFFF]"
menubar.buttons = {}
- local button_base = -1.8
+ local button_base = -0.25
local maxbuttons = #gamemgr.games
- if maxbuttons > 12 then
- maxbuttons = 12
+ if maxbuttons > 10 then
+ maxbuttons = 10
end
for i=1,maxbuttons,1 do
local btn_name = "menubar_btn_" .. gamemgr.games[i].id
- local buttonpos = button_base + (i-1) * 1.3
+ local buttonpos = button_base + (i-1) * 1.245
if gamemgr.games[i].menuicon_path ~= nil and
gamemgr.games[i].menuicon_path ~= "" then
menubar.formspec = menubar.formspec ..
- "image_button[" .. buttonpos .. ",7.9;1.3,1.3;" ..
+ "image_button[" .. buttonpos .. ",5.7;1.3,1.3;" ..
gamemgr.games[i].menuicon_path .. ";" .. btn_name .. ";;true;false]"
else
text = text .. "\n" .. part3
end
menubar.formspec = menubar.formspec ..
- "image_button[" .. buttonpos .. ",7.9;1.3,1.3;;" ..btn_name ..
+ "image_button[" .. buttonpos .. ",5.7;1.3,1.3;;" ..btn_name ..
";" .. text .. ";true;true]"
end
if gameindex > 0 and
worldname ~= "" then
- engine.setting_set("mg_name",fields["dd_mapgen"])
- local message = engine.create_world(worldname,gameindex)
+ menu.worldlist = engine.get_worlds()
+
+ local found = false
+ for i=1,#menu.worldlist,1 do
+ if worldlist[i].name == worldname then
+ found = true
+ break
+ end
+ end
+
+ local message = nil
- menu.last_game = gameindex
- engine.setting_set("main_menu_last_game_idx",gameindex)
+ if not found then
+ engine.setting_set("mg_name",fields["dd_mapgen"])
+ message = engine.create_world(worldname,gameindex)
+ else
+ message = "A world named \"" .. worldname .. "\" already exists"
+ end
if message ~= nil then
gamedata.errormessage = message
else
+ menu.last_game = gameindex
+ engine.setting_set("main_menu_last_game_idx",gameindex)
menu.worldlist = engine.get_worlds()
local worldlist = menu.worldlist
if fields["world_delete_confirm"] then
if menu.last_world > 0 and
- menu.last_world < #menu.worldlist then
+ menu.last_world <= #menu.worldlist then
engine.delete_world(menu.last_world)
menu.worldlist = engine.get_worlds()
menu.last_world = 1
--------------------------------------------------------------------------------
function tabbuilder.handle_multiplayer_buttons(fields)
+
+ if fields["te_name"] ~= nil then
+ gamedata.playername = fields["te_name"]
+ engine.setting_set("name", fields["te_name"])
+ end
+
if fields["favourites"] ~= nil then
local event = explode_textlist_event(fields["favourites"])
if event.typ == "DCL" then
- gamedata.address = menu.favorites[event.index].name
+ --gamedata.address = menu.favorites[event.index].name
if gamedata.address == nil then
gamedata.address = menu.favorites[event.index].address
end
gamedata.port = menu.favorites[event.index].port
gamedata.playername = fields["te_name"]
- gamedata.password = fields["te_pwd"]
+ if fields["te_pwd"] ~= nil then
+ gamedata.password = fields["te_pwd"]
+ end
gamedata.selected_world = 0
if gamedata.address ~= nil and
engine.setting_set("address",address)
engine.setting_set("port",port)
end
+
+ menu.fav_selected = event.index
end
return
end
+ if fields["key_up"] ~= nil or
+ fields["key_down"] ~= nil then
+
+ local fav_idx = engine.get_textlist_index("favourites")
+
+ if fields["key_up"] ~= nil and fav_idx > 1 then
+ fav_idx = fav_idx -1
+ else if fields["key_down"] and fav_idx < #menu.favorites then
+ fav_idx = fav_idx +1
+ end end
+
+ local address = menu.favorites[fav_idx].name
+ if address == nil then
+ address = menu.favorites[fav_idx].address
+ end
+ local port = menu.favorites[fav_idx].port
+
+ if address ~= nil and
+ port ~= nil then
+ engine.setting_set("address",address)
+ engine.setting_set("port",port)
+ end
+
+ menu.fav_selected = fav_idx
+ return
+ end
+
if fields["cb_public_serverlist"] ~= nil then
engine.setting_setbool("public_serverlist",
tabbuilder.tobool(fields["cb_public_serverlist"]))
else
menu.favorites = engine.get_favorites("local")
end
+
+ return
end
if fields["btn_delete_favorite"] ~= nil then
return
end
- if fields["btn_mp_connect"] ~= nil then
+ if fields["btn_mp_connect"] ~= nil or
+ fields["key_enter"] then
+
gamedata.playername = fields["te_name"]
gamedata.password = fields["te_pwd"]
gamedata.address = fields["te_address"]
gamedata.port = fields["te_port"]
gamedata.selected_world = 0
-
+
engine.start()
return
end
local world_doubleclick = false
- if fields["worlds"] ~= nil then
- local event = explode_textlist_event(fields["worlds"])
+ if fields["srv_worlds"] ~= nil then
+ local event = explode_textlist_event(fields["srv_worlds"])
- if event.typ == "DBL" then
+ if event.typ == "DCL" then
world_doubleclick = true
end
+ if event.typ == "CHG" then
+ engine.setting_set("main_menu_last_world_idx",engine.get_textlist_index("srv_worlds"))
+ end
+ end
+
+ if fields["key_up"] then
+ local oldidx = engine.get_textlist_index("srv_worlds")
+
+ if oldidx > 1 then
+ local newidx = oldidx -1
+ engine.setting_set("main_menu_last_world_idx",newidx)
+ end
+ end
+
+ if fields["key_down"] then
+ local oldidx = engine.get_textlist_index("srv_worlds")
+
+ if oldidx < #menu.worldlist then
+ local newidx = oldidx + 1
+ engine.setting_set("main_menu_last_world_idx",newidx)
+ end
end
if fields["cb_creative_mode"] then
if fields["cb_enable_damage"] then
engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"]))
end
-
+
+
if fields["start_server"] ~= nil or
- world_doubleclick then
+ world_doubleclick or
+ fields["key_enter"] then
local selected = engine.get_textlist_index("srv_worlds")
if selected > 0 then
+
gamedata.playername = fields["te_playername"]
- gamedata.password = fields["te_pwd"]
- gamedata.address = ""
+ gamedata.password = fields["te_passwd"]
gamedata.port = fields["te_serverport"]
+ gamedata.address = ""
gamedata.selected_world = selected
engine.setting_set("main_menu_tab",tabbuilder.current_tab)
if fields["world_delete"] ~= nil then
local selected = engine.get_textlist_index("srv_worlds")
if selected > 0 then
- menu.last_world = engine.get_textlist_index("worlds")
+ menu.last_world = engine.get_textlist_index("srv_worlds")
if menu.lastworld() ~= nil and
menu.lastworld().name ~= nil and
menu.lastworld().name ~= "" then
if event.typ == "DCL" then
world_doubleclick = true
end
+
+ if event.typ == "CHG" then
+ engine.setting_set("main_menu_singleplayer_world_idx",engine.get_textlist_index("sp_worlds"))
+ end
+ end
+
+ if fields["key_up"] then
+ local oldidx = engine.get_textlist_index("sp_worlds")
+
+ if oldidx > 1 then
+ local newidx = oldidx -1
+ engine.setting_set("main_menu_singleplayer_world_idx",newidx)
+ end
+ end
+
+ if fields["key_down"] then
+ local oldidx = engine.get_textlist_index("sp_worlds")
+
+ if oldidx < #menu.filtered_game_list_raw() then
+ local newidx = oldidx + 1
+ engine.setting_set("main_menu_singleplayer_world_idx",newidx)
+ end
end
if fields["cb_creative_mode"] then
end
if fields["play"] ~= nil or
- world_doubleclick then
+ world_doubleclick or
+ fields["key_enter"] then
local selected = engine.get_textlist_index("sp_worlds")
if selected > 0 then
gamedata.selected_world = menu.filtered_index_to_plain(selected)
--------------------------------------------------------------------------------
function tabbuilder.tab_multiplayer()
+
local retval =
"vertlabel[0,-0.25;CLIENT]" ..
"label[1,-0.25;Favorites:]"..
retval = retval .. "," .. render_favourite(menu.favorites[i])
end
end
-
- retval = retval .. ";1]"
+
+ print("cfav: " .. dump(menu.fav_selected))
+ if menu.fav_selected ~= nil then
+ retval = retval .. ";" .. menu.fav_selected .. "]"
+ else
+ retval = retval .. ";0]"
+ end
return retval
end
--------------------------------------------------------------------------------
function tabbuilder.tab_server()
+ local index = engine.setting_get("main_menu_last_world_idx")
+
+ if index == nil then
+ index = 0
+ end
+
local retval =
"button[4,4.15;2.6,0.5;world_delete;Delete]" ..
"button[6.5,4.15;2.8,0.5;world_create;New]" ..
if #menu.worldlist > 0 then
retval = retval .. menu.worldlist[1].name ..
- " [[" .. menu.worldlist[1].gameid .. "]]"
+ " \\[" .. menu.worldlist[1].gameid .. "\\]"
for i=2,#menu.worldlist,1 do
retval = retval .. "," .. menu.worldlist[i].name ..
- " [[" .. menu.worldlist[i].gameid .. "]]"
+ " \\[" .. menu.worldlist[i].gameid .. "\\]"
end
end
- retval = retval .. ";" .. menu.last_world .. "]"
+ retval = retval .. ";" .. index .. "]"
return retval
end
return "vertlabel[0,-0.5;CREDITS]" ..
"label[0.5,3;Minetest " .. engine.get_version() .. "]" ..
"label[0.5,3.3;http://minetest.net]" ..
- "image[0.5,1;" .. menu.basetexturedir .. "logo.png]" ..
+ "image[0.5,1;" .. menu.defaulttexturedir .. "logo.png]" ..
"textlist[3.5,-0.25;8.5,5.8;list_credits;" ..
"#FFFF00Core Developers," ..
"Perttu Ahola (celeron55) <celeron55@gmail.com>,"..
m_use_gettext(false),
m_lock(false)
{
+ current_keys_pending.key_down = false;
+ current_keys_pending.key_up = false;
+ current_keys_pending.key_enter = false;
+
}
GUIFormSpecMenu::~GUIFormSpecMenu()
else {
std::string current = "";
current += s.c_str()[0];
- bool last_was_delim = false;
+ bool last_was_escape = false;
for(unsigned int i=1; i < s.size(); i++) {
- if (last_was_delim) {
+ if (last_was_escape) {
+ current += '\\';
+ current += s.c_str()[i];
+ last_was_escape = false;
+ }
+ else {
if (s.c_str()[i] == delim) {
- current += s.c_str()[i];
- last_was_delim = false;
- }
- else {
tokens.push_back(current);
-
current = "";
- current += s.c_str()[i];
- last_was_delim = false;
+ last_was_escape = false;
}
- }
- else {
- if (s.c_str()[i] == delim) {
- last_was_delim = true;
+ else if (s.c_str()[i] == '\\'){
+ last_was_escape = true;
}
else {
- last_was_delim = false;
current += s.c_str()[i];
+ last_was_escape = false;
}
}
}
for (unsigned int i=0; i < items.size(); i++) {
if (items[i].c_str()[0] == '#') {
if (items[i].c_str()[1] == '#') {
- e->addItem(narrow_to_wide(items[i]).c_str() +1);
+ e->addItem(narrow_to_wide(unescape_string(items[i])).c_str() +1);
}
else {
- std::wstring toadd = narrow_to_wide(items[i].c_str() + 7);
std::string color = items[i].substr(1,6);
+ std::wstring toadd =
+ narrow_to_wide(unescape_string(items[i]).c_str() + 7);
+
e->addItem(toadd.c_str());
irr::video::SColor toset;
- if (parseColor(color,toset))
+ if (parseColor(color, toset))
e->setItemOverrideColor(i,toset);
}
}
else {
- e->addItem(narrow_to_wide(items[i]).c_str());
+ e->addItem(narrow_to_wide(unescape_string(items[i])).c_str());
}
}
- if (str_initial_selection != "")
- e->setSelected(stoi(str_initial_selection.c_str())-1);
-
if (data->listbox_selections.find(fname_w) != data->listbox_selections.end()) {
e->setSelected(data->listbox_selections[fname_w]);
}
+ if (str_initial_selection != "")
+ e->setSelected(stoi(str_initial_selection.c_str())-1);
+
m_listboxes.push_back(std::pair<FieldSpec,gui::IGUIListBox*>(spec,e));
m_fields.push_back(spec);
return;
irr::video::SColor color;
- if (parseColor(color_str,color)) {
+ if (parseColor(color_str, color)) {
BoxDrawSpec spec(pos,geom,color);
m_boxes.push_back(spec);
std::vector<std::string> parts = split(element,'[', true);
- if (parts.size() != 2)
+ // ugly workaround to keep compatibility
+ if (parts.size() > 2) {
+ if (trim(parts[0]) == "image") {
+ for (unsigned int i=2;i< parts.size(); i++) {
+ parts[1] += "[" + parts[i];
+ }
+ }
+ else { return; }
+ }
+
+ if (parts.size() < 2) {
return;
+ }
std::string type = trim(parts[0]);
std::string description = trim(parts[1]);
{
std::map<std::string, std::string> fields;
+ 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;
+ }
+
+ if (current_keys_pending.key_escape) {
+ fields["key_escape"] = "true";
+ current_keys_pending.key_escape = false;
+ }
+
for(u32 i=0; i<m_fields.size(); i++)
{
const FieldSpec &s = m_fields[i];
m_text_dst->gotText(narrow_to_wide("MenuQuit"));
return true;
}
- if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
- {
+ 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:
+ if (m_allowclose) {
+ acceptInput();
+ quitMenu();
+ }
+ else
+ current_keys_pending.key_enter = true;
+ 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!
+ assert("reached a source line that can't ever been reached" == 0);
+ break;
+ }
acceptInput();
-
- if (m_allowclose)
- quitMenu();
- else
- m_text_dst->gotText(narrow_to_wide("KeyEnter"));
return true;
}
+
}
if(event.EventType==EET_MOUSE_INPUT_EVENT
&& event.MouseInput.Event != EMIE_MOUSE_MOVED)
{
if(event.GUIEvent.Caller->getID() > 257)
{
- acceptInput();
- if (m_allowclose)
+
+ if (m_allowclose) {
+ acceptInput();
quitMenu();
- else
- m_text_dst->gotText(narrow_to_wide("EditBoxEnter"));
+ }
+ else {
+ current_keys_pending.key_enter = true;
+ acceptInput();
+ }
// quitMenu deallocates menu
return true;
}
bool GUIFormSpecMenu::parseColor(std::string color, irr::video::SColor& outcolor) {
outcolor = irr::video::SColor(0,0,0,0);
- if(!string_allowed(color, "0123456789abcdefABCDEF"))
+ if (!string_allowed(color, "0123456789abcdefABCDEF"))
return false;
u32 color_value;
std::istringstream iss(color);
iss >> std::hex >> color_value;
+
outcolor = irr::video::SColor(color_value);
outcolor.setAlpha(255);
return true;
}
-