DEADSOFTWARE

render: use only r_render to access render-specific info
[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, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_holmes;
18 interface
20 uses
21 mempool, geom,
22 e_log, e_input,
23 g_basic, g_phys, g_grid, g_player, g_monsters,
24 g_map, g_triggers, g_items, g_game, g_panel, g_console,
25 xprofiler,
26 sdlcarcass,
27 fui_common, fui_events, fui_ctls,
28 fui_gfx_gl;
31 procedure g_Holmes_Draw ();
32 procedure g_Holmes_DrawUI ();
34 procedure g_Holmes_OnEvent (var ev: TFUIEvent);
36 // hooks for player
37 procedure g_Holmes_plrViewPos (viewPortX, viewPortY: Integer);
38 procedure g_Holmes_plrViewSize (viewPortW, viewPortH: Integer);
39 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
42 var
43 g_holmes_imfunctional: Boolean = false;
44 g_holmes_enabled: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}false{$ENDIF};
47 implementation
49 uses
50 {$INCLUDE ../nogl/noGLuses.inc}
51 {$IFDEF ENABLE_GFX}
52 g_gfx,
53 {$ENDIF}
54 {$IFDEF ENABLE_GIBS}
55 g_gibs,
56 {$ENDIF}
57 {rttiobj,} typinfo, e_res,
58 SysUtils, Classes, SDL2,
59 MAPDEF, g_options,
60 utils, hashtable, xparser;
63 var
64 hlmContext: TGxContext = nil;
65 //globalInited: Boolean = false;
66 msX: Integer = -666;
67 msY: Integer = -666;
68 msB: Word = 0; // button state
69 kbS: Word = 0; // keyboard modifiers state
70 showGrid: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
71 showMonsInfo: Boolean = false;
72 showMonsLOS2Plr: Boolean = false;
73 showAllMonsCells: Boolean = false;
74 showMapCurPos: Boolean = false;
75 showLayersWindow: Boolean = false;
76 showOutlineWindow: Boolean = false;
77 showTriggers: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
78 showTraceBox: Boolean = {$IF DEFINED(D2F_DEBUG)}false{$ELSE}false{$ENDIF};
81 // ////////////////////////////////////////////////////////////////////////// //
82 {$INCLUDE g_holmes.inc}
83 {$INCLUDE g_holmes_ol.inc} // outliner
86 // ////////////////////////////////////////////////////////////////////////// //
87 {$INCLUDE g_holmes_cmd.inc}
88 procedure holmesInitCommands (); forward;
89 procedure holmesInitBinds (); forward;
92 // ////////////////////////////////////////////////////////////////////////// //
93 var
94 g_ol_nice: Boolean = false;
95 g_ol_fill_walls: Boolean = false;
96 g_ol_rlayer_back: Boolean = false;
97 g_ol_rlayer_step: Boolean = false;
98 g_ol_rlayer_wall: Boolean = false;
99 g_ol_rlayer_door: Boolean = false;
100 g_ol_rlayer_acid1: Boolean = false;
101 g_ol_rlayer_acid2: Boolean = false;
102 g_ol_rlayer_water: Boolean = false;
103 g_ol_rlayer_fore: Boolean = false;
106 // ////////////////////////////////////////////////////////////////////////// //
107 var
108 winHelp: TUITopWindow = nil;
109 winOptions: TUITopWindow = nil;
110 winLayers: TUITopWindow = nil;
111 winOutlines: TUITopWindow = nil;
114 procedure createHelpWindow (); forward;
115 procedure createOptionsWindow (); forward;
116 procedure createLayersWindow (); forward;
117 procedure createOutlinesWindow (); forward;
120 procedure toggleLayersWindowCB (me: TUIControl);
121 begin
122 showLayersWindow := not showLayersWindow;
123 if showLayersWindow then
124 begin
125 if (winLayers = nil) then createLayersWindow();
126 uiAddWindow(winLayers);
127 end
128 else
129 begin
130 uiRemoveWindow(winLayers);
131 end;
132 end;
134 procedure toggleOutlineWindowCB (me: TUIControl);
135 begin
136 showOutlineWindow := not showOutlineWindow;
137 if showOutlineWindow then
138 begin
139 if (winOutlines = nil) then createOutlinesWindow();
140 uiAddWindow(winOutlines);
141 end
142 else
143 begin
144 uiRemoveWindow(winOutlines);
145 end;
146 end;
149 procedure createHelpWindow ();
150 procedure addHelpEmptyLine ();
151 var
152 stx: TUIStaticText;
153 begin
154 stx := TUIStaticText.Create();
155 stx.flExpand := true;
156 stx.halign := 0; // center
157 stx.text := '';
158 stx.header := false;
159 stx.line := false;
160 winHelp.appendChild(stx);
161 end;
163 procedure addHelpCaptionLine (const txt: AnsiString);
164 var
165 stx: TUIStaticText;
166 begin
167 stx := TUIStaticText.Create();
168 stx.flExpand := true;
169 stx.halign := 0; // center
170 stx.text := txt;
171 stx.header := true;
172 stx.line := true;
173 winHelp.appendChild(stx);
174 end;
176 procedure addHelpCaption (const txt: AnsiString);
177 var
178 stx: TUIStaticText;
179 begin
180 stx := TUIStaticText.Create();
181 stx.flExpand := true;
182 stx.halign := 0; // center
183 stx.text := txt;
184 stx.header := true;
185 stx.line := false;
186 winHelp.appendChild(stx);
187 end;
189 procedure addHelpKeyMouse (const key, txt, grp: AnsiString);
190 var
191 box: TUIHBox;
192 span: TUISpan;
193 stx: TUIStaticText;
194 begin
195 box := TUIHBox.Create();
196 box.flExpand := true;
197 // key
198 stx := TUIStaticText.Create();
199 stx.flExpand := true;
200 stx.halign := 1; // right
201 stx.valign := 0; // center
202 stx.text := key;
203 stx.header := true;
204 stx.line := false;
205 stx.flHGroup := grp;
206 box.appendChild(stx);
207 // span
208 span := TUISpan.Create();
209 span.flDefaultSize := TLaySize.Create(12, 1);
210 span.flExpand := true;
211 box.appendChild(span);
212 // text
213 stx := TUIStaticText.Create();
214 stx.flExpand := true;
215 stx.halign := -1; // left
216 stx.valign := 0; // center
217 stx.text := txt;
218 stx.header := false;
219 stx.line := false;
220 box.appendChild(stx);
221 winHelp.appendChild(box);
222 end;
224 procedure addHelpKey (const key, txt: AnsiString); begin addHelpKeyMouse(key, txt, 'help-keys'); end;
225 procedure addHelpMouse (const key, txt: AnsiString); begin addHelpKeyMouse(key, txt, 'help-mouse'); end;
227 var
228 slist: array of AnsiString = nil;
229 cmd: PHolmesCommand;
230 bind: THolmesBinding;
231 f: Integer;
233 llb: TUISimpleText;
234 maxkeylen: Integer;
235 s: AnsiString;
237 begin
238 winHelp := TUITopWindow.Create('Holmes Help');
239 winHelp.escClose := true;
240 winHelp.flHoriz := false;
242 // keyboard
243 for cmd in cmdlist do cmd.helpmark := false;
245 //maxkeylen := 0;
246 for bind in keybinds do
247 begin
248 if (Length(bind.key) = 0) then continue;
249 if cmdlist.get(bind.cmdName, cmd) then
250 begin
251 if (Length(cmd.help) > 0) then
252 begin
253 cmd.helpmark := true;
254 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
255 end;
256 end;
257 end;
259 for cmd in cmdlist do
260 begin
261 if not cmd.helpmark then continue;
262 if (Length(cmd.help) = 0) then begin cmd.helpmark := false; continue; end;
263 f := 0;
264 while (f < Length(slist)) and (CompareText(slist[f], cmd.section) <> 0) do Inc(f);
265 if (f = Length(slist)) then
266 begin
267 SetLength(slist, Length(slist)+1);
268 slist[High(slist)] := cmd.section;
269 end;
270 end;
272 addHelpCaptionLine('KEYBOARD');
273 //llb := TUISimpleText.Create(0, 0);
274 for f := 0 to High(slist) do
275 begin
276 //if (f > 0) then llb.appendItem('');
277 if (f > 0) then addHelpEmptyLine();
278 //llb.appendItem(slist[f], true, true);
279 addHelpCaption(slist[f]);
280 for cmd in cmdlist do
281 begin
282 if not cmd.helpmark then continue;
283 if (CompareText(cmd.section, slist[f]) <> 0) then continue;
284 for bind in keybinds do
285 begin
286 if (Length(bind.key) = 0) then continue;
287 if (cmd.name = bind.cmdName) then
288 begin
289 //s := bind.key;
290 //while (Length(s) < maxkeylen) do s += ' ';
291 //s := ' '+s+' -- '+cmd.help;
292 //llb.appendItem(s);
293 addHelpMouse(bind.key, cmd.help);
294 end;
295 end;
296 end;
297 end;
299 // mouse
300 for cmd in cmdlist do cmd.helpmark := false;
302 //maxkeylen := 0;
303 for bind in msbinds do
304 begin
305 if (Length(bind.key) = 0) then continue;
306 if cmdlist.get(bind.cmdName, cmd) then
307 begin
308 if (Length(cmd.help) > 0) then
309 begin
310 cmd.helpmark := true;
311 //if (maxkeylen < Length(bind.key)) then maxkeylen := Length(bind.key);
312 end;
313 end;
314 end;
316 //llb.appendItem('');
317 //llb.appendItem('mouse', true, true);
318 if (f > 0) then addHelpEmptyLine();
319 addHelpCaptionLine('MOUSE');
320 for bind in msbinds do
321 begin
322 if (Length(bind.key) = 0) then continue;
323 if cmdlist.get(bind.cmdName, cmd) then
324 begin
325 if (Length(cmd.help) > 0) then
326 begin
327 //s := bind.key;
328 //while (Length(s) < maxkeylen) do s += ' ';
329 //s := ' '+s+' -- '+cmd.help;
330 //llb.appendItem(s);
331 addHelpKey(bind.key, cmd.help);
332 end;
333 end;
334 end;
336 //winHelp.appendChild(llb);
338 uiLayoutCtl(winHelp);
339 winHelp.escClose := true;
340 winHelp.centerInScreen();
341 end;
344 procedure winLayersClosed (me: TUIControl); begin showLayersWindow := false; end;
345 procedure winOutlinesClosed (me: TUIControl); begin showOutlineWindow := false; end;
347 procedure addCheckBox (parent: TUIControl; const text: AnsiString; pvar: PBoolean; const aid: AnsiString='');
348 var
349 cb: TUICheckBox;
350 begin
351 cb := TUICheckBox.Create();
352 cb.flExpand := true;
353 cb.setVar(pvar);
354 cb.text := text;
355 cb.id := aid;
356 parent.appendChild(cb);
357 end;
359 procedure addButton (parent: TUIControl; const text: AnsiString; cb: TUIControl.TActionCB);
360 var
361 but: TUIButton;
362 begin
363 but := TUIButton.Create();
364 //but.flExpand := true;
365 but.actionCB := cb;
366 but.text := text;
367 parent.appendChild(but);
368 end;
371 procedure actionFillWalls (cb: TUIControl);
372 begin
373 TUICheckBox(cb).checked := not TUICheckBox(cb).checked;
374 TUICheckBox(cb.topLevel['cbcontour']).enabled := not TUICheckBox(cb).checked;
375 end;
377 procedure createLayersWindow ();
378 var
379 box: TUIVBox;
380 begin
381 winLayers := TUITopWindow.Create('layers');
382 winLayers.flHoriz := false;
383 winLayers.x0 := 10;
384 winLayers.y0 := 10;
385 winLayers.flHoriz := false;
386 winLayers.escClose := true;
387 winLayers.closeCB := winLayersClosed;
389 box := TUIVBox.Create();
390 addCheckBox(box, '~background', @g_rlayer_back);
391 addCheckBox(box, '~steps', @g_rlayer_step);
392 addCheckBox(box, '~walls', @g_rlayer_wall);
393 addCheckBox(box, '~doors', @g_rlayer_door);
394 addCheckBox(box, 'acid~1', @g_rlayer_acid1);
395 addCheckBox(box, 'acid~2', @g_rlayer_acid2);
396 addCheckBox(box, 'wate~r', @g_rlayer_water);
397 addCheckBox(box, '~foreground', @g_rlayer_fore);
398 winLayers.appendChild(box);
400 uiLayoutCtl(winLayers);
401 end;
404 procedure createOutlinesWindow ();
405 var
406 box: TUIVBox;
407 begin
408 winOutlines := TUITopWindow.Create('outlines');
409 winOutlines.flHoriz := false;
410 winOutlines.x0 := 100;
411 winOutlines.y0 := 30;
412 winOutlines.flHoriz := false;
413 winOutlines.escClose := true;
414 winOutlines.closeCB := winOutlinesClosed;
416 box := TUIVBox.Create();
417 box.hasFrame := true;
418 box.caption := 'layers';
419 addCheckBox(box, '~background', @g_ol_rlayer_back);
420 addCheckBox(box, '~steps', @g_ol_rlayer_step);
421 addCheckBox(box, '~walls', @g_ol_rlayer_wall);
422 addCheckBox(box, '~doors', @g_ol_rlayer_door);
423 addCheckBox(box, 'acid~1', @g_ol_rlayer_acid1);
424 addCheckBox(box, 'acid~2', @g_ol_rlayer_acid2);
425 addCheckBox(box, 'wate~r', @g_ol_rlayer_water);
426 addCheckBox(box, '~foreground', @g_ol_rlayer_fore);
427 winOutlines.appendChild(box);
429 box := TUIVBox.Create();
430 box.hasFrame := true;
431 box.caption := 'options';
432 addCheckBox(box, 'fi~ll walls', @g_ol_fill_walls, 'cbfill');
433 addCheckBox(box, 'con~tours', @g_ol_nice, 'cbcontour');
434 winOutlines.appendChild(box);
436 winOutlines.setActionCBFor('cbfill', actionFillWalls);
438 uiLayoutCtl(winOutlines);
439 end;
442 procedure createOptionsWindow ();
443 var
444 box: TUIBox;
445 span: TUISpan;
446 begin
447 winOptions := TUITopWindow.Create('Holmes Options');
448 winOptions.flHoriz := false;
449 winOptions.flHoriz := false;
450 winOptions.escClose := true;
452 box := TUIVBox.Create();
453 box.hasFrame := true;
454 box.caption := 'visual';
455 addCheckBox(box, 'map ~grid', @showGrid);
456 addCheckBox(box, 'cursor ~position on map', @showMapCurPos);
457 addCheckBox(box, '~monster info', @showMonsInfo);
458 addCheckBox(box, 'monster LO~S to player', @showMonsLOS2Plr);
459 addCheckBox(box, 'monster ~cells (SLOW!)', @showAllMonsCells);
460 addCheckBox(box, 'draw ~triggers (SLOW!)', @showTriggers);
461 winOptions.appendChild(box);
463 box := TUIHBox.Create();
464 box.hasFrame := true;
465 box.caption := 'windows';
466 box.captionAlign := 0;
467 box.flAlign := 0;
468 addButton(box, '~layers', toggleLayersWindowCB);
469 span := TUISpan.Create();
470 span.flExpand := true;
471 span.flDefaultSize := TLaySize.Create(4, 1);
472 box.appendChild(span);
473 addButton(box, '~outline', toggleOutlineWindowCB);
474 winOptions.appendChild(box);
476 uiLayoutCtl(winOptions);
477 winOptions.centerInScreen();
478 end;
481 procedure toggleLayersWindow (arg: Integer=-1);
482 begin
483 if (arg < 0) then showLayersWindow := not showLayersWindow else showLayersWindow := (arg > 0);
484 showLayersWindow := not showLayersWindow; // hack for callback
485 toggleLayersWindowCB(nil);
486 end;
488 procedure toggleOutlineWindow (arg: Integer=-1);
489 begin
490 if (arg < 0) then showOutlineWindow := not showOutlineWindow else showOutlineWindow := (arg > 0);
491 showOutlineWindow := not showOutlineWindow; // hack for callback
492 toggleOutlineWindowCB(nil);
493 end;
495 procedure toggleHelpWindow (arg: Integer=-1);
496 begin
497 if (winHelp = nil) then
498 begin
499 if (arg = 0) then exit;
500 createHelpWindow();
501 end;
502 if (arg < 0) then begin if not uiVisibleWindow(winHelp) then uiAddWindow(winHelp) else uiRemoveWindow(winHelp); end
503 else if (arg = 0) then begin if uiVisibleWindow(winHelp) then uiRemoveWindow(winHelp); end
504 else begin if (not uiVisibleWindow(winHelp)) then uiAddWindow(winHelp); end;
505 if (not uiVisibleWindow(winHelp)) then FreeAndNil(winHelp);
506 end;
508 procedure toggleOptionsWindow (arg: Integer=-1);
509 begin
510 if (winOptions = nil) then createOptionsWindow();
511 if (arg < 0) then begin if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions) else uiRemoveWindow(winOptions); end
512 else if (arg = 0) then begin if uiVisibleWindow(winOptions) then uiRemoveWindow(winOptions); end
513 else begin if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions); end
514 end;
517 // ////////////////////////////////////////////////////////////////////////// //
518 var
519 vpSet: Boolean = false;
520 vpx, vpy: Integer;
521 vpw, vph: Integer;
522 laserSet: Boolean = false;
523 laserX0, laserY0, laserX1, laserY1: Integer;
524 monMarkedUID: Integer = -1;
525 platMarkedGUID: Integer = -1;
528 procedure g_Holmes_plrViewPos (viewPortX, viewPortY: Integer);
529 begin
530 vpSet := true;
531 vpx := viewPortX;
532 vpy := viewPortY;
533 end;
535 procedure g_Holmes_plrViewSize (viewPortW, viewPortH: Integer);
536 begin
537 vpSet := true;
538 vpw := viewPortW;
539 vph := viewPortH;
540 end;
542 procedure g_Holmes_plrLaser (ax0, ay0, ax1, ay1: Integer);
543 begin
544 laserSet := true;
545 laserX0 := ax0;
546 laserY0 := ay0;
547 laserX1 := ax1;
548 laserY1 := ay1;
549 laserSet := laserSet; // shut up, fpc!
550 end;
553 function pmsCurMapX (): Integer; inline; begin result := round(msX/g_dbg_scale)+vpx; end;
554 function pmsCurMapY (): Integer; inline; begin result := round(msY/g_dbg_scale)+vpy; end;
557 {$IFDEF HOLMES_OLD_OUTLINES}
558 var
559 edgeBmp: array of Byte = nil;
562 procedure drawOutlines ();
563 var
564 r, g, b: Integer;
566 procedure clearEdgeBmp ();
567 begin
568 SetLength(edgeBmp, (gScreenWidth+4)*(gScreenHeight+4));
569 FillChar(edgeBmp[0], Length(edgeBmp)*sizeof(edgeBmp[0]), 0);
570 end;
572 procedure drawPanel (pan: TPanel);
573 var
574 sx, len, y0, y1: Integer;
575 begin
576 if (pan = nil) or (pan.Width < 1) or (pan.Height < 1) then exit;
577 if (pan.X+pan.Width <= vpx-1) or (pan.Y+pan.Height <= vpy-1) then exit;
578 if (pan.X >= vpx+vpw+1) or (pan.Y >= vpy+vph+1) then exit;
579 if g_ol_nice or g_ol_fill_walls then
580 begin
581 sx := pan.X-(vpx-1);
582 len := pan.Width;
583 if (len > gScreenWidth+4) then len := gScreenWidth+4;
584 if (sx < 0) then begin len += sx; sx := 0; end;
585 if (sx+len > gScreenWidth+4) then len := gScreenWidth+4-sx;
586 if (len < 1) then exit;
587 assert(sx >= 0);
588 assert(sx+len <= gScreenWidth+4);
589 y0 := pan.Y-(vpy-1);
590 y1 := y0+pan.Height;
591 if (y0 < 0) then y0 := 0;
592 if (y1 > gScreenHeight+4) then y1 := gScreenHeight+4;
593 while (y0 < y1) do
594 begin
595 FillChar(edgeBmp[y0*(gScreenWidth+4)+sx], len*sizeof(edgeBmp[0]), 1);
596 Inc(y0);
597 end;
598 end
599 else
600 begin
601 drawRect(pan.X, pan.Y, pan.Width, pan.Height, r, g, b);
602 end;
603 end;
605 var
606 lsx: Integer = -1;
607 lex: Integer = -1;
608 lsy: Integer = -1;
610 procedure flushLine ();
611 begin
612 if (lsy > 0) and (lsx > 0) then
613 begin
614 if (lex = lsx) then
615 begin
616 glBegin(GL_POINTS);
617 glVertex2f(lsx-1+vpx+0.37, lsy-1+vpy+0.37);
618 glEnd();
619 end
620 else
621 begin
622 glBegin(GL_LINES);
623 glVertex2f(lsx-1+vpx+0.37, lsy-1+vpy+0.37);
624 glVertex2f(lex-0+vpx+0.37, lsy-1+vpy+0.37);
625 glEnd();
626 end;
627 end;
628 lsx := -1;
629 lex := -1;
630 end;
632 procedure startLine (y: Integer);
633 begin
634 flushLine();
635 lsy := y;
636 end;
638 procedure putPixel (x: Integer);
639 begin
640 if (x < 1) then exit;
641 if (lex+1 <> x) then flushLine();
642 if (lsx < 0) then lsx := x;
643 lex := x;
644 end;
646 procedure drawEdges ();
647 var
648 x, y: Integer;
649 a: PByte;
650 begin
651 glDisable(GL_BLEND);
652 glDisable(GL_TEXTURE_2D);
653 glLineWidth(1);
654 glPointSize(1);
655 glDisable(GL_LINE_SMOOTH);
656 glDisable(GL_POLYGON_SMOOTH);
657 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
658 for y := 1 to vph do
659 begin
660 a := @edgeBmp[y*(gScreenWidth+4)+1];
661 startLine(y);
662 for x := 1 to vpw do
663 begin
664 if (a[0] <> 0) then
665 begin
666 if (a[-1] = 0) or (a[1] = 0) or (a[-(gScreenWidth+4)] = 0) or (a[gScreenWidth+4] = 0) or
667 (a[-(gScreenWidth+4)-1] = 0) or (a[-(gScreenWidth+4)+1] = 0) or
668 (a[gScreenWidth+4-1] = 0) or (a[gScreenWidth+4+1] = 0) then
669 begin
670 putPixel(x);
671 end;
672 end;
673 Inc(a);
674 end;
675 flushLine();
676 end;
677 end;
679 procedure drawFilledWalls ();
680 var
681 x, y: Integer;
682 a: PByte;
683 begin
684 glDisable(GL_BLEND);
685 glDisable(GL_TEXTURE_2D);
686 glLineWidth(1);
687 glPointSize(1);
688 glDisable(GL_LINE_SMOOTH);
689 glDisable(GL_POLYGON_SMOOTH);
690 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
691 for y := 1 to vph do
692 begin
693 a := @edgeBmp[y*(gScreenWidth+4)+1];
694 startLine(y);
695 for x := 1 to vpw do
696 begin
697 if (a[0] <> 0) then putPixel(x);
698 Inc(a);
699 end;
700 flushLine();
701 end;
702 end;
704 procedure doWallsOld (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
705 var
706 f: Integer;
707 pan: TPanel;
708 begin
709 r := ar;
710 g := ag;
711 b := ab;
712 if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
713 for f := 0 to High(parr) do
714 begin
715 pan := parr[f];
716 if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then continue;
717 if ((pan.PanelType and ptype) = 0) then continue;
718 drawPanel(pan);
719 end;
720 if g_ol_nice then drawEdges();
721 if g_ol_fill_walls then drawFilledWalls();
722 end;
724 var
725 xptag: Word;
727 function doWallCB (pan: TPanel; tag: Integer): Boolean;
728 begin
729 result := false; // don't stop
730 //if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then exit;
731 if ((pan.PanelType and xptag) = 0) then exit;
732 drawPanel(pan);
733 end;
735 procedure doWalls (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
736 begin
737 r := ar;
738 g := ag;
739 b := ab;
740 xptag := ptype;
741 if ((ptype and (PANEL_WALL or PANEL_OPENDOOR or PANEL_CLOSEDOOR)) <> 0) then ptype := GridTagWall or GridTagDoor
742 else panelTypeToTag(ptype);
743 if g_ol_nice or g_ol_fill_walls then clearEdgeBmp();
744 mapGrid.forEachInAABB(vpx-1, vpy-1, vpw+2, vph+2, doWallCB, ptype);
745 if g_ol_nice then drawEdges();
746 if g_ol_fill_walls then drawFilledWalls();
747 end;
749 begin
750 if g_ol_rlayer_back then doWallsOld(gRenderBackgrounds, PANEL_BACK, 255, 127, 0);
751 if g_ol_rlayer_step then doWallsOld(gSteps, PANEL_STEP, 192, 192, 192);
752 if g_ol_rlayer_wall then doWallsOld(gWalls, PANEL_WALL, 255, 255, 255);
753 if g_ol_rlayer_door then doWallsOld(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR, 0, 255, 0);
754 if g_ol_rlayer_acid1 then doWallsOld(gAcid1, PANEL_ACID1, 255, 0, 0);
755 if g_ol_rlayer_acid2 then doWallsOld(gAcid2, PANEL_ACID2, 198, 198, 0);
756 if g_ol_rlayer_water then doWallsOld(gWater, PANEL_WATER, 0, 255, 255);
757 if g_ol_rlayer_fore then doWallsOld(gRenderForegrounds, PANEL_FORE, 210, 210, 210);
758 end;
760 {$ELSE}
761 var
762 oliner: TOutliner = nil;
764 procedure drawOutlines ();
765 var
766 r, g, b: Integer;
768 procedure clearOliner ();
769 begin
770 //if (oliner <> nil) and ((oliner.height <> vph+2) or (oliner.width <> vpw+2)) then begin oliner.Free(); oliner := nil; end;
771 if (oliner = nil) then oliner := TOutliner.Create(vpw+2, vph+2) else oliner.setup(vpw+2, vph+2);
772 end;
774 procedure drawOutline (ol: TOutliner; sx, sy: Integer);
775 procedure xline (x0, x1, y: Integer);
776 var
777 x: Integer;
778 begin
779 if (g_dbg_scale < 1.0) then
780 begin
781 glBegin(GL_POINTS);
782 for x := x0 to x1 do glVertex2f(sx+x+0.375, sy+y+0.375);
783 glEnd();
784 end
785 else
786 begin
787 glBegin(GL_QUADS);
788 glVertex2f(sx+x0+0, sy+y+0);
789 glVertex2f(sx+x1+1, sy+y+0);
790 glVertex2f(sx+x1+1, sy+y+1);
791 glVertex2f(sx+x0+0, sy+y+1);
792 glEnd();
793 end;
794 end;
795 var
796 y: Integer;
797 sp: TOutliner.TSpanX;
798 begin
799 if (ol = nil) then exit;
800 glPointSize(1);
801 glDisable(GL_POINT_SMOOTH);
802 for y := 0 to ol.height-1 do
803 begin
804 for sp in ol.eachSpanAtY(y) do
805 begin
806 if (g_dbg_scale <= 1.0) then
807 begin
808 glBegin(GL_POINTS);
809 glVertex2f(sx+sp.x0+0.375, sy+y+0.375);
810 glVertex2f(sx+sp.x1+0.375, sy+y+0.375);
811 glEnd();
812 end
813 else
814 begin
815 glBegin(GL_QUADS);
816 glVertex2f(sx+sp.x0+0, sy+y+0);
817 glVertex2f(sx+sp.x0+1, sy+y+0);
818 glVertex2f(sx+sp.x0+1, sy+y+1);
819 glVertex2f(sx+sp.x0+0, sy+y+1);
821 glVertex2f(sx+sp.x1+0, sy+y+0);
822 glVertex2f(sx+sp.x1+1, sy+y+0);
823 glVertex2f(sx+sp.x1+1, sy+y+1);
824 glVertex2f(sx+sp.x1+0, sy+y+1);
825 glEnd();
826 end;
827 end;
828 for sp in ol.eachSpanEdgeAtY(y, -1) do
829 begin
830 xline(sp.x0, sp.x1, y);
832 glBegin(GL_QUADS);
833 glVertex2f(sx+sp.x0+0, sy+y+0);
834 glVertex2f(sx+sp.x1+1, sy+y+0);
835 glVertex2f(sx+sp.x1+1, sy+y+1);
836 glVertex2f(sx+sp.x0+0, sy+y+1);
837 glEnd();
839 end;
840 for sp in ol.eachSpanEdgeAtY(y, +1) do
841 begin
842 xline(sp.x0, sp.x1, y);
844 glBegin(GL_QUADS);
845 glVertex2f(sx+sp.x0+0, sy+y+0);
846 glVertex2f(sx+sp.x1+1, sy+y+0);
847 glVertex2f(sx+sp.x1+1, sy+y+1);
848 glVertex2f(sx+sp.x0+0, sy+y+1);
849 glEnd();
851 end;
852 end;
853 end;
855 procedure doWallsOld (parr: array of TPanel; ptype: Word; ar, ag, ab: Integer);
856 var
857 f: Integer;
858 pan: TPanel;
859 begin
860 r := ar;
861 g := ag;
862 b := ab;
863 if g_ol_nice then clearOliner();
864 hlmContext.color := TGxRGBA.Create(r, g, b);
865 for f := 0 to High(parr) do
866 begin
867 pan := parr[f];
868 if (pan = nil) or not pan.Enabled or (pan.Width < 1) or (pan.Height < 1) then continue;
869 if ((pan.PanelType and ptype) = 0) then continue;
870 if (pan.X > vpx+vpw+41) or (pan.Y > vpy+vph+41) then continue;
871 if (pan.X+pan.Width < vpx-41) then continue;
872 if (pan.Y+pan.Height < vpy-41) then continue;
873 if g_ol_nice then
874 begin
875 oliner.addRect(pan.X-(vpx+1), pan.Y-(vpy+1), pan.Width, pan.Height);
876 end;
877 if g_ol_fill_walls then
878 begin
879 hlmContext.fillRect(pan.X, pan.Y, pan.Width, pan.Height);
880 end
881 else if not g_ol_nice then
882 begin
883 hlmContext.rect(pan.X, pan.Y, pan.Width, pan.Height);
884 end;
885 end;
886 if g_ol_nice then
887 begin
888 glColor4f(r/255.0, g/255.0, b/255.0, 1.0);
889 drawOutline(oliner, vpx+1, vpy+1);
890 end;
891 end;
893 begin
894 if (vpw < 2) or (vph < 2) then exit;
895 if g_ol_rlayer_back then doWallsOld(gRenderBackgrounds, PANEL_BACK, 255, 127, 0);
896 if g_ol_rlayer_step then doWallsOld(gSteps, PANEL_STEP, 192, 192, 192);
897 if g_ol_rlayer_wall then doWallsOld(gWalls, PANEL_WALL, 255, 255, 255);
898 if g_ol_rlayer_door then doWallsOld(gWalls, PANEL_OPENDOOR or PANEL_CLOSEDOOR, 0, 255, 0);
899 if g_ol_rlayer_acid1 then doWallsOld(gAcid1, PANEL_ACID1, 255, 0, 0);
900 if g_ol_rlayer_acid2 then doWallsOld(gAcid2, PANEL_ACID2, 198, 198, 0);
901 if g_ol_rlayer_water then doWallsOld(gWater, PANEL_WATER, 0, 255, 255);
902 if g_ol_rlayer_fore then doWallsOld(gRenderForegrounds, PANEL_FORE, 210, 210, 210);
903 end;
904 {$ENDIF}
907 procedure plrDebugDraw ();
908 procedure drawTileGrid ();
909 var
910 x, y: Integer;
911 begin
912 hlmContext.color := TGxRGBA.Create(96, 96, 96);
913 for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
914 begin
915 hlmContext.line(mapGrid.gridX0, mapGrid.gridY0+y*mapGrid.tileSize, mapGrid.gridX0+mapGrid.gridWidth, mapGrid.gridY0+y*mapGrid.tileSize);
916 end;
918 hlmContext.color := TGxRGBA.Create(96, 96, 96);
919 for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
920 begin
921 hlmContext.line(mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0, mapGrid.gridX0+x*mapGrid.tileSize, mapGrid.gridY0+y*mapGrid.gridHeight);
922 end;
923 end;
925 {$IFDEF ENABLE_GFX}
926 procedure drawAwakeCells ();
927 var
928 x, y: Integer;
929 begin
930 hlmContext.color := TGxRGBA.Create(128, 0, 128, 64);
931 for y := 0 to (mapGrid.gridHeight div mapGrid.tileSize) do
932 begin
933 for x := 0 to (mapGrid.gridWidth div mapGrid.tileSize) do
934 begin
935 if awmIsSetHolmes(x*mapGrid.tileSize+mapGrid.gridX0+1, y*mapGrid.tileSize++mapGrid.gridY0+1) then
936 begin
937 hlmContext.fillRect(x*mapGrid.tileSize++mapGrid.gridX0, y*mapGrid.tileSize++mapGrid.gridY0, monsGrid.tileSize, monsGrid.tileSize);
938 end;
939 end;
940 end;
941 end;
942 {$ENDIF}
944 procedure drawTraceBox ();
945 var
946 plr: TPlayer;
947 px, py, pw, ph: Integer;
948 pdx, pdy: Integer;
949 ex, ey: Integer;
950 pan: TPanel;
951 begin
952 if (Length(gPlayers) < 1) then exit;
953 plr := gPlayers[0];
954 if (plr = nil) then exit;
955 plr.getMapBox(px, py, pw, ph);
956 hlmContext.color := TGxRGBA.Create(255, 0, 255, 200);
957 hlmContext.rect(px, py, pw, ph);
958 pdx := pmsCurMapX-(px+pw div 2);
959 pdy := pmsCurMapY-(py+ph div 2);
960 hlmContext.color := TGxRGBA.Create(255, 0, 255, 200);
961 hlmContext.line(px+pw div 2, py+ph div 2, px+pw div 2+pdx, py+ph div 2+pdy);
962 pan := mapGrid.traceBox(ex, ey, px, py, pw, ph, pdx, pdy, GridTagObstacle);
963 if (pan = nil) then
964 begin
965 hlmContext.color := TGxRGBA.Create(255, 255, 255, 180);
966 hlmContext.rect(px+pdx, py+pdy, pw, ph);
967 end
968 else
969 begin
970 hlmContext.color := TGxRGBA.Create(255, 255, 0, 180);
971 hlmContext.rect(px+pdx, py+pdy, pw, ph);
972 end;
973 hlmContext.color := TGxRGBA.Create(255, 127, 0, 180);
974 hlmContext.rect(ex, ey, pw, ph);
975 end;
977 procedure hilightCell (cx, cy: Integer);
978 begin
979 hlmContext.color := TGxRGBA.Create(0, 128, 0, 64);
980 hlmContext.fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize);
981 end;
983 procedure hilightBodyCells (proxyId: Integer);
984 var
985 it: CellCoordIter;
986 pcellxy: PGridCellCoord;
987 begin
988 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
989 it := monsGrid.forEachBodyCell(proxyId);
990 for pcellxy in it do hilightCell(pcellxy^.x, pcellxy^.y);
991 it.release();
992 end;
994 procedure hilightCell1 (cx, cy: Integer);
995 begin
996 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
997 cx := cx and (not (monsGrid.tileSize-1));
998 cy := cy and (not (monsGrid.tileSize-1));
999 hlmContext.color := TGxRGBA.Create(255, 255, 0, 92);
1000 hlmContext.fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize);
1001 end;
1003 function hilightWallTrc (pan: TPanel; tag: Integer; x, y, prevx, prevy: Integer): Boolean;
1004 begin
1005 result := false; // don't stop
1006 if (pan = nil) then exit; // cell completion, ignore
1007 //e_WriteLog(Format('h1: (%d,%d)', [cx, cy]), MSG_NOTIFY);
1008 hlmContext.color := TGxRGBA.Create(0, 128, 128, 64);
1009 hlmContext.fillRect(pan.X, pan.Y, pan.Width, pan.Height);
1010 end;
1012 procedure monsCollector (mon: TMonster);
1013 var
1014 ex, ey: Integer;
1015 mx, my, mw, mh: Integer;
1016 begin
1017 mon.getMapBox(mx, my, mw, mh);
1018 hlmContext.color := TGxRGBA.Create(255, 255, 0, 160);
1019 hlmContext.rect(mx, my, mw, mh);
1020 //e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
1021 if lineAABBIntersects(laserX0, laserY0, laserX1, laserY1, mx, my, mw, mh, ex, ey) then
1022 begin
1023 //e_DrawPoint(8, ex, ey, 0, 255, 0);
1024 hlmContext.color := TGxRGBA.Create(0, 255, 0, 220);
1025 hlmContext.fillRect(ex-2, ey-2, 7, 7);
1026 end;
1027 end;
1029 procedure drawMonsterInfo (mon: TMonster);
1030 var
1031 mx, my, mw, mh: Integer;
1033 procedure drawMonsterTargetLine ();
1034 var
1035 emx, emy, emw, emh: Integer;
1036 enemy: TMonster;
1037 eplr: TPlayer;
1038 ex, ey: Integer;
1039 begin
1040 if (g_GetUIDType(mon.MonsterTargetUID) = UID_PLAYER) then
1041 begin
1042 eplr := g_Player_Get(mon.MonsterTargetUID);
1043 if (eplr <> nil) then eplr.getMapBox(emx, emy, emw, emh) else exit;
1044 end
1045 else if (g_GetUIDType(mon.MonsterTargetUID) = UID_MONSTER) then
1046 begin
1047 enemy := g_Monsters_ByUID(mon.MonsterTargetUID);
1048 if (enemy <> nil) then enemy.getMapBox(emx, emy, emw, emh) else exit;
1049 end
1050 else
1051 begin
1052 exit;
1053 end;
1054 mon.getMapBox(mx, my, mw, mh);
1055 hlmContext.color := TGxRGBA.Create(255, 0, 0);
1056 hlmContext.line(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2);
1057 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
1058 begin
1059 hlmContext.color := TGxRGBA.Create(0, 255, 0);
1060 hlmContext.line(mx+mw div 2, my+mh div 2, ex, ey);
1061 end;
1062 end;
1064 procedure drawLOS2Plr ();
1065 var
1066 emx, emy, emw, emh: Integer;
1067 eplr: TPlayer;
1068 ex, ey: Integer;
1069 begin
1070 eplr := gPlayers[0];
1071 if (eplr = nil) then exit;
1072 eplr.getMapBox(emx, emy, emw, emh);
1073 mon.getMapBox(mx, my, mw, mh);
1074 hlmContext.color := TGxRGBA.Create(255, 0, 0);
1075 hlmContext.line(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2);
1076 {$IF DEFINED(D2F_DEBUG)}
1077 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1078 {$ENDIF}
1079 if (g_Map_traceToNearestWall(mx+mw div 2, my+mh div 2, emx+emw div 2, emy+emh div 2, @ex, @ey) <> nil) then
1080 //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
1081 begin
1082 hlmContext.color := TGxRGBA.Create(0, 255, 0);
1083 hlmContext.line(mx+mw div 2, my+mh div 2, ex, ey);
1084 end;
1085 {$IF DEFINED(D2F_DEBUG)}
1086 mapGrid.dbgRayTraceTileHitCB := nil;
1087 {$ENDIF}
1088 end;
1090 begin
1091 if (mon = nil) then exit;
1092 mon.getMapBox(mx, my, mw, mh);
1093 //mx += mw div 2;
1095 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1096 hilightBodyCells(mon.proxyId);
1098 if showMonsInfo then
1099 begin
1100 //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
1101 hlmContext.font := 'msx6';
1102 hlmContext.color := TGxRGBA.Create(255, 127, 0);
1104 hlmContext.darkenRect(mx-4, my-7*hlmContext.charWidth(' ')-6, 110, 7*hlmContext.charWidth(' ')+6, 128);
1105 my -= 8;
1106 my -= 2;
1108 // type
1109 hlmContext.drawText(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID])); my -= hlmContext.charWidth(' ');
1110 // beh
1111 hlmContext.drawText(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)])); my -= hlmContext.charWidth(' ');
1112 // state
1113 hlmContext.drawText(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep])); my -= hlmContext.charWidth(' ');
1114 // health
1115 hlmContext.drawText(mx, my, Format('Health:%d', [mon.MonsterHealth])); my -= hlmContext.charWidth(' ');
1116 // ammo
1117 hlmContext.drawText(mx, my, Format('Ammo:%d', [mon.MonsterAmmo])); my -= hlmContext.charWidth(' ');
1118 // target
1119 hlmContext.drawText(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID])); my -= hlmContext.charWidth(' ');
1120 hlmContext.drawText(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime])); my -= hlmContext.charWidth(' ');
1121 end;
1123 drawMonsterTargetLine();
1124 if showMonsLOS2Plr then drawLOS2Plr();
1126 property MonsterRemoved: Boolean read FRemoved write FRemoved;
1127 property MonsterPain: Integer read FPain write FPain;
1128 property MonsterAnim: Byte read FCurAnim write FCurAnim;
1130 end;
1132 function highlightAllMonsterCells (mon: TMonster): Boolean;
1133 begin
1134 result := false; // don't stop
1135 //monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
1136 hilightBodyCells(mon.proxyId);
1137 end;
1139 procedure drawSelectedPlatformCells ();
1140 var
1141 pan: TPanel;
1142 begin
1143 if not showGrid then exit;
1144 pan := g_Map_PanelByGUID(platMarkedGUID);
1145 if (pan = nil) then exit;
1146 //mapGrid.forEachBodyCell(pan.proxyId, hilightCell);
1147 hilightBodyCells(pan.proxyId);
1148 hlmContext.color := TGxRGBA.Create(0, 200, 0, 200);
1149 hlmContext.rect(pan.x, pan.y, pan.width, pan.height);
1150 end;
1152 procedure drawTrigger (var trig: TTrigger);
1154 procedure drawPanelDest (pguid: Integer);
1155 var
1156 pan: TPanel;
1157 begin
1158 pan := g_Map_PanelByGUID(pguid);
1159 if (pan = nil) then exit;
1160 hlmContext.color := TGxRGBA.Create(255, 0, 255, 220);
1161 hlmContext.line(trig.trigCenter.x, trig.trigCenter.y, pan.x+pan.width div 2, pan.y+pan.height div 2);
1162 end;
1164 var
1165 tts: AnsiString;
1166 tx: Integer;
1167 begin
1168 hlmContext.font := 'msx6';
1169 hlmContext.color := TGxRGBA.Create(255, 0, 255, 96);
1170 hlmContext.fillRect(trig.x, trig.y, trig.width, trig.height);
1171 tts := trigType2Str(trig.TriggerType);
1172 tx := trig.x+(trig.width-Length(tts)*6) div 2;
1173 hlmContext.darkenRect(tx-2, trig.y-10, Length(tts)*6+4, 10, 64);
1174 hlmContext.color := TGxRGBA.Create(255, 127, 0);
1175 hlmContext.drawText(tx, trig.y-9, tts);
1176 tx := trig.x+(trig.width-Length(trig.mapId)*6) div 2;
1177 hlmContext.darkenRect(tx-2, trig.y-20, Length(trig.mapId)*6+4, 10, 64);
1178 hlmContext.color := TGxRGBA.Create(255, 255, 0);
1179 hlmContext.drawText(tx, trig.y-19, trig.mapId);
1180 drawPanelDest(trig.trigPanelGUID);
1181 case trig.TriggerType of
1182 TRIGGER_NONE: begin end;
1183 TRIGGER_EXIT: begin end;
1184 TRIGGER_TELEPORT: begin end;
1185 TRIGGER_OPENDOOR: begin end;
1186 TRIGGER_CLOSEDOOR: begin end;
1187 TRIGGER_DOOR: begin end;
1188 TRIGGER_DOOR5: begin end;
1189 TRIGGER_CLOSETRAP: begin end;
1190 TRIGGER_TRAP: begin end;
1191 TRIGGER_SECRET: begin end;
1192 TRIGGER_LIFTUP: begin end;
1193 TRIGGER_LIFTDOWN: begin end;
1194 TRIGGER_LIFT: begin end;
1195 TRIGGER_TEXTURE: begin end;
1196 TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF, TRIGGER_PRESS:
1197 begin
1198 if (trig.trigDataRec.trigTWidth > 0) and (trig.trigDataRec.trigTHeight > 0) then
1199 begin
1200 hlmContext.color := TGxRGBA.Create(0, 255, 255, 42);
1201 hlmContext.fillRect(
1202 trig.trigDataRec.trigTX, trig.trigDataRec.trigTY,
1203 trig.trigDataRec.trigTWidth, trig.trigDataRec.trigTHeight);
1204 hlmContext.color := TGxRGBA.Create(255, 0, 255, 220);
1205 hlmContext.line(
1206 trig.trigCenter.x, trig.trigCenter.y,
1207 trig.trigDataRec.trigTX+trig.trigDataRec.trigTWidth div 2,
1208 trig.trigDataRec.trigTY+trig.trigDataRec.trigTHeight div 2);
1209 end;
1210 end;
1211 TRIGGER_SOUND: begin end;
1212 TRIGGER_SPAWNMONSTER: begin end;
1213 TRIGGER_SPAWNITEM: begin end;
1214 TRIGGER_MUSIC: begin end;
1215 TRIGGER_PUSH: begin end;
1216 TRIGGER_SCORE: begin end;
1217 TRIGGER_MESSAGE: begin end;
1218 TRIGGER_DAMAGE: begin end;
1219 TRIGGER_HEALTH: begin end;
1220 TRIGGER_SHOT: begin end;
1221 TRIGGER_EFFECT: begin end;
1222 TRIGGER_SCRIPT: begin end;
1223 end;
1224 //trigType2Str
1225 //trigPanelId: Integer;
1226 end;
1228 procedure drawTriggers ();
1229 var
1230 f: Integer;
1231 begin
1232 for f := 0 to High(gTriggers) do drawTrigger(gTriggers[f]);
1233 end;
1235 {$IFDEF ENABLE_GIBS}
1236 procedure drawGibsBoxes ();
1237 var
1238 f: Integer;
1239 px, py, pw, ph: Integer;
1240 gib: PGib;
1241 begin
1242 for f := 0 to High(gGibs) do
1243 begin
1244 gib := @gGibs[f];
1245 if gib.alive then
1246 begin
1247 gib.getMapBox(px, py, pw, ph);
1248 hlmContext.color := TGxRGBA.Create(255, 0, 255);
1249 hlmContext.rect(px, py, pw, ph);
1250 end;
1251 end;
1252 end;
1253 {$ENDIF}
1255 var
1256 mon: TMonster;
1257 mit: PMonster;
1258 it: TMonsterGrid.Iter;
1259 mx, my, mw, mh: Integer;
1260 //pan: TPanel;
1261 //ex, ey: Integer;
1262 s: AnsiString;
1263 dx, dy: Integer;
1264 begin
1265 if (gPlayer1 = nil) then exit;
1267 if (hlmContext = nil) then hlmContext := TGxContext.Create();
1269 gxSetContext(hlmContext);
1270 try
1271 //glScissor(0, gScreenHeight-gPlayerScreenSize.Y-1, vpw, vph);
1272 //hlmContext.clip := TGxRect.Create(0, gScreenHeight-gPlayerScreenSize.Y-1, gPlayerScreenSize.X, gPlayerScreenSize.Y);
1275 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
1276 glTranslatef(-vpx, -vpy, 0);
1278 hlmContext.glSetScaleTrans(g_dbg_scale, -vpx, -vpy);
1279 glEnable(GL_SCISSOR_TEST);
1280 glScissor(0, gScreenHeight-gPlayerScreenSize.Y-1, gPlayerScreenSize.X, gPlayerScreenSize.Y);
1282 if (showGrid) then drawTileGrid();
1283 drawOutlines();
1285 if (laserSet) then
1286 begin
1287 //g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
1288 it := monsGrid.forEachAlongLine(laserX0, laserY0, laserX1, laserY1, -1, true);
1289 for mit in it do monsCollector(mit^);
1290 it.release();
1291 end;
1293 if (monMarkedUID <> -1) then
1294 begin
1295 mon := g_Monsters_ByUID(monMarkedUID);
1296 if (mon <> nil) then
1297 begin
1298 mon.getMapBox(mx, my, mw, mh);
1299 //e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
1300 hlmContext.color := TGxRGBA.Create(255, 0, 0, 220);
1301 hlmContext.rect(mx, my, mw, mh);
1302 drawMonsterInfo(mon);
1303 end;
1304 end;
1306 if showAllMonsCells and showGrid then g_Mons_ForEach(highlightAllMonsterCells);
1307 if showTriggers then drawTriggers();
1308 if showGrid then drawSelectedPlatformCells();
1310 {$IFDEF ENABLE_GFX}
1311 // drawAwakeCells();
1312 {$ENDIF}
1314 if showTraceBox then drawTraceBox();
1316 {$IFDEF ENABLE_GIBS}
1317 // drawGibsBoxes();
1318 {$ENDIF}
1320 //pan := g_Map_traceToNearest(16, 608, 16, 8, (GridTagObstacle or GridTagLiquid), @ex, @ey);
1321 (*
1322 {$IF DEFINED(D2F_DEBUG)}
1323 mapGrid.dbgRayTraceTileHitCB := hilightCell1;
1324 {$ENDIF}
1325 pan := mapGrid.traceRay(ex, ey, 16, 608, 16, 8, nil, (GridTagObstacle or GridTagLiquid));
1326 if (pan <> nil) then writeln('end=(', ex, ',', ey, ')');
1327 {$IF DEFINED(D2F_DEBUG)}
1328 mapGrid.dbgRayTraceTileHitCB := nil;
1329 {$ENDIF}
1331 pan := g_Map_PanelAtPoint(16, 608, (GridTagObstacle or GridTagLiquid));
1332 if (pan <> nil) then writeln('hit!');
1333 *)
1335 finally
1336 gxSetContext(nil);
1337 end;
1339 if showMapCurPos then
1340 begin
1341 s := Format('mappos:(%d,%d)', [pmsCurMapX, pmsCurMapY]);
1342 gxSetContext(hlmContext);
1343 hlmContext.font := 'win8';
1344 hlmContext.color := TGxRGBA.Create(0, 0, 0);
1345 for dy := -1 to 1 do
1346 begin
1347 for dx := -1 to 1 do
1348 begin
1349 if (dx <> 0) or (dy <> 0) then hlmContext.drawText(4+dx, gScreenHeight-10+dy, s);
1350 end;
1351 end;
1352 hlmContext.color := TGxRGBA.Create(255, 255, 0);
1353 hlmContext.drawText(4, gScreenHeight-10, s);
1354 gxSetContext(nil);
1355 end;
1356 end;
1359 // ////////////////////////////////////////////////////////////////////////// //
1360 procedure onKeyEvent (var ev: TFUIEvent);
1361 {$IF DEFINED(D2F_DEBUG)}
1362 var
1363 pan: TPanel;
1364 ex, ey: Integer;
1365 dx, dy: Integer;
1366 {$ENDIF}
1368 procedure dummyWallTrc (cx, cy: Integer);
1369 begin
1370 end;
1372 begin
1373 // press
1374 if (ev.press) then
1375 begin
1376 {$IF DEFINED(D2F_DEBUG)}
1377 // C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
1378 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
1379 ((ev.kstate and TFUIEvent.ModCtrl) <> 0) then
1380 begin
1381 ev.eat();
1382 dx := pmsCurMapX;
1383 dy := pmsCurMapY;
1384 case ev.scan of
1385 SDL_SCANCODE_UP: dy -= 120;
1386 SDL_SCANCODE_DOWN: dy += 120;
1387 SDL_SCANCODE_LEFT: dx -= 120;
1388 SDL_SCANCODE_RIGHT: dx += 120;
1389 end;
1390 {$IF DEFINED(D2F_DEBUG)}
1391 //mapGrid.dbgRayTraceTileHitCB := dummyWallTrc;
1392 mapGrid.dbgShowTraceLog := true;
1393 {$ENDIF}
1394 pan := g_Map_traceToNearest(pmsCurMapX, pmsCurMapY, dx, dy, (GridTagWall or GridTagDoor or GridTagStep or GridTagAcid1 or GridTagAcid2 or GridTagWater), @ex, @ey);
1395 {$IF DEFINED(D2F_DEBUG)}
1396 //mapGrid.dbgRayTraceTileHitCB := nil;
1397 mapGrid.dbgShowTraceLog := false;
1398 {$ENDIF}
1399 e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX, pmsCurMapY, dx, dy, ex, ey, (pan <> nil)]);
1400 exit;
1401 end;
1402 {$ENDIF}
1403 end;
1404 end;
1407 // ////////////////////////////////////////////////////////////////////////// //
1408 procedure g_Holmes_OnEvent (var ev: TFUIEvent);
1409 var doeat: Boolean = false;
1410 begin
1411 if g_Game_IsNet then exit;
1412 if not g_holmes_enabled then exit;
1413 if g_holmes_imfunctional then exit;
1415 holmesInitCommands();
1416 holmesInitBinds();
1418 msB := ev.bstate;
1419 kbS := ev.kstate;
1421 if (ev.key) then
1422 begin
1423 {$IFDEF USE_SDL2}
1424 case ev.scan of
1425 SDL_SCANCODE_LCTRL, SDL_SCANCODE_RCTRL,
1426 SDL_SCANCODE_LALT, SDL_SCANCODE_RALT,
1427 SDL_SCANCODE_LSHIFT, SDL_SCANCODE_RSHIFT:
1428 doeat := true;
1429 end;
1430 {$ENDIF}
1431 end
1432 else if (ev.mouse) then
1433 begin
1434 msX := ev.x;
1435 msY := ev.y;
1436 msB := ev.bstate;
1437 kbS := ev.kstate;
1438 msB := msB;
1439 end;
1441 uiDispatchEvent(ev);
1442 if (not ev.alive) then exit;
1444 if (ev.mouse) then
1445 begin
1446 if (gPlayer1 <> nil) and (vpSet) then msbindExecute(ev);
1447 ev.eat();
1448 end
1449 else
1450 begin
1451 if keybindExecute(ev) then ev.eat();
1452 if (ev.alive) then onKeyEvent(ev);
1453 end;
1455 if (doeat) then ev.eat();
1456 end;
1459 // ////////////////////////////////////////////////////////////////////////// //
1460 procedure g_Holmes_Draw ();
1461 begin
1462 if g_Game_IsNet then exit;
1463 if not g_holmes_enabled then exit;
1464 if g_holmes_imfunctional then exit;
1466 holmesInitCommands();
1467 holmesInitBinds();
1469 {$IFDEF ENABLE_RENDER}
1470 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
1471 glDisable(GL_STENCIL_TEST);
1472 glDisable(GL_BLEND);
1473 glDisable(GL_SCISSOR_TEST);
1474 glDisable(GL_TEXTURE_2D);
1476 if gGameOn then plrDebugDraw();
1477 {$ENDIF}
1479 laserSet := false;
1480 end;
1483 procedure g_Holmes_DrawUI ();
1484 begin
1485 if g_Game_IsNet then exit;
1486 if not g_holmes_enabled then exit;
1487 if g_holmes_imfunctional then exit;
1489 gGfxDoClear := false;
1491 {$IFDEF ENABLE_RENDER}
1492 //if assigned(prerenderFrameCB) then prerenderFrameCB();
1493 uiDraw();
1494 glMatrixMode(GL_MODELVIEW);
1495 glPushMatrix();
1496 try
1497 //glLoadIdentity();
1498 if assigned(postrenderFrameCB) then postrenderFrameCB();
1499 finally
1500 glPopMatrix();
1501 end;
1502 {$ENDIF}
1503 end;
1506 // ////////////////////////////////////////////////////////////////////////// //
1507 procedure bcOneMonsterThinkStep (); begin gmon_debug_think := false; gmon_debug_one_think_step := true; end;
1508 procedure bcOneMPlatThinkStep (); begin g_dbgpan_mplat_active := false; g_dbgpan_mplat_step := true; end;
1509 procedure bcMPlatToggle (); begin g_dbgpan_mplat_active := not g_dbgpan_mplat_active; end;
1511 procedure bcToggleMonsterInfo (arg: Integer=-1); begin if (arg < 0) then showMonsInfo := not showMonsInfo else showMonsInfo := (arg > 0); end;
1512 procedure bcToggleMonsterLOSPlr (arg: Integer=-1); begin if (arg < 0) then showMonsLOS2Plr := not showMonsLOS2Plr else showMonsLOS2Plr := (arg > 0); end;
1513 procedure bcToggleMonsterCells (arg: Integer=-1); begin if (arg < 0) then showAllMonsCells := not showAllMonsCells else showAllMonsCells := (arg > 0); end;
1514 procedure bcToggleDrawTriggers (arg: Integer=-1); begin if (arg < 0) then showTriggers := not showTriggers else showTriggers := (arg > 0); end;
1516 procedure bcToggleCurPos (arg: Integer=-1); begin if (arg < 0) then showMapCurPos := not showMapCurPos else showMapCurPos := (arg > 0); end;
1517 procedure bcToggleGrid (arg: Integer=-1); begin if (arg < 0) then showGrid := not showGrid else showGrid := (arg > 0); end;
1519 procedure bcMonsterSpawn (s: AnsiString);
1520 var
1521 mon: TMonster;
1522 begin
1523 if not gGameOn or g_Game_IsClient then
1524 begin
1525 conwriteln('cannot spawn monster in this mode');
1526 exit;
1527 end;
1528 mon := g_Mons_SpawnAt(s, pmsCurMapX, pmsCurMapY);
1529 if (mon = nil) then begin conwritefln('unknown monster id: ''%s''', [s]); exit; end;
1530 monMarkedUID := mon.UID;
1531 end;
1533 procedure bcMonsterWakeup ();
1534 var
1535 mon: TMonster;
1536 begin
1537 if (monMarkedUID <> -1) then
1538 begin
1539 mon := g_Monsters_ByUID(monMarkedUID);
1540 if (mon <> nil) then mon.WakeUp();
1541 end;
1542 end;
1544 procedure bcPlayerTeleport ();
1545 var
1546 x, y, w, h: Integer;
1547 begin
1548 //e_WriteLog(Format('TELEPORT: (%d,%d)', [pmsCurMapX, pmsCurMapY]), MSG_NOTIFY);
1549 if (gPlayers[0] <> nil) then
1550 begin
1551 gPlayers[0].getMapBox(x, y, w, h);
1552 gPlayers[0].TeleportTo(pmsCurMapX-w div 2, pmsCurMapY-h div 2, true, 69); // 69: don't change dir
1553 end;
1554 end;
1556 procedure dbgToggleTraceBox (arg: Integer=-1); begin if (arg < 0) then showTraceBox := not showTraceBox else showTraceBox := (arg > 0); end;
1558 procedure dbgToggleHolmesPause (arg: Integer=-1); begin if (arg < 0) then g_Game_HolmesPause(not gPauseHolmes) else g_Game_HolmesPause(arg > 0); end;
1560 procedure cbAtcurSelectMonster ();
1561 function monsAtDump (mon: TMonster{; tag: Integer}): Boolean;
1562 begin
1563 result := true; // stop
1564 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), TMsgType.Notify);
1565 monMarkedUID := mon.UID;
1566 dumpPublishedProperties(mon);
1567 end;
1568 var
1569 plr: TPlayer;
1570 x, y, w, h: Integer;
1571 mit: PMonster;
1572 it: TMonsterGrid.Iter;
1573 begin
1574 monMarkedUID := -1;
1575 if (Length(gPlayers) > 0) then
1576 begin
1577 plr := gPlayers[0];
1578 if (plr <> nil) then
1579 begin
1580 plr.getMapBox(x, y, w, h);
1581 if (pmsCurMapX >= x) and (pmsCurMapY >= y) and (pmsCurMapX < x+w) and (pmsCurMapY < y+h) then
1582 begin
1583 dumpPublishedProperties(plr);
1584 end;
1585 end;
1586 end;
1587 //e_WriteLog('===========================', MSG_NOTIFY);
1588 it := monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY);
1589 for mit in it do monsAtDump(mit^);
1590 it.release();
1591 //e_WriteLog('---------------------------', MSG_NOTIFY);
1592 end;
1594 procedure cbAtcurDumpMonsters ();
1595 function monsAtDump (mon: TMonster{; tag: Integer}): Boolean;
1596 begin
1597 result := false; // don't stop
1598 e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), TMsgType.Notify);
1599 end;
1600 var
1601 mit: PMonster;
1602 it: TMonsterGrid.Iter;
1603 begin
1604 it := monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY);
1605 if (it.length > 0) then
1606 begin
1607 e_WriteLog('===========================', TMsgType.Notify);
1608 for mit in it do monsAtDump(mit^);
1609 e_WriteLog('---------------------------', TMsgType.Notify);
1610 end;
1611 it.release();
1612 end;
1614 procedure cbAtcurDumpWalls ();
1615 function wallToggle (pan: TPanel{; tag: Integer}): Boolean;
1616 begin
1617 result := false; // don't stop
1618 if (platMarkedGUID = -1) then platMarkedGUID := pan.guid;
1619 e_LogWritefln('wall ''%s'' #%d(%d); enabled=%d (%d); (%d,%d)-(%d,%d)', [pan.mapId, pan.arrIdx, pan.proxyId, Integer(pan.Enabled), Integer(mapGrid.proxyEnabled[pan.proxyId]), pan.X, pan.Y, pan.Width, pan.Height]);
1620 dumpPublishedProperties(pan);
1621 end;
1622 var
1623 hasTrigs: Boolean = false;
1624 f: Integer;
1625 trig: PTrigger;
1626 mwit: PPanel;
1627 it: TPanelGrid.Iter;
1628 begin
1629 platMarkedGUID := -1;
1630 it := mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, (GridTagWall or GridTagDoor));
1631 if (it.length > 0) then
1632 begin
1633 e_WriteLog('=== TOGGLE WALL ===', TMsgType.Notify);
1634 for mwit in it do wallToggle(mwit^);
1635 e_WriteLog('--- toggle wall ---', TMsgType.Notify);
1636 end;
1637 it.release();
1638 if showTriggers then
1639 begin
1640 for f := 0 to High(gTriggers) do
1641 begin
1642 trig := @gTriggers[f];
1643 if (pmsCurMapX >= trig.x) and (pmsCurMapY >= trig.y) and (pmsCurMapX < trig.x+trig.width) and (pmsCurMapY < trig.y+trig.height) then
1644 begin
1645 if not hasTrigs then begin writeln('=== TRIGGERS ==='); hasTrigs := true; end;
1646 writeln('trigger ''', trig.mapId, ''' of type ''', trigType2Str(trig.TriggerType), '''');
1647 end;
1648 end;
1649 if hasTrigs then writeln('--- triggers ---');
1650 end;
1651 end;
1653 procedure cbAtcurToggleWalls ();
1654 function wallToggle (pan: TPanel{; tag: Integer}): Boolean;
1655 begin
1656 result := false; // don't stop
1657 //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);
1658 if pan.Enabled then g_Map_DisableWallGUID(pan.guid) else g_Map_EnableWallGUID(pan.guid);
1659 end;
1660 var
1661 mwit: PPanel;
1662 it: TPanelGrid.Iter;
1663 begin
1664 //e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
1665 //e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
1666 it := mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, (GridTagWall or GridTagDoor));
1667 for mwit in it do wallToggle(mwit^);
1668 it.release();
1669 end;
1672 // ////////////////////////////////////////////////////////////////////////// //
1673 procedure holmesInitCommands ();
1674 begin
1675 if (cmdlist <> nil) then exit;
1676 cmdAdd('win_layers', toggleLayersWindow, 'toggle layers window', 'window control');
1677 cmdAdd('win_outline', toggleOutlineWindow, 'toggle outline window', 'window control');
1678 cmdAdd('win_help', toggleHelpWindow, 'toggle help window', 'window control');
1679 cmdAdd('win_options', toggleOptionsWindow, 'toggle options window', 'window control');
1681 cmdAdd('mon_think_step', bcOneMonsterThinkStep, 'one monster think step', 'monster control');
1682 cmdAdd('mon_info', bcToggleMonsterInfo, 'toggle monster info', 'monster control');
1683 cmdAdd('mon_los_plr', bcToggleMonsterLOSPlr, 'toggle monster LOS to player', 'monster control');
1684 cmdAdd('mon_cells', bcToggleMonsterCells, 'toggle "show all cells occupied by monsters" (SLOW!)', 'monster control');
1685 cmdAdd('mon_wakeup', bcMonsterWakeup, 'wake up selected monster', 'monster control');
1687 cmdAdd('mon_spawn', bcMonsterSpawn, 'spawn monster', 'monster control');
1689 cmdAdd('mplat_step', bcOneMPlatThinkStep, 'one mplat think step', 'mplat control');
1690 cmdAdd('mplat_toggle', bcMPlatToggle, 'activate/deactivate moving platforms', 'mplat control');
1692 cmdAdd('plr_teleport', bcPlayerTeleport, 'teleport player', 'player control');
1694 cmdAdd('dbg_curpos', bcToggleCurPos, 'toggle "show cursor position on the map"', 'various');
1695 cmdAdd('dbg_grid', bcToggleGrid, 'toggle grid', 'various');
1696 cmdAdd('dbg_triggers', bcToggleDrawTriggers, 'show/hide triggers (SLOW!)', 'various');
1698 cmdAdd('atcur_select_monster', cbAtcurSelectMonster, 'select monster to operate', 'monster control');
1699 cmdAdd('atcur_dump_monsters', cbAtcurDumpMonsters, 'dump monsters in cell', 'monster control');
1700 cmdAdd('atcur_dump_walls', cbAtcurDumpWalls, 'dump walls in cell', 'wall control');
1701 cmdAdd('atcur_disable_walls', cbAtcurToggleWalls, 'disable walls', 'wall control');
1703 cmdAdd('dbg_tracebox', dbgToggleTraceBox, 'test traceBox()', 'player control');
1705 cmdAdd('hlm_pause', dbgToggleHolmesPause, '"Holmes" pause mode', 'game control');
1706 end;
1709 procedure holmesInitBinds ();
1710 var
1711 st: TStream = nil;
1712 pr: TTextParser = nil;
1713 s, kn, v: AnsiString;
1714 kmods: Byte;
1715 mbuts: Byte;
1716 begin
1717 kbS := kbS;
1718 if not keybindsInited then
1719 begin
1720 // keyboard
1721 keybindAdd('F1', 'win_help');
1722 keybindAdd('M-F1', 'win_options');
1723 keybindAdd('C-O', 'win_outline');
1724 keybindAdd('C-L', 'win_layers');
1726 keybindAdd('M-M', 'mon_think_step');
1727 keybindAdd('M-I', 'mon_info');
1728 keybindAdd('M-L', 'mon_los_plr');
1729 keybindAdd('M-G', 'mon_cells');
1730 keybindAdd('M-A', 'mon_wakeup');
1732 keybindAdd('M-P', 'mplat_step');
1733 keybindAdd('M-O', 'mplat_toggle');
1735 keybindAdd('C-T', 'plr_teleport');
1736 keybindAdd('M-T', 'dbg_tracebox');
1738 keybindAdd('C-P', 'dbg_curpos');
1739 keybindAdd('C-G', 'dbg_grid');
1740 keybindAdd('C-X', 'dbg_triggers');
1742 keybindAdd('C-1', 'mon_spawn zombie');
1744 keybindAdd('C-S-P', 'hlm_pause');
1746 // mouse
1747 msbindAdd('LMB', 'atcur_select_monster');
1748 msbindAdd('M-LMB', 'atcur_dump_monsters');
1749 msbindAdd('RMB', 'atcur_dump_walls');
1750 msbindAdd('M-RMB', 'atcur_disable_walls');
1752 // load bindings from file
1753 try
1754 st := e_OpenResourceRO(ConfigDirs, 'holmes.rc');
1755 pr := TFileTextParser.Create(st);
1756 conwriteln('parsing "holmes.rc"...');
1757 while (pr.tokType <> pr.TTEOF) do
1758 begin
1759 s := pr.expectId();
1760 if (s = 'stop') then break
1761 else if (s = 'unbind_keys') then keybinds := nil
1762 else if (s = 'unbind_mouse') then msbinds := nil
1763 else if (s = 'bind') then
1764 begin
1765 if (pr.tokType = pr.TTStr) then s := pr.expectStr(false)
1766 else if (pr.tokType = pr.TTInt) then s := Format('%d', [pr.expectInt()])
1767 else s := pr.expectId();
1769 if (pr.tokType = pr.TTStr) then v := pr.expectStr(false)
1770 else if (pr.tokType = pr.TTInt) then v := Format('%d', [pr.expectInt()])
1771 else v := pr.expectId();
1773 kn := parseModKeys(s, kmods, mbuts);
1774 if (CompareText(kn, 'lmb') = 0) or (CompareText(kn, 'rmb') = 0) or (CompareText(kn, 'mmb') = 0) or (CompareText(kn, 'None') = 0) then
1775 begin
1776 msbindAdd(s, v);
1777 end
1778 else
1779 begin
1780 keybindAdd(s, v);
1781 end;
1782 end;
1783 end;
1784 except on e: Exception do // sorry
1785 if (pr <> nil) then conwritefln('Holmes config parse error at (%s,%s): %s', [pr.tokLine, pr.tokCol, e.message]);
1786 end;
1787 if (pr <> nil) then pr.Free() else st.Free(); // ownership
1788 end;
1789 end;
1792 begin
1793 // shut up, fpc!
1794 msB := msB;
1795 vpSet := vpSet;
1797 fuiEventCB := g_Holmes_OnEvent;
1798 //uiContext.font := 'win14';
1800 conRegVar('hlm_ui_scale', @fuiRenderScale, 0.01, 5.0, 'Holmes UI scale', '', false);
1801 end.