From: Ketmar Dark Date: Mon, 28 Aug 2017 09:50:49 +0000 (+0300) Subject: F1 in Holmes now shows simple help X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=d886132bbe3ba73ffaa0be8c6525c19f0179440e;p=d2df-sdl.git F1 in Holmes now shows simple help --- diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index 82256a8..9b0055c 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -132,11 +132,45 @@ var // ////////////////////////////////////////////////////////////////////////// // 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; @@ -227,6 +261,7 @@ begin winOptions := THTopWindow.Create('Holmes Options', 100, 100); winOptions.escClose := true; winOptions.appendChild(llb); + winOptions.centerInScreen(); end; @@ -294,7 +329,7 @@ procedure plrDebugMouse (var ev: THMouseEvent); 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; @@ -321,33 +356,33 @@ begin 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; @@ -866,12 +901,21 @@ begin 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 @@ -897,6 +941,7 @@ begin 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; diff --git a/src/game/g_holmes_ui.inc b/src/game/g_holmes_ui.inc index 79a21e7..17cb20f 100644 --- a/src/game/g_holmes_ui.inc +++ b/src/game/g_holmes_ui.inc @@ -133,6 +133,8 @@ type 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; @@ -142,6 +144,31 @@ type 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 @@ -167,6 +194,7 @@ type function keyEvent (var ev: THKeyEvent): Boolean; override; end; + // ////////////////////////////////////////////////////////////////////////// // var uiTopList: array of THControl = nil; @@ -817,6 +845,16 @@ begin 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); @@ -961,6 +999,88 @@ begin 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 @@ -1014,7 +1134,7 @@ 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