ReadableGump.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004-2006  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 "ReadableGump.h"
00021 
00022 #include "TextWidget.h"
00023 #include "GameData.h"
00024 #include "Shape.h"
00025 #include "GumpShapeArchive.h"
00026 #include "ShapeFrame.h"
00027 #include "UCMachine.h"
00028 #include "GumpNotifyProcess.h"
00029 #include "Item.h"
00030 #include "getObject.h"
00031 #include "CoreApp.h"
00032 #include "GameInfo.h"
00033 #include "util.h"
00034 
00035 #include "IDataSource.h"
00036 #include "ODataSource.h"
00037 
00038 DEFINE_RUNTIME_CLASSTYPE_CODE(ReadableGump,ModalGump);
00039 
00040 const int jpsub_font = 6;
00041 
00042 ReadableGump::ReadableGump()
00043         : ModalGump()
00044 {
00045 
00046 }
00047 
00048 ReadableGump::ReadableGump(ObjId owner, uint16 shape, int font, std::string msg) :
00049         ModalGump(0, 0, 100, 100, owner), shapenum(shape), fontnum(font), text(msg)
00050 {
00051 }
00052 
00053 ReadableGump::~ReadableGump(void)
00054 {
00055 }
00056 
00057 void ReadableGump::InitGump(Gump* newparent, bool take_focus)
00058 {
00059         ModalGump::InitGump(newparent, take_focus);
00060 
00061         Shape* shape = GameData::get_instance()->getGumps()->getShape(shapenum);
00062 
00063         SetShape(shape, 0);
00064 
00065         ShapeFrame* sf = shape->getFrame(0);
00066         assert(sf);
00067 
00068         dims.w = sf->width;
00069         dims.h = sf->height;
00070 
00071         if (CoreApp::get_instance()->getGameInfo()->language ==
00072                 GameInfo::GAMELANG_JAPANESE)
00073         {
00074                 // Japanese subtitles
00075                 std::string::size_type pos;
00076                 pos = text.find('%');
00077                 if (pos != std::string::npos) {
00078                         std::string jpsub = text.substr(pos + 1);
00079                         text = text.substr(0, pos);
00080 
00081                         Gump* subwidget = new TextWidget(0, 0, jpsub, true, jpsub_font, 0, 0, Pentagram::Font::TEXT_CENTER);
00082                         subwidget->InitGump(this);
00083                         subwidget->setRelativePosition(BOTTOM_CENTER, 0, -8);
00084                 }
00085         }
00086 
00087         Gump *widget = new TextWidget(0, 0, text, true, fontnum, dims.w - 16, 0, Pentagram::Font::TEXT_CENTER);
00088         widget->InitGump(this);
00089         widget->setRelativePosition(CENTER);
00090 }
00091 
00092 Gump *ReadableGump::OnMouseDown(int button, int mx, int my)
00093 {
00094         Close();
00095         return this;
00096 }
00097 
00098 uint32 ReadableGump::I_readGrave(const uint8* args, unsigned int /*argsize*/)
00099 {
00100         ARG_ITEM_FROM_PTR(item);
00101         ARG_UINT16(shape);
00102         ARG_STRING(str);
00103         assert(item);
00104 
00105         Gump *gump = new ReadableGump(item->getObjId(), shape, 11, str);
00106         gump->InitGump(0);
00107         gump->setRelativePosition(CENTER);
00108         
00109         return gump->GetNotifyProcess()->getPid();
00110 }
00111 
00112 uint32 ReadableGump::I_readPlaque(const uint8* args, unsigned int /*argsize*/)
00113 {
00114         ARG_ITEM_FROM_PTR(item);
00115         ARG_UINT16(shape);
00116         ARG_STRING(str);
00117         assert(item);
00118 
00119         Gump *gump = new ReadableGump(item->getObjId(), shape, 10, str);
00120         gump->InitGump(0);
00121         gump->setRelativePosition(CENTER);
00122         
00123         return gump->GetNotifyProcess()->getPid();
00124 }
00125 
00126 void ReadableGump::saveData(ODataSource* ods)
00127 {
00128         CANT_HAPPEN_MSG("Trying to load ModalGump");
00129 }
00130 
00131 bool ReadableGump::loadData(IDataSource* ids, uint32 version)
00132 {
00133         CANT_HAPPEN_MSG("Trying to load ModalGump");
00134 
00135         return false;
00136 }
00137 

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