summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f6c2d91)
raw | patch | inline | side by side (parent: f6c2d91)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 28 Aug 2017 09:31:48 +0000 (12:31 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 28 Aug 2017 09:32:05 +0000 (12:32 +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 0fb34c00c47a220fc175ebc1bc1b40ebcdb0c46f..82256a81a0ea3692debe27236dc52789f3361b27 100644 (file)
--- a/src/game/g_holmes.pas
+++ b/src/game/g_holmes.pas
showMapCurPos: Boolean = false;
showLayersWindow: Boolean = false;
showOutlineWindow: Boolean = false;
- oldShowLayersWindow: Boolean = false;
- oldShowOutlineWindow: Boolean = false;
// ////////////////////////////////////////////////////////////////////////// //
{$INCLUDE g_holmes.inc}
winOutlines: THTopWindow = nil;
-procedure createOptionsWindow ();
-var
- llb: THCtlCBListBox;
-begin
- llb := THCtlCBListBox.Create(0, 0);
- llb.appendItem('map grid', @showGrid);
- llb.appendItem('cursor position on map', @showMapCurPos);
- llb.appendItem('monster info', @showMonsInfo);
- llb.appendItem('monster LOS to player', @showMonsLOS2Plr);
- llb.appendItem('monster cells (SLOW!)', @showAllMonsCells);
- llb.appendItem('WINDOWS', nil);
- llb.appendItem('layers window', @showLayersWindow);
- llb.appendItem('outline window', @showOutlineWindow);
- winOptions := THTopWindow.Create('Holmes Options', 100, 100);
- winOptions.escClose := true;
- winOptions.appendChild(llb);
-end;
-
+procedure winLayersClosed (me: THControl; dummy: Integer); begin showLayersWindow := false; end;
+procedure winOutlinesClosed (me: THControl; dummy: Integer); begin showOutlineWindow := false; end;
procedure createLayersWindow ();
var
winLayers := THTopWindow.Create('visible', 10, 10);
winLayers.escClose := true;
winLayers.appendChild(llb);
+ winLayers.closeCB := winLayersClosed;
end;
winOutlines := THTopWindow.Create('outlines', 100, 10);
winOutlines.escClose := true;
winOutlines.appendChild(llb);
+ winOutlines.closeCB := winOutlinesClosed;
+end;
+
+
+procedure toggleLayersWindow (me: THControl; checked: Integer);
+begin
+ if showLayersWindow then
+ begin
+ if (winLayers = nil) then createLayersWindow();
+ uiAddWindow(winLayers);
+ end
+ else
+ begin
+ uiRemoveWindow(winLayers);
+ end;
+end;
+
+
+procedure toggleOutlineWindow (me: THControl; checked: Integer);
+begin
+ if showOutlineWindow then
+ begin
+ if (winOutlines = nil) then createOutlinesWindow();
+ uiAddWindow(winOutlines);
+ end
+ else
+ begin
+ uiRemoveWindow(winOutlines);
+ end;
+end;
+
+
+procedure createOptionsWindow ();
+var
+ llb: THCtlCBListBox;
+begin
+ llb := THCtlCBListBox.Create(0, 0);
+ llb.appendItem('map grid', @showGrid);
+ llb.appendItem('cursor position on map', @showMapCurPos);
+ llb.appendItem('monster info', @showMonsInfo);
+ llb.appendItem('monster LOS to player', @showMonsLOS2Plr);
+ llb.appendItem('monster cells (SLOW!)', @showAllMonsCells);
+ llb.appendItem('WINDOWS', nil);
+ llb.appendItem('layers window', @showLayersWindow, toggleLayersWindow);
+ llb.appendItem('outline window', @showOutlineWindow, toggleOutlineWindow);
+ winOptions := THTopWindow.Create('Holmes Options', 100, 100);
+ winOptions.escClose := true;
+ winOptions.appendChild(llb);
end;
begin
result := true;
showLayersWindow := not showLayersWindow;
+ toggleLayersWindow(nil, 0);
exit;
end;
// C-O: toggle outlines window
begin
result := true;
showOutlineWindow := not showOutlineWindow;
+ toggleOutlineWindow(nil, 0);
exit;
end;
// F1: toggle options window
// ////////////////////////////////////////////////////////////////////////// //
procedure g_Holmes_Draw ();
begin
- if (oldShowLayersWindow <> showLayersWindow) then
- begin
- oldShowLayersWindow := showLayersWindow;
- if showLayersWindow then
- begin
- if (winLayers = nil) then createLayersWindow();
- uiAddWindow(winLayers);
- end
- else
- begin
- uiRemoveWindow(winLayers);
- end;
- end
- else
- begin
- showLayersWindow := uiVisibleWindow(winLayers);
- oldShowLayersWindow := showLayersWindow;
- end;
-
- if (oldShowOutlineWindow <> showOutlineWindow) then
- begin
- oldShowOutlineWindow := showOutlineWindow;
- if showOutlineWindow then
- begin
- if (winOutlines = nil) then createOutlinesWindow();
- uiAddWindow(winOutlines);
- end
- else
- begin
- uiRemoveWindow(winOutlines);
- end;
- end
- else
- begin
- showOutlineWindow := uiVisibleWindow(winOutlines);
- oldShowOutlineWindow := showOutlineWindow;
- end;
-
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND);
index e903279ac3e0cd0360810387a76776dcad7de4db..79a21e77a0763b1876bb008b7b7ef614e39763c0 100644 (file)
--- a/src/game/g_holmes_ui.inc
+++ b/src/game/g_holmes_ui.inc
// ////////////////////////////////////////////////////////////////////////// //
type
THControl = class
+ public
+ type TActionCB = procedure (me: THControl; uinfo: Integer);
+
private
mParent: THControl;
mX, mY: Integer;
// modifies rect0
class function intersectRect (var x0, y0, w0, h0: Integer; const x1, y1, w1, h1: Integer): Boolean;
+ public
+ actionCB: TActionCB;
+
public
constructor Create (ax, ay, aw, ah: Integer; aparent: THControl=nil);
destructor Destroy (); override;
protected
procedure blurred (); override;
+ public
+ closeCB: TActionCB; // called after window was removed from ui window list
+
public
constructor Create (const atitle: AnsiString; ax, ay: Integer; aw: Integer=-1; ah: Integer=-1);
THCtlCBListBox = class(THControl)
private
- mItems: array of AnsiString;
- mChecks: array of PBoolean;
+ type
+ PItem = ^TItem;
+ TItem = record
+ title: AnsiString;
+ varp: PBoolean;
+ actionCB: TActionCB;
+ end;
+ private
+ mItems: array of TItem;
mCurIndex: Integer;
public
constructor Create (ax, ay: Integer; aparent: THControl=nil);
destructor Destroy (); override;
- procedure appendItem (const atext: AnsiString; bv: PBoolean);
+ procedure appendItem (const atext: AnsiString; bv: PBoolean; aaction: TActionCB=nil);
procedure drawControl (sx, sy: Integer); override;
ctl.blurred();
for c := f+1 to High(uiTopList) do uiTopList[c-1] := uiTopList[c];
SetLength(uiTopList, Length(uiTopList)-1);
+ if (ctl is THTopWindow) then
+ begin
+ if assigned(THTopWindow(ctl).closeCB) then THTopWindow(ctl).closeCB(ctl, 0);
+ end;
exit;
end;
end;
mEatKeys := false;
scallowed := false;
mDrawShadow := false;
+ actionCB := nil;
end;
begin
if (ctl <> topLevel.mFocused) then ctl.setFocused(true);
result := ctl.mouseEvent(ev);
+ end
+ else if (ctl = self) and assigned(actionCB) then
+ begin
+ actionCB(self, 0);
end;
end;
mDrawShadow := true;
mWaitingClose := false;
mInClose := false;
+ closeCB := nil;
end;
constructor THCtlCBListBox.Create (ax, ay: Integer; aparent: THControl=nil);
begin
mItems := nil;
- mChecks := nil;
mCurIndex := -1;
inherited Create(ax, ay, 4, 4);
end;
destructor THCtlCBListBox.Destroy ();
begin
mItems := nil;
- mChecks := nil;
inherited;
end;
-procedure THCtlCBListBox.appendItem (const atext: AnsiString; bv: PBoolean);
+procedure THCtlCBListBox.appendItem (const atext: AnsiString; bv: PBoolean; aaction: TActionCB=nil);
+var
+ it: PItem;
begin
- if (Length(atext)*8+4+3*8+2 > mWidth) then mWidth := Length(atext)*8+4+3*8+2;
+ if (Length(atext)*8+3*8+2 > mWidth) then mWidth := Length(atext)*8+3*8+2;
SetLength(mItems, Length(mItems)+1);
- mItems[High(mItems)] := atext;
- SetLength(mChecks, Length(mChecks)+1);
- mChecks[High(mChecks)] := bv;
- if (Length(mItems)*8+4 > mHeight) then mHeight := Length(mItems)*8+4;
+ it := @mItems[High(mItems)];
+ it.title := atext;
+ it.varp := bv;
+ it.actionCB := aaction;
+ if (Length(mItems)*8 > mHeight) then mHeight := Length(mItems)*8;
if (mCurIndex < 0) then mCurIndex := 0;
end;
procedure THCtlCBListBox.drawControl (sx, sy: Integer);
var
f, tx: Integer;
+ it: PItem;
begin
- //fillRect(sx, sy, mWidth, mHeight, 0, 128, 0);
- Inc(sx, 2);
- Inc(sy, 2);
for f := 0 to High(mItems) do
begin
- if (mCurIndex = f) then fillRect(sx-2, sy, mWidth, 8, 0, 128, 0);
- if (mChecks[f] <> nil) then
+ it := @mItems[f];
+ if (mCurIndex = f) then fillRect(sx, sy, mWidth, 8, 0, 128, 0);
+ if (it.varp <> nil) then
begin
- //drawText8(sx, sy, '[ ]', 255, 255, 255);
- //if mChecks[f]^ then drawText8(sx+6, sy, 'x', 255, 255, 255);
- if mChecks[f]^ then drawText8(sx, sy, '[x]', 255, 255, 255) else drawText8(sx, sy, '[ ]', 255, 255, 255);
- drawText8(sx+3*8+2, sy, mItems[f], 255, 255, 0);
+ if it.varp^ then drawText8(sx, sy, '[x]', 255, 255, 255) else drawText8(sx, sy, '[ ]', 255, 255, 255);
+ drawText8(sx+3*8+2, sy, it.title, 255, 255, 0);
end
- else if (Length(mItems[f]) > 0) then
+ else if (Length(it.title) > 0) then
begin
- tx := sx+(mWidth-Length(mItems[f])*8) div 2;
+ tx := sx+(mWidth-Length(it.title)*8) div 2;
if (tx-3 > sx+4) then
begin
drawLine(sx+4, sy+3, tx-3, sy+3, 255, 255, 255);
- drawLine(tx+Length(mItems[f])*8, sy+3, sx+mWidth-4, 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(mItems[f])*8) div 2, sy, mItems[f], 255, 255, 255);
+ drawText8(sx+(mWidth-Length(it.title)*8) div 2, sy, it.title, 255, 255, 255);
end
else
begin
function THCtlCBListBox.mouseEvent (var ev: THMouseEvent): Boolean;
var
lx, ly: Integer;
+ it: PItem;
begin
result := inherited mouseEvent(ev);
- if not result and (Length(mItems) > 0) and (ev.kind = ev.Press) then
+ lx := ev.x;
+ ly := ev.y;
+ if not result and toLocal(lx, ly) then
begin
- lx := ev.x;
- ly := ev.y;
- if toLocal(lx, ly) then
+ result := true;
+ if (ev.kind = ev.Press) then
begin
- if (ly < 2) then ly := 2;
ly := ly div 8;
- if (ly < 0) then ly := 0 else if (ly > High(mItems)) then ly := High(mItems);
- if (mChecks[ly] <> nil) then
+ if (ly >= 0) and (ly < Length(mItems)) then
begin
- mCurIndex := ly;
- if (mChecks[ly] <> nil) then mChecks[ly]^ := not mChecks[ly]^;
+ it := @mItems[ly];
+ if (it.varp <> nil) then
+ begin
+ mCurIndex := ly;
+ it.varp^ := not it.varp^;
+ if assigned(it.actionCB) then it.actionCB(self, Integer(it.varp^));
+ if assigned(actionCB) then actionCB(self, ly);
+ end;
end;
end;
end;
function THCtlCBListBox.keyEvent (var ev: THKeyEvent): Boolean;
+var
+ it: PItem;
begin
result := inherited keyEvent(ev);
if not getFocused then exit;
while (mCurIndex > 0) do
begin
Dec(mCurIndex);
- if (mChecks[mCurIndex] <> nil) then break;
+ if (mItems[mCurIndex].varp <> nil) then break;
end;
end
else
while (mCurIndex < High(mItems)) do
begin
Inc(mCurIndex);
- if (mChecks[mCurIndex] <> nil) then break;
+ if (mItems[mCurIndex].varp <> nil) then break;
end;
end
else
SDL_SCANCODE_RETURN:
begin
result := true;
- if (mCurIndex >= 0) and (mCurIndex < Length(mChecks)) and (mChecks[mCurIndex] <> nil) then mChecks[mCurIndex]^ := not mChecks[mCurIndex]^;
+ if (mCurIndex >= 0) and (mCurIndex < Length(mItems)) and (mItems[mCurIndex].varp <> nil) then
+ begin
+ it := @mItems[mCurIndex];
+ it.varp^ := not it.varp^;
+ if assigned(it.actionCB) then it.actionCB(self, Integer(it.varp^));
+ if assigned(actionCB) then actionCB(self, mCurIndex);
+ end;
end;
end;
end;