DEADSOFTWARE

panel outlines in Holmes
[d2df-sdl.git] / src / game / g_holmes.pas
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_holmes;
19 interface
21 uses
22 e_log,
23 g_textures, g_basic, e_graphics, g_phys, g_grid, g_player, g_monsters,
24 g_window, g_map, g_triggers, g_items, g_game, g_panel, g_console,
25 xprofiler;
28 type
29 THMouseEvent = record
30 public
31 const
32 // both for but and for bstate
33 Left = $0001;
34 Right = $0002;
35 Middle = $0004;
36 WheelUp = $0008;
37 WheelDown = $0010;
39 // event types
40 Release = 0;
41 Press = 1;
42 Motion = 2;
44 public
45 kind: Byte; // motion, press, release
46 x, y: Integer;
47 dx, dy: Integer; // for wheel this is wheel motion, otherwise this is relative mouse motion
48 but: Word; // current pressed/released button, or 0 for motion
49 bstate: Word; // button state
50 kstate: Word; // keyboard state (see THKeyEvent);
51 end;
53 THKeyEvent = record
54 public
55 const
56 // modifiers
57 ModCtrl = $0001;
58 ModAlt = $0002;
59 ModShift = $0004;
61 // event types
62 Release = 0;
63 Press = 1;
65 public
66 kind: Byte;
67 scan: Word; // SDL_SCANCODE_XXX
68 sym: Word; // SDLK_XXX
69 bstate: Word; // button state
70 kstate: Word; // keyboard state
71 end;
74 procedure g_Holmes_VidModeChanged ();
75 procedure g_Holmes_WindowFocused ();
76 procedure g_Holmes_WindowBlured ();
78 procedure g_Holmes_Draw ();
79 procedure g_Holmes_DrawUI ();
81 function g_Holmes_MouseEvent (var ev: THMouseEvent): Boolean; // returns `true` if event was eaten
82 function g_Holmes_KeyEvent (var ev: THKeyEvent): Boolean; // returns `true` if event was eaten
84 // hooks for player
85 procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer);
86 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
89 var
90 g_holmes_enabled: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
93 implementation
95 uses
96 SysUtils, GL, SDL2,
97 MAPDEF, g_options;
100 var
101 //globalInited: Boolean = false;
102 msX: Integer = -666;
103 msY: Integer = -666;
104 msB: Word = 0; // button state
105 kbS: Word = 0; // keyboard modifiers state
106 showGrid: Boolean = true;
107 showMonsInfo: Boolean = false;
108 showMonsLOS2Plr: Boolean = false;
109 showAllMonsCells: Boolean = false;
110 showMapCurPos: Boolean = false;
113 // ////////////////////////////////////////////////////////////////////////// //
114 {$INCLUDE g_holmes.inc}
115 {$INCLUDE g_holmes_ui.inc}
118 // ////////////////////////////////////////////////////////////////////////// //
119 var
120 g_ol_nice: Boolean = false;
121 g_ol_rlayer_back: Boolean = false;
122 g_ol_rlayer_step: Boolean = false;
123 g_ol_rlayer_wall: Boolean = false;
124 g_ol_rlayer_door: Boolean = false;
125 g_ol_rlayer_acid1: Boolean = false;
126 g_ol_rlayer_acid2: Boolean = false;
127 g_ol_rlayer_water: Boolean = false;
128 g_ol_rlayer_fore: Boolean = false;
131 // ////////////////////////////////////////////////////////////////////////// //
132 var
133 winOptions: THTopWindow = nil;
134 winLayers: THTopWindow = nil;
135 winOutlines: THTopWindow = nil;
138 procedure createOptionsWindow ();
139 var
140 llb: THCtlCBListBox;
141 begin
142 llb := THCtlCBListBox.Create(0, 0);
143 llb.appendItem('map grid', @showGrid);
144 llb.appendItem('cursor position on map', @showMapCurPos);
145 llb.appendItem('monster info', @showMonsInfo);
146 llb.appendItem('monster LOS to player', @showMonsLOS2Plr);
147 llb.appendItem('monster cells (SLOW!)', @showAllMonsCells);
148 winOptions := THTopWindow.Create('Holmes Options', 100, 100);
149 winOptions.escClose := true;
150 winOptions.appendChild(llb);
151 end;
154 procedure createLayersWindow ();
155 var
156 llb: THCtlCBListBox;
157 begin
158 llb := THCtlCBListBox.Create(0, 0);
159 llb.appendItem('background', @g_rlayer_back);
160 llb.appendItem('steps', @g_rlayer_step);
161 llb.appendItem('walls', @g_rlayer_wall);
162 llb.appendItem('doors', @g_rlayer_door);
163 llb.appendItem('acid1', @g_rlayer_acid1);
164 llb.appendItem('acid2', @g_rlayer_acid2);
165 llb.appendItem('water', @g_rlayer_water);
166 llb.appendItem('foreground', @g_rlayer_fore);
167 winLayers := THTopWindow.Create('visible', 10, 10);
168 winLayers.escClose := true;
169 winLayers.appendChild(llb);
170 end;
173 procedure createOutlinesWindow ();
174 var
175 llb: THCtlCBListBox;
176 begin
177 llb := THCtlCBListBox.Create(0, 0);
178 llb.appendItem('background', @g_ol_rlayer_back);
179 llb.appendItem('steps', @g_ol_rlayer_step);
180 llb.appendItem('walls', @g_ol_rlayer_wall);
181 llb.appendItem('doors', @g_ol_rlayer_door);
182 llb.appendItem('acid1', @g_ol_rlayer_acid1);
183 llb.appendItem('acid2', @g_ol_rlayer_acid2);
184 llb.appendItem('water', @g_ol_rlayer_water);
185 llb.appendItem('foreground', @g_ol_rlayer_fore);
186 llb.appendItem('', nil);
187 llb.appendItem('slow''n''nice', @g_ol_nice);
188 winOutlines := THTopWindow.Create('outlines', 100, 10);
189 winOutlines.escClose := true;
190 winOutlines.appendChild(llb);
191 end;
194 // ////////////////////////////////////////////////////////////////////////// //
195 procedure g_Holmes_VidModeChanged ();
196 begin
197 e_WriteLog(Format('Inspector: videomode changed: %dx%d', [gScreenWidth, gScreenHeight]), MSG_NOTIFY);
198 // texture space is possibly lost here, idc
199 curtexid := 0;
200 font6texid := 0;
201 font8texid := 0;
202 prfont6texid := 0;
203 prfont8texid := 0;
204 //createCursorTexture();
205 end;
207 procedure g_Holmes_WindowFocused ();
208 begin
209 msB := 0;
210 kbS := 0;
211 end;
213 procedure g_Holmes_WindowBlured ();
214 begin
215 end;
218 // ////////////////////////////////////////////////////////////////////////// //
219 var
220 vpSet: Boolean = false;
221 vpx, vpy: Integer;
222 vpw, vph: Integer;
223 laserSet: Boolean = false;
224 laserX0, laserY0, laserX1, laserY1: Integer;
225 monMarkedUID: Integer = -1;
228 procedure g_Holmes_plrView (viewPortX, viewPortY, viewPortW, viewPortH: Integer);
229 begin
230 vpSet := true;
231 vpx := viewPortX;
232 vpy := viewPortY;
233 vpw := viewPortW;
234 vph := viewPortH;
235 end;
237 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
238 begin
239 laserSet := true;
240 laserX0 := ax0;
241 laserY0 := ay0;
242 laserX1 := ax1;
243 laserY1 := ay1;
244 laserSet := laserSet; // shut up, fpc!
245 end;
248 function pmsCurMapX (): Integer; inline; begin result := msX+vpx; end;
249 function pmsCurMapY (): Integer; inline; begin result := msY+vpy; end;
252 procedure plrDebugMouse (var ev: THMouseEvent);
254 function wallToggle (pan: TPanel; tag: Integer): Boolean;
255 begin
256 result := false; // don't stop
257 e_WriteLog(Format('wall #%d(%d); enabled=%d (%d); (%d,%d)-(%d,%d)', [pan.arrIdx, pan.proxyId, Integer(pan.Enabled), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.X, pan.Y, pan.Width, pan.Height]), MSG_NOTIFY);
258 if ((kbS and THKeyEvent.ModAlt) <> 0) then
259 begin
260 if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
261 end;
262 end;
264 function monsAtDump (mon: TMonster; tag: Integer): Boolean;
265 begin
266 result := false; // don't stop
267 e_WriteLog(Format('monster #%d; UID=%d', [mon.arrIdx, mon.UID]), MSG_NOTIFY);
268 monMarkedUID := mon.UID;
269 //if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
270 end;
272 function monsInCell (mon: TMonster; tag: Integer): Boolean;
273 begin
274 result := false; // don't stop
275 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), MSG_NOTIFY);
276 end;
278 begin
279 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
280 if (gPlayer1 = nil) or not vpSet then exit;
281 if (ev.kind <> THMouseEvent.Press) then exit;
283 e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
285 if (ev.but = THMouseEvent.Left) then
286 begin
287 if ((kbS and THKeyEvent.ModShift) <> 0) then
288 begin
289 // dump monsters in cell
290 e_WriteLog('===========================', MSG_NOTIFY);
291 monsGrid.forEachInCell(pmsCurMapX, pmsCurMapY, monsInCell);
292 e_WriteLog('---------------------------', MSG_NOTIFY);
293 end
294 else
295 begin
296 // toggle wall
297 e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
298 mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
299 e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
300 end;
301 exit;
302 end;
304 if (ev.but = THMouseEvent.Right) then
305 begin
306 monMarkedUID := -1;
307 e_WriteLog('===========================', MSG_NOTIFY);
308 monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
309 e_WriteLog('---------------------------', MSG_NOTIFY);
310 exit;
311 end;
312 end;
315 var
316 edgeBmp: array of Byte = nil;
319 procedure drawOutlines ();
320 procedure clearEdgeBmp ();
321 begin
322 SetLength(edgeBmp, (gWinSizeX+4)*(gWinSizeY+4));
323 FillChar(edgeBmp[0], Length(edgeBmp)*sizeof(edgeBmp[0]), 0);
324 end;
326 procedure drawPanel (pan: TPanel);
327 var
328 sx, len, y0, y1: Integer;
329 begin
330 if (pan = nil) or (pan.Width < 1) or (pan.Height < 1) then exit;
331 if (pan.X+pan.Width <= vpx-1) or (pan.Y+pan.Height <= vpy-1) or (pan.X >= vpx+vpw+1) or (pan.Y >= vpy+vph+1) then exit;
332 if g_ol_nice then
333 begin
334 sx := pan.X-(vpx-1);
335 len := pan.Width;
336 if (len > vpw+2) then len := vpw+2;
337 if (sx < 0) then begin len += sx; sx := 0; end;
338 if (sx+len > vpw+2) then len := vpw+2-sx;
339 if (len < 1) then exit;
340 assert(sx >= 0);
341 assert(sx+len <= vpw+2);
342 y0 := pan.Y-(vpy-1);
343 y1 := y0+pan.Height;
344 if (y0 < 0) then y0 := 0;
345 if (y1 > vph+2) then y1 := vph+2;
346 while (y0 < y1) do
347 begin
348 FillChar(edgeBmp[y0*(gWinSizeX+4)+sx], len*sizeof(edgeBmp[0]), 1);
349 Inc(y0);
350 end;
351 end
352 else
353 begin
354 drawRect(pan.X, pan.Y, pan.Width, pan.Height, 255, 255, 255);
355 end;
356 end;
358 procedure drawEdges ();
359 var
360 x, y: Integer;
361 a: PByte;
362 begin
363 glDisable(GL_BLEND);
364 glDisable(GL_TEXTURE_2D);
365 glLineWidth(1);
366 glPointSize(1);
367 glDisable(GL_LINE_SMOOTH);
368 glDisable(GL_POLYGON_SMOOTH);
369 glColor4f(1.0, 1.0, 1.0, 1.0);
370 glBegin(GL_POINTS);
371 for y := 1 to vph do
372 begin
373 a := @edgeBmp[y*(gWinSizeX+4)+1];
374 for x := 1 to vpw do
375 begin
376 if (a[0] <> 0) then
377 begin
378 if (a[-1] = 0) or (a[1] = 0) or (a[-(gWinSizeX+4)] = 0) or (a[gWinSizeX+4] = 0) or
379 (a[-(gWinSizeX+4)-1] = 0) or (a[-(gWinSizeX+4)+1] = 0) or
380 (a[gWinSizeX+4-1] = 0) or (a[gWinSizeX+4+1] = 0) then
381 begin
382 glVertex2i(x-1+vpx, y-1+vpy);
383 end;
384 end;
385 Inc(a);
386 end;
387 end;
388 glEnd();
389 end;
391 procedure doWalls (parr: array of TPanel; ptype: Word);
392 var
393 f: Integer;
394 pan: TPanel;
395 begin
396 if g_ol_nice then clearEdgeBmp();
397 for f := 0 to High(parr) do
398 begin
399 pan := parr[f];
400 if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then continue;
401 if ((pan.PanelType and ptype) = 0) then continue;
402 drawPanel(pan);
403 end;
404 if g_ol_nice then drawEdges();
405 end;
407 begin
408 //function forEachInAABB (x, y, w, h: Integer; cb: TGridQueryCB; tagmask: Integer=-1; allowDisabled: Boolean=false): ITP;
409 if g_ol_rlayer_back then doWalls(gRenderBackgrounds, PANEL_BACK);
410 if g_ol_rlayer_step then doWalls(gSteps, PANEL_STEP);
411 if g_ol_rlayer_wall then doWalls(gWalls, PANEL_WALL);
412 if g_ol_rlayer_door then doWalls(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR);
413 if g_ol_rlayer_acid1 then doWalls(gAcid1, PANEL_ACID1);
414 if g_ol_rlayer_acid2 then doWalls(gAcid2, PANEL_ACID2);
415 if g_ol_rlayer_water then doWalls(gWater, PANEL_WATER);
416 if g_ol_rlayer_fore then doWalls(gRenderForegrounds, PANEL_FORE);
417 end;
420 procedure plrDebugDraw ();
422 procedure drawTileGrid ();
423 var
424 x, y: Integer;
425 begin
426 for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
427 begin
428 drawLine(mapGrid.gridX0, mapGrid.gridY0+y*mapGrid.tileSize, mapGrid.gridX0+mapGrid.gridWidth, mapGrid.gridY0+y*mapGrid.tileSize, 96, 96, 96, 255);
429 end;
431 for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
432 begin
433 drawLine(mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0, mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0+y*mapGrid.gridHeight, 96, 96, 96, 255);
434 end;
435 end;
437 procedure hilightCell (cx, cy: Integer);
438 begin
439 fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, 0, 128, 0, 64);
440 end;
442 procedure hilightCell1 (cx, cy: Integer);
443 begin
444 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
445 fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, 255, 255, 0, 92);
446 end;
448 function hilightWallTrc (pan: TPanel; tag: Integer; x, y, prevx, prevy: Integer): Boolean;
449 begin
450 result := false; // don't stop
451 if (pan = nil) then exit; // cell completion, ignore
452 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
453 fillRect(pan.X, pan.Y, pan.Width, pan.Height, 0, 128, 128, 64);
454 end;
456 function monsCollector (mon: TMonster; tag: Integer): Boolean;
457 var
458 ex, ey: Integer;
459 mx, my, mw, mh: Integer;
460 begin
461 result := false;
462 mon.getMapBox(mx, my, mw, mh);
463 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
464 if lineAABBIntersects(laserX0, laserY0, laserX1, laserY1, mx, my, mw, mh, ex, ey) then
465 begin
466 e_DrawPoint(8, ex, ey, 0, 255, 0);
467 end;
468 end;
470 procedure drawMonsterInfo (mon: TMonster);
471 var
472 mx, my, mw, mh: Integer;
474 procedure drawMonsterTargetLine ();
475 var
476 emx, emy, emw, emh: Integer;
477 enemy: TMonster;
478 eplr: TPlayer;
479 ex, ey: Integer;
480 begin
481 if (g_GetUIDType(mon.MonsterTargetUID) = UID_PLAYER) then
482 begin
483 eplr := g_Player_Get(mon.MonsterTargetUID);
484 if (eplr <> nil) then eplr.getMapBox(emx, emy, emw, emh) else exit;
485 end
486 else if (g_GetUIDType(mon.MonsterTargetUID) = UID_MONSTER) then
487 begin
488 enemy := g_Monsters_ByUID(mon.MonsterTargetUID);
489 if (enemy <> nil) then enemy.getMapBox(emx, emy, emw, emh) else exit;
490 end
491 else
492 begin
493 exit;
494 end;
495 mon.getMapBox(mx, my, mw, mh);
496 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, 255, 0, 0, 255);
497 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
498 begin
499 drawLine(mx+mw div 2, my+mh div 2, ex, ey, 0, 255, 0, 255);
500 end;
501 end;
503 procedure drawLOS2Plr ();
504 var
505 emx, emy, emw, emh: Integer;
506 eplr: TPlayer;
507 ex, ey: Integer;
508 begin
509 eplr := gPlayers[0];
510 if (eplr = nil) then exit;
511 eplr.getMapBox(emx, emy, emw, emh);
512 mon.getMapBox(mx, my, mw, mh);
513 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, 255, 0, 0, 255);
514 {$IF DEFINED(D2F_DEBUG)}
515 //mapGrid.dbgRayTraceTileHitCB := hilightCell1;
516 {$ENDIF}
517 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
518 //if (mapGrid.traceRay(ex, ey, mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, hilightWallTrc, (GridTagWall or GridTagDoor)) <> nil) then
519 begin
520 drawLine(mx+mw div 2, my+mh div 2, ex, ey, 0, 255, 0, 255);
521 end;
522 {$IF DEFINED(D2F_DEBUG)}
523 //mapGrid.dbgRayTraceTileHitCB := nil;
524 {$ENDIF}
525 end;
527 begin
528 if (mon = nil) then exit;
529 mon.getMapBox(mx, my, mw, mh);
530 //mx += mw div 2;
532 monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
534 if showMonsInfo then
535 begin
536 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
537 darkenRect(mx-4, my-7*8-6, 110, 7*8+6, 128);
538 my -= 8;
539 my -= 2;
541 // type
542 drawText6(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID]), 255, 127, 0); my -= 8;
543 // beh
544 drawText6(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)]), 255, 127, 0); my -= 8;
545 // state
546 drawText6(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep]), 255, 127, 0); my -= 8;
547 // health
548 drawText6(mx, my, Format('Health:%d', [mon.MonsterHealth]), 255, 127, 0); my -= 8;
549 // ammo
550 drawText6(mx, my, Format('Ammo:%d', [mon.MonsterAmmo]), 255, 127, 0); my -= 8;
551 // target
552 drawText6(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID]), 255, 127, 0); my -= 8;
553 drawText6(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime]), 255, 127, 0); my -= 8;
554 end;
556 drawMonsterTargetLine();
557 if showMonsLOS2Plr then drawLOS2Plr();
559 property MonsterRemoved: Boolean read FRemoved write FRemoved;
560 property MonsterPain: Integer read FPain write FPain;
561 property MonsterAnim: Byte read FCurAnim write FCurAnim;
563 end;
565 function highlightAllMonsterCells (mon: TMonster): Boolean;
566 begin
567 result := false; // don't stop
568 monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
569 end;
571 var
572 mon: TMonster;
573 mx, my, mw, mh: Integer;
574 begin
575 if (gPlayer1 = nil) then exit;
577 glEnable(GL_SCISSOR_TEST);
578 glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph);
580 glPushMatrix();
581 glTranslatef(-vpx, -vpy, 0);
583 if (showGrid) then drawTileGrid();
584 drawOutlines();
586 if (laserSet) then g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
588 if (monMarkedUID <> -1) then
589 begin
590 mon := g_Monsters_ByUID(monMarkedUID);
591 if (mon <> nil) then
592 begin
593 mon.getMapBox(mx, my, mw, mh);
594 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
595 drawMonsterInfo(mon);
596 end;
597 end;
599 if showAllMonsCells then g_Mons_ForEach(highlightAllMonsterCells);
601 glPopMatrix();
603 glDisable(GL_SCISSOR_TEST);
605 if showMapCurPos then drawText8(4, gWinSizeY-10, Format('mappos:(%d,%d)', [pmsCurMapX, pmsCurMapY]), 255, 255, 0);
606 end;
609 // ////////////////////////////////////////////////////////////////////////// //
610 function g_Holmes_MouseEvent (var ev: THMouseEvent): Boolean;
611 begin
612 result := true;
613 msX := ev.x;
614 msY := ev.y;
615 msB := ev.bstate;
616 kbS := ev.kstate;
617 msB := msB;
618 if not uiMouseEvent(ev) then plrDebugMouse(ev);
619 end;
622 function g_Holmes_KeyEvent (var ev: THKeyEvent): Boolean;
623 var
624 mon: TMonster;
625 pan: TPanel;
626 x, y, w, h: Integer;
627 ex, ey: Integer;
628 dx, dy: Integer;
630 procedure dummyWallTrc (cx, cy: Integer);
631 begin
632 end;
634 begin
635 result := false;
636 msB := ev.bstate;
637 kbS := ev.kstate;
638 case ev.scan of
639 SDL_SCANCODE_LCTRL, SDL_SCANCODE_RCTRL,
640 SDL_SCANCODE_LALT, SDL_SCANCODE_RALT,
641 SDL_SCANCODE_LSHIFT, SDL_SCANCODE_RSHIFT:
642 result := true;
643 end;
644 if uiKeyEvent(ev) then begin result := true; exit; end;
645 // press
646 if (ev.kind = THKeyEvent.Press) then
647 begin
648 // M-M: one monster think step
649 if (ev.scan = SDL_SCANCODE_M) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
650 begin
651 result := true;
652 gmon_debug_think := false;
653 gmon_debug_one_think_step := true; // do one step
654 exit;
655 end;
656 // M-I: toggle monster info
657 if (ev.scan = SDL_SCANCODE_I) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
658 begin
659 result := true;
660 showMonsInfo := not showMonsInfo;
661 exit;
662 end;
663 // M-L: toggle monster LOS to player
664 if (ev.scan = SDL_SCANCODE_L) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
665 begin
666 result := true;
667 showMonsLOS2Plr := not showMonsLOS2Plr;
668 exit;
669 end;
670 // M-G: toggle "show all cells occupied by monsters"
671 if (ev.scan = SDL_SCANCODE_G) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
672 begin
673 result := true;
674 showAllMonsCells := not showAllMonsCells;
675 exit;
676 end;
677 // M-A: wake up monster
678 if (ev.scan = SDL_SCANCODE_A) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
679 begin
680 result := true;
681 if (monMarkedUID <> -1) then
682 begin
683 mon := g_Monsters_ByUID(monMarkedUID);
684 if (mon <> nil) then mon.WakeUp();
685 end;
686 exit;
687 end;
688 // C-T: teleport player
689 if (ev.scan = SDL_SCANCODE_T) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
690 begin
691 result := true;
692 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
693 if (gPlayers[0] <> nil) then
694 begin
695 gPlayers[0].getMapBox(x, y, w, h);
696 gPlayers[0].TeleportTo(pmsCurMapX-w div 2, pmsCurMapY-h div 2, true, 69); // 69: don't change dir
697 end;
698 exit;
699 end;
700 // C-P: show cursor position on the map
701 if (ev.scan = SDL_SCANCODE_P) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
702 begin
703 result := true;
704 showMapCurPos := not showMapCurPos;
705 exit;
706 end;
707 // C-G: toggle grid
708 if (ev.scan = SDL_SCANCODE_G) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
709 begin
710 result := true;
711 showGrid := not showGrid;
712 exit;
713 end;
714 // C-L: toggle layers window
715 if (ev.scan = SDL_SCANCODE_L) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
716 begin
717 result := true;
718 if (winLayers = nil) then createLayersWindow();
719 if not uiVisibleWindow(winLayers) then uiAddWindow(winLayers) else uiRemoveWindow(winLayers);
720 exit;
721 end;
722 // C-O: toggle outlines window
723 if (ev.scan = SDL_SCANCODE_O) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
724 begin
725 result := true;
726 if (winOutlines = nil) then createOutlinesWindow();
727 if not uiVisibleWindow(winOutlines) then uiAddWindow(winOutlines) else uiRemoveWindow(winOutlines);
728 exit;
729 end;
730 // F1: toggle options window
731 if (ev.scan = SDL_SCANCODE_F1) and (ev.kstate = 0) then
732 begin
733 result := true;
734 if (winOptions = nil) then createOptionsWindow();
735 if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions) else uiRemoveWindow(winOptions);
736 exit;
737 end;
738 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
739 if ((ev.scan = SDL_SCANCODE_UP) or (ev.scan = SDL_SCANCODE_DOWN) or (ev.scan = SDL_SCANCODE_LEFT) or (ev.scan = SDL_SCANCODE_RIGHT)) and
740 ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
741 begin
742 result := true;
743 dx := pmsCurMapX;
744 dy := pmsCurMapY;
745 case ev.scan of
746 SDL_SCANCODE_UP: dy -= 120;
747 SDL_SCANCODE_DOWN: dy += 120;
748 SDL_SCANCODE_LEFT: dx -= 120;
749 SDL_SCANCODE_RIGHT: dx += 120;
750 end;
751 {$IF DEFINED(D2F_DEBUG)}
752 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
753 mapGrid.dbgShowTraceLog := true;
754 {$ENDIF}
755 pan := g_Map_traceToNearest(pmsCurMapX, pmsCurMapY, dx, dy, (GridTagWall or GridTagDoor or GridTagStep or GridTagAcid1 or GridTagAcid2 or GridTagWater), @ex, @ey);
756 {$IF DEFINED(D2F_DEBUG)}
757 //mapGrid.dbgRayTraceTileHitCB := nil;
758 mapGrid.dbgShowTraceLog := false;
759 {$ENDIF}
760 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX, pmsCurMapY, dx, dy, ex, ey, (pan <> nil)]);
761 exit;
762 end;
763 end;
764 end;
767 // ////////////////////////////////////////////////////////////////////////// //
768 procedure g_Holmes_Draw ();
769 begin
770 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
771 glDisable(GL_STENCIL_TEST);
772 glDisable(GL_BLEND);
773 glDisable(GL_SCISSOR_TEST);
774 glDisable(GL_TEXTURE_2D);
776 if gGameOn then
777 begin
778 plrDebugDraw();
779 end;
781 laserSet := false;
782 end;
785 procedure g_Holmes_DrawUI ();
786 begin
787 uiDraw();
788 drawCursor();
789 end;
792 end.