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 wchar_t* text = wgettext("You died.");
97 Environment->addStaticText(text, rect, false,
102 core::rect<s32> rect(0, 0, 140, 30);
103 rect = rect + v2s32(size.X/2-140/2, size.Y/2-30/2+25);
104 wchar_t* text = wgettext("Respawn");
105 gui::IGUIElement *e =
106 Environment->addButton(rect, this, 257,
109 Environment->setFocus(e);
114 void GUIDeathScreen::drawMenu()
116 gui::IGUISkin* skin = Environment->getSkin();
119 video::IVideoDriver* driver = Environment->getVideoDriver();
122 video::SColor color(180,50,0,0);
123 driver->draw2DRectangle(color,
124 core::rect<s32>(0,0,m_screensize.X,m_screensize.Y), NULL);
127 video::SColor bgcolor(50,0,0,0);
128 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
131 gui::IGUIElement::draw();
134 bool GUIDeathScreen::OnEvent(const SEvent& event)
136 if(event.EventType==EET_KEY_INPUT_EVENT)
138 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
144 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
151 if(event.EventType==EET_GUI_EVENT)
153 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
156 if(!canTakeFocus(event.GUIEvent.Element))
158 dstream<<"GUIDeathScreen: Not allowing focus change."
160 // Returning true disables focus change
164 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
166 switch(event.GUIEvent.Caller->getID())
176 return Parent ? Parent->OnEvent(event) : false;
179 void GUIDeathScreen::respawn()
181 m_respawner->respawn();