MiniStatsGump.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004  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 "MiniStatsGump.h"
00021 
00022 #include "GameData.h"
00023 #include "GumpShapeArchive.h"
00024 #include "Shape.h"
00025 #include "ShapeFrame.h"
00026 #include "MainActor.h"
00027 #include "RenderSurface.h"
00028 #include "Mouse.h"
00029 #include "PaperdollGump.h"
00030 #include "getObject.h"
00031 
00032 #include "IDataSource.h"
00033 #include "ODataSource.h"
00034 
00035 DEFINE_RUNTIME_CLASSTYPE_CODE(MiniStatsGump,Gump);
00036 
00037 static const int gumpshape = 33;
00038 static const int hpx = 6;
00039 static const int manax = 13;
00040 static const int bary = 19;
00041 static const int barheight = 14;
00042 
00043 static const uint32 hpcolour[] = { 0x980404, 0xBC0C0C, 0xD43030 };
00044 static const uint32 manacolour[] = { 0x4050FC, 0x1C28FC, 0x0C0CCC };
00045 
00046 
00047 MiniStatsGump::MiniStatsGump() : Gump()
00048 {
00049 
00050 }
00051 
00052 MiniStatsGump::MiniStatsGump(int x, int y, uint32 _Flags, sint32 layer)
00053         : Gump(x, y, 5, 5, 0, _Flags, layer)
00054 {
00055 
00056 }
00057 
00058 MiniStatsGump::~MiniStatsGump()
00059 {
00060 
00061 }
00062 
00063 void MiniStatsGump::InitGump(Gump* newparent, bool take_focus)
00064 {
00065         Gump::InitGump(newparent, take_focus);
00066 
00067         shape = GameData::get_instance()->getGumps()->getShape(gumpshape);
00068         ShapeFrame* sf = shape->getFrame(0);
00069         assert(sf);
00070 
00071         dims.w = sf->width;
00072         dims.h = sf->height;
00073 }
00074 
00075 void MiniStatsGump::PaintThis(RenderSurface* surf, sint32 lerp_factor, bool scaled)
00076 {
00077         Gump::PaintThis(surf, lerp_factor, scaled);
00078 
00079         Actor *a = getMainActor();
00080         assert(a);
00081 
00082         sint16 maxmana = a->getMaxMana();
00083         sint16 mana = a->getMana();
00084 
00085         uint16 maxhp = a->getMaxHP();
00086         uint16 hp = a->getHP();
00087 
00088         int manaheight, hpheight;
00089 
00090 
00091         if (maxmana == 0)
00092                 manaheight = 0;
00093         else
00094                 manaheight = (mana * barheight) / maxmana;
00095 
00096         if (maxhp == 0)
00097                 hpheight = 0;
00098         else
00099                 hpheight = (hp * barheight) / maxhp;
00100 
00101         for (int i = 0; i < 3; ++i) {
00102                 surf->Fill32(hpcolour[i], hpx+i, bary-hpheight+1, 1, hpheight);
00103                 surf->Fill32(manacolour[i], manax+i, bary-manaheight+1, 1, manaheight);
00104         }
00105 }
00106 
00107 uint16 MiniStatsGump::TraceObjId(int mx, int my)
00108 {
00109         uint16 objid = Gump::TraceObjId(mx, my);
00110         if (objid && objid != 65535) return objid;
00111 
00112         if (PointOnGump(mx, my)) return getObjId();
00113 
00114         return 0;
00115 }
00116 
00117 Gump* MiniStatsGump::OnMouseDown(int button, int mx, int my)
00118 {
00119         if (button == BUTTON_LEFT)
00120                 return this;
00121 
00122         return 0;
00123 }
00124 
00125 void MiniStatsGump::OnMouseDouble(int button, int mx, int my)
00126 {
00127         // check if there already is an open PaperdollGump
00128         MainActor* av = getMainActor();
00129         if (!av->getGump()) {
00130                 av->callUsecodeEvent_use();
00131         }
00132 
00133         Close();
00134 }
00135 
00136 void MiniStatsGump::saveData(ODataSource* ods)
00137 {
00138         Gump::saveData(ods);
00139 }
00140 
00141 bool MiniStatsGump::loadData(IDataSource* ids, uint32 version)
00142 {
00143         if (!Gump::loadData(ids, version)) return false;
00144 
00145         return true;
00146 }

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