Replace pause and message menu by formspec ones

This commit is contained in:
sapier 2014-03-04 19:57:39 +01:00
parent 062de11b4c
commit a4e2198e41
14 changed files with 273 additions and 711 deletions

@ -176,7 +176,7 @@ function update_menu()
-- handle errors -- handle errors
if gamedata.errormessage ~= nil then if gamedata.errormessage ~= nil then
formspec = "size[12,5.2]" .. formspec = "size[12,5.2,true]" ..
"textarea[1,2;10,2;;ERROR: " .. "textarea[1,2;10,2;;ERROR: " ..
engine.formspec_escape(gamedata.errormessage) .. engine.formspec_escape(gamedata.errormessage) ..
";]".. ";]"..
@ -365,7 +365,7 @@ end
function tabbuilder.gettab() function tabbuilder.gettab()
local tsize = tabbuilder.tabsizes[tabbuilder.current_tab] or {width=12, height=5.2} local tsize = tabbuilder.tabsizes[tabbuilder.current_tab] or {width=12, height=5.2}
local retval = "size[" .. tsize.width .. "," .. tsize.height .. "]" local retval = "size[" .. tsize.width .. "," .. tsize.height .. ",true]"
if tabbuilder.show_buttons then if tabbuilder.show_buttons then
retval = retval .. tabbuilder.tab_header() retval = retval .. tabbuilder.tab_header()

@ -422,7 +422,7 @@ function modmgr.dialog_configure_world()
local mod = filterlist.get_list(modmgr.modlist)[modmgr.world_config_selected_mod] local mod = filterlist.get_list(modmgr.modlist)[modmgr.world_config_selected_mod]
local retval = local retval =
"size[11,6.5]" .. "size[11,6.5,true]" ..
"label[0.5,-0.25;" .. fgettext("World:") .. "]" .. "label[0.5,-0.25;" .. fgettext("World:") .. "]" ..
"label[1.75,-0.25;" .. worldspec.name .. "]" "label[1.75,-0.25;" .. worldspec.name .. "]"

@ -98,7 +98,7 @@ end
-- @function [parent=#modstore] getsuccessfuldialog -- @function [parent=#modstore] getsuccessfuldialog
function modstore.getsuccessfuldialog() function modstore.getsuccessfuldialog()
local retval = "" local retval = ""
retval = retval .. "size[6,2]" retval = retval .. "size[6,2,true]"
if modstore.lastmodentry ~= nil then if modstore.lastmodentry ~= nil then
retval = retval .. "label[0,0.25;" .. fgettext("Successfully installed:") .. "]" retval = retval .. "label[0,0.25;" .. fgettext("Successfully installed:") .. "]"
retval = retval .. "label[3,0.25;" .. modstore.lastmodentry.moddetails.title .. "]" retval = retval .. "label[3,0.25;" .. modstore.lastmodentry.moddetails.title .. "]"
@ -152,7 +152,7 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- @function [parent=#modstore] tabheader -- @function [parent=#modstore] tabheader
function modstore.tabheader(tabname) function modstore.tabheader(tabname)
local retval = "size[12,10.25]" local retval = "size[12,10.25,true]"
retval = retval .. "tabheader[-0.3,-0.99;modstore_tab;" .. retval = retval .. "tabheader[-0.3,-0.99;modstore_tab;" ..
"Unsorted,Search;" .. "Unsorted,Search;" ..
modstore.nametoindex(tabname) .. ";true;false]" .. modstore.nametoindex(tabname) .. ";true;false]" ..

@ -849,7 +849,7 @@ Example stuff:
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", meta:set_string("formspec",
"invsize[8,9;]".. "size[8,9]"..
"list[context;main;0,0;8,4;]".. "list[context;main;0,0;8,4;]"..
"list[current_player;main;0,5;8,4;]") "list[current_player;main;0,5;8,4;]")
meta:set_string("infotext", "Chest"); meta:set_string("infotext", "Chest");
@ -861,7 +861,7 @@ meta:from_table({
main = {[1] = "default:dirt", [2] = "", [3] = "", [4] = "", [5] = "", [6] = "", [7] = "", [8] = "", [9] = "", [10] = "", [11] = "", [12] = "", [13] = "", [14] = "default:cobble", [15] = "", [16] = "", [17] = "", [18] = "", [19] = "", [20] = "default:cobble", [21] = "", [22] = "", [23] = "", [24] = "", [25] = "", [26] = "", [27] = "", [28] = "", [29] = "", [30] = "", [31] = "", [32] = ""} main = {[1] = "default:dirt", [2] = "", [3] = "", [4] = "", [5] = "", [6] = "", [7] = "", [8] = "", [9] = "", [10] = "", [11] = "", [12] = "", [13] = "", [14] = "default:cobble", [15] = "", [16] = "", [17] = "", [18] = "", [19] = "", [20] = "default:cobble", [21] = "", [22] = "", [23] = "", [24] = "", [25] = "", [26] = "", [27] = "", [28] = "", [29] = "", [30] = "", [31] = "", [32] = ""}
}, },
fields = { fields = {
formspec = "invsize[8,9;]list[context;main;0,0;8,4;]list[current_player;main;0,5;8,4;]", formspec = "size[8,9]list[context;main;0,0;8,4;]list[current_player;main;0,5;8,4;]",
infotext = "Chest" infotext = "Chest"
} }
}) })
@ -876,17 +876,17 @@ examples.
Examples: Examples:
- Chest: - Chest:
invsize[8,9;] size[8,9]
list[context;main;0,0;8,4;] list[context;main;0,0;8,4;]
list[current_player;main;0,5;8,4;] list[current_player;main;0,5;8,4;]
- Furnace: - Furnace:
invsize[8,9;] size[8,9]
list[context;fuel;2,3;1,1;] list[context;fuel;2,3;1,1;]
list[context;src;2,1;1,1;] list[context;src;2,1;1,1;]
list[context;dst;5,1;2,2;] list[context;dst;5,1;2,2;]
list[current_player;main;0,5;8,4;] list[current_player;main;0,5;8,4;]
- Minecraft-like player inventory - Minecraft-like player inventory
invsize[8,7.5;] size[8,7.5]
image[1,0.6;1,2;player.png] image[1,0.6;1,2;player.png]
list[current_player;main;0,3.5;8,4;] list[current_player;main;0,3.5;8,4;]
list[current_player;craft;3,0;3,3;] list[current_player;craft;3,0;3,3;]
@ -894,8 +894,9 @@ Examples:
Elements: Elements:
size[<W>,<H>] size[<W>,<H>,<fixed_size>]
^ Define the size of the menu in inventory slots ^ Define the size of the menu in inventory slots
^ fixed_size true/false (optional)
^ deprecated: invsize[<W>,<H>;] ^ deprecated: invsize[<W>,<H>;]
list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;] list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]

@ -424,11 +424,9 @@ set(minetest_SRCS
chat.cpp chat.cpp
hud.cpp hud.cpp
guiKeyChangeMenu.cpp guiKeyChangeMenu.cpp
guiMessageMenu.cpp
guiTextInputMenu.cpp guiTextInputMenu.cpp
guiFormSpecMenu.cpp guiFormSpecMenu.cpp
guiTable.cpp guiTable.cpp
guiPauseMenu.cpp
guiPasswordChange.cpp guiPasswordChange.cpp
guiVolumeChange.cpp guiVolumeChange.cpp
guiDeathScreen.cpp guiDeathScreen.cpp

@ -28,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "IMeshCache.h" #include "IMeshCache.h"
#include "client.h" #include "client.h"
#include "server.h" #include "server.h"
#include "guiPauseMenu.h"
#include "guiPasswordChange.h" #include "guiPasswordChange.h"
#include "guiVolumeChange.h" #include "guiVolumeChange.h"
#include "guiFormSpecMenu.h" #include "guiFormSpecMenu.h"
@ -75,24 +74,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Text input system Text input system
*/ */
struct TextDestChat : public TextDest
{
TextDestChat(Client *client)
{
m_client = client;
}
void gotText(std::wstring text)
{
m_client->typeChatMessage(text);
}
void gotText(std::map<std::string, std::string> fields)
{
m_client->typeChatMessage(narrow_to_wide(fields["text"]));
}
Client *m_client;
};
struct TextDestNodeMetadata : public TextDest struct TextDestNodeMetadata : public TextDest
{ {
TextDestNodeMetadata(v3s16 p, Client *client) TextDestNodeMetadata(v3s16 p, Client *client)
@ -136,12 +117,76 @@ struct TextDestPlayerInventory : public TextDest
m_client->sendInventoryFields(m_formname, fields); m_client->sendInventoryFields(m_formname, fields);
} }
void setFormName(std::string formname) { Client *m_client;
};
struct LocalFormspecHandler : public TextDest
{
LocalFormspecHandler();
LocalFormspecHandler(std::string formname) {
m_formname = formname; m_formname = formname;
} }
LocalFormspecHandler(std::string formname,Client *client) {
m_formname = formname;
m_client = client;
}
void gotText(std::string message) {
errorstream << "LocalFormspecHandler::gotText old style message received" << std::endl;
}
void gotText(std::map<std::string, std::string> fields)
{
if (m_formname == "MT_PAUSE_MENU") {
if (fields.find("btn_sound") != fields.end()) {
g_gamecallback->changeVolume();
return;
}
if (fields.find("btn_exit_menu") != fields.end()) {
g_gamecallback->disconnect();
return;
}
if (fields.find("btn_exit_os") != fields.end()) {
g_gamecallback->exitToOS();
return;
}
if (fields.find("quit") != fields.end()) {
return;
}
if (fields.find("btn_continue") != fields.end()) {
return;
}
}
if (m_formname == "MT_CHAT_MENU") {
if ((fields.find("btn_send") != fields.end()) ||
(fields.find("quit") != fields.end())) {
if (fields.find("f_text") != fields.end()) {
if (m_client != 0) {
m_client->typeChatMessage(narrow_to_wide(fields["f_text"]));
}
else {
errorstream << "LocalFormspecHandler::gotText received chat message but m_client is NULL" << std::endl;
}
}
return;
}
}
errorstream << "LocalFormspecHandler::gotText unhandled >" << m_formname << "< event" << std::endl;
int i = 0;
for (std::map<std::string,std::string>::iterator iter = fields.begin();
iter != fields.end(); iter++) {
errorstream << "\t"<< i << ": " << iter->first << "=" << iter->second << std::endl;
i++;
}
}
Client *m_client; Client *m_client;
std::string m_formname;
}; };
/* Respawn menu callback */ /* Respawn menu callback */
@ -224,13 +269,9 @@ inline bool isPointableNode(const MapNode& n,
Find what the player is pointing at Find what the player is pointing at
*/ */
PointedThing getPointedThing(Client *client, v3f player_position, PointedThing getPointedThing(Client *client, v3f player_position,
v3f camera_direction, v3f camera_position, v3f camera_direction, v3f camera_position, core::line3d<f32> shootline,
core::line3d<f32> shootline, f32 d, f32 d, bool liquids_pointable, bool look_for_object, v3s16 camera_offset,
bool liquids_pointable, std::vector<aabb3f> &hilightboxes, ClientActiveObject *&selected_object)
bool look_for_object,
v3s16 camera_offset,
std::vector<aabb3f> &hilightboxes,
ClientActiveObject *&selected_object)
{ {
PointedThing result; PointedThing result;
@ -379,9 +420,8 @@ PointedThing getPointedThing(Client *client, v3f player_position,
Additionally, a progressbar can be drawn when percent is set between 0 and 100. Additionally, a progressbar can be drawn when percent is set between 0 and 100.
*/ */
/*gui::IGUIStaticText **/ /*gui::IGUIStaticText **/
void draw_load_screen(const std::wstring &text, void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
IrrlichtDevice* device, gui::IGUIFont* font, gui::IGUIFont* font, float dtime=0 ,int percent=0, bool clouds=true)
float dtime=0 ,int percent=0, bool clouds=true)
{ {
video::IVideoDriver* driver = device->getVideoDriver(); video::IVideoDriver* driver = device->getVideoDriver();
v2u32 screensize = driver->getScreenSize(); v2u32 screensize = driver->getScreenSize();
@ -430,8 +470,8 @@ void draw_load_screen(const std::wstring &text,
/* Profiler display */ /* Profiler display */
void update_profiler_gui(gui::IGUIStaticText *guitext_profiler, void update_profiler_gui(gui::IGUIStaticText *guitext_profiler,
gui::IGUIFont *font, u32 text_height, gui::IGUIFont *font, u32 text_height, u32 show_profiler,
u32 show_profiler, u32 show_profiler_max) u32 show_profiler_max)
{ {
if(show_profiler == 0) if(show_profiler == 0)
{ {
@ -833,8 +873,7 @@ public:
}; };
bool nodePlacementPrediction(Client &client, bool nodePlacementPrediction(Client &client,
const ItemDefinition &playeritem_def, const ItemDefinition &playeritem_def, v3s16 nodepos, v3s16 neighbourpos)
v3s16 nodepos, v3s16 neighbourpos)
{ {
std::string prediction = playeritem_def.node_placement_prediction; std::string prediction = playeritem_def.node_placement_prediction;
INodeDefManager *nodedef = client.ndef(); INodeDefManager *nodedef = client.ndef();
@ -930,26 +969,86 @@ bool nodePlacementPrediction(Client &client,
return false; return false;
} }
static void show_chat_menu(FormspecFormSource* current_formspec,
TextDest* current_textdest, IWritableTextureSource* tsrc,
IrrlichtDevice * device, Client* client, std::string text)
{
std::string formspec =
"size[11,5.5,true]"
"field[3,2.35;6,0.5;f_text;;" + text + "]"
"button_exit[4,3;3,0.5;btn_send;" + std::string(gettext("Proceed")) + "]"
;
void the_game( /* Create menu */
bool &kill, /* Note: FormspecFormSource and LocalFormspecHandler
bool random_input, * are deleted by guiFormSpecMenu */
InputHandler *input, current_formspec = new FormspecFormSource(formspec,&current_formspec);
IrrlichtDevice *device, current_textdest = new LocalFormspecHandler("MT_CHAT_MENU",client);
gui::IGUIFont* font, GUIFormSpecMenu *menu =
std::string map_dir, new GUIFormSpecMenu(device, guiroot, -1,
std::string playername, &g_menumgr,
std::string password, NULL, NULL, tsrc);
std::string address, // If "", local server is used menu->setFormSource(current_formspec);
u16 port, menu->setTextDest(current_textdest);
std::wstring &error_message, menu->drop();
ChatBackend &chat_backend, }
const SubgameSpec &gamespec, // Used for local game,
bool simple_singleplayer_mode /******************************************************************************/
) static void show_pause_menu(FormspecFormSource* current_formspec,
TextDest* current_textdest, IWritableTextureSource* tsrc,
IrrlichtDevice * device)
{
const char* control_text = gettext("Default Controls:\n"
"- WASD: move\n"
"- Space: jump/climb\n"
"- Shift: sneak/go down\n"
"- Q: drop item\n"
"- I: inventory\n"
"- Mouse: turn/look\n"
"- Mouse left: dig/punch\n"
"- Mouse right: place/use\n"
"- Mouse wheel: select item\n"
"- T: chat\n"
);
std::ostringstream os;
os<<"Minetest\n";
os<<minetest_build_info<<"\n";
os<<"path_user = "<<wrap_rows(porting::path_user, 20)<<"\n";
std::string formspec =
"size[11,5.5,true]"
"button_exit[4,1;3,0.5;btn_continue;" + std::string(gettext("Continue"))+ "]"
"button[4,2;3,0.5;btn_sound;" + std::string(gettext("Sound Volume")) + "]"
"button[4,3;3,0.5;btn_exit_menu;" + std::string(gettext("Exit to Menu")) + "]"
"button[4,4;3,0.5;btn_exit_os;" + std::string(gettext("Exit to OS")) + "]"
"textarea[7.5,0.25;3.75,6;;" + std::string(control_text) + ";]"
"textarea[0.4,0.25;3.5,6;;" + os.str() + ";]"
;
/* Create menu */
/* Note: FormspecFormSource and LocalFormspecHandler *
* are deleted by guiFormSpecMenu */
current_formspec = new FormspecFormSource(formspec,&current_formspec);
current_textdest = new LocalFormspecHandler("MT_PAUSE_MENU");
GUIFormSpecMenu *menu =
new GUIFormSpecMenu(device, guiroot, -1, &g_menumgr, NULL, NULL, tsrc);
menu->setFormSource(current_formspec);
menu->setTextDest(current_textdest);
menu->drop();
}
/******************************************************************************/
void the_game(bool &kill, bool random_input, InputHandler *input,
IrrlichtDevice *device, gui::IGUIFont* font, std::string map_dir,
std::string playername, std::string password,
std::string address /* If "", local server is used */,
u16 port, std::wstring &error_message, ChatBackend &chat_backend,
const SubgameSpec &gamespec /* Used for local game */,
bool simple_singleplayer_mode)
{ {
FormspecFormSource* current_formspec = 0; FormspecFormSource* current_formspec = 0;
TextDestPlayerInventory* current_textdest = 0; TextDest* current_textdest = 0;
video::IVideoDriver* driver = device->getVideoDriver(); video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager(); scene::ISceneManager* smgr = device->getSceneManager();
@ -1788,33 +1887,15 @@ void the_game(
} }
else if(input->wasKeyDown(EscapeKey)) else if(input->wasKeyDown(EscapeKey))
{ {
infostream<<"the_game: " show_pause_menu(current_formspec, current_textdest, tsrc, device);
<<"Launching pause menu"<<std::endl;
// It will delete itself by itself
(new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
&g_menumgr, simple_singleplayer_mode))->drop();
// Move mouse cursor on top of the disconnect button
if(simple_singleplayer_mode)
input->setMousePos(displaycenter.X, displaycenter.Y+0);
else
input->setMousePos(displaycenter.X, displaycenter.Y+25);
} }
else if(input->wasKeyDown(getKeySetting("keymap_chat"))) else if(input->wasKeyDown(getKeySetting("keymap_chat")))
{ {
TextDest *dest = new TextDestChat(&client); show_chat_menu(current_formspec, current_textdest, tsrc, device, &client,"");
(new GUITextInputMenu(guienv, guiroot, -1,
&g_menumgr, dest,
L""))->drop();
} }
else if(input->wasKeyDown(getKeySetting("keymap_cmd"))) else if(input->wasKeyDown(getKeySetting("keymap_cmd")))
{ {
TextDest *dest = new TextDestChat(&client); show_chat_menu(current_formspec, current_textdest, tsrc, device, &client,"/");
(new GUITextInputMenu(guienv, guiroot, -1,
&g_menumgr, dest,
L"/"))->drop();
} }
else if(input->wasKeyDown(getKeySetting("keymap_console"))) else if(input->wasKeyDown(getKeySetting("keymap_console")))
{ {

@ -66,12 +66,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/ */
GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev, GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
gui::IGUIElement* parent, s32 id, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
IMenuManager *menumgr, InventoryManager *invmgr, IGameDef *gamedef,
InventoryManager *invmgr, ISimpleTextureSource *tsrc) :
IGameDef *gamedef,
ISimpleTextureSource *tsrc
):
GUIModalMenu(dev->getGUIEnvironment(), parent, id, menumgr), GUIModalMenu(dev->getGUIEnvironment(), parent, id, menumgr),
m_device(dev), m_device(dev),
m_invmgr(invmgr), m_invmgr(invmgr),
@ -248,10 +245,11 @@ std::vector<std::string> split(const std::string &s, char delim) {
return tokens; return tokens;
} }
void GUIFormSpecMenu::parseSize(parserData* data,std::string element) { void GUIFormSpecMenu::parseSize(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,','); std::vector<std::string> parts = split(element,',');
if (parts.size() == 2) { if ((parts.size() == 2) || parts.size() == 3) {
v2f invsize; v2f invsize;
if (parts[1].find(';') != std::string::npos) if (parts[1].find(';') != std::string::npos)
@ -260,6 +258,13 @@ void GUIFormSpecMenu::parseSize(parserData* data,std::string element) {
invsize.X = stof(parts[0]); invsize.X = stof(parts[0]);
invsize.Y = stof(parts[1]); invsize.Y = stof(parts[1]);
lockSize(false);
if (parts.size() == 3) {
if (parts[2] == "true") {
lockSize(true,v2u32(800,600));
}
}
if (m_lock) { if (m_lock) {
v2u32 current_screensize = m_device->getVideoDriver()->getScreenSize(); v2u32 current_screensize = m_device->getVideoDriver()->getScreenSize();
v2u32 delta = current_screensize - m_lockscreensize; v2u32 delta = current_screensize - m_lockscreensize;
@ -305,8 +310,8 @@ void GUIFormSpecMenu::parseSize(parserData* data,std::string element) {
errorstream<< "Invalid size element (" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid size element (" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseList(parserData* data,std::string element) { void GUIFormSpecMenu::parseList(parserData* data,std::string element)
{
if (m_gamedef == 0) { if (m_gamedef == 0) {
errorstream<<"WARNING: invalid use of 'list' with m_gamedef==0"<<std::endl; errorstream<<"WARNING: invalid use of 'list' with m_gamedef==0"<<std::endl;
return; return;
@ -358,7 +363,8 @@ void GUIFormSpecMenu::parseList(parserData* data,std::string element) {
errorstream<< "Invalid list element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid list element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element) { void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if ((parts.size() == 3) || (parts.size() == 4)) { if ((parts.size() == 3) || (parts.size() == 4)) {
@ -408,7 +414,8 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element) {
errorstream<< "Invalid checkbox element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid checkbox element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseImage(parserData* data,std::string element) { void GUIFormSpecMenu::parseImage(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if (parts.size() == 3) { if (parts.size() == 3) {
@ -451,7 +458,8 @@ void GUIFormSpecMenu::parseImage(parserData* data,std::string element) {
errorstream<< "Invalid image element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid image element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseItemImage(parserData* data,std::string element) { void GUIFormSpecMenu::parseItemImage(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if (parts.size() == 3) { if (parts.size() == 3) {
@ -478,7 +486,9 @@ void GUIFormSpecMenu::parseItemImage(parserData* data,std::string element) {
errorstream<< "Invalid ItemImage element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid ItemImage element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseButton(parserData* data,std::string element,std::string type) { void GUIFormSpecMenu::parseButton(parserData* data,std::string element,
std::string type)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if (parts.size() == 4) { if (parts.size() == 4) {
@ -530,7 +540,8 @@ void GUIFormSpecMenu::parseButton(parserData* data,std::string element,std::stri
errorstream<< "Invalid button element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid button element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseBackground(parserData* data,std::string element) { void GUIFormSpecMenu::parseBackground(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if ((parts.size() == 3) || (parts.size() == 4)) { if ((parts.size() == 3) || (parts.size() == 4)) {
@ -565,7 +576,8 @@ void GUIFormSpecMenu::parseBackground(parserData* data,std::string element) {
errorstream<< "Invalid background element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid background element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseTableOptions(parserData* data,std::string element) { void GUIFormSpecMenu::parseTableOptions(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
data->table_options.clear(); data->table_options.clear();
@ -576,7 +588,8 @@ void GUIFormSpecMenu::parseTableOptions(parserData* data,std::string element) {
} }
} }
void GUIFormSpecMenu::parseTableColumns(parserData* data,std::string element) { void GUIFormSpecMenu::parseTableColumns(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
data->table_columns.clear(); data->table_columns.clear();
@ -595,7 +608,8 @@ void GUIFormSpecMenu::parseTableColumns(parserData* data,std::string element) {
} }
} }
void GUIFormSpecMenu::parseTable(parserData* data,std::string element) { void GUIFormSpecMenu::parseTable(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if ((parts.size() == 4) || (parts.size() == 5)) { if ((parts.size() == 4) || (parts.size() == 5)) {
@ -664,7 +678,8 @@ void GUIFormSpecMenu::parseTable(parserData* data,std::string element) {
errorstream<< "Invalid table element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid table element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseTextList(parserData* data,std::string element) { void GUIFormSpecMenu::parseTextList(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if ((parts.size() == 4) || (parts.size() == 5) || (parts.size() == 6)) { if ((parts.size() == 4) || (parts.size() == 5) || (parts.size() == 6)) {
@ -737,7 +752,8 @@ void GUIFormSpecMenu::parseTextList(parserData* data,std::string element) {
} }
void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element) { void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if (parts.size() == 5) { if (parts.size() == 5) {
@ -790,7 +806,8 @@ void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element) {
<< element << "'" << std::endl; << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element) { void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if (parts.size() == 4) { if (parts.size() == 4) {
@ -856,7 +873,9 @@ void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element) {
errorstream<< "Invalid pwdfield element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid pwdfield element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseSimpleField(parserData* data,std::vector<std::string> &parts) { void GUIFormSpecMenu::parseSimpleField(parserData* data,
std::vector<std::string> &parts)
{
std::string name = parts[0]; std::string name = parts[0];
std::string label = parts[1]; std::string label = parts[1];
std::string default_val = parts[2]; std::string default_val = parts[2];
@ -935,7 +954,9 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,std::vector<std::string>
m_fields.push_back(spec); m_fields.push_back(spec);
} }
void GUIFormSpecMenu::parseTextArea(parserData* data,std::vector<std::string>& parts,std::string type) { void GUIFormSpecMenu::parseTextArea(parserData* data,
std::vector<std::string>& parts,std::string type)
{
std::vector<std::string> v_pos = split(parts[0],','); std::vector<std::string> v_pos = split(parts[0],',');
std::vector<std::string> v_geom = split(parts[1],','); std::vector<std::string> v_geom = split(parts[1],',');
@ -1026,7 +1047,9 @@ void GUIFormSpecMenu::parseTextArea(parserData* data,std::vector<std::string>& p
m_fields.push_back(spec); m_fields.push_back(spec);
} }
void GUIFormSpecMenu::parseField(parserData* data,std::string element,std::string type) { void GUIFormSpecMenu::parseField(parserData* data,std::string element,
std::string type)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if (parts.size() == 3) { if (parts.size() == 3) {
@ -1041,7 +1064,8 @@ void GUIFormSpecMenu::parseField(parserData* data,std::string element,std::strin
errorstream<< "Invalid field element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid field element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseLabel(parserData* data,std::string element) { void GUIFormSpecMenu::parseLabel(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if (parts.size() == 2) { if (parts.size() == 2) {
@ -1076,7 +1100,8 @@ void GUIFormSpecMenu::parseLabel(parserData* data,std::string element) {
errorstream<< "Invalid label element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid label element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element) { void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if (parts.size() == 2) { if (parts.size() == 2) {
@ -1116,7 +1141,9 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element) {
errorstream<< "Invalid vertlabel element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid vertlabel element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,std::string type) { void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,
std::string type)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if ((parts.size() == 5) || (parts.size() == 7) || (parts.size() == 8)) { if ((parts.size() == 5) || (parts.size() == 7) || (parts.size() == 8)) {
@ -1202,7 +1229,8 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,std:
errorstream<< "Invalid imagebutton element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid imagebutton element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseTabHeader(parserData* data,std::string element) { void GUIFormSpecMenu::parseTabHeader(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if ((parts.size() == 4) || (parts.size() == 6)) { if ((parts.size() == 4) || (parts.size() == 6)) {
@ -1269,7 +1297,8 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data,std::string element) {
errorstream<< "Invalid TabHeader element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid TabHeader element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseItemImageButton(parserData* data,std::string element) { void GUIFormSpecMenu::parseItemImageButton(parserData* data,std::string element)
{
if (m_gamedef == 0) { if (m_gamedef == 0) {
errorstream<<"WARNING: invalid use of item_image_button with m_gamedef==0"<<std::endl; errorstream<<"WARNING: invalid use of item_image_button with m_gamedef==0"<<std::endl;
@ -1335,7 +1364,8 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data,std::string element)
errorstream<< "Invalid ItemImagebutton element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid ItemImagebutton element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseBox(parserData* data,std::string element) { void GUIFormSpecMenu::parseBox(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if (parts.size() == 3) { if (parts.size() == 3) {
@ -1368,7 +1398,8 @@ void GUIFormSpecMenu::parseBox(parserData* data,std::string element) {
errorstream<< "Invalid Box element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid Box element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseBackgroundColor(parserData* data,std::string element) { void GUIFormSpecMenu::parseBackgroundColor(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if ((parts.size() == 1) || (parts.size() == 2)) { if ((parts.size() == 1) || (parts.size() == 2)) {
@ -1383,7 +1414,8 @@ void GUIFormSpecMenu::parseBackgroundColor(parserData* data,std::string element)
errorstream<< "Invalid bgcolor element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid bgcolor element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseListColors(parserData* data,std::string element) { void GUIFormSpecMenu::parseListColors(parserData* data,std::string element)
{
std::vector<std::string> parts = split(element,';'); std::vector<std::string> parts = split(element,';');
if ((parts.size() == 2) || (parts.size() == 3) || (parts.size() == 5)) { if ((parts.size() == 2) || (parts.size() == 3) || (parts.size() == 5)) {
@ -1408,8 +1440,8 @@ void GUIFormSpecMenu::parseListColors(parserData* data,std::string element) {
errorstream<< "Invalid listcolors element(" << parts.size() << "): '" << element << "'" << std::endl; errorstream<< "Invalid listcolors element(" << parts.size() << "): '" << element << "'" << std::endl;
} }
void GUIFormSpecMenu::parseElement(parserData* data,std::string element) { void GUIFormSpecMenu::parseElement(parserData* data,std::string element)
{
//some prechecks //some prechecks
if (element == "") if (element == "")
return; return;
@ -2132,16 +2164,22 @@ ItemStack GUIFormSpecMenu::verifySelectedItem()
return ItemStack(); return ItemStack();
} }
void GUIFormSpecMenu::acceptInput(bool quit=false) void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
{ {
if(m_text_dst) if(m_text_dst)
{ {
std::map<std::string, std::string> fields; std::map<std::string, std::string> fields;
if (quit) { if (quitmode == quit_mode_accept) {
fields["quit"] = "true"; fields["quit"] = "true";
} }
if (quitmode == quit_mode_cancel) {
fields["quit"] = "true";
m_text_dst->gotText(fields);
return;
}
if (current_keys_pending.key_down) { if (current_keys_pending.key_down) {
fields["key_down"] = "true"; fields["key_down"] = "true";
current_keys_pending.key_down = false; current_keys_pending.key_down = false;
@ -2281,10 +2319,10 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
if (event.KeyInput.PressedDown && (kp == EscapeKey || if (event.KeyInput.PressedDown && (kp == EscapeKey ||
kp == getKeySetting("keymap_inventory"))) kp == getKeySetting("keymap_inventory")))
{ {
if (m_allowclose) { if (m_allowclose){
acceptInput(true); acceptInput(quit_mode_cancel);
quitMenu(); quitMenu();
} else { } else {
m_text_dst->gotText(narrow_to_wide("MenuQuit")); m_text_dst->gotText(narrow_to_wide("MenuQuit"));
} }
return true; return true;
@ -2313,7 +2351,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
break; break;
} }
if (current_keys_pending.key_enter && m_allowclose) { if (current_keys_pending.key_enter && m_allowclose) {
acceptInput(true); acceptInput(quit_mode_accept);
quitMenu(); quitMenu();
} }
else { else {
@ -2643,7 +2681,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
if (btn_id == 257) { if (btn_id == 257) {
if (m_allowclose) { if (m_allowclose) {
acceptInput(true); acceptInput(quit_mode_accept);
quitMenu(); quitMenu();
} else { } else {
acceptInput(); acceptInput();
@ -2666,7 +2704,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
acceptInput(); acceptInput();
if(s.is_exit){ if(s.is_exit){
if (m_allowclose) { if (m_allowclose) {
acceptInput(true); acceptInput(quit_mode_accept);
quitMenu(); quitMenu();
} else { } else {
m_text_dst->gotText(narrow_to_wide("ExitButton")); m_text_dst->gotText(narrow_to_wide("ExitButton"));
@ -2685,7 +2723,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
{ {
if (m_allowclose) { if (m_allowclose) {
acceptInput(true); acceptInput(quit_mode_accept);
quitMenu(); quitMenu();
} }
else { else {
@ -2723,7 +2761,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
return Parent ? Parent->OnEvent(event) : false; return Parent ? Parent->OnEvent(event) : false;
} }
bool GUIFormSpecMenu::parseColor(const std::string &value, video::SColor &color, bool quiet) bool GUIFormSpecMenu::parseColor(const std::string &value, video::SColor &color,
bool quiet)
{ {
const char *hexpattern = NULL; const char *hexpattern = NULL;
if (value[0] == '#') { if (value[0] == '#') {

@ -42,12 +42,22 @@ typedef enum {
f_Unknown f_Unknown
} FormspecFieldType; } FormspecFieldType;
typedef enum {
quit_mode_no,
quit_mode_accept,
quit_mode_cancel
} FormspecQuitMode;
struct TextDest struct TextDest
{ {
virtual ~TextDest() {}; virtual ~TextDest() {};
// This is deprecated I guess? -celeron55 // This is deprecated I guess? -celeron55
virtual void gotText(std::wstring text){} virtual void gotText(std::wstring text){}
virtual void gotText(std::map<std::string, std::string> fields) = 0; virtual void gotText(std::map<std::string, std::string> fields) = 0;
virtual void setFormName(std::string formname)
{ m_formname = formname;};
std::string m_formname;
}; };
class IFormSource class IFormSource
@ -139,7 +149,8 @@ class GUIFormSpecMenu : public GUIModalMenu
FieldSpec() FieldSpec()
{ {
} }
FieldSpec(const std::wstring name, const std::wstring label, const std::wstring fdeflt, int id): FieldSpec(const std::wstring name, const std::wstring label,
const std::wstring fdeflt, int id) :
fname(name), fname(name),
flabel(label), flabel(label),
fdefault(fdeflt), fdefault(fdeflt),
@ -228,7 +239,7 @@ public:
void updateSelectedItem(); void updateSelectedItem();
ItemStack verifySelectedItem(); ItemStack verifySelectedItem();
void acceptInput(bool quit); void acceptInput(FormspecQuitMode quitmode);
bool preprocessEvent(const SEvent& event); bool preprocessEvent(const SEvent& event);
bool OnEvent(const SEvent& event); bool OnEvent(const SEvent& event);
@ -332,7 +343,8 @@ private:
void parsePwdField(parserData* data,std::string element); void parsePwdField(parserData* data,std::string element);
void parseField(parserData* data,std::string element,std::string type); void parseField(parserData* data,std::string element,std::string type);
void parseSimpleField(parserData* data,std::vector<std::string> &parts); void parseSimpleField(parserData* data,std::vector<std::string> &parts);
void parseTextArea(parserData* data,std::vector<std::string>& parts,std::string type); void parseTextArea(parserData* data,std::vector<std::string>& parts,
std::string type);
void parseLabel(parserData* data,std::string element); void parseLabel(parserData* data,std::string element);
void parseVertLabel(parserData* data,std::string element); void parseVertLabel(parserData* data,std::string element);
void parseImageButton(parserData* data,std::string element,std::string type); void parseImageButton(parserData* data,std::string element,std::string type);

@ -1,173 +0,0 @@
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
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
(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
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "guiMessageMenu.h"
#include "debug.h"
#include "serialization.h"
#include <string>
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include "gettext.h"
GUIMessageMenu::GUIMessageMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr,
std::wstring message_text
):
GUIModalMenu(env, parent, id, menumgr),
m_message_text(message_text),
m_status(false)
{
}
GUIMessageMenu::~GUIMessageMenu()
{
removeChildren();
}
void GUIMessageMenu::removeChildren()
{
{
gui::IGUIElement *e = getElementFromId(256);
if(e != NULL)
e->remove();
}
{
gui::IGUIElement *e = getElementFromId(257);
if(e != NULL)
e->remove();
}
}
void GUIMessageMenu::regenerateGui(v2u32 screensize)
{
/*
Remove stuff
*/
removeChildren();
/*
Calculate new sizes and positions
*/
core::rect<s32> rect(
screensize.X/2 - 580/2,
screensize.Y/2 - 300/2,
screensize.X/2 + 580/2,
screensize.Y/2 + 300/2
);
DesiredRect = rect;
recalculateAbsolutePosition(false);
v2s32 size = rect.getSize();
gui::IGUISkin *skin = Environment->getSkin();
gui::IGUIFont *font = skin->getFont();
s32 msg_h = font->getDimension(m_message_text.c_str()).Height;
s32 msg_w = font->getDimension(m_message_text.c_str()).Width;
if(msg_h > 200)
msg_h = 200;
if(msg_w > 540)
msg_w = 540;
/*
Add stuff
*/
{
core::rect<s32> rect(0, 0, msg_w, msg_h);
rect += v2s32(size.X/2-msg_w/2, size.Y/2-30/2 - msg_h/2);
Environment->addStaticText(m_message_text.c_str(),
rect, false, true, this, -1);
}
int bw = 140;
{
core::rect<s32> rect(0, 0, bw, 30);
rect = rect + v2s32(size.X/2-bw/2, size.Y/2-30/2+5 + msg_h/2);
wchar_t* text = wgettext("Proceed");
gui::IGUIElement *e =
Environment->addButton(rect, this, 257,
text);
Environment->setFocus(e);
delete[] text;
}
}
void GUIMessageMenu::drawMenu()
{
gui::IGUISkin* skin = Environment->getSkin();
if (!skin)
return;
video::IVideoDriver* driver = Environment->getVideoDriver();
video::SColor bgcolor(140,0,0,0);
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
gui::IGUIElement::draw();
}
bool GUIMessageMenu::OnEvent(const SEvent& event)
{
if(event.EventType==EET_KEY_INPUT_EVENT)
{
if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
{
m_status = true;
quitMenu();
return true;
}
if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
{
m_status = true;
quitMenu();
return true;
}
}
if(event.EventType==EET_GUI_EVENT)
{
if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
&& isVisible())
{
if(!canTakeFocus(event.GUIEvent.Element))
{
dstream<<"GUIMessageMenu: Not allowing focus change."
<<std::endl;
// Returning true disables focus change
return true;
}
}
if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
{
switch(event.GUIEvent.Caller->getID())
{
case 257:
m_status = true;
quitMenu();
return true;
}
}
}
return Parent ? Parent->OnEvent(event) : false;
}

@ -1,60 +0,0 @@
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
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
(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
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef GUIMESSAGEMENU_HEADER
#define GUIMESSAGEMENU_HEADER
#include "irrlichttypes_extrabloated.h"
#include "modalMenu.h"
#include <string>
class GUIMessageMenu : public GUIModalMenu
{
public:
GUIMessageMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr,
std::wstring message_text);
~GUIMessageMenu();
void removeChildren();
/*
Remove and re-add (or reposition) stuff
*/
void regenerateGui(v2u32 screensize);
void drawMenu();
bool OnEvent(const SEvent& event);
/*
true = ok'd
*/
bool getStatus()
{
return m_status;
}
private:
std::wstring m_message_text;
bool m_status;
};
#endif

@ -1,280 +0,0 @@
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
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
(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
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "guiPauseMenu.h"
#include "debug.h"
#include "serialization.h"
#include "porting.h"
#include "config.h"
#include "version.h"
#include "main.h"
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include "gettext.h"
#include "util/string.h"
GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
IGameCallback *gamecallback,
IMenuManager *menumgr,
bool simple_singleplayer_mode):
GUIModalMenu(env, parent, id, menumgr),
m_gamecallback(gamecallback),
m_simple_singleplayer_mode(simple_singleplayer_mode)
{
}
GUIPauseMenu::~GUIPauseMenu()
{
removeChildren();
}
void GUIPauseMenu::removeChildren()
{
{
gui::IGUIElement *e = getElementFromId(256);
if(e != NULL)
e->remove();
}
{
gui::IGUIElement *e = getElementFromId(257);
if(e != NULL)
e->remove();
}
{
gui::IGUIElement *e = getElementFromId(258);
if(e != NULL)
e->remove();
}
{
gui::IGUIElement *e = getElementFromId(259);
if(e != NULL)
e->remove();
}
{
gui::IGUIElement *e = getElementFromId(260);
if(e != NULL)
e->remove();
}
{
gui::IGUIElement *e = getElementFromId(261);
if(e != NULL)
e->remove();
}
{
gui::IGUIElement *e = getElementFromId(262);
if(e != NULL)
e->remove();
}
}
void GUIPauseMenu::regenerateGui(v2u32 screensize)
{
/*
Remove stuff
*/
removeChildren();
/*
Calculate new sizes and positions
*/
core::rect<s32> rect(
screensize.X/2 - 580/2,
screensize.Y/2 - 300/2,
screensize.X/2 + 580/2,
screensize.Y/2 + 300/2
);
DesiredRect = rect;
recalculateAbsolutePosition(false);
v2s32 size = rect.getSize();
/*
Add stuff
*/
const s32 btn_height = 30;
const s32 btn_gap = 20;
const s32 btn_num = m_simple_singleplayer_mode ? 4 : 5;
s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2;
{
core::rect<s32> rect(0, 0, 140, btn_height);
rect = rect + v2s32(size.X/2-140/2, btn_y);
wchar_t* text = wgettext("Continue");
Environment->addButton(rect, this, 256,
text);
delete[] text;
}
btn_y += btn_height + btn_gap;
if(!m_simple_singleplayer_mode)
{
{
core::rect<s32> rect(0, 0, 140, btn_height);
rect = rect + v2s32(size.X/2-140/2, btn_y);
wchar_t* text = wgettext("Change Password");
Environment->addButton(rect, this, 261,
text);
delete[] text;
}
btn_y += btn_height + btn_gap;
}
{
core::rect<s32> rect(0, 0, 140, btn_height);
rect = rect + v2s32(size.X/2-140/2, btn_y);
wchar_t* text = wgettext("Sound Volume");
Environment->addButton(rect, this, 262,
text);
delete[] text;
}
btn_y += btn_height + btn_gap;
{
core::rect<s32> rect(0, 0, 140, btn_height);
rect = rect + v2s32(size.X/2-140/2, btn_y);
wchar_t* text = wgettext("Exit to Menu");
Environment->addButton(rect, this, 260,
text);
delete[] text;
}
btn_y += btn_height + btn_gap;
{
core::rect<s32> rect(0, 0, 140, btn_height);
rect = rect + v2s32(size.X/2-140/2, btn_y);
wchar_t* text = wgettext("Exit to OS");
Environment->addButton(rect, this, 257,
text);
delete[] text;
}
{
core::rect<s32> rect(0, 0, 180, 240);
rect = rect + v2s32(size.X/2 + 90, size.Y/2-rect.getHeight()/2);
wchar_t* text = wgettext("Default Controls:\n"
"- WASD: move\n"
"- Space: jump/climb\n"
"- Shift: sneak/go down\n"
"- Q: drop item\n"
"- I: inventory\n"
"- Mouse: turn/look\n"
"- Mouse left: dig/punch\n"
"- Mouse right: place/use\n"
"- Mouse wheel: select item\n"
"- T: chat\n"
);
Environment->addStaticText(text, rect, false, true, this, 258);
delete[] text;
}
{
core::rect<s32> rect(0, 0, 180, 220);
rect = rect + v2s32(size.X/2 - 90 - rect.getWidth(), size.Y/2-rect.getHeight()/2);
v2u32 max_texture_size;
{
video::IVideoDriver* driver = Environment->getVideoDriver();
max_texture_size = driver->getMaxTextureSize();
}
std::ostringstream os;
os<<"Minetest\n";
os<<minetest_build_info<<"\n";
os<<"path_user = "<<wrap_rows(porting::path_user, 20)<<"\n";
Environment->addStaticText(narrow_to_wide(os.str()).c_str(), rect, false, true, this, 259);
}
}
void GUIPauseMenu::drawMenu()
{
gui::IGUISkin* skin = Environment->getSkin();
if (!skin)
return;
video::IVideoDriver* driver = Environment->getVideoDriver();
video::SColor bgcolor(140,0,0,0);
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
gui::IGUIElement::draw();
}
bool GUIPauseMenu::OnEvent(const SEvent& event)
{
if(event.EventType==EET_KEY_INPUT_EVENT)
{
if(event.KeyInput.PressedDown)
{
if(event.KeyInput.Key==KEY_ESCAPE)
{
quitMenu();
return true;
}
else if(event.KeyInput.Key==KEY_RETURN)
{
quitMenu();
return true;
}
}
}
if(event.EventType==EET_GUI_EVENT)
{
if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
&& isVisible())
{
if(!canTakeFocus(event.GUIEvent.Element))
{
dstream<<"GUIPauseMenu: Not allowing focus change."
<<std::endl;
// Returning true disables focus change
return true;
}
}
if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
{
switch(event.GUIEvent.Caller->getID())
{
case 256: // continue
quitMenu();
// ALWAYS return immediately after quitMenu()
return true;
case 261:
m_gamecallback->changePassword();
quitMenu();
return true;
case 262:
m_gamecallback->changeVolume();
quitMenu();
return true;
case 260: // disconnect
m_gamecallback->disconnect();
quitMenu();
return true;
case 257: // exit
m_gamecallback->exitToOS();
quitMenu();
return true;
}
}
}
return Parent ? Parent->OnEvent(event) : false;
}

@ -1,63 +0,0 @@
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
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
(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
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef GUIPAUSEMENU_HEADER
#define GUIPAUSEMENU_HEADER
#include "irrlichttypes_extrabloated.h"
#include "modalMenu.h"
class IGameCallback
{
public:
virtual void exitToOS() = 0;
virtual void disconnect() = 0;
virtual void changePassword() = 0;
virtual void changeVolume() = 0;
};
class GUIPauseMenu : public GUIModalMenu
{
public:
GUIPauseMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
IGameCallback *gamecallback,
IMenuManager *menumgr,
bool simple_singleplayer_mode);
~GUIPauseMenu();
void removeChildren();
/*
Remove and re-add (or reposition) stuff
*/
void regenerateGui(v2u32 screensize);
void drawMenu();
bool OnEvent(const SEvent& event);
bool pausesGame(){ return true; }
private:
IGameCallback *m_gamecallback;
bool m_simple_singleplayer_mode;
};
#endif

@ -55,7 +55,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "constants.h" #include "constants.h"
#include "porting.h" #include "porting.h"
#include "gettime.h" #include "gettime.h"
#include "guiMessageMenu.h"
#include "filesys.h" #include "filesys.h"
#include "config.h" #include "config.h"
#include "version.h" #include "version.h"

@ -25,9 +25,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/ */
#include "debug.h" // assert #include "debug.h" // assert
#include "modalMenu.h" #include "modalMenu.h"
#include "guiPauseMenu.h" //For IGameCallback
#include <list> #include <list>
class IGameCallback
{
public:
virtual void exitToOS() = 0;
virtual void disconnect() = 0;
virtual void changePassword() = 0;
virtual void changeVolume() = 0;
};
extern gui::IGUIEnvironment* guienv; extern gui::IGUIEnvironment* guienv;
extern gui::IGUIStaticText *guiroot; extern gui::IGUIStaticText *guiroot;