-- handle errors
if gamedata.errormessage ~= nil then
- formspec = "size[12,5.2]" ..
+ formspec = "size[12,5.2,true]" ..
"textarea[1,2;10,2;;ERROR: " ..
engine.formspec_escape(gamedata.errormessage) ..
";]"..
function tabbuilder.gettab()
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
retval = retval .. tabbuilder.tab_header()
local mod = filterlist.get_list(modmgr.modlist)[modmgr.world_config_selected_mod]
local retval =
- "size[11,6.5]" ..
+ "size[11,6.5,true]" ..
"label[0.5,-0.25;" .. fgettext("World:") .. "]" ..
"label[1.75,-0.25;" .. worldspec.name .. "]"
-- @function [parent=#modstore] getsuccessfuldialog
function modstore.getsuccessfuldialog()
local retval = ""
- retval = retval .. "size[6,2]"
+ retval = retval .. "size[6,2,true]"
if modstore.lastmodentry ~= nil then
retval = retval .. "label[0,0.25;" .. fgettext("Successfully installed:") .. "]"
retval = retval .. "label[3,0.25;" .. modstore.lastmodentry.moddetails.title .. "]"
--------------------------------------------------------------------------------
-- @function [parent=#modstore] tabheader
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;" ..
"Unsorted,Search;" ..
modstore.nametoindex(tabname) .. ";true;false]" ..
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
- "invsize[8,9;]"..
+ "size[8,9]"..
"list[context;main;0,0;8,4;]"..
"list[current_player;main;0,5;8,4;]")
meta:set_string("infotext", "Chest");
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 = {
- 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"
}
})
Examples:
- Chest:
- invsize[8,9;]
+ size[8,9]
list[context;main;0,0;8,4;]
list[current_player;main;0,5;8,4;]
- Furnace:
- invsize[8,9;]
+ size[8,9]
list[context;fuel;2,3;1,1;]
list[context;src;2,1;1,1;]
list[context;dst;5,1;2,2;]
list[current_player;main;0,5;8,4;]
- Minecraft-like player inventory
- invsize[8,7.5;]
+ size[8,7.5]
image[1,0.6;1,2;player.png]
list[current_player;main;0,3.5;8,4;]
list[current_player;craft;3,0;3,3;]
Elements:
-size[<W>,<H>]
+size[<W>,<H>,<fixed_size>]
^ Define the size of the menu in inventory slots
+^ fixed_size true/false (optional)
^ deprecated: invsize[<W>,<H>;]
list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;]
chat.cpp
hud.cpp
guiKeyChangeMenu.cpp
- guiMessageMenu.cpp
guiTextInputMenu.cpp
guiFormSpecMenu.cpp
guiTable.cpp
- guiPauseMenu.cpp
guiPasswordChange.cpp
guiVolumeChange.cpp
guiDeathScreen.cpp
#include "IMeshCache.h"
#include "client.h"
#include "server.h"
-#include "guiPauseMenu.h"
#include "guiPasswordChange.h"
#include "guiVolumeChange.h"
#include "guiFormSpecMenu.h"
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
{
TextDestNodeMetadata(v3s16 p, Client *client)
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;
}
+ 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;
- std::string m_formname;
};
/* Respawn menu callback */
Find what the player is pointing at
*/
PointedThing getPointedThing(Client *client, v3f player_position,
- v3f camera_direction, v3f camera_position,
- core::line3d<f32> shootline, f32 d,
- bool liquids_pointable,
- bool look_for_object,
- v3s16 camera_offset,
- std::vector<aabb3f> &hilightboxes,
- ClientActiveObject *&selected_object)
+ v3f camera_direction, v3f camera_position, core::line3d<f32> shootline,
+ f32 d, bool liquids_pointable, bool look_for_object, v3s16 camera_offset,
+ std::vector<aabb3f> &hilightboxes, ClientActiveObject *&selected_object)
{
PointedThing result;
Additionally, a progressbar can be drawn when percent is set between 0 and 100.
*/
/*gui::IGUIStaticText **/
-void draw_load_screen(const std::wstring &text,
- IrrlichtDevice* device, gui::IGUIFont* font,
- float dtime=0 ,int percent=0, bool clouds=true)
+void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
+ gui::IGUIFont* font, float dtime=0 ,int percent=0, bool clouds=true)
{
video::IVideoDriver* driver = device->getVideoDriver();
v2u32 screensize = driver->getScreenSize();
/* Profiler display */
void update_profiler_gui(gui::IGUIStaticText *guitext_profiler,
- gui::IGUIFont *font, u32 text_height,
- u32 show_profiler, u32 show_profiler_max)
+ gui::IGUIFont *font, u32 text_height, u32 show_profiler,
+ u32 show_profiler_max)
{
if(show_profiler == 0)
{
};
bool nodePlacementPrediction(Client &client,
- const ItemDefinition &playeritem_def,
- v3s16 nodepos, v3s16 neighbourpos)
+ const ItemDefinition &playeritem_def, v3s16 nodepos, v3s16 neighbourpos)
{
std::string prediction = playeritem_def.node_placement_prediction;
INodeDefManager *nodedef = client.ndef();
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")) + "]"
+ ;
+
+ /* Create menu */
+ /* Note: FormspecFormSource and LocalFormspecHandler
+ * are deleted by guiFormSpecMenu */
+ current_formspec = new FormspecFormSource(formspec,¤t_formspec);
+ current_textdest = new LocalFormspecHandler("MT_CHAT_MENU",client);
+ GUIFormSpecMenu *menu =
+ new GUIFormSpecMenu(device, guiroot, -1,
+ &g_menumgr,
+ NULL, NULL, tsrc);
+ menu->setFormSource(current_formspec);
+ menu->setTextDest(current_textdest);
+ menu->drop();
+}
+
+/******************************************************************************/
+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,¤t_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
-)
+/******************************************************************************/
+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;
- TextDestPlayerInventory* current_textdest = 0;
+ TextDest* current_textdest = 0;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
}
else if(input->wasKeyDown(EscapeKey))
{
- infostream<<"the_game: "
- <<"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);
+ show_pause_menu(current_formspec, current_textdest, tsrc, device);
}
else if(input->wasKeyDown(getKeySetting("keymap_chat")))
{
- TextDest *dest = new TextDestChat(&client);
-
- (new GUITextInputMenu(guienv, guiroot, -1,
- &g_menumgr, dest,
- L""))->drop();
+ show_chat_menu(current_formspec, current_textdest, tsrc, device, &client,"");
}
else if(input->wasKeyDown(getKeySetting("keymap_cmd")))
{
- TextDest *dest = new TextDestChat(&client);
-
- (new GUITextInputMenu(guienv, guiroot, -1,
- &g_menumgr, dest,
- L"/"))->drop();
+ show_chat_menu(current_formspec, current_textdest, tsrc, device, &client,"/");
}
else if(input->wasKeyDown(getKeySetting("keymap_console")))
{
*/
GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
- gui::IGUIElement* parent, s32 id,
- IMenuManager *menumgr,
- InventoryManager *invmgr,
- IGameDef *gamedef,
- ISimpleTextureSource *tsrc
-):
+ gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
+ InventoryManager *invmgr, IGameDef *gamedef,
+ ISimpleTextureSource *tsrc) :
GUIModalMenu(dev->getGUIEnvironment(), parent, id, menumgr),
m_device(dev),
m_invmgr(invmgr),
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,',');
- if (parts.size() == 2) {
+ if ((parts.size() == 2) || parts.size() == 3) {
v2f invsize;
if (parts[1].find(';') != std::string::npos)
invsize.X = stof(parts[0]);
invsize.Y = stof(parts[1]);
+ lockSize(false);
+ if (parts.size() == 3) {
+ if (parts[2] == "true") {
+ lockSize(true,v2u32(800,600));
+ }
+ }
+
if (m_lock) {
v2u32 current_screensize = m_device->getVideoDriver()->getScreenSize();
v2u32 delta = current_screensize - m_lockscreensize;
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) {
errorstream<<"WARNING: invalid use of 'list' with m_gamedef==0"<<std::endl;
return;
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,';');
if ((parts.size() == 3) || (parts.size() == 4)) {
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,';');
if (parts.size() == 3) {
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,';');
if (parts.size() == 3) {
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,';');
if (parts.size() == 4) {
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,';');
if ((parts.size() == 3) || (parts.size() == 4)) {
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,';');
data->table_options.clear();
}
}
-void GUIFormSpecMenu::parseTableColumns(parserData* data,std::string element) {
+void GUIFormSpecMenu::parseTableColumns(parserData* data,std::string element)
+{
std::vector<std::string> parts = split(element,';');
data->table_columns.clear();
}
}
-void GUIFormSpecMenu::parseTable(parserData* data,std::string element) {
+void GUIFormSpecMenu::parseTable(parserData* data,std::string element)
+{
std::vector<std::string> parts = split(element,';');
if ((parts.size() == 4) || (parts.size() == 5)) {
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,';');
if ((parts.size() == 4) || (parts.size() == 5) || (parts.size() == 6)) {
}
-void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element) {
+void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element)
+{
std::vector<std::string> parts = split(element,';');
if (parts.size() == 5) {
<< 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,';');
if (parts.size() == 4) {
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 label = parts[1];
std::string default_val = parts[2];
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_geom = split(parts[1],',');
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,';');
if (parts.size() == 3) {
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,';');
if (parts.size() == 2) {
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,';');
if (parts.size() == 2) {
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,';');
if ((parts.size() == 5) || (parts.size() == 7) || (parts.size() == 8)) {
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,';');
if ((parts.size() == 4) || (parts.size() == 6)) {
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) {
errorstream<<"WARNING: invalid use of item_image_button with m_gamedef==0"<<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,';');
if (parts.size() == 3) {
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,';');
if ((parts.size() == 1) || (parts.size() == 2)) {
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,';');
if ((parts.size() == 2) || (parts.size() == 3) || (parts.size() == 5)) {
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
if (element == "")
return;
return ItemStack();
}
-void GUIFormSpecMenu::acceptInput(bool quit=false)
+void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
{
if(m_text_dst)
{
std::map<std::string, std::string> fields;
- if (quit) {
+ if (quitmode == quit_mode_accept) {
fields["quit"] = "true";
}
+ if (quitmode == quit_mode_cancel) {
+ fields["quit"] = "true";
+ m_text_dst->gotText(fields);
+ return;
+ }
+
if (current_keys_pending.key_down) {
fields["key_down"] = "true";
current_keys_pending.key_down = false;
if (event.KeyInput.PressedDown && (kp == EscapeKey ||
kp == getKeySetting("keymap_inventory")))
{
- if (m_allowclose) {
- acceptInput(true);
+ if (m_allowclose){
+ acceptInput(quit_mode_cancel);
quitMenu();
- } else {
+ } else {
m_text_dst->gotText(narrow_to_wide("MenuQuit"));
}
return true;
break;
}
if (current_keys_pending.key_enter && m_allowclose) {
- acceptInput(true);
+ acceptInput(quit_mode_accept);
quitMenu();
}
else {
if (btn_id == 257) {
if (m_allowclose) {
- acceptInput(true);
+ acceptInput(quit_mode_accept);
quitMenu();
} else {
acceptInput();
acceptInput();
if(s.is_exit){
if (m_allowclose) {
- acceptInput(true);
+ acceptInput(quit_mode_accept);
quitMenu();
} else {
m_text_dst->gotText(narrow_to_wide("ExitButton"));
{
if (m_allowclose) {
- acceptInput(true);
+ acceptInput(quit_mode_accept);
quitMenu();
}
else {
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;
if (value[0] == '#') {
f_Unknown
} FormspecFieldType;
+typedef enum {
+ quit_mode_no,
+ quit_mode_accept,
+ quit_mode_cancel
+} FormspecQuitMode;
+
struct TextDest
{
virtual ~TextDest() {};
// This is deprecated I guess? -celeron55
virtual void gotText(std::wstring text){}
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
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),
flabel(label),
fdefault(fdeflt),
void updateSelectedItem();
ItemStack verifySelectedItem();
- void acceptInput(bool quit);
+ void acceptInput(FormspecQuitMode quitmode);
bool preprocessEvent(const SEvent& event);
bool OnEvent(const SEvent& event);
void parsePwdField(parserData* data,std::string element);
void parseField(parserData* data,std::string element,std::string type);
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 parseVertLabel(parserData* data,std::string element);
void parseImageButton(parserData* data,std::string element,std::string type);
+++ /dev/null
-/*
-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;
-}
-
+++ /dev/null
-/*
-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
-
+++ /dev/null
-/*
-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;
-}
-
+++ /dev/null
-/*
-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
-
#include "constants.h"
#include "porting.h"
#include "gettime.h"
-#include "guiMessageMenu.h"
#include "filesys.h"
#include "config.h"
#include "version.h"
*/
#include "debug.h" // assert
#include "modalMenu.h"
-#include "guiPauseMenu.h" //For IGameCallback
#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::IGUIStaticText *guiroot;