diff options
author | tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2009-07-23 15:07:57 +0000 |
---|---|---|
committer | tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2009-07-23 15:07:57 +0000 |
commit | 34c3fa9fec4f5d23a67ba4ef9dfdec28bf043bf8 (patch) | |
tree | 494b46856f83a1d9a296ce321f9c0916f3b870ad /unicode | |
parent | 8cfc0fff4c3f039b65dbfedb290cd211b673a060 (diff) | |
download | usdx-34c3fa9fec4f5d23a67ba4ef9dfdec28bf043bf8.tar.gz usdx-34c3fa9fec4f5d23a67ba4ef9dfdec28bf043bf8.tar.xz usdx-34c3fa9fec4f5d23a67ba4ef9dfdec28bf043bf8.zip |
More generic popup dialog. A callback can be defined to be called after the popup is closed.
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1866 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r-- | unicode/src/menu/UMenu.pas | 22 | ||||
-rw-r--r-- | unicode/src/screens/UScreenPopup.pas | 89 |
2 files changed, 65 insertions, 46 deletions
diff --git a/unicode/src/menu/UMenu.pas b/unicode/src/menu/UMenu.pas index 0c6ebc63..f7e98d32 100644 --- a/unicode/src/menu/UMenu.pas +++ b/unicode/src/menu/UMenu.pas @@ -1176,13 +1176,33 @@ begin AudioPlayback.PlaySound( aSound ); end; +procedure OnSaveEncodingError(Value: boolean; Data: Pointer); +begin + Display.CheckOK := Value; + if (Value) then + begin + //Hack to Finish Singscreen correct on Exit with Q Shortcut + if (Display.NextScreenWithCheck = nil) then + begin + if (Display.CurrentScreen = @ScreenSing) then + ScreenSing.Finish + else if (Display.CurrentScreen = @ScreenSingModi) then + ScreenSingModi.Finish; + end; + end + else + begin + Display.NextScreenWithCheck := nil; + end; +end; + //popup hack procedure TMenu.CheckFadeTo(Screen: PMenu; msg: string); begin Display.Fade := 0; Display.NextScreenWithCheck := Screen; Display.CheckOK := false; - ScreenPopupCheck.ShowPopup(msg); + ScreenPopupCheck.ShowPopup(msg, OnSaveEncodingError, nil, false); end; procedure TMenu.AddButtonText(AddX, AddY: real; const AddText: UTF8String); diff --git a/unicode/src/screens/UScreenPopup.pas b/unicode/src/screens/UScreenPopup.pas index c8b8a743..906335e7 100644 --- a/unicode/src/screens/UScreenPopup.pas +++ b/unicode/src/screens/UScreenPopup.pas @@ -42,34 +42,43 @@ uses UThemes; type + TPopupCheckHandler = procedure(Value: boolean; Data: Pointer); + TScreenPopupCheck = class(TMenu) + private + fHandler: TPopupCheckHandler; + fHandlerData: Pointer; + public - Visible: boolean; //Whether the Menu should be Drawn + Visible: boolean; // whether the menu should be drawn constructor Create; override; function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; - procedure onShow; override; - procedure ShowPopup(msg: string); + procedure OnShow; override; + procedure ShowPopup(Msg: string; Handler: TPopupCheckHandler; + HandlerData: Pointer; DefaultValue: boolean = false); function Draw: boolean; override; end; type TScreenPopupError = class(TMenu) -{ private - CurMenu: byte; //Num of the cur. Shown Menu} + { + private + CurMenu: byte; //Num of the cur. Shown Menu + } public Visible: boolean; //Whether the Menu should be Drawn constructor Create; override; function ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; override; - procedure onShow; override; - procedure onHide; override; + procedure OnShow; override; + procedure OnHide; override; procedure ShowPopup(msg: string); function Draw: boolean; override; end; var -// ISelections: array of string; + //ISelections: array of string; SelectValue: integer; implementation @@ -86,67 +95,51 @@ uses UUnicodeUtils; function TScreenPopupCheck.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; PressedDown: boolean): boolean; +var + Value: boolean; begin Result := true; if (PressedDown) then begin // Key Down - // check normal keys - case UCS4UpperCase(CharCode) of - Ord('Q'): - begin - Result := false; - Exit; - end; - end; - // check special keys case PressedKey of SDLK_ESCAPE, SDLK_BACKSPACE : begin - Display.CheckOK := false; - Display.NextScreenWithCheck := NIL; + Value := false; Visible := false; Result := false; end; SDLK_RETURN: begin - case Interaction of - 0: begin - //Hack to Finish Singscreen correct on Exit with Q Shortcut - if (Display.NextScreenWithCheck = NIL) then - begin - if (Display.CurrentScreen = @ScreenSing) then - ScreenSing.Finish - else if (Display.CurrentScreen = @ScreenSingModi) then - ScreenSingModi.Finish; - end; - - Display.CheckOK := true; - end; - 1: begin - Display.CheckOK := false; - Display.NextScreenWithCheck := NIL; - end; - end; + Value := (Interaction = 0); Visible := false; Result := false; end; - SDLK_DOWN: InteractNext; - SDLK_UP: InteractPrev; - + SDLK_DOWN: InteractNext; + SDLK_UP: InteractPrev; + SDLK_RIGHT: InteractNext; - SDLK_LEFT: InteractPrev; + SDLK_LEFT: InteractPrev; end; end; + + if (not Result) then + begin + if (@fHandler <> nil) then + fHandler(Value, fHandlerData); + end; end; constructor TScreenPopupCheck.Create; begin inherited Create; + fHandler := nil; + fHandlerData := nil; + AddText(Theme.CheckPopup.TextCheck); LoadFromTheme(Theme.CheckPopup); @@ -164,18 +157,24 @@ end; function TScreenPopupCheck.Draw: boolean; begin - Draw:=inherited Draw; + Result := inherited Draw; end; -procedure TScreenPopupCheck.onShow; +procedure TScreenPopupCheck.OnShow; begin inherited; end; -procedure TScreenPopupCheck.ShowPopup(msg: string); +procedure TScreenPopupCheck.ShowPopup(Msg: string; Handler: TPopupCheckHandler; + HandlerData: Pointer; DefaultValue: boolean); begin - Interaction := 0; //Reset Interaction + if (DefaultValue) then + Interaction := 0 + else + Interaction := 1; Visible := true; //Set Visible + fHandler := Handler; + fHandlerData := HandlerData; Text[0].Text := Language.Translate(msg); |