Replace deathscreen by formspec variant
parent
eda9214f81
commit
0d93119040
|
@ -449,7 +449,6 @@ set(minetest_SRCS
|
|||
guiTable.cpp
|
||||
guiPasswordChange.cpp
|
||||
guiVolumeChange.cpp
|
||||
guiDeathScreen.cpp
|
||||
guiChatConsole.cpp
|
||||
client.cpp
|
||||
clientmedia.cpp
|
||||
|
|
77
src/game.cpp
77
src/game.cpp
|
@ -32,7 +32,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "guiVolumeChange.h"
|
||||
#include "guiFormSpecMenu.h"
|
||||
#include "guiTextInputMenu.h"
|
||||
#include "guiDeathScreen.h"
|
||||
#include "tool.h"
|
||||
#include "guiChatConsole.h"
|
||||
#include "config.h"
|
||||
|
@ -182,6 +181,13 @@ struct LocalFormspecHandler : public TextDest
|
|||
}
|
||||
}
|
||||
|
||||
if (m_formname == "MT_DEATH_SCREEN") {
|
||||
if ((fields.find("btn_respawn") != fields.end())) {
|
||||
m_client->sendRespawn();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
errorstream << "LocalFormspecHandler::gotText unhandled >" << m_formname << "< event" << std::endl;
|
||||
int i = 0;
|
||||
for (std::map<std::string,std::string>::iterator iter = fields.begin();
|
||||
|
@ -194,26 +200,6 @@ struct LocalFormspecHandler : public TextDest
|
|||
Client *m_client;
|
||||
};
|
||||
|
||||
/* Respawn menu callback */
|
||||
|
||||
class MainRespawnInitiator: public IRespawnInitiator
|
||||
{
|
||||
public:
|
||||
MainRespawnInitiator(bool *active, Client *client):
|
||||
m_active(active), m_client(client)
|
||||
{
|
||||
*m_active = true;
|
||||
}
|
||||
void respawn()
|
||||
{
|
||||
*m_active = false;
|
||||
m_client->sendRespawn();
|
||||
}
|
||||
private:
|
||||
bool *m_active;
|
||||
Client *m_client;
|
||||
};
|
||||
|
||||
/* Form update callback */
|
||||
|
||||
class NodeMetadataFormSource: public IFormSource
|
||||
|
@ -1002,6 +988,32 @@ static void show_chat_menu(FormspecFormSource* current_formspec,
|
|||
menu->drop();
|
||||
}
|
||||
|
||||
static void show_deathscreen(FormspecFormSource* current_formspec,
|
||||
TextDest* current_textdest, IWritableTextureSource* tsrc,
|
||||
IrrlichtDevice * device, Client* client)
|
||||
{
|
||||
std::string formspec =
|
||||
std::string("") +
|
||||
"size[11,5.5,true]"
|
||||
"label[4.85,1.35;You died.]"
|
||||
"button_exit[4,3;3,0.5;btn_respawn;" + gettext("Respawn") + "]"
|
||||
;
|
||||
|
||||
/* Create menu */
|
||||
/* Note: FormspecFormSource and LocalFormspecHandler
|
||||
* are deleted by guiFormSpecMenu */
|
||||
current_formspec = new FormspecFormSource(formspec,¤t_formspec);
|
||||
current_textdest = new LocalFormspecHandler("MT_DEATH_SCREEN",client);
|
||||
GUIFormSpecMenu *menu =
|
||||
new GUIFormSpecMenu(device, guiroot, -1,
|
||||
&g_menumgr,
|
||||
NULL, NULL, tsrc);
|
||||
menu->doPause = false;
|
||||
menu->setFormSource(current_formspec);
|
||||
menu->setTextDest(current_textdest);
|
||||
menu->drop();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
static void show_pause_menu(FormspecFormSource* current_formspec,
|
||||
TextDest* current_textdest, IWritableTextureSource* tsrc,
|
||||
|
@ -1593,7 +1605,6 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
|
|||
|
||||
bool invert_mouse = g_settings->getBool("invert_mouse");
|
||||
|
||||
bool respawn_menu_active = false;
|
||||
bool update_wielded_item_trigger = true;
|
||||
|
||||
bool show_hud = true;
|
||||
|
@ -2384,36 +2395,18 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
|
|||
}
|
||||
else if(event.type == CE_DEATHSCREEN)
|
||||
{
|
||||
if(respawn_menu_active)
|
||||
continue;
|
||||
show_deathscreen(current_formspec, current_textdest,
|
||||
tsrc, device, &client);
|
||||
|
||||
/*bool set_camera_point_target =
|
||||
event.deathscreen.set_camera_point_target;
|
||||
v3f camera_point_target;
|
||||
camera_point_target.X = event.deathscreen.camera_point_target_x;
|
||||
camera_point_target.Y = event.deathscreen.camera_point_target_y;
|
||||
camera_point_target.Z = event.deathscreen.camera_point_target_z;*/
|
||||
MainRespawnInitiator *respawner =
|
||||
new MainRespawnInitiator(
|
||||
&respawn_menu_active, &client);
|
||||
GUIDeathScreen *menu =
|
||||
new GUIDeathScreen(guienv, guiroot, -1,
|
||||
&g_menumgr, respawner);
|
||||
menu->drop();
|
||||
|
||||
chat_backend.addMessage(L"", L"You died.");
|
||||
|
||||
/* Handle visualization */
|
||||
|
||||
damage_flash = 0;
|
||||
|
||||
LocalPlayer* player = client.getEnv().getLocalPlayer();
|
||||
player->hurt_tilt_timer = 0;
|
||||
player->hurt_tilt_strength = 0;
|
||||
|
||||
/*LocalPlayer* player = client.getLocalPlayer();
|
||||
player->setPosition(player->getPosition() + v3f(0,-BS,0));
|
||||
camera.update(player, busytime, screensize);*/
|
||||
}
|
||||
else if (event.type == CE_SHOW_FORMSPEC)
|
||||
{
|
||||
|
|
|
@ -1,182 +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 "guiDeathScreen.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"
|
||||
#include "client.h"
|
||||
|
||||
GUIDeathScreen::GUIDeathScreen(gui::IGUIEnvironment* env,
|
||||
gui::IGUIElement* parent, s32 id,
|
||||
IMenuManager *menumgr, IRespawnInitiator *respawner
|
||||
):
|
||||
GUIModalMenu(env, parent, id, menumgr),
|
||||
m_respawner(respawner),
|
||||
m_screensize(1,1)
|
||||
{
|
||||
}
|
||||
|
||||
GUIDeathScreen::~GUIDeathScreen()
|
||||
{
|
||||
removeChildren();
|
||||
delete m_respawner;
|
||||
}
|
||||
|
||||
void GUIDeathScreen::removeChildren()
|
||||
{
|
||||
const core::list<gui::IGUIElement*> &children = getChildren();
|
||||
core::list<gui::IGUIElement*> children_copy;
|
||||
for(core::list<gui::IGUIElement*>::ConstIterator
|
||||
i = children.begin(); i != children.end(); i++)
|
||||
{
|
||||
children_copy.push_back(*i);
|
||||
}
|
||||
for(core::list<gui::IGUIElement*>::Iterator
|
||||
i = children_copy.begin();
|
||||
i != children_copy.end(); i++)
|
||||
{
|
||||
(*i)->remove();
|
||||
}
|
||||
}
|
||||
|
||||
void GUIDeathScreen::regenerateGui(v2u32 screensize)
|
||||
{
|
||||
m_screensize = screensize;
|
||||
|
||||
/*
|
||||
Remove stuff
|
||||
*/
|
||||
removeChildren();
|
||||
|
||||
/*
|
||||
Calculate new sizes and positions
|
||||
*/
|
||||
core::rect<s32> rect(
|
||||
screensize.X/2 - 500/2,
|
||||
screensize.Y/2 - 200/2,
|
||||
screensize.X/2 + 500/2,
|
||||
screensize.Y/2 + 200/2
|
||||
);
|
||||
|
||||
DesiredRect = rect;
|
||||
recalculateAbsolutePosition(false);
|
||||
|
||||
v2s32 size = rect.getSize();
|
||||
|
||||
/*
|
||||
Add stuff
|
||||
*/
|
||||
|
||||
{
|
||||
core::rect<s32> rect(0, 0, 400, 50);
|
||||
rect = rect + v2s32(size.X/2-400/2, size.Y/2-50/2-25);
|
||||
wchar_t* text = wgettext("You died.");
|
||||
Environment->addStaticText(text, rect, false,
|
||||
true, this, 256);
|
||||
delete[] text;
|
||||
}
|
||||
{
|
||||
core::rect<s32> rect(0, 0, 140, 30);
|
||||
rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
|
||||
wchar_t* text = wgettext("Respawn");
|
||||
gui::IGUIElement *e =
|
||||
Environment->addButton(rect, this, 257,
|
||||
text);
|
||||
delete[] text;
|
||||
Environment->setFocus(e);
|
||||
}
|
||||
}
|
||||
|
||||
void GUIDeathScreen::drawMenu()
|
||||
{
|
||||
gui::IGUISkin* skin = Environment->getSkin();
|
||||
if (!skin)
|
||||
return;
|
||||
video::IVideoDriver* driver = Environment->getVideoDriver();
|
||||
|
||||
{
|
||||
video::SColor color(180,50,0,0);
|
||||
driver->draw2DRectangle(color,
|
||||
core::rect<s32>(0,0,m_screensize.X,m_screensize.Y), NULL);
|
||||
}
|
||||
{
|
||||
video::SColor bgcolor(50,0,0,0);
|
||||
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
|
||||
}
|
||||
|
||||
gui::IGUIElement::draw();
|
||||
}
|
||||
|
||||
bool GUIDeathScreen::OnEvent(const SEvent& event)
|
||||
{
|
||||
if(event.EventType==EET_KEY_INPUT_EVENT)
|
||||
{
|
||||
if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
|
||||
{
|
||||
respawn();
|
||||
quitMenu();
|
||||
return true;
|
||||
}
|
||||
if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
|
||||
{
|
||||
respawn();
|
||||
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<<"GUIDeathScreen: 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:
|
||||
respawn();
|
||||
quitMenu();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Parent ? Parent->OnEvent(event) : false;
|
||||
}
|
||||
|
||||
void GUIDeathScreen::respawn()
|
||||
{
|
||||
m_respawner->respawn();
|
||||
}
|
||||
|
|
@ -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 IRespawnInitiator
|
||||
{
|
||||
public:
|
||||
virtual void respawn() = 0;
|
||||
virtual ~IRespawnInitiator() {};
|
||||
};
|
||||
|
||||
class GUIDeathScreen : public GUIModalMenu
|
||||
{
|
||||
public:
|
||||
GUIDeathScreen(gui::IGUIEnvironment* env,
|
||||
gui::IGUIElement* parent, s32 id,
|
||||
IMenuManager *menumgr, IRespawnInitiator *respawner);
|
||||
~GUIDeathScreen();
|
||||
|
||||
void removeChildren();
|
||||
/*
|
||||
Remove and re-add (or reposition) stuff
|
||||
*/
|
||||
void regenerateGui(v2u32 screensize);
|
||||
|
||||
void drawMenu();
|
||||
|
||||
bool OnEvent(const SEvent& event);
|
||||
|
||||
void respawn();
|
||||
|
||||
private:
|
||||
IRespawnInitiator *m_respawner;
|
||||
v2u32 m_screensize;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue