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 "ItemRelativeGump.h"
00021 #include "GameMapGump.h"
00022 #include "Item.h"
00023 #include "Container.h"
00024 #include "ShapeInfo.h"
00025 #include "getObject.h"
00026 #include "IDataSource.h"
00027 #include "ODataSource.h"
00028
00029 DEFINE_RUNTIME_CLASSTYPE_CODE(ItemRelativeGump,Gump);
00030
00031 ItemRelativeGump::ItemRelativeGump()
00032 : Gump(), ix(0), iy(0)
00033 {
00034 }
00035
00036 ItemRelativeGump::ItemRelativeGump(int x, int y, int width, int height,
00037 uint16 owner, uint32 _Flags, sint32 _Layer)
00038 : Gump(x, y, width, height, owner, _Flags, _Layer), ix(0), iy(0)
00039 {
00040 }
00041
00042 ItemRelativeGump::~ItemRelativeGump(void)
00043 {
00044 }
00045
00046 void ItemRelativeGump::InitGump(Gump* newparent, bool take_focus)
00047 {
00048 Gump::InitGump(newparent, take_focus);
00049
00050 GetItemLocation(0);
00051
00052 if (!newparent && parent)
00053 MoveOnScreen();
00054 }
00055
00056 void ItemRelativeGump::MoveOnScreen()
00057 {
00058 assert(parent);
00059 Pentagram::Rect sd, gd;
00060 parent->GetDims(sd);
00061
00062
00063 x = 0;
00064 y = 0;
00065
00066
00067 sint32 left,right,top,bottom;
00068 left = -dims.x;
00069 right = left + dims.w;
00070 top = -dims.y;
00071 bottom = top + dims.h;
00072 GumpToParent(left,top);
00073 GumpToParent(right,bottom);
00074
00075 sint32 movex = 0, movey = 0;
00076
00077 if (left < -sd.x)
00078 movex = -sd.x - left;
00079 else if (right > -sd.x + sd.w)
00080 movex = -sd.x + sd.w - right;
00081
00082 if (top < -sd.y)
00083 movey = -sd.y - top;
00084 else if (bottom > -sd.y + sd.h)
00085 movey = -sd.y + sd.h - bottom;
00086
00087 Move(left+movex, top+movey);
00088 }
00089
00090
00091
00092 void ItemRelativeGump::Paint(RenderSurface*surf, sint32 lerp_factor, bool scaled)
00093 {
00094 GetItemLocation(lerp_factor);
00095 Gump::Paint(surf,lerp_factor, scaled);
00096 }
00097
00098
00099
00100 void ItemRelativeGump::ParentToGump(int &px, int &py, PointRoundDir r)
00101 {
00102 px -= ix;
00103 py -= iy;
00104 Gump::ParentToGump(px,py,r);
00105 }
00106
00107
00108 void ItemRelativeGump::GumpToParent(int &gx, int &gy, PointRoundDir r)
00109 {
00110 Gump::GumpToParent(gx,gy,r);
00111 gx += ix;
00112 gy += iy;
00113 }
00114
00115 void ItemRelativeGump::GetItemLocation(sint32 lerp_factor)
00116 {
00117 Item *it = 0;
00118 Item *next = 0;
00119 Item *prev = 0;
00120 Gump *gump = 0;
00121
00122 it = getItem(owner);
00123
00124 if (!it) {
00125
00126
00127 Close();
00128 return;
00129 }
00130
00131 while ((next = it->getParentAsContainer()) != 0)
00132 {
00133 prev = it;
00134 it = next;
00135 gump = getGump(it->getGump());
00136 if (gump) break;
00137 }
00138
00139 int gx, gy;
00140
00141 if (!gump)
00142 {
00143 gump = GetRootGump()->FindGump(GameMapGump::ClassType);
00144
00145 if (!gump) {
00146 perr << "ItemRelativeGump::GetItemLocation(): "
00147 << "Unable to find GameMapGump!?!?" << std::endl;
00148 return;
00149 }
00150
00151 gump->GetLocationOfItem(owner, gx, gy, lerp_factor);
00152 }
00153 else
00154 {
00155 gump->GetLocationOfItem(prev->getObjId(), gx, gy, lerp_factor);
00156 }
00157
00158
00159
00160 gy = gy-it->getShapeInfo()->z*8-16;
00161 gump->GumpToScreenSpace(gx,gy);
00162
00163
00164 if (parent) parent->ScreenSpaceToGump(gx,gy);
00165
00166
00167 ix = gx-dims.w/2;
00168
00169 iy = gy-dims.h;
00170
00171
00172 if (flags & FLAG_KEEP_VISIBLE)
00173 MoveOnScreen();
00174 }
00175
00176 void ItemRelativeGump::Move(int x_, int y_)
00177 {
00178 ParentToGump(x_, y_);
00179 x += x_;
00180 y += y_;
00181 }
00182
00183 void ItemRelativeGump::saveData(ODataSource* ods)
00184 {
00185 Gump::saveData(ods);
00186 }
00187
00188 bool ItemRelativeGump::loadData(IDataSource* ids, uint32 version)
00189 {
00190 if (!Gump::loadData(ids, version)) return false;
00191
00192 return true;
00193 }
00194
00195