summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 97f895c)
raw | patch | inline | side by side (parent: 97f895c)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sun, 17 Apr 2016 05:38:25 +0000 (08:38 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sun, 17 Apr 2016 05:38:52 +0000 (08:38 +0300) |
src/game/g_gui.pas | patch | blob | history | |
src/game/g_menu.pas | patch | blob | history |
diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas
index 08ecee3316b007a783f681974e47f58785f7fbe3..0100e36ffcf22ff242052d5f17f5442e3fdddc88 100644 (file)
--- a/src/game/g_gui.pas
+++ b/src/game/g_gui.pas
FEnabled: Boolean;
FWindow : TGUIWindow;
FName: string;
+ FUserData: Pointer;
public
constructor Create;
procedure OnMessage(var Msg: TMessage); virtual;
property Y: Integer read FY write FY;
property Enabled: Boolean read FEnabled write FEnabled;
property Name: string read FName write FName;
+ property UserData: Pointer read FUserData write FUserData;
end;
TGUIWindow = class
FShowWindow: string;
public
Proc: procedure;
+ ProcEx: procedure (sender: TGUITextButton);
constructor Create(Proc: Pointer; FontID: DWORD; Text: string);
destructor Destroy(); override;
procedure OnMessage(var Msg: TMessage); override;
FCounter: Byte;
FAlign: Boolean;
FLeft: Integer;
+ FYesNo: Boolean;
function NewItem(): Integer;
public
constructor Create(HeaderFont, ItemsFont: DWORD; Header: string);
procedure UpdateIndex();
property Align: Boolean read FAlign write FAlign;
property Left: Integer read FLeft write FLeft;
+ property YesNo: Boolean read FYesNo write FYesNo;
end;
var
procedure TGUITextButton.Click(Silent: Boolean = False);
begin
- if (FSound <> '') and (not Silent) then
- g_Sound_PlayEx(FSound);
+ if (FSound <> '') and (not Silent) then g_Sound_PlayEx(FSound);
+
+ if @Proc <> nil then Proc();
+ if @ProcEx <> nil then ProcEx(self);
- if @Proc <> nil then
- Proc();
- if FShowWindow <> '' then
- g_GUI_ShowWindow(FShowWindow);
+ if FShowWindow <> '' then g_GUI_ShowWindow(FShowWindow);
end;
constructor TGUITextButton.Create(Proc: Pointer; FontID: DWORD; Text: string);
inherited Create();
Self.Proc := Proc;
+ ProcEx := nil;
FFont := TFont.Create(FontID, FONT_CHAR);
with FItems[i] do
begin
Text := TGUILabel.Create(l[a], FFontID);
- with Text do
+ if FYesNo then
begin
- FColor := MENU_ITEMSTEXT_COLOR;
+ with Text do begin FColor := _RGB(255, 0, 0); end;
+ end
+ else
+ begin
+ with Text do begin FColor := MENU_ITEMSTEXT_COLOR; end;
end;
Control := nil;
FFontID := ItemsFont;
FCounter := MENU_MARKERDELAY;
FAlign := True;
+ FYesNo := false;
FHeader := TGUILabel.Create(Header, HeaderFont);
with FHeader do
IK_RETURN, IK_KPRETURN:
begin
if FIndex <> -1 then
- if FItems[FIndex].Control <> nil then
- FItems[FIndex].Control.OnMessage(Msg);
-
+ begin
+ if FItems[FIndex].Control <> nil then FItems[FIndex].Control.OnMessage(Msg);
+ end;
g_Sound_PlayEx(MENU_CLICKSOUND);
end;
+ // dirty hacks
+ IK_Y:
+ if FYesNo and (length(FItems) > 1) then
+ begin
+ Msg.wParam := IK_RETURN; // to register keypress
+ FIndex := High(FItems)-1;
+ if FItems[FIndex].Control <> nil then FItems[FIndex].Control.OnMessage(Msg);
+ end;
+ IK_N:
+ if FYesNo and (length(FItems) > 1) then
+ begin
+ Msg.wParam := IK_RETURN; // to register keypress
+ FIndex := High(FItems);
+ if FItems[FIndex].Control <> nil then FItems[FIndex].Control.OnMessage(Msg);
+ end;
end;
end;
end;
cx := 0;
for a := 0 to High(FItems) do
+ begin
with FItems[a] do
begin
if (Text <> nil) and (Control = nil) then Continue;
-
w := 0;
if Text <> nil then w := tx+Text.GetWidth;
-
if w > cx then cx := w;
end;
+ end;
cx := cx+MENU_HSPACE;
h := FHeader.GetHeight*2+MENU_VSPACE*(Length(FItems)-1);
for a := 0 to High(FItems) do
+ begin
with FItems[a] do
begin
if (ControlType = TGUIListBox) or (ControlType = TGUIFileListBox) then
else
h := h+e_CharFont_GetMaxHeight(FFontID);
end;
+ end;
h := (gScreenHeight div 2)-(h div 2);
else
Inc(h, e_CharFont_GetMaxHeight(FFontID)+MENU_VSPACE);
end;
+
+ // another ugly hack
+ if FYesNo and (length(FItems) > 1) then
+ begin
+ w := -1;
+ for a := High(FItems)-1 to High(FItems) do
+ begin
+ if (FItems[a].Control <> nil) and (FItems[a].ControlType = TGUITextButton) then
+ begin
+ cx := (FItems[a].Control as TGUITextButton).GetWidth;
+ if cx > w then w := cx;
+ end;
+ end;
+ if w > 0 then
+ begin
+ for a := High(FItems)-1 to High(FItems) do
+ begin
+ if (FItems[a].Control <> nil) and (FItems[a].ControlType = TGUITextButton) then
+ begin
+ FItems[a].Control.FX := (gScreenWidth-w) div 2;
+ end;
+ end;
+ end;
+ end;
end;
function TGUIMenu.AddScroll(fText: string): TGUIScroll;
diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas
index 015c1e2556f31c61b0905dc464af6633e45ee029..23e9629666c3a91727a73c2829b8ce74dd283072 100644 (file)
--- a/src/game/g_menu.pas
+++ b/src/game/g_menu.pas
end;
end;
-function CreateYNMenu (Name, Text: String; MaxLen: Word; FontID: DWORD; ActionProc: TYNCallback): TGUIWindow;
+procedure YesButtonCB (ctl: TGUITextButton);
+begin
+ if ctl.UserData = nil then exit;
+ TYNCallback(ctl.UserData)(true);
+end;
+
+procedure NoButtonCB (ctl: TGUITextButton);
+begin
+ if ctl.UserData = nil then exit;
+ TYNCallback(ctl.UserData)(false);
+end;
+
+function CreateYNMenu (WinName, Text: String; MaxLen: Word; FontID: DWORD; ActionProc: TYNCallback): TGUIWindow;
var
- a: Integer;
- h, _x: Word;
- lines: SArray;
+ menu: TGUIMenu;
begin
- Result := TGUIWindow.Create(Name);
+ //if length(Text) = 0 then exit;
+ Result := TGUIWindow.Create(WinName);
with Result do
begin
- OnKeyDownEx := @YNKeyDownProc;
- UserData := @ActionProc;
- lines := GetLines(Text, FontID, MaxLen);
- h := e_CharFont_GetMaxHeight(FontID);
- _x := (gScreenHeight div 2)-(h*Length(lines) div 2);
- if lines <> nil then
+ //OnKeyDownEx := @YNKeyDownProc;
+ //UserData := @ActionProc;
+ menu := TGUIMenu(Result.AddChild(TGUIMenu.Create(gMenuSmallFont, gMenuSmallFont, '')));
+ with menu do
begin
- for a := 0 to High(lines) do
- begin
- with TGUILabel(Result.AddChild(TGUILabel.Create(lines[a], FontID))) do
- begin
- X := (gScreenWidth div 2)-(GetWidth div 2);
- Y := _x;
- Color := _RGB(255, 0, 0);
- _x := _x+h;
- end;
- end;
- with TGUILabel(Result.AddChild(TGUILabel.Create('(Y/N)', FontID))) do
- begin
- X := (gScreenWidth div 2)-(GetWidth div 2);
- Y := _x;
- Color := _RGB(255, 0, 0);
- end;
+ Name := '__temp_yes_no_menu:'+WinName;
+ YesNo := true;
+ AddText(Text, MaxLen);
+ with AddButton(nil, 'Yes') do begin ProcEx := @YesButtonCB; UserData := @ActionProc; end;
+ with AddButton(nil, 'No') do begin ProcEx := @NoButtonCB; UserData := @ActionProc; end;
end;
- DefControl := '';
+ DefControl := '__temp_yes_no_menu:'+WinName;
SetActive(nil);
end;
end;