3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "guiDeathScreen.h"
22 #include "serialization.h"
24 #include <IGUICheckBox.h>
25 #include <IGUIEditBox.h>
26 #include <IGUIButton.h>
27 #include <IGUIStaticText.h>
32 GUIDeathScreen::GUIDeathScreen(gui::IGUIEnvironment* env,
33 gui::IGUIElement* parent, s32 id,
34 IMenuManager *menumgr, IRespawnInitiator *respawner
36 GUIModalMenu(env, parent, id, menumgr),
37 m_respawner(respawner),
42 GUIDeathScreen::~GUIDeathScreen()
48 void GUIDeathScreen::removeChildren()
50 const core::list<gui::IGUIElement*> &children = getChildren();
51 core::list<gui::IGUIElement*> children_copy;
52 for(core::list<gui::IGUIElement*>::ConstIterator
53 i = children.begin(); i != children.end(); i++)
55 children_copy.push_back(*i);
57 for(core::list<gui::IGUIElement*>::Iterator
58 i = children_copy.begin();
59 i != children_copy.end(); i++)
65 void GUIDeathScreen::regenerateGui(v2u32 screensize)
67 m_screensize = screensize;
75 Calculate new sizes and positions
78 screensize.X/2 - 500/2,
79 screensize.Y/2 - 200/2,
80 screensize.X/2 + 500/2,
81 screensize.Y/2 + 200/2
85 recalculateAbsolutePosition(false);
87 v2s32 size = rect.getSize();
94 core::rect<s32> rect(0, 0, 400, 50);
95 rect = rect + v2s32(size.X/2-400/2, size.Y/2-50/2-25);
96 Environment->addStaticText(wgettext("You died."), rect, false,
100 core::rect<s32> rect(0, 0, 140, 30);
101 rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
102 gui::IGUIElement *e =
103 Environment->addButton(rect, this, 257,
104 wgettext("Respawn"));
105 Environment->setFocus(e);
110 void GUIDeathScreen::drawMenu()
112 gui::IGUISkin* skin = Environment->getSkin();
115 video::IVideoDriver* driver = Environment->getVideoDriver();
118 video::SColor color(180,50,0,0);
119 driver->draw2DRectangle(color,
120 core::rect<s32>(0,0,m_screensize.X,m_screensize.Y), NULL);
123 video::SColor bgcolor(50,0,0,0);
124 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
127 gui::IGUIElement::draw();
130 bool GUIDeathScreen::OnEvent(const SEvent& event)
132 if(event.EventType==EET_KEY_INPUT_EVENT)
134 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
140 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
147 if(event.EventType==EET_GUI_EVENT)
149 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
152 if(!canTakeFocus(event.GUIEvent.Element))
154 dstream<<"GUIDeathScreen: Not allowing focus change."
156 // Returning true disables focus change
160 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
162 switch(event.GUIEvent.Caller->getID())
172 return Parent ? Parent->OnEvent(event) : false;
175 void GUIDeathScreen::respawn()
177 m_respawner->respawn();