Dialog windows (to display some information, or ask user for confirmation, or ask user to input a simple value) as a user-interface state (TUIState). This unit defines the user-interface state classes (TUIState descendants) to display given dialog.
If you use TCastleWindow with most platforms (but not iOS), then it's usually more comfortable to use the unit CastleMessages instead of this unit. Using the CastleMessages, you get comfortable functions like MessageOK and MessageYesNo that wait until user presses a button (like "OK", "Yes", "No") to close the dialog. This is comfortable to use, as you can write code like this:
if MessageYesNo(Window, 'Are you sure you want to delete this file?') then DeleteFile(...);
However, if you need to work on iOS, then you cannot use most of routines from the CastleMessages unit. You can use MessageOK if you turn on the MessageOKPushesState flag, but nothing else. E.g. MessageYesNo cannot work on iOS now. Making modal boxes like that is not supported on iOS.
In this case you should use this unit and instantiate the user-interface classes yourself, and you need to organize your whole game using TUIState classes. See https://castle-engine.io/manual_2d_user_interface.php#section_ui_state about how to use TUIState. Like this:
type TMyGameState = class(TUIState) private DialogAskDeleteFile: TStateDialogYesNo; public function Press(const Event: TInputPressRelease): boolean; override; procedure Resume; override; end; function Press(const Event: TInputPressRelease): boolean; override; begin Result := inherited; if Result then Exit; if Event.IsKey(keyEnter) then begin DialogAskDeleteFile := TStateDialogYesNo.Create(Self); DialogAskDeleteFile.Caption := 'Are you sure you want to delete this file?'; TUIState.Push(DialogAskDeleteFile); end; end; procedure TStatePlay.Resume; begin inherited; if DialogAskDeleteFile <> nil then // returning from DialogAskDeleteFile begin if DialogAskDeleteFile.Answer then DeleteFile(...); FreeAndNil(DialogAskDeleteFile); end; end;
Classes, Interfaces, Objects and Records
||Abstract class for a modal dialog user-interface state.|
||Wait for simple confirmation ("OK") from user.|
||Ask user a simple "yes" / "no" question.|
||Ask user to choose from a number of options.|
||Ask user to input a string, or cancel.|
||Ask user a press any key, and return this key.|
||Ask user a press anything (key, mouse button, mouse wheel), for example to configure a keybinding for a game.|
Generated by PasDoc 0.16.0.