2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/shock/shkpsamp.cpp,v 1.9 2000/02/19 13:25:59 toml Exp $
22 //#include <shkscrpt.h>
37 // ui library not C++ ized properly yet
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];
66 //--------------------------------------------------------------------------------------
67 void ShockPsiAmpInit(int which
)
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)
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
)
124 for (i
=0; i
< NUM_STAT_RECTS
; i
++)
126 if (RectTestPt(&stat_rects
[i
], mpt
))
134 //--------------------------------------------------------------------------------------
135 static int GetPsiPower(Point mpt
)
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
];
145 retval
= retval
+ (y
* 2);
148 //--------------------------------------------------------------------------------------
149 static void DrawMouseOverText(ObjID obj
)
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
;
166 power
= GetPsiPower(mpt
);
171 ShockStringFetch(temp
,sizeof(temp
),"psi","psihelp",power
);
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 //--------------------------------------------------------------------------------------
190 void ShockPsiAmpDraw(void)
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
;
218 // okay to do this since psi_levels is padded one high
219 while (power
< psi_levels
[gPsiLevel
+1])
221 if (curpower
== power
)
223 else if (pShockPlayer
->PsiPower(obj
, (ePsiPowers
)power
))
227 ShockDrawPsiIcon((ePsiPowers
)power
,dx
,dy
,kind
);
230 if (dx
== PSI_X1
+ r
.ul
.x
)
231 dx
= PSI_X2
+ r
.ul
.x
;
234 dx
= PSI_X1
+ r
.ul
.x
;
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
);
252 AutoAppIPtr(ShockPlayer
);
254 if (shock_cursor_mode
!= SCM_NORMAL
)
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
;
269 slot
= FindSlot(mpt
);
272 power
= GetPsiPower(mpt
);
276 // if we have the power already, then set it
277 if (pShockPlayer
->PsiPower(obj
,(ePsiPowers
)power
))
280 AutoAppIPtr(PlayerPsi
);
281 pPlayerPsi
->Select((ePsiPowers
)power
);
286 //--------------------------------------------------------------------------------------
287 static bool close_cb(short action
, void* data
, LGadBox
* vb
)
289 SchemaPlay((Label
*)"subpanel_cl",NULL
);
290 uiDefer(DeferOverlayClose
,(void *)kOverlayPsiAmp
);
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();
320 DestroyInterfaceButtons();
323 //--------------------------------------------------------------------------------------
324 // Check for transparency in the source art
325 //--------------------------------------------------------------------------------------
326 bool ShockPsiAmpCheckTransp(Point pt
)
330 retval = ShockOverlayCheckTransp(pt, kOverlayLook, gLookBack);