summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 25ba665)
raw | patch | inline | side by side (parent: 25ba665)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 28 Aug 2017 09:50:49 +0000 (12:50 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 28 Aug 2017 09:51:06 +0000 (12:51 +0300) |
src/game/g_holmes.pas | patch | blob | history | |
src/game/g_holmes_ui.inc | patch | blob | history |
diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas
index 82256a81a0ea3692debe27236dc52789f3361b27..9b0055c839ff42b9f9229fbcdebc0913b0cd1efe 100644 (file)
--- a/src/game/g_holmes.pas
+++ b/src/game/g_holmes.pas
// ////////////////////////////////////////////////////////////////////////// //
var
+ winHelp: THTopWindow = nil;
winOptions: THTopWindow = nil;
winLayers: THTopWindow = nil;
winOutlines: THTopWindow = nil;
+procedure createHelpWindow ();
+var
+ llb: THCtlSimpleText;
+begin
+ llb := THCtlSimpleText.Create(0, 0);
+ llb.appendItem('common keys', true, true);
+ llb.appendItem(' F1 -- toggle this window');
+ llb.appendItem(' M-F1 -- toggle options window');
+ llb.appendItem('');
+ llb.appendItem('control keys', true, true);
+ llb.appendItem(' M-M -- one monster think step');
+ llb.appendItem(' M-I -- toggle monster info');
+ llb.appendItem(' M-K -- toggle monster LOS to player');
+ llb.appendItem(' M-G -- toggle "show all cells occupied by monsters" (SLOW!)');
+ llb.appendItem(' M-A -- wake up monster');
+ llb.appendItem(' C-T -- teleport player');
+ llb.appendItem(' C-P -- show cursor position on the map');
+ llb.appendItem(' C-G -- toggle grid');
+ llb.appendItem(' C-L -- toggle layers window');
+ llb.appendItem(' C-O -- toggle outlines window');
+ llb.appendItem('');
+ llb.appendItem('mouse', true, true);
+ llb.appendItem(' LMB -- select monster');
+ llb.appendItem(' M-LMB -- dump monsters in cell (to log)');
+ llb.appendItem(' RMB -- dump wall info to log');
+ llb.appendItem(' M-LMB -- disable wall');
+ winHelp := THTopWindow.Create('Holmes Help', 10, 10);
+ winHelp.escClose := true;
+ winHelp.appendChild(llb);
+ winHelp.centerInScreen();
+end;
+
+
procedure winLayersClosed (me: THControl; dummy: Integer); begin showLayersWindow := false; end;
procedure winOutlinesClosed (me: THControl; dummy: Integer); begin showOutlineWindow := false; end;
winOptions := THTopWindow.Create('Holmes Options', 100, 100);
winOptions.escClose := true;
winOptions.appendChild(llb);
+ winOptions.centerInScreen();
end;
begin
result := false; // don't stop
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);
- if ((kbS and THKeyEvent.ModAlt) <> 0) then
+ if (kbS = THKeyEvent.ModAlt) then
begin
if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
end;
e_WriteLog(Format('mev: %d', [Integer(ev.kind)]), MSG_NOTIFY);
+ if (ev.but = THMouseEvent.Right) then
+ begin
+ // dump/toggle wall
+ e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
+ mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
+ e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
+ exit;
+ end;
+
if (ev.but = THMouseEvent.Left) then
begin
- if ((kbS and THKeyEvent.ModShift) <> 0) then
+ if (kbS = THKeyEvent.ModAlt) then
begin
// dump monsters in cell
e_WriteLog('===========================', MSG_NOTIFY);
monsGrid.forEachInCell(pmsCurMapX, pmsCurMapY, monsInCell);
e_WriteLog('---------------------------', MSG_NOTIFY);
end
- else
+ else if (kbS = 0) then
begin
- // toggle wall
- e_WriteLog('=== TOGGLE WALL ===', MSG_NOTIFY);
- mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
- e_WriteLog('--- toggle wall ---', MSG_NOTIFY);
+ monMarkedUID := -1;
+ e_WriteLog('===========================', MSG_NOTIFY);
+ monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
+ e_WriteLog('---------------------------', MSG_NOTIFY);
end;
exit;
end;
-
- if (ev.but = THMouseEvent.Right) then
- begin
- monMarkedUID := -1;
- e_WriteLog('===========================', MSG_NOTIFY);
- monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
- e_WriteLog('---------------------------', MSG_NOTIFY);
- exit;
- end;
end;
end;
// F1: toggle options window
if (ev.scan = SDL_SCANCODE_F1) and (ev.kstate = 0) then
+ begin
+ result := true;
+ if (winHelp = nil) then createHelpWindow();
+ if not uiVisibleWindow(winHelp) then uiAddWindow(winHelp) else uiRemoveWindow(winHelp);
+ exit;
+ end;
+ // M-F1: toggle options window
+ if (ev.scan = SDL_SCANCODE_F1) and (ev.kstate = THKeyEvent.ModAlt) then
begin
result := true;
if (winOptions = nil) then createOptionsWindow();
if not uiVisibleWindow(winOptions) then uiAddWindow(winOptions) else uiRemoveWindow(winOptions);
exit;
end;
+ {$IF DEFINED(D2F_DEBUG)}
// C-UP, C-DOWN, C-LEFT, C-RIGHT: trace 10 pixels from cursor in the respective direction
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
((ev.kstate and THKeyEvent.ModCtrl) <> 0) then
e_LogWritefln('v-trace: (%d,%d)-(%d,%d); end=(%d,%d); hit=%d', [pmsCurMapX, pmsCurMapY, dx, dy, ex, ey, (pan <> nil)]);
exit;
end;
+ {$ENDIF}
end;
end;
index 79a21e77a0763b1876bb008b7b7ef614e39763c0..17cb20f644c3f86abae44cb1fc0b6f0a554b3e2a 100644 (file)
--- a/src/game/g_holmes_ui.inc
+++ b/src/game/g_holmes_ui.inc
public
constructor Create (const atitle: AnsiString; ax, ay: Integer; aw: Integer=-1; ah: Integer=-1);
+ procedure centerInScreen ();
+
// `sx` and `sy` are screen coordinates
procedure drawControl (sx, sy: Integer); override;
procedure drawControlPost (sx, sy: Integer); override;
end;
+ THCtlSimpleText = class(THControl)
+ private
+ type
+ PItem = ^TItem;
+ TItem = record
+ title: AnsiString;
+ centered: Boolean;
+ hline: Boolean;
+ end;
+ private
+ mItems: array of TItem;
+
+ public
+ constructor Create (ax, ay: Integer; aparent: THControl=nil);
+ destructor Destroy (); override;
+
+ procedure appendItem (const atext: AnsiString; acentered: Boolean=false; ahline: Boolean=false);
+
+ procedure drawControl (sx, sy: Integer); override;
+
+ function mouseEvent (var ev: THMouseEvent): Boolean; override;
+ function keyEvent (var ev: THKeyEvent): Boolean; override;
+ end;
+
+
THCtlCBListBox = class(THControl)
private
type
function keyEvent (var ev: THKeyEvent): Boolean; override;
end;
+
// ////////////////////////////////////////////////////////////////////////// //
var
uiTopList: array of THControl = nil;
end;
+procedure THTopWindow.centerInScreen ();
+begin
+ if (mWidth > 0) and (mHeight > 0) then
+ begin
+ mX := (gWinSizeX-mWidth) div 2;
+ mY := (gWinSizeY-mHeight) div 2;
+ end;
+end;
+
+
procedure THTopWindow.drawControl (sx, sy: Integer);
begin
fillRect(sx, sy, mWidth, mHeight, 0, 0, 128);
end;
+// ////////////////////////////////////////////////////////////////////////// //
+constructor THCtlSimpleText.Create (ax, ay: Integer; aparent: THControl=nil);
+begin
+ mItems := nil;
+ inherited Create(ax, ay, 4, 4);
+end;
+
+
+destructor THCtlSimpleText.Destroy ();
+begin
+ mItems := nil;
+ inherited;
+end;
+
+
+procedure THCtlSimpleText.appendItem (const atext: AnsiString; acentered: Boolean=false; ahline: Boolean=false);
+var
+ it: PItem;
+begin
+ if (Length(atext)*8+3*8+2 > mWidth) then mWidth := Length(atext)*8+3*8+2;
+ SetLength(mItems, Length(mItems)+1);
+ it := @mItems[High(mItems)];
+ it.title := atext;
+ it.centered := acentered;
+ it.hline := ahline;
+ if (Length(mItems)*8 > mHeight) then mHeight := Length(mItems)*8;
+end;
+
+
+procedure THCtlSimpleText.drawControl (sx, sy: Integer);
+var
+ f, tx: Integer;
+ it: PItem;
+ r, g, b: Integer;
+begin
+ for f := 0 to High(mItems) do
+ begin
+ it := @mItems[f];
+ tx := sx;
+ r := 255;
+ g := 255;
+ b := 0;
+ if it.centered then begin b := 255; tx := sx+(mWidth-Length(it.title)*8) div 2; end;
+ if it.hline then
+ begin
+ b := 255;
+ if (Length(it.title) = 0) then
+ begin
+ drawLine(sx+4, sy+3, sx+mWidth-8, sy+3, r, g, b);
+ end
+ else if (tx-3 > sx+4) then
+ begin
+ drawLine(sx+4, sy+3, tx-3, sy+3, r, g, b);
+ drawLine(tx+Length(it.title)*8, sy+3, sx+mWidth-4, sy+3, r, g, b);
+ end;
+ end;
+ drawText8(tx, sy, it.title, r, g, b);
+ Inc(sy, 8);
+ end;
+end;
+
+
+function THCtlSimpleText.mouseEvent (var ev: THMouseEvent): Boolean;
+var
+ lx, ly: Integer;
+begin
+ result := inherited mouseEvent(ev);
+ lx := ev.x;
+ ly := ev.y;
+ if not result and toLocal(lx, ly) then
+ begin
+ result := true;
+ end;
+end;
+
+
+function THCtlSimpleText.keyEvent (var ev: THKeyEvent): Boolean;
+begin
+ result := inherited keyEvent(ev);
+end;
+
+
// ////////////////////////////////////////////////////////////////////////// //
constructor THCtlCBListBox.Create (ax, ay: Integer; aparent: THControl=nil);
begin
drawLine(sx+4, sy+3, tx-3, sy+3, 255, 255, 255);
drawLine(tx+Length(it.title)*8, sy+3, sx+mWidth-4, sy+3, 255, 255, 255);
end;
- drawText8(sx+(mWidth-Length(it.title)*8) div 2, sy, it.title, 255, 255, 255);
+ drawText8(tx, sy, it.title, 255, 255, 255);
end
else
begin