@@ -122,13 +122,16 @@ struct TextDestPlayerInventory : public TextDest
122
122
struct LocalFormspecHandler : public TextDest
123
123
{
124
124
LocalFormspecHandler ();
125
- LocalFormspecHandler (std::string formname) {
125
+ LocalFormspecHandler (std::string formname) :
126
+ m_client (0 )
127
+ {
126
128
m_formname = formname;
127
129
}
128
130
129
- LocalFormspecHandler (std::string formname,Client *client) {
131
+ LocalFormspecHandler (std::string formname, Client *client) :
132
+ m_client (client)
133
+ {
130
134
m_formname = formname;
131
- m_client = client;
132
135
}
133
136
134
137
void gotText (std::wstring message) {
@@ -167,25 +170,27 @@ struct LocalFormspecHandler : public TextDest
167
170
}
168
171
}
169
172
if (m_formname == " MT_CHAT_MENU" ) {
173
+ assert (m_client != 0 );
170
174
if ((fields.find (" btn_send" ) != fields.end ()) ||
171
175
(fields.find (" quit" ) != fields.end ())) {
172
176
if (fields.find (" f_text" ) != fields.end ()) {
173
- if (m_client != 0 ) {
174
- m_client->typeChatMessage (narrow_to_wide (fields[" f_text" ]));
175
- }
176
- else {
177
- errorstream << " LocalFormspecHandler::gotText received chat message but m_client is NULL" << std::endl;
178
- }
177
+ m_client->typeChatMessage (narrow_to_wide (fields[" f_text" ]));
179
178
}
180
179
return ;
181
180
}
182
181
}
183
182
184
183
if (m_formname == " MT_DEATH_SCREEN" ) {
184
+ assert (m_client != 0 );
185
185
if ((fields.find (" btn_respawn" ) != fields.end ())) {
186
186
m_client->sendRespawn ();
187
187
return ;
188
188
}
189
+
190
+ if (fields.find (" quit" ) != fields.end ()) {
191
+ m_client->sendRespawn ();
192
+ return ;
193
+ }
189
194
}
190
195
191
196
errorstream << " LocalFormspecHandler::gotText unhandled >" << m_formname << " < event" << std::endl;
@@ -963,34 +968,47 @@ bool nodePlacementPrediction(Client &client,
963
968
return false ;
964
969
}
965
970
966
- static void show_chat_menu (FormspecFormSource* current_formspec,
967
- TextDest* current_textdest, IWritableTextureSource* tsrc,
968
- IrrlichtDevice * device, Client* client, std::string text)
971
+ static inline void create_formspec_menu (GUIFormSpecMenu** cur_formspec,
972
+ InventoryManager *invmgr, IGameDef *gamedef,
973
+ IWritableTextureSource* tsrc, IrrlichtDevice * device,
974
+ IFormSource* fs_src, TextDest* txt_dest
975
+ ) {
976
+
977
+ if (*cur_formspec == 0 ) {
978
+ *cur_formspec = new GUIFormSpecMenu (device, guiroot, -1 , &g_menumgr,
979
+ invmgr, gamedef, tsrc, fs_src, txt_dest, cur_formspec );
980
+ (*cur_formspec)->doPause = false ;
981
+ (*cur_formspec)->drop ();
982
+ }
983
+ else {
984
+ (*cur_formspec)->setFormSource (fs_src);
985
+ (*cur_formspec)->setTextDest (txt_dest);
986
+ }
987
+ }
988
+
989
+ static void show_chat_menu (GUIFormSpecMenu** cur_formspec,
990
+ InventoryManager *invmgr, IGameDef *gamedef,
991
+ IWritableTextureSource* tsrc, IrrlichtDevice * device,
992
+ Client* client, std::string text)
969
993
{
970
994
std::string formspec =
971
995
" size[11,5.5,true]"
972
996
" field[3,2.35;6,0.5;f_text;;" + text + " ]"
973
- " button_exit[4,3;3,0.5;btn_send;" + wide_to_narrow (wstrgettext (" Proceed" )) + " ]"
997
+ " button_exit[4,3;3,0.5;btn_send;" + wide_to_narrow (wstrgettext (" Proceed" )) + " ]"
974
998
;
975
999
976
1000
/* Create menu */
977
1001
/* Note: FormspecFormSource and LocalFormspecHandler
978
1002
* are deleted by guiFormSpecMenu */
979
- current_formspec = new FormspecFormSource (formspec,¤t_formspec);
980
- current_textdest = new LocalFormspecHandler (" MT_CHAT_MENU" ,client);
981
- GUIFormSpecMenu *menu =
982
- new GUIFormSpecMenu (device, guiroot, -1 ,
983
- &g_menumgr,
984
- NULL , NULL , tsrc);
985
- menu->doPause = false ;
986
- menu->setFormSource (current_formspec);
987
- menu->setTextDest (current_textdest);
988
- menu->drop ();
1003
+ FormspecFormSource* fs_src = new FormspecFormSource (formspec);
1004
+ LocalFormspecHandler* txt_dst = new LocalFormspecHandler (" MT_CHAT_MENU" , client);
1005
+
1006
+ create_formspec_menu (cur_formspec, invmgr, gamedef, tsrc, device, fs_src, txt_dst);
989
1007
}
990
1008
991
- static void show_deathscreen (FormspecFormSource* current_formspec ,
992
- TextDest* current_textdest, IWritableTextureSource* tsrc ,
993
- IrrlichtDevice * device, Client* client)
1009
+ static void show_deathscreen (GUIFormSpecMenu** cur_formspec ,
1010
+ InventoryManager *invmgr, IGameDef *gamedef ,
1011
+ IWritableTextureSource* tsrc, IrrlichtDevice * device, Client* client)
994
1012
{
995
1013
std::string formspec =
996
1014
std::string (" " ) +
@@ -1003,24 +1021,18 @@ static void show_deathscreen(FormspecFormSource* current_formspec,
1003
1021
/* Create menu */
1004
1022
/* Note: FormspecFormSource and LocalFormspecHandler
1005
1023
* are deleted by guiFormSpecMenu */
1006
- current_formspec = new FormspecFormSource (formspec,¤t_formspec);
1007
- current_textdest = new LocalFormspecHandler (" MT_DEATH_SCREEN" ,client);
1008
- GUIFormSpecMenu *menu =
1009
- new GUIFormSpecMenu (device, guiroot, -1 ,
1010
- &g_menumgr,
1011
- NULL , NULL , tsrc);
1012
- menu->doPause = false ;
1013
- menu->setFormSource (current_formspec);
1014
- menu->setTextDest (current_textdest);
1015
- menu->drop ();
1024
+ FormspecFormSource* fs_src = new FormspecFormSource (formspec);
1025
+ LocalFormspecHandler* txt_dst = new LocalFormspecHandler (" MT_DEATH_SCREEN" , client);
1026
+
1027
+ create_formspec_menu (cur_formspec, invmgr, gamedef, tsrc, device, fs_src, txt_dst);
1016
1028
}
1017
1029
1018
1030
/* *****************************************************************************/
1019
- static void show_pause_menu (FormspecFormSource* current_formspec,
1020
- TextDest* current_textdest, IWritableTextureSource* tsrc,
1021
- IrrlichtDevice * device, bool singleplayermode)
1031
+ static void show_pause_menu (GUIFormSpecMenu** cur_formspec,
1032
+ InventoryManager *invmgr, IGameDef *gamedef,
1033
+ IWritableTextureSource* tsrc, IrrlichtDevice * device,
1034
+ bool singleplayermode)
1022
1035
{
1023
-
1024
1036
std::string control_text = wide_to_narrow (wstrgettext (" Default Controls:\n "
1025
1037
" - WASD: move\n "
1026
1038
" - Space: jump/climb\n "
@@ -1046,7 +1058,7 @@ static void show_pause_menu(FormspecFormSource* current_formspec,
1046
1058
<< wide_to_narrow (wstrgettext (" Change Password" )) << " ]" ;
1047
1059
}
1048
1060
1049
- os << " button_exit[4," << (ypos++) << " ;3,0.5;btn_sound;"
1061
+ os << " button_exit[4," << (ypos++) << " ;3,0.5;btn_sound;"
1050
1062
<< wide_to_narrow (wstrgettext (" Sound Volume" )) << " ]" ;
1051
1063
os << " button_exit[4," << (ypos++) << " ;3,0.5;btn_exit_menu;"
1052
1064
<< wide_to_narrow (wstrgettext (" Exit to Menu" )) << " ]" ;
@@ -1061,14 +1073,10 @@ static void show_pause_menu(FormspecFormSource* current_formspec,
1061
1073
/* Create menu */
1062
1074
/* Note: FormspecFormSource and LocalFormspecHandler *
1063
1075
* are deleted by guiFormSpecMenu */
1064
- current_formspec = new FormspecFormSource (os.str (),¤t_formspec);
1065
- current_textdest = new LocalFormspecHandler (" MT_PAUSE_MENU" );
1066
- GUIFormSpecMenu *menu =
1067
- new GUIFormSpecMenu (device, guiroot, -1 , &g_menumgr, NULL , NULL , tsrc);
1068
- menu->doPause = true ;
1069
- menu->setFormSource (current_formspec);
1070
- menu->setTextDest (current_textdest);
1071
- menu->drop ();
1076
+ FormspecFormSource* fs_src = new FormspecFormSource (os.str ());
1077
+ LocalFormspecHandler* txt_dst = new LocalFormspecHandler (" MT_PAUSE_MENU" );
1078
+
1079
+ create_formspec_menu (cur_formspec, invmgr, gamedef, tsrc, device, fs_src, txt_dst);
1072
1080
}
1073
1081
1074
1082
/* *****************************************************************************/
@@ -1080,8 +1088,7 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
1080
1088
const SubgameSpec &gamespec /* Used for local game */ ,
1081
1089
bool simple_singleplayer_mode)
1082
1090
{
1083
- FormspecFormSource* current_formspec = 0 ;
1084
- TextDest* current_textdest = 0 ;
1091
+ GUIFormSpecMenu* current_formspec = 0 ;
1085
1092
video::IVideoDriver* driver = device->getVideoDriver ();
1086
1093
scene::ISceneManager* smgr = device->getSceneManager ();
1087
1094
@@ -1911,34 +1918,29 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
1911
1918
infostream<<" the_game: "
1912
1919
<<" Launching inventory" <<std::endl;
1913
1920
1914
- GUIFormSpecMenu *menu =
1915
- new GUIFormSpecMenu (device, guiroot, - 1 ,
1916
- &g_menumgr,
1917
- & client, gamedef, tsrc);
1921
+ PlayerInventoryFormSource* fs_src = new PlayerInventoryFormSource (&client);
1922
+ TextDest* txt_dst = new TextDestPlayerInventory (&client);
1923
+
1924
+ create_formspec_menu (¤t_formspec, & client, gamedef, tsrc, device, fs_src, txt_dst );
1918
1925
1919
1926
InventoryLocation inventoryloc;
1920
1927
inventoryloc.setCurrentPlayer ();
1921
-
1922
- PlayerInventoryFormSource *src = new PlayerInventoryFormSource (&client);
1923
- assert (src);
1924
- menu->doPause = false ;
1925
- menu->setFormSpec (src->getForm (), inventoryloc);
1926
- menu->setFormSource (src);
1927
- menu->setTextDest (new TextDestPlayerInventory (&client));
1928
- menu->drop ();
1928
+ current_formspec->setFormSpec (fs_src->getForm (), inventoryloc);
1929
1929
}
1930
1930
else if (input->wasKeyDown (EscapeKey))
1931
1931
{
1932
- show_pause_menu (current_formspec, current_textdest , tsrc, device,
1932
+ show_pause_menu (& current_formspec, &client, gamedef , tsrc, device,
1933
1933
simple_singleplayer_mode);
1934
1934
}
1935
1935
else if (input->wasKeyDown (getKeySetting (" keymap_chat" )))
1936
1936
{
1937
- show_chat_menu (current_formspec, current_textdest, tsrc, device, &client," " );
1937
+ show_chat_menu (¤t_formspec, &client, gamedef, tsrc, device,
1938
+ &client," " );
1938
1939
}
1939
1940
else if (input->wasKeyDown (getKeySetting (" keymap_cmd" )))
1940
1941
{
1941
- show_chat_menu (current_formspec, current_textdest, tsrc, device, &client," /" );
1942
+ show_chat_menu (¤t_formspec, &client, gamedef, tsrc, device,
1943
+ &client," /" );
1942
1944
}
1943
1945
else if (input->wasKeyDown (getKeySetting (" keymap_console" )))
1944
1946
{
@@ -2396,8 +2398,8 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
2396
2398
}
2397
2399
else if (event.type == CE_DEATHSCREEN)
2398
2400
{
2399
- show_deathscreen (current_formspec, current_textdest ,
2400
- tsrc, device, &client);
2401
+ show_deathscreen (& current_formspec, &client, gamedef, tsrc ,
2402
+ device, &client);
2401
2403
2402
2404
chat_backend.addMessage (L" " , L" You died." );
2403
2405
@@ -2411,29 +2413,14 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
2411
2413
}
2412
2414
else if (event.type == CE_SHOW_FORMSPEC)
2413
2415
{
2414
- if (current_formspec == 0 )
2415
- {
2416
- /* Create menu */
2417
- /* Note: FormspecFormSource and TextDestPlayerInventory
2418
- * are deleted by guiFormSpecMenu */
2419
- current_formspec = new FormspecFormSource (*(event.show_formspec .formspec ),¤t_formspec);
2420
- current_textdest = new TextDestPlayerInventory (&client,*(event.show_formspec .formname ));
2421
- GUIFormSpecMenu *menu =
2422
- new GUIFormSpecMenu (device, guiroot, -1 ,
2423
- &g_menumgr,
2424
- &client, gamedef, tsrc);
2425
- menu->doPause = false ;
2426
- menu->setFormSource (current_formspec);
2427
- menu->setTextDest (current_textdest);
2428
- menu->drop ();
2429
- }
2430
- else
2431
- {
2432
- assert (current_textdest != 0 );
2433
- /* update menu */
2434
- current_textdest->setFormName (*(event.show_formspec .formname ));
2435
- current_formspec->setForm (*(event.show_formspec .formspec ));
2436
- }
2416
+ FormspecFormSource* fs_src =
2417
+ new FormspecFormSource (*(event.show_formspec .formspec ));
2418
+ TextDestPlayerInventory* txt_dst =
2419
+ new TextDestPlayerInventory (&client,*(event.show_formspec .formname ));
2420
+
2421
+ create_formspec_menu (¤t_formspec, &client, gamedef,
2422
+ tsrc, device, fs_src, txt_dst);
2423
+
2437
2424
delete (event.show_formspec .formspec );
2438
2425
delete (event.show_formspec .formname );
2439
2426
}
@@ -2986,19 +2973,14 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
2986
2973
InventoryLocation inventoryloc;
2987
2974
inventoryloc.setNodeMeta (nodepos);
2988
2975
2989
- /* Create menu */
2990
-
2991
- GUIFormSpecMenu *menu =
2992
- new GUIFormSpecMenu (device, guiroot, -1 ,
2993
- &g_menumgr,
2994
- &client, gamedef, tsrc);
2995
- menu->doPause = false ;
2996
- menu->setFormSpec (meta->getString (" formspec" ),
2997
- inventoryloc);
2998
- menu->setFormSource (new NodeMetadataFormSource (
2999
- &client.getEnv ().getClientMap (), nodepos));
3000
- menu->setTextDest (new TextDestNodeMetadata (nodepos, &client));
3001
- menu->drop ();
2976
+ NodeMetadataFormSource* fs_src = new NodeMetadataFormSource (
2977
+ &client.getEnv ().getClientMap (), nodepos);
2978
+ TextDest* txt_dst = new TextDestNodeMetadata (nodepos, &client);
2979
+
2980
+ create_formspec_menu (¤t_formspec, &client, gamedef,
2981
+ tsrc, device, fs_src, txt_dst);
2982
+
2983
+ current_formspec->setFormSpec (meta->getString (" formspec" ), inventoryloc);
3002
2984
}
3003
2985
// Otherwise report right click to server
3004
2986
else
0 commit comments