Unit CastleDialogStates

Functions and Procedures
Types
Constants
Variables

Description

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(...);

Underneath, the MessageYesNo will use a TStateDialogYesNo, making sure that your normal window callbacks are redirected as appropriate. But you don't need to be concerned with this.

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;

Uses

Overview

Classes, Interfaces, Objects and Records

Name Description
Class TStateDialog Abstract class for a modal dialog user-interface state.
Class TStateDialogOK Wait for simple confirmation ("OK") from user.
Class TStateDialogYesNo Ask user a simple "yes" / "no" question.
Class TStateDialogChoice Ask user to choose from a number of options.
Class TStateDialogInput Ask user to input a string, or cancel.
Class TStateDialogKey Ask user a press any key, and return this key.
Class TStateDialogPressEvent 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.