Linux makefiles
[canaan.git] / prj / cam / src / shock / shkpsamp.cpp
blob9af29b1ca726b5bd39a9a3cd85ca2365de89a009
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/shock/shkpsamp.cpp,v 1.9 2000/02/19 13:25:59 toml Exp $
8 #if 0
10 #include <dev2d.h>
11 #include <string.h>
12 #include <res.h>
13 #include <appagg.h>
15 #include <resapi.h>
16 #include <mprintf.h>
17 #include <schema.h>
19 #include <playrobj.h>
21 #include <shkprop.h>
22 //#include <shkscrpt.h>
23 #include <shkpsamp.h>
24 #include <shkpsapi.h>
25 #include <shkpsiif.h>
26 #include <shkovrly.h>
27 #include <shkovcst.h>
28 #include <shkutils.h>
29 #include <shkgame.h>
30 #include <shkcurm.h>
31 #include <shkplayr.h>
32 #include <shkplcst.h>
33 #include <shkplprp.h>
34 #include <shkiftul.h>
35 #include <shkmfddm.h>
37 // ui library not C++ ized properly yet
38 extern "C" {
39 #include <event.h>
40 #include <gadbox.h>
41 #include <gadblist.h>
42 #include <gadbutt.h>
43 #include <memall.h>
44 #include <dbmem.h> // must be last header!
47 static int gPsiLevel = 0;
49 static IRes *gPsiBack = NULL;
51 static IRes *gLevelHandles[NUM_PSI_LEVELS];
53 static Rect full_rect = {{LMFD_X, LMFD_Y}, {LMFD_X + LMFD_W, LMFD_Y + LMFD_H}};
54 static Rect close_rect = {{163,8},{163 + 20, 8 + 21}};
56 static LGadButton close_button;
57 static DrawElement close_elem;
58 static IRes *close_handles[2];
59 static grs_bitmap *close_bitmaps[4];
61 #define MAIN_DX 69
62 #define MAIN_DY 30
64 #define POOL_X 116
65 #define POOL_Y 166
66 //--------------------------------------------------------------------------------------
67 void ShockPsiAmpInit(int which)
69 int i;
70 char temp[255];
72 close_handles[0] = LoadPCX("CloseOff");
73 close_handles[1] = LoadPCX("CloseOn");
74 close_bitmaps[0] = (grs_bitmap *) close_handles[0]->Lock();
75 close_bitmaps[1] = (grs_bitmap *) close_handles[1]->Lock();
76 for (i = 2; i < 4; i++)
78 close_bitmaps[i] = close_bitmaps[0];
81 for (i=0; i < NUM_PSI_LEVELS; i++)
83 sprintf(temp,"psi%d",i+1);
84 gLevelHandles[i] = LoadPCX(temp);
87 gPsiBack = LoadPCX("psiamp");
88 ShockOverlaySetRect(which, full_rect);
91 //--------------------------------------------------------------------------------------
92 void ShockPsiAmpTerm(void)
94 int i;
95 SafeFreeHnd(&gPsiBack);
96 for (i=0; i < NUM_PSI_LEVELS; i++)
98 SafeFreeHnd(&gLevelHandles[i]);
101 close_handles[0]->Unlock();
102 close_handles[1]->Unlock();
103 SafeFreeHnd(&close_handles[0]);
104 SafeFreeHnd(&close_handles[1]);
107 //--------------------------------------------------------------------------------------
109 static Rect stat_rects[] = {
110 {{13,11},{155,28}}, // level select
111 {{13,32},{155,158}}, // powers area
113 #define NUM_STAT_RECTS (sizeof(stat_rects) / sizeof(Rect))
114 static Rect main_rect = {{13,32},{155,158}};
115 static Rect level_rect = {{13,11},{155,28}};
116 static Rect text_rect = {{13,162},{172,236}};
118 //--------------------------------------------------------------------------------------
119 static int FindSlot(Point mpt)
121 int retval = -1;
122 int i;
124 for (i=0; i < NUM_STAT_RECTS; i++)
126 if (RectTestPt(&stat_rects[i], mpt))
128 retval = i;
129 break;
132 return(retval);
134 //--------------------------------------------------------------------------------------
135 static int GetPsiPower(Point mpt)
137 int x,y;
138 int retval = -1;
139 x = (mpt.x - main_rect.ul.x) / MAIN_DX;
140 y = (mpt.y - main_rect.ul.y) / MAIN_DY;
141 // do we have the current level?
142 AutoAppIPtr(ShockPlayer);
143 retval = psi_levels[gPsiLevel];
144 retval = retval + x;
145 retval = retval + (y * 2);
146 return(retval);
148 //--------------------------------------------------------------------------------------
149 static void DrawMouseOverText(ObjID obj)
151 Point mpt;
152 int i;
153 int power;
154 char temp[255];
155 int dx,dy;
156 Rect r = ShockOverlayGetRect(kOverlayPsiAmp);
158 mouse_get_xy(&mpt.x,&mpt.y);
159 mpt.x = mpt.x - r.ul.x;
160 mpt.y = mpt.y - r.ul.y;
161 i = FindSlot(mpt);
162 if (i != -1)
164 if (i == 1)
166 power = GetPsiPower(mpt);
167 if (power == -1)
169 return;
171 ShockStringFetch(temp,sizeof(temp),"psi","psihelp",power);
173 else
175 ShockStringFetch(temp,sizeof(temp),"amptext","psihelp",i);
177 gr_font_string_wrap(gShockFont,temp,RectWidth(&text_rect));
178 dx = r.ul.x + text_rect.ul.x;
179 dy = r.ul.y + text_rect.ul.y;
180 gr_font_string(gShockFont,temp,dx,dy);
183 //--------------------------------------------------------------------------------------
185 #define PSI_X1 13
186 #define PSI_X2 82
187 #define PSI_Y 34
188 #define PSI_DY 30
190 void ShockPsiAmpDraw(void)
192 Rect r;
193 int dx,dy;
194 Point drawpt;
195 ObjID obj;
196 int power,curpower;
197 int kind;
199 AutoAppIPtr(ShockPlayer);
200 obj = PlayerObject();
202 // draw the background
203 r = ShockOverlayGetRect(kOverlayPsiAmp);
204 DrawByHandle(gPsiBack,r.ul);
206 // draw currently selected level
207 drawpt.x = level_rect.ul.x + r.ul.x;
208 drawpt.y = level_rect.ul.y + r.ul.y;
209 //mprintf("psilevel = %d\n",gPsiLevel);
210 DrawByHandle(gLevelHandles[gPsiLevel],drawpt);
212 // draw the psi powers for the current level
213 AutoAppIPtr(PlayerPsi);
214 curpower = pPlayerPsi->GetSelectedPower();
215 power = psi_levels[gPsiLevel];
216 dx = PSI_X1 + r.ul.x;
217 dy = PSI_Y + r.ul.y;
218 // okay to do this since psi_levels is padded one high
219 while (power < psi_levels[gPsiLevel+1])
221 if (curpower == power)
222 kind = 2;
223 else if (pShockPlayer->PsiPower(obj, (ePsiPowers)power))
224 kind = 1;
225 else
226 kind = 0;
227 ShockDrawPsiIcon((ePsiPowers)power,dx,dy,kind);
229 // advance
230 if (dx == PSI_X1 + r.ul.x)
231 dx = PSI_X2 + r.ul.x;
232 else
234 dx = PSI_X1 + r.ul.x;
235 dy = dy + PSI_DY;
237 power = power + 1;
240 LGadDrawBox(VB(&close_button),NULL);
242 // draw the current stat description
243 DrawMouseOverText(obj);
246 //--------------------------------------------------------------------------------------
247 bool ShockPsiAmpHandleMouse(Point mpt)
249 Rect r = ShockOverlayGetRect(kOverlayPsiAmp);
250 ObjID obj;
251 int slot,power;
252 AutoAppIPtr(ShockPlayer);
254 if (shock_cursor_mode != SCM_NORMAL)
255 return(TRUE);
257 obj = PlayerObject();
259 if (RectTestPt(&level_rect,mpt))
261 int dx = RectWidth(&level_rect) / NUM_PSI_LEVELS;
262 int newlevel = (mpt.x - level_rect.ul.x) / dx;
263 if (newlevel < 0) newlevel = 0;
264 if (newlevel >= NUM_PSI_LEVELS)
265 newlevel = NUM_PSI_LEVELS - 1;
266 gPsiLevel = newlevel;
268 // click on arrows
269 slot = FindSlot(mpt);
270 if (slot == 1)
272 power = GetPsiPower(mpt);
273 if (power == -1)
274 return(TRUE);
276 // if we have the power already, then set it
277 if (pShockPlayer->PsiPower(obj,(ePsiPowers)power))
279 // set it
280 AutoAppIPtr(PlayerPsi);
281 pPlayerPsi->Select((ePsiPowers)power);
284 return(TRUE);
286 //--------------------------------------------------------------------------------------
287 static bool close_cb(short action, void* data, LGadBox* vb)
289 SchemaPlay((Label *)"subpanel_cl",NULL);
290 uiDefer(DeferOverlayClose,(void *)kOverlayPsiAmp);
291 return(TRUE);
293 //--------------------------------------------------------------------------------------
294 static void BuildInterfaceButtons(void)
296 Rect r = ShockOverlayGetRect(kOverlayPsiAmp);
298 close_elem.draw_type = DRAWTYPE_BITMAPOFFSET;
299 close_elem.draw_data = close_bitmaps;
300 close_elem.draw_data2 = (void *)4; // should be 2 but hackery required
302 LGadCreateButtonArgs(&close_button, LGadCurrentRoot(), close_rect.ul.x + r.ul.x, close_rect.ul.y + r.ul.y,
303 RectWidth(&close_rect), RectHeight(&close_rect), &close_elem, close_cb, 0);
306 //--------------------------------------------------------------------------------------
307 static void DestroyInterfaceButtons(void)
309 LGadDestroyBox(VB(&close_button),FALSE);
311 //--------------------------------------------------------------------------------------
312 void ShockPsiAmpStateChange(int which)
314 if (ShockOverlayCheck(which))
316 BuildInterfaceButtons();
318 else
320 DestroyInterfaceButtons();
323 //--------------------------------------------------------------------------------------
324 // Check for transparency in the source art
325 //--------------------------------------------------------------------------------------
326 bool ShockPsiAmpCheckTransp(Point pt)
329 bool retval;
330 retval = ShockOverlayCheckTransp(pt, kOverlayLook, gLookBack);
331 return(retval);
333 return(FALSE);
336 #endif