summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 17c0529)
raw | patch | inline | side by side (parent: 17c0529)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sun, 17 Apr 2016 04:50:13 +0000 (07:50 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sun, 17 Apr 2016 04:55:03 +0000 (07:55 +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 7acbf0b101213d9203f4c9562aa20bf4c868523c..08ecee3316b007a783f681974e47f58785f7fbe3 100644 (file)
--- a/src/game/g_gui.pas
+++ b/src/game/g_gui.pas
end;
TGUIControl = class;
+ TGUIWindow = class;
TOnKeyDownEvent = procedure(Key: Byte);
+ TOnKeyDownEventEx = procedure(win: TGUIWindow; Key: Byte);
TOnCloseEvent = procedure;
TOnShowEvent = procedure;
TOnClickEvent = procedure;
TOnChangeEvent = procedure(Sender: TGUIControl);
TOnEnterEvent = procedure(Sender: TGUIControl);
- TGUIWindow = class;
-
TGUIControl = class
private
FX, FY: Integer;
FBackTexture: string;
FMainWindow: Boolean;
FOnKeyDown: TOnKeyDownEvent;
+ FOnKeyDownEx: TOnKeyDownEventEx;
FOnCloseEvent: TOnCloseEvent;
FOnShowEvent: TOnShowEvent;
+ FUserData: Pointer;
public
Childs: array of TGUIControl;
constructor Create(Name: string);
procedure SetActive(Control: TGUIControl);
function GetControl(Name: string): TGUIControl;
property OnKeyDown: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown;
+ property OnKeyDownEx: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx;
property OnClose: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent;
property OnShow: TOnShowEvent read FOnShowEvent write FOnShowEvent;
property Name: string read FName;
property DefControl: string read FDefControl write FDefControl;
property BackTexture: string read FBackTexture write FBackTexture;
property MainWindow: Boolean read FMainWindow write FMainWindow;
+ property UserData: Pointer read FUserData write FUserData;
end;
TGUITextButton = class(TGUIControl)
FActiveControl := nil;
FName := Name;
FOnKeyDown := nil;
+ FOnKeyDownEx := nil;
FOnCloseEvent := nil;
FOnShowEvent := nil;
end;
begin
if FActiveControl <> nil then FActiveControl.OnMessage(Msg);
if @FOnKeyDown <> nil then FOnKeyDown(Msg.wParam);
+ if @FOnKeyDownEx <> nil then FOnKeyDownEx(self, Msg.wParam);
if Msg.Msg = WM_KEYDOWN then
if Msg.wParam = IK_ESCAPE then
diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas
index f2abfb72daf04ca688986d1f544f18fbbae5e076..a3bf1ef5937613de1b959c5e5ac8cc1614b52ba2 100644 (file)
--- a/src/game/g_menu.pas
+++ b/src/game/g_menu.pas
e_textures, GL, GLExt, g_language,
g_net, g_netmsg, g_netmaster, g_items, e_input;
+
+type TYNCallback = procedure (yes:Boolean);
+
+procedure YNKeyDownProc (win: TGUIWindow; Key: Byte);
+begin
+ if win.UserData = nil then exit;
+ //writeln('YNEX; key=', Key, '; ', (Key = ord('y')));
+ if Key = ord('y') then TYNCallback(win.UserData)(true)
+ else if Key = ord('n') then TYNCallback(win.UserData)(false);
+end;
+
+function CreateYNMenu (Name, Text: String; MaxLen: Word; FontID: DWORD; ActionProc: TYNCallback): TGUIWindow;
+var
+ a: Integer;
+ h, _x: Word;
+ lines: SArray;
+begin
+ Result := TGUIWindow.Create(Name);
+ 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
+ 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;
+ end;
+ DefControl := '';
+ SetActive(nil);
+ end;
+end;
+
+
procedure ProcChangeColor(Sender: TGUIControl); forward;
procedure ProcSelectModel(Sender: TGUIControl); forward;
gMusic.Play();
end;
-procedure ProcExitMenuKeyDown(Key: Byte);
+procedure ProcExitMenuKeyDown (yes: Boolean);
var
s: ShortString;
snd: TPlayableSound;
res: Boolean;
begin
- if Key = IK_Y then
+ if yes then
begin
g_Game_StopAllSounds(True);
case (Random(18)) of
15: s := 'SOUND_MONSTER_SPIDER_ALERT';
else s := 'SOUND_PLAYER_FALL';
end;
-
snd := TPlayableSound.Create();
res := snd.SetByName(s);
- if not res then
- res := snd.SetByName('SOUND_PLAYER_FALL');
-
+ if not res then res := snd.SetByName('SOUND_PLAYER_FALL');
if res then
begin
snd.Play(True);
- while snd.IsPlaying() do
- ;
+ while snd.IsPlaying() do begin end;
end;
-
g_Game_Quit();
- end
- else
- if Key = IK_N then
- g_GUI_HideWindow();
+ exit;
+ end;
+ g_GUI_HideWindow();
end;
procedure ProcLoadMenu();
if Direction = D_LEFT then Direction := D_RIGHT else Direction := D_LEFT;
end;
-procedure ProcDefaultMenuKeyDown(Key: Byte);
+procedure ProcDefaultMenuKeyDown (yes: Boolean);
begin
- if Key = Ord('y') then
+ if yes then
begin
g_Options_SetDefault();
ReadOptions();
- g_GUI_HideWindow();
- end else
- if Key = Ord('n') then g_GUI_HideWindow;
+ end;
+ g_GUI_HideWindow();
end;
-procedure ProcSavedMenuKeyDown(Key: Byte);
+procedure ProcSavedMenuKeyDown (yes: Boolean);
begin
- if Key = Ord('y') then
- begin
- ReadOptions();
- g_GUI_HideWindow();
- end else
- if Key = Ord('n') then g_GUI_HideWindow;
+ if yes then ReadOptions();
+ g_GUI_HideWindow();
end;
procedure ProcAuthorsClose();
g_Game_Pause(False);
end;
-procedure ProcRestartMenuKeyDown(Key: Byte);
+procedure ProcRestartMenuKeyDown (yes: Boolean);
begin
- if Key = Ord('y') then g_Game_Restart()
- else if Key = Ord('n') then g_GUI_HideWindow;
+ if yes then g_Game_Restart() else g_GUI_HideWindow;
end;
-procedure ProcEndMenuKeyDown(Key: Byte);
+procedure ProcEndMenuKeyDown (yes: Boolean);
begin
- if Key = Ord('y') then gExit := EXIT_SIMPLE
- else if Key = Ord('n') then g_GUI_HideWindow;
+ if yes then gExit := EXIT_SIMPLE else g_GUI_HideWindow;
end;
procedure ProcSetRussianLanguage();
ProcApplyOptions();
end;
-function CreateYNMenu(Name, Text: String; MaxLen: Word; FontID: DWORD;
- KeyDownProc: Pointer): TGUIWindow;
-var
- a: Integer;
- h, _x: Word;
- lines: SArray;
-begin
- Result := TGUIWindow.Create(Name);
-
- with Result do
- begin
- OnKeyDown := KeyDownProc;
-
- lines := GetLines(Text, FontID, MaxLen);
-
- h := e_CharFont_GetMaxHeight(FontID);
- _x := (gScreenHeight div 2)-(h*Length(lines) div 2);
-
- if lines <> nil then
- begin
- for a := 0 to High(lines) do
- 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;
-
- 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;
- end;
-
- DefControl := '';
- SetActive(nil);
- end;
-end;
-
procedure ProcSetFirstRussianLanguage();
begin
gLanguage := LANGUAGE_RUSSIAN;