00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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