convert line ends
[canaan.git] / prj / cam / src / deepc / ui / dpcmeter.cpp
blob6ad42a02dc57063b58b570f1f66563eb67544224
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 #include <2d.h>
7 #include <appagg.h>
9 #include <res.h>
10 #include <guistyle.h>
12 #include <resapi.h>
13 #include <mprintf.h>
14 #include <scrnmode.h>
16 #include <playrobj.h>
17 #include <objhp.h>
18 #include <plyrmode.h>
20 #include <netman.h> // for IsNetworkGame()
22 #include <dpcgame.h>
23 #include <dpcutils.h>
24 #include <dpcovrly.h>
25 #include <dpcovcst.h>
26 #include <dpccurm.h>
27 #include <dpcinv.h>
28 #include <dpcplayr.h>
29 #include <dpcplcst.h>
30 #include <dpclooko.h>
31 #include <dpcifstr.h>
33 #include <dpcmeter.h>
35 #include <vismeter.h> // Visibility meter.
37 IRes *gHndHealth = NULL;
38 IRes *gHndBio = NULL;
39 IRes *gHndBioFull = NULL;
41 //--------------------------------------------------------------------------------------
42 // HP Meter initializer
43 //--------------------------------------------------------------------------------------
44 #define BIO_X 2
45 #define BIO_Y 414
46 Rect meters_rect = {{BIO_X,BIO_Y},{BIO_X + 260,BIO_Y+ 64}}; // 128
48 void DPCMetersInit(int which)
50 gHndHealth = LoadPCX("hpbar");
51 gHndBio = LoadPCX("bio");
52 gHndBioFull = LoadPCX("biofull");
53 AssertMsg(gHndHealth, "DPCMetersInit: Missing health bar art");
54 AssertMsg(gHndBio, "DPCMetersInit: Missing bio art");
55 AssertMsg(gHndBioFull, "DPCMetersInit: Missing bio full art");
57 Rect use_rect;
58 sScrnMode smode;
59 ScrnModeGet(&smode);
60 use_rect.ul.x = meters_rect.ul.x;
61 use_rect.ul.y = smode.h - (480 - meters_rect.ul.y);
62 use_rect.lr.x = use_rect.ul.x + RectWidth(&meters_rect);
63 use_rect.lr.y = use_rect.ul.y + RectHeight(&meters_rect);
65 DPCOverlaySetRect(which,use_rect);
67 // @NOTE: Visibility meter code
68 VisMeterEnterMode();
71 //--------------------------------------------------------------------------------------
72 // Main Meters shutdown
73 //--------------------------------------------------------------------------------------
74 void DPCMetersTerm(void)
76 SafeFreeHnd(&gHndHealth);
77 SafeFreeHnd(&gHndBio);
78 SafeFreeHnd(&gHndBioFull);
80 // @NOTE: Visibility meter code
81 VisMeterExitMode();
84 //--------------------------------------------------------------------------------------
85 // Draw health meters.
86 //--------------------------------------------------------------------------------------
87 #define HP_X 8
88 #define HP_Y 18
89 #define HPTEXT_X 92
90 #define HPTEXT_Y 18
92 // @TODO: compute top and bottom margins for real
93 static float gStatusH = 0.25; // %of screen
94 static float gStatusMargin = 4.0f/480.0f; // %of screen
95 static int air_x[2] = {655, 644};
96 static int hp_x[2] = {1, 505};
98 static void DrawMeters(unsigned long inDeltaTicks)
100 #if 0
101 char temp[255];
102 Rect r = DPCOverlayGetRect(kOverlayMeters);
104 // set initial vals in case we don't have relevant properties
105 int hp = 0;
106 int hpmax = 0;
108 strcpy(temp,"");
110 if (gHndHealth == NULL)
112 //WARNING(("Could not get meter art!\n"));
113 return;
116 // Determine the percentages.
117 ObjID po = PlayerObject();
118 ObjGetHitPoints(po, &hp);
119 if (hp < 0)
121 hp = 0;
123 if (GetPlayerMode() == kPM_Dead)
125 hp = 0;
127 ObjGetMaxHitPoints(po, &hpmax);
129 grs_clip saveClip = grd_gc.clip; // Clip it good!
131 grd_gc.clip = saveClip;
132 gr_set_fcolor(gDPCTextColor);
134 grs_bitmap *bm = (grs_bitmap *) gHndHealth->Lock();
136 int clippix = 0;
137 if ((hp == 0) || (hpmax == 0))
139 clippix = 0;
141 else
143 clippix = (bm->w * hp / hpmax);
146 if (clippix < 0)
148 clippix = 0;
151 gr_safe_set_cliprect(HP_X + r.ul.x,HP_Y + r.ul.y,HP_X + r.ul.x + clippix,HP_Y + r.ul.y + bm->h);
152 gr_bitmap(bm, HP_X + r.ul.x, HP_Y + r.ul.y);
153 gHndHealth->Unlock();
155 AssertMsg(gDPCFont, "DrawMeters: No font!");
156 grd_gc.clip = saveClip;
157 sprintf(temp,"%d", hp); // / %d",hp,hpmax);
158 gr_font_string(gDPCFont,temp, HPTEXT_X + r.ul.x, HPTEXT_Y + r.ul.y);
159 #endif // 0
161 // @NOTE: Visibility meter code
162 int bot = (int)(grd_canvas->bm.h * (1.0f - gStatusMargin));
164 if (bot > grd_canvas->bm.h - 1)
166 bot = grd_canvas->bm.h -1;
169 int top = bot-(int)(grd_canvas->bm.h*gStatusH);
170 // @ render_stat_bars(msec,top,bot);
172 // compute rect for vis meter
173 enum {kExtentX = 640, kExtentY = 480};
174 Rect vis_r = { 0, top, 0, bot};
175 vis_r.ul.x = hp_x[1] * grd_canvas->bm.w/kExtentX;
176 vis_r.lr.x = air_x[0] * grd_canvas->bm.w/kExtentX;
178 VisMeterUpdate(inDeltaTicks, &vis_r);
181 //--------------------------------------------------------------------------------------
182 // Draw main Meters
183 //--------------------------------------------------------------------------------------
184 void DPCMetersDraw(unsigned long inDeltaTicks)
186 #if 0
187 // @Note: Draws the bio meter.
188 IRes *useres = (!DPC_mouse) ? gHndBio : gHndBioFull;
190 grs_bitmap *bm = (grs_bitmap *)useres->Lock();
191 Rect r = DPCOverlayGetRect(kOverlayMeters);
192 gr_bitmap(bm, r.ul.x, r.ul.y);
193 useres->Unlock();
195 Point mpt;
196 mouse_get_xy(&mpt.x,&mpt.y);
197 if (RectTestPt(&r,mpt))
199 if (mpt.x - r.ul.x < HPTEXT_X)
201 DPCStringFetch(gHelpString, sizeof(gHelpString), "MouseHelpHP", "misc");
204 #endif // 0
205 DrawMeters(inDeltaTicks);
208 //--------------------------------------------------------------------------------------
209 // Basic Meters handling. Also covers the inventory popup by virtue of
210 // calling the InvFindObjSlot which covers both quick slots & real slots
211 //--------------------------------------------------------------------------------------
212 bool DPCMetersHandleMouse(Point pt)
214 bool retval = TRUE;
216 if (DPC_cursor_mode == SCM_DRAGOBJ)
217 DPCInvAddObj(PlayerObject(),drag_obj);
219 AutoAppIPtr(DPCPlayer);
221 if (DPC_cursor_mode == SCM_LOOK)
223 ObjID fakeobj = OBJ_NULL;
224 extern Rect fake_rects[4];
225 Rect r = DPCOverlayGetRect(kOverlayTicker);
226 Rect r2 = DPCOverlayGetRect(kOverlayMeters);
227 Point usept;
228 usept.x = pt.x + r2.ul.x;
229 usept.y = pt.y + r2.ul.y;
231 // okay, we have to fixup the fake_rects for high resolution positioning, thus the offset
232 Rect userect;
233 Point offset;
234 offset.x = 0;
235 offset.y = r.ul.y;
237 // query nanites?
238 RectOffsettedRect(&fake_rects[0], offset, &userect);
239 if (RectTestPt(&userect,usept))
241 fakeobj = pDPCPlayer->GetEquip(PlayerObject(), kEquipFakeNanites);
244 // query cookies?
245 RectOffsettedRect(&fake_rects[1], offset, &userect);
246 if (RectTestPt(&userect,usept))
248 fakeobj = pDPCPlayer->GetEquip(PlayerObject(), kEquipFakeCookies);
251 if (fakeobj != OBJ_NULL)
253 DPCLookPopup(fakeobj);
254 ClearCursor();
258 return(retval);
260 //--------------------------------------------------------------------------------------
261 // Handle drag/drop. This is mainly intended so we can split nanites.
262 // It only works in multiplayer, since it's kinda pointless in SP.
263 extern void DPCSplitStack(ObjID o, BOOL leaveEmpty);
264 bool DPCMetersDragDrop(Point pt, BOOL start)
266 AutoAppIPtr(NetManager);
267 if (!pNetManager->IsNetworkGame())
268 return(TRUE);
270 // For now, this only deals with the case where the player wants to
271 // split his nanites or cookies
272 if ((DPC_cursor_mode == SCM_SPLIT) && start)
274 AutoAppIPtr(DPCPlayer);
275 extern Rect fake_rects[4];
276 Point usept;
277 Rect r = DPCOverlayGetRect(kOverlayTicker);
278 Rect r2 = DPCOverlayGetRect(kOverlayMeters);
280 usept.x = pt.x + r2.ul.x;
281 usept.y = pt.y + r2.ul.y;
283 // okay, we have to fixup the fake_rects for high resolution positioning, thus the offset
284 Rect userect;
285 Point offset;
286 offset.x = 0;
287 offset.y = r.ul.y;
289 // query nanites?
290 RectOffsettedRect(&fake_rects[0], offset, &userect);
292 if (RectTestPt(&userect, usept))
294 ObjID o = pDPCPlayer->GetEquip(PlayerObject(), kEquipFakeNanites);
295 ClearCursor();
296 if (o != OBJ_NULL)
298 DPCSplitStack(o, TRUE);
302 return(TRUE);
305 //--------------------------------------------------------------------------------------
306 // Check for transparency in the source art
307 //--------------------------------------------------------------------------------------
308 bool DPCMetersCheckTransp(Point p)
311 bool retval = FALSE;
312 int pix = HandleGetPix(gHndBio,p);
313 if (pix == 0)
314 retval = TRUE;
315 //mprintf("SICT: %d (%d)\n",retval,pix);
316 return(retval);
318 return(FALSE);