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 "PagedGump.h"
00021
00022 #include "GameData.h"
00023 #include "GumpShapeArchive.h"
00024 #include "Shape.h"
00025 #include "ShapeFrame.h"
00026 #include "GUIApp.h"
00027 #include "ButtonWidget.h"
00028
00029 DEFINE_RUNTIME_CLASSTYPE_CODE(PagedGump,ModalGump);
00030
00031 PagedGump::PagedGump(int left, int right, int top, int shape):
00032 ModalGump(0, 0, 5, 5), leftOff(left), rightOff(right), topOff(top),
00033 gumpShape(shape), nextButton(0), prevButton(0), buttonsEnabled(true)
00034 {
00035 current = gumps.end();
00036 }
00037
00038 PagedGump::~PagedGump(void)
00039 {
00040 gumps.clear();
00041 }
00042
00043 void PagedGump::Close(bool no_del)
00044 {
00045 GUIApp::get_instance()->popMouseCursor();
00046 std::vector<Gump*>::iterator iter;
00047 for (iter=gumps.begin(); iter != gumps.end(); ++iter) {
00048 (*iter)->Close(no_del);
00049 }
00050
00051 ModalGump::Close(no_del);
00052 }
00053
00054 static const int pageOverShape = 34;
00055
00056 void PagedGump::InitGump(Gump* newparent, bool take_focus)
00057 {
00058 ModalGump::InitGump(newparent, take_focus);
00059
00060 shape = GameData::get_instance()->getGumps()->getShape(gumpShape);
00061 ShapeFrame* sf = shape->getFrame(0);
00062 assert(sf);
00063
00064 dims.w = sf->width;
00065 dims.h = sf->height;
00066
00067 FrameID buttonleft(GameData::GUMPS, pageOverShape, 0);
00068 FrameID buttonright(GameData::GUMPS, pageOverShape, 1);
00069
00071 nextButton = new ButtonWidget(0, 0, buttonright, buttonright, false,
00072 LAYER_ABOVE_NORMAL);
00073 nextButton->InitGump(this);
00074 nextButton->setRelativePosition(TOP_RIGHT, rightOff, topOff);
00075
00076 prevButton = new ButtonWidget(0, 0, buttonleft, buttonleft, false,
00077 LAYER_ABOVE_NORMAL);
00078 prevButton->InitGump(this);
00079 prevButton->setRelativePosition(TOP_LEFT, leftOff, topOff);
00080 prevButton->HideGump();
00081
00082 GUIApp * guiapp = GUIApp::get_instance();
00083 guiapp->pushMouseCursor();
00084 guiapp->setMouseCursor(GUIApp::MOUSE_HAND);
00085 }
00086
00087 void PagedGump::PaintThis(RenderSurface* surf, sint32 lerp_factor, bool scaled)
00088 {
00089 Gump::PaintThis(surf, lerp_factor, scaled);
00090 }
00091
00092
00093
00094 bool PagedGump::OnKeyDown(int key, int mod)
00095 {
00096 if (current != gumps.end())
00097 if ((*current)->OnKeyDown(key, mod)) return true;
00098
00099 switch (key)
00100 {
00101 case SDLK_ESCAPE:
00102 Close();
00103 return true;
00104 default:
00105 break;
00106 }
00107
00108 return true;
00109 }
00110
00111 void PagedGump::ChildNotify(Gump *child, uint32 message)
00112 {
00113 if (!buttonsEnabled) return;
00114 if (gumps.empty()) return;
00115
00116 ObjId cid = child->getObjId();
00117
00118 if (message == ButtonWidget::BUTTON_CLICK)
00119 {
00120 if (cid == nextButton->getObjId())
00121 {
00122 if (current + 1 != gumps.end())
00123 {
00124 (*current)->HideGump();
00125 ++current;
00126 (*current)->UnhideGump();
00127 (*current)->MakeFocus();
00128
00129 if (current + 1 == gumps.end())
00130 nextButton->HideGump();
00131
00132 prevButton->UnhideGump();
00133 }
00134 }
00135 else if (cid == prevButton->getObjId())
00136 {
00137 if (current != gumps.begin())
00138 {
00139 (*current)->HideGump();
00140 --current;
00141 (*current)->UnhideGump();
00142 (*current)->MakeFocus();
00143
00144 if (current == gumps.begin())
00145 prevButton->HideGump();
00146
00147 nextButton->UnhideGump();
00148 }
00149 }
00150 }
00151 }
00152
00153 void PagedGump::addPage(Gump * g)
00154 {
00155 assert(g->GetParent() == this);
00156 g->setRelativePosition(TOP_CENTER, 0, 3 + topOff);
00157 g->HideGump();
00158 gumps.push_back(g);
00159
00160 current = gumps.begin();
00161 (*current)->UnhideGump();
00162 if (focus_child != *current)
00163 (*current)->MakeFocus();
00164
00165 if (current + 1 == gumps.end())
00166 nextButton->HideGump();
00167 else
00168 nextButton->UnhideGump();
00169 }
00170
00171 bool PagedGump::loadData(IDataSource* ids)
00172 {
00173 CANT_HAPPEN_MSG("Trying to load ModalGump");
00174 return false;
00175 }
00176
00177 void PagedGump::saveData(ODataSource* ods)
00178 {
00179 CANT_HAPPEN_MSG("Trying to save ModalGump");
00180 }
00181