DEADSOFTWARE

Holmes UI is more important than console! ;-)
[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 procedure plrDebugDraw ();
317 procedure drawTileGrid ();
318 var
319 x, y: Integer;
320 begin
322 y := mapGrid.gridY0;
323 while (y < mapGrid.gridY0+mapGrid.gridHeight) do
324 begin
325 x := mapGrid.gridX0;
326 while (x < mapGrid.gridX0+mapGrid.gridWidth) do
327 begin
328 if (x+mapGrid.tileSize > vpx) and (y+mapGrid.tileSize > vpy) and
329 (x < vpx+vpw) and (y < vpy+vph) then
330 begin
331 //e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96);
332 drawRect(x, y, mapGrid.tileSize, mapGrid.tileSize, 96, 96, 96, 255);
333 end;
334 Inc(x, mapGrid.tileSize);
335 end;
336 Inc(y, mapGrid.tileSize);
337 end;
339 for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
340 begin
341 drawLine(mapGrid.gridX0, mapGrid.gridY0+y*mapGrid.tileSize, mapGrid.gridX0+mapGrid.gridWidth, mapGrid.gridY0+y*mapGrid.tileSize, 96, 96, 96, 255);
342 end;
344 for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
345 begin
346 drawLine(mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0, mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0+y*mapGrid.gridHeight, 96, 96, 96, 255);
347 end;
348 end;
350 procedure hilightCell (cx, cy: Integer);
351 begin
352 fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, 0, 128, 0, 64);
353 end;
355 procedure hilightCell1 (cx, cy: Integer);
356 begin
357 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
358 fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, 255, 255, 0, 92);
359 end;
361 function hilightWallTrc (pan: TPanel; tag: Integer; x, y, prevx, prevy: Integer): Boolean;
362 begin
363 result := false; // don't stop
364 if (pan = nil) then exit; // cell completion, ignore
365 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
366 fillRect(pan.X, pan.Y, pan.Width, pan.Height, 0, 128, 128, 64);
367 end;
369 function monsCollector (mon: TMonster; tag: Integer): Boolean;
370 var
371 ex, ey: Integer;
372 mx, my, mw, mh: Integer;
373 begin
374 result := false;
375 mon.getMapBox(mx, my, mw, mh);
376 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
377 if lineAABBIntersects(laserX0, laserY0, laserX1, laserY1, mx, my, mw, mh, ex, ey) then
378 begin
379 e_DrawPoint(8, ex, ey, 0, 255, 0);
380 end;
381 end;
383 procedure drawMonsterInfo (mon: TMonster);
384 var
385 mx, my, mw, mh: Integer;
387 procedure drawMonsterTargetLine ();
388 var
389 emx, emy, emw, emh: Integer;
390 enemy: TMonster;
391 eplr: TPlayer;
392 ex, ey: Integer;
393 begin
394 if (g_GetUIDType(mon.MonsterTargetUID) = UID_PLAYER) then
395 begin
396 eplr := g_Player_Get(mon.MonsterTargetUID);
397 if (eplr <> nil) then eplr.getMapBox(emx, emy, emw, emh) else exit;
398 end
399 else if (g_GetUIDType(mon.MonsterTargetUID) = UID_MONSTER) then
400 begin
401 enemy := g_Monsters_ByUID(mon.MonsterTargetUID);
402 if (enemy <> nil) then enemy.getMapBox(emx, emy, emw, emh) else exit;
403 end
404 else
405 begin
406 exit;
407 end;
408 mon.getMapBox(mx, my, mw, mh);
409 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, 255, 0, 0, 255);
410 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
411 begin
412 drawLine(mx+mw div 2, my+mh div 2, ex, ey, 0, 255, 0, 255);
413 end;
414 end;
416 procedure drawLOS2Plr ();
417 var
418 emx, emy, emw, emh: Integer;
419 eplr: TPlayer;
420 ex, ey: Integer;
421 begin
422 eplr := gPlayers[0];
423 if (eplr = nil) then exit;
424 eplr.getMapBox(emx, emy, emw, emh);
425 mon.getMapBox(mx, my, mw, mh);
426 drawLine(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, 255, 0, 0, 255);
427 {$IF DEFINED(D2F_DEBUG)}
428 //mapGrid.dbgRayTraceTileHitCB := hilightCell1;
429 {$ENDIF}
430 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
431 //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
432 begin
433 drawLine(mx+mw div 2, my+mh div 2, ex, ey, 0, 255, 0, 255);
434 end;
435 {$IF DEFINED(D2F_DEBUG)}
436 //mapGrid.dbgRayTraceTileHitCB := nil;
437 {$ENDIF}
438 end;
440 begin
441 if (mon = nil) then exit;
442 mon.getMapBox(mx, my, mw, mh);
443 //mx += mw div 2;
445 monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
447 if showMonsInfo then
448 begin
449 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
450 darkenRect(mx-4, my-7*8-6, 110, 7*8+6, 128);
451 my -= 8;
452 my -= 2;
454 // type
455 drawText6(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID]), 255, 127, 0); my -= 8;
456 // beh
457 drawText6(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)]), 255, 127, 0); my -= 8;
458 // state
459 drawText6(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep]), 255, 127, 0); my -= 8;
460 // health
461 drawText6(mx, my, Format('Health:%d', [mon.MonsterHealth]), 255, 127, 0); my -= 8;
462 // ammo
463 drawText6(mx, my, Format('Ammo:%d', [mon.MonsterAmmo]), 255, 127, 0); my -= 8;
464 // target
465 drawText6(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID]), 255, 127, 0); my -= 8;
466 drawText6(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime]), 255, 127, 0); my -= 8;
467 end;
469 drawMonsterTargetLine();
470 if showMonsLOS2Plr then drawLOS2Plr();
472 property MonsterRemoved: Boolean read FRemoved write FRemoved;
473 property MonsterPain: Integer read FPain write FPain;
474 property MonsterAnim: Byte read FCurAnim write FCurAnim;
476 end;
478 function highlightAllMonsterCells (mon: TMonster): Boolean;
479 begin
480 result := false; // don't stop
481 monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
482 end;
484 var
485 mon: TMonster;
486 mx, my, mw, mh: Integer;
487 begin
488 if (gPlayer1 = nil) then exit;
490 glEnable(GL_SCISSOR_TEST);
491 glScissor(0, gWinSizeY-gPlayerScreenSize.Y-1, vpw, vph);
493 glPushMatrix();
494 glTranslatef(-vpx, -vpy, 0);
496 if (showGrid) then drawTileGrid();
498 if (laserSet) then g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
500 if (monMarkedUID <> -1) then
501 begin
502 mon := g_Monsters_ByUID(monMarkedUID);
503 if (mon <> nil) then
504 begin
505 mon.getMapBox(mx, my, mw, mh);
506 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
507 drawMonsterInfo(mon);
508 end;
509 end;
511 if showAllMonsCells then g_Mons_ForEach(highlightAllMonsterCells);
513 glPopMatrix();
515 glDisable(GL_SCISSOR_TEST);
517 if showMapCurPos then drawText8(4, gWinSizeY-10, Format('mappos:(%d,%d)', [pmsCurMapX, pmsCurMapY]), 255, 255, 0);
518 end;
521 // ////////////////////////////////////////////////////////////////////////// //
522 function g_Holmes_MouseEvent (var ev: THMouseEvent): Boolean;
523 begin
524 result := true;
525 msX := ev.x;
526 msY := ev.y;
527 msB := ev.bstate;
528 kbS := ev.kstate;
529 msB := msB;
530 if not uiMouseEvent(ev) then plrDebugMouse(ev);
531 end;
534 function g_Holmes_KeyEvent (var ev: THKeyEvent): Boolean;
535 var
536 mon: TMonster;
537 pan: TPanel;
538 x, y, w, h: Integer;
539 ex, ey: Integer;
540 dx, dy: Integer;
542 procedure dummyWallTrc (cx, cy: Integer);
543 begin
544 end;
546 begin
547 result := false;
548 msB := ev.bstate;
549 kbS := ev.kstate;
550 case ev.scan of
551 SDL_SCANCODE_LCTRL, SDL_SCANCODE_RCTRL,
552 SDL_SCANCODE_LALT, SDL_SCANCODE_RALT,
553 SDL_SCANCODE_LSHIFT, SDL_SCANCODE_RSHIFT:
554 result := true;
555 end;
556 if uiKeyEvent(ev) then begin result := true; exit; end;
557 // press
558 if (ev.kind = THKeyEvent.Press) then
559 begin
560 // M-M: one monster think step
561 if (ev.scan = SDL_SCANCODE_M) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
562 begin
563 result := true;
564 gmon_debug_think := false;
565 gmon_debug_one_think_step := true; // do one step
566 exit;
567 end;
568 // M-I: toggle monster info
569 if (ev.scan = SDL_SCANCODE_I) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
570 begin
571 result := true;
572 showMonsInfo := not showMonsInfo;
573 exit;
574 end;
575 // M-L: toggle monster LOS to player
576 if (ev.scan = SDL_SCANCODE_L) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
577 begin
578 result := true;
579 showMonsLOS2Plr := not showMonsLOS2Plr;
580 exit;
581 end;
582 // M-G: toggle "show all cells occupied by monsters"
583 if (ev.scan = SDL_SCANCODE_G) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
584 begin
585 result := true;
586 showAllMonsCells := not showAllMonsCells;
587 exit;
588 end;
589 // M-A: wake up monster
590 if (ev.scan = SDL_SCANCODE_A) and ((ev.kstate and THKeyEvent.ModAlt) <> 0) then
591 begin
592 result := true;
593 if (monMarkedUID <> -1) then
594 begin
595 mon := g_Monsters_ByUID(monMarkedUID);
596 if (mon <> nil) then mon.WakeUp();
597 end;
598 exit;
599 end;
600 // C-T: teleport player
601 if (ev.scan = SDL_SCANCODE_T) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
602 begin
603 result := true;
604 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
605 if (gPlayers[0] <> nil) then
606 begin
607 gPlayers[0].getMapBox(x, y, w, h);
608 gPlayers[0].TeleportTo(pmsCurMapX-w div 2, pmsCurMapY-h div 2, true, 69); // 69: don't change dir
609 end;
610 exit;
611 end;
612 // C-P: show cursor position on the map
613 if (ev.scan = SDL_SCANCODE_P) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
614 begin
615 result := true;
616 showMapCurPos := not showMapCurPos;
617 exit;
618 end;
619 // C-G: toggle grid
620 if (ev.scan = SDL_SCANCODE_G) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
621 begin
622 result := true;
623 showGrid := not showGrid;
624 exit;
625 end;
626 // C-L: toggle layers window
627 if (ev.scan = SDL_SCANCODE_L) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
628 begin
629 result := true;
630 if (winLayers = nil) then createLayersWindow();
631 if not uiVisibleWindow(winLayers) then uiAddWindow(winLayers) else uiRemoveWindow(winLayers);
632 exit;
633 end;
634 // C-O: toggle outlines window
635 if (ev.scan = SDL_SCANCODE_O) and ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
636 begin
637 result := true;
638 if (winOutlines = nil) then createOutlinesWindow();
639 if not uiVisibleWindow(winOutlines) then uiAddWindow(winOutlines) else uiRemoveWindow(winOutlines);
640 exit;
641 end;
642 // F1: toggle options window
643 if (ev.scan = SDL_SCANCODE_F1) and (ev.kstate = 0) then
644 begin
645 result := true;
646 if (winOptions = nil) then createOptionsWindow();
647 if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions) else uiRemoveWindow(winOptions);
648 exit;
649 end;
650 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
651 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
652 ((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
653 begin
654 result := true;
655 dx := pmsCurMapX;
656 dy := pmsCurMapY;
657 case ev.scan of
658 SDL_SCANCODE_UP: dy -= 120;
659 SDL_SCANCODE_DOWN: dy += 120;
660 SDL_SCANCODE_LEFT: dx -= 120;
661 SDL_SCANCODE_RIGHT: dx += 120;
662 end;
663 {$IF DEFINED(D2F_DEBUG)}
664 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
665 mapGrid.dbgShowTraceLog := true;
666 {$ENDIF}
667 pan := g_Map_traceToNearest(pmsCurMapX, pmsCurMapY, dx, dy, (GridTagWall or GridTagDoor or GridTagStep or GridTagAcid1 or GridTagAcid2 or GridTagWater), @ex, @ey);
668 {$IF DEFINED(D2F_DEBUG)}
669 //mapGrid.dbgRayTraceTileHitCB := nil;
670 mapGrid.dbgShowTraceLog := false;
671 {$ENDIF}
672 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX, pmsCurMapY, dx, dy, ex, ey, (pan <> nil)]);
673 exit;
674 end;
675 end;
676 end;
679 // ////////////////////////////////////////////////////////////////////////// //
680 procedure g_Holmes_Draw ();
681 begin
682 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
683 glDisable(GL_STENCIL_TEST);
684 glDisable(GL_BLEND);
685 glDisable(GL_SCISSOR_TEST);
686 glDisable(GL_TEXTURE_2D);
688 if gGameOn then
689 begin
690 plrDebugDraw();
691 end;
693 laserSet := false;
694 end;
697 procedure g_Holmes_DrawUI ();
698 begin
699 uiDraw();
700 drawCursor();
701 end;
704 end.