QuitGump.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004-2005  The Pentagram Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include "pent_include.h"
00020 #include "QuitGump.h"
00021 
00022 #include "GameData.h"
00023 #include "GumpShapeArchive.h"
00024 #include "Shape.h"
00025 #include "ShapeFrame.h"
00026 #include "GUIApp.h"
00027 #include "DesktopGump.h"
00028 #include "ButtonWidget.h"
00029 #include "TextWidget.h"
00030 
00031 #include "IDataSource.h"
00032 #include "ODataSource.h"
00033 
00034 DEFINE_RUNTIME_CLASSTYPE_CODE(QuitGump,ModalGump);
00035 
00036 QuitGump::QuitGump(): ModalGump(0, 0, 5, 5)
00037 {
00038         GUIApp * app = GUIApp::get_instance();
00039         app->pushMouseCursor();
00040         app->setMouseCursor(GUIApp::MOUSE_HAND);
00041 }
00042 
00043 QuitGump::~QuitGump()
00044 {
00045         GUIApp::get_instance()->popMouseCursor();
00046 }
00047 
00048 static const int gumpShape = 17;
00049 static const int askShapeId = 18;
00050 static const int yesShapeId = 47;
00051 static const int noShapeId = 50;
00052 
00053 void QuitGump::InitGump(Gump* newparent, bool take_focus)
00054 {
00055         ModalGump::InitGump(newparent, take_focus);
00056 
00057         shape = GameData::get_instance()->getGumps()->getShape(gumpShape);
00058         ShapeFrame* sf = shape->getFrame(0);
00059         assert(sf);
00060 
00061         dims.w = sf->width;
00062         dims.h = sf->height;
00063 
00064         FrameID askshape(GameData::GUMPS, askShapeId, 0);
00065         askshape = _TL_SHP_(askshape);
00066 
00067         Shape* askShape = GameData::get_instance()->getShape(askshape);
00068         sf = askShape->getFrame(askshape.framenum);
00069         assert(sf);
00070 
00071         Gump * ask = new Gump(0, 0, sf->width, sf->height);
00072         ask->SetShape(askShape, askshape.framenum);
00073         ask->InitGump(this);
00074         ask->setRelativePosition(TOP_CENTER, 0, 5);
00075 
00076         FrameID yesbutton_up(GameData::GUMPS, yesShapeId, 0);
00077         FrameID yesbutton_down(GameData::GUMPS, yesShapeId, 1);
00078         yesbutton_up = _TL_SHP_(yesbutton_up);
00079         yesbutton_down = _TL_SHP_(yesbutton_down);
00080 
00081         Gump * widget;
00082         widget = new ButtonWidget(0, 0, yesbutton_up, yesbutton_down);
00083         widget->InitGump(this);
00084         widget->setRelativePosition(TOP_LEFT, 16, 38);
00085         yesWidget = widget->getObjId();
00086 
00087         FrameID nobutton_up(GameData::GUMPS, noShapeId, 0);
00088         FrameID nobutton_down(GameData::GUMPS, noShapeId, 1);
00089         nobutton_up = _TL_SHP_(nobutton_up);
00090         nobutton_down = _TL_SHP_(nobutton_down);
00091 
00092         widget = new ButtonWidget(0, 0, nobutton_up, nobutton_down);
00093         widget->InitGump(this);
00094         widget->setRelativePosition(TOP_RIGHT, -16, 38);
00095         noWidget = widget->getObjId();
00096 }
00097 
00098 
00099 void QuitGump::PaintThis(RenderSurface* surf, sint32 lerp_factor, bool scaled)
00100 {
00101         Gump::PaintThis(surf, lerp_factor, scaled);
00102 }
00103 
00104 bool QuitGump::OnKeyDown(int key, int mod)
00105 {
00106         switch (key)
00107         {
00108         case SDLK_ESCAPE:
00109         {
00110                 Close();
00111         } break;
00112         default:
00113                 break;
00114         }
00115 
00116         return true;
00117 }
00118 
00119 void QuitGump::ChildNotify(Gump *child, uint32 message)
00120 {
00121         ObjId cid = child->getObjId();
00122         if (message == ButtonWidget::BUTTON_CLICK)
00123         {
00124                 if (cid == yesWidget)
00125                 {
00126                         GUIApp::get_instance()->ForceQuit();
00127                 }
00128                 else if (cid == noWidget)
00129                 {
00130                         Close();
00131                 }
00132         }
00133 }
00134 
00135 bool QuitGump::OnTextInput(int unicode)
00136 {
00137         if (!(unicode & 0xFF80)) {
00138                 char c = unicode & 0x7F;
00139                 if (_TL_("Yy").find(c) != std::string::npos) {
00140                         GUIApp::get_instance()->ForceQuit();
00141                 } else if (_TL_("Nn").find(c) != std::string::npos) {
00142                         Close();
00143                 }
00144         }
00145         return true;
00146 }
00147 
00148 //static
00149 void QuitGump::verifyQuit()
00150 {
00151         ModalGump* gump = new QuitGump();
00152         gump->InitGump(0);
00153         gump->setRelativePosition(CENTER);
00154 }
00155 
00156 void QuitGump::ConCmd_verifyQuit(const Console::ArgvType &argv)
00157 {
00158         QuitGump::verifyQuit();
00159 }
00160 
00161 bool QuitGump::loadData(IDataSource* ids)
00162 {
00163         CANT_HAPPEN_MSG("Trying to load ModalGump");
00164         return true;
00165 }
00166 
00167 void QuitGump::saveData(ODataSource* ods)
00168 {
00169         CANT_HAPPEN_MSG("Trying to save ModalGump");
00170 }
00171 

Generated on Fri Jul 27 22:27:30 2007 for pentagram by  doxygen 1.4.7