private with Ada.Real_Time;
private with Ada.Strings.Unbounded;
private with Allegro.Keyboard;
private with Entities;
private with Events.Game;
private with Events.Keen;
private with Events.World;
package Game_Views.Keen is
private
use Ada.Real_Time;
use Ada.Strings.Unbounded;
use Allegro.Keyboard;
use Entities;
use Events.Game;
use Events.Keen;
use Events.World;
type Boolean_Key_Array is array (1..KEY_MAX) of Boolean;
type Keen_View is new Game_View with
record
-- true if a game is currently in-session
gameInProgress : Boolean := False;
-- paused automatically by the gui. this indicates that the gui
-- should resume the game because the pause command was not given by
-- the user. (ex: auto pause when showing progress board or entering
-- the menu)
autoPaused : Boolean := False;
-- player can pause/resume the game. the gui may lock the pause
-- feature temporarily so the user can't directly pause/resume.
pauseEnabled : Boolean := True;
-- the id of the player entity, for sending impulses.
playerId : Entity_Id := INVALID_ID;
-- events from these keys sent to the scene should be ignored until
-- the next key press event.
ignoreKey : Boolean_Key_Array := Boolean_Key_Array'(others => False);
-- time when the loading screen was shown; the time is set when
-- the world introduction text is put into it, not when the message
-- box is first displayed. this allows a minimum time to pass where
-- the player can read the text before it is hidden again.
loadScreenStarted : Time := Time_Last;
-- true when loading is in progress.
loading : Boolean := False;
-- the name of the music for the current world. this is set when the
-- 'music' world property changes and played when the world loading
-- dialog is closed.
worldMusic : Unbounded_String;
-- the id of the most recent dialog event pending a response.
dialogId : Integer := 0;
end record;
type A_Keen_View is access all Keen_View'Class;
procedure Construct( this : access Keen_View );
procedure Handle( this : not null access Keen_View'Class;
evt : not null A_Dialog_Event );
procedure Handle( this : not null access Keen_View'Class;
evt : not null A_Game_State_Event );
procedure Handle( this : not null access Keen_View'Class;
evt : not null A_Game_Var_Changed_Event );
procedure Handle( this : not null access Keen_View'Class;
evt : not null A_Scroll_View_Event );
procedure Handle( this : not null access Keen_View'Class;
evt : not null A_World_Property_Changed_Event );
procedure Handle_Close_Request( this : access Keen_View );
-- Inherited from the Event_Listener interface. Handles events that the view
-- is registered to receive.
procedure Handle_Event( this : access Keen_View;
evt : in out A_Event;
resp : out Response_Type );
pragma Precondition( evt /= null );
-- This is called when the application starts and stops loading resources.
procedure Handle_Loading( this : access Keen_View; loading : Boolean );
-- This is called when a new world is loaded by the Game.
procedure Handle( this : not null access Keen_View'Class;
evt : not null A_New_World_Event );
-- This is called when the paused state of the Game changes.
procedure Handle_Paused( this : access Keen_View; paused : Boolean );
-- This is called to start the view and attach it to the application
-- framework on startup.
procedure Start_View( this : access Keen_View );
-- This is called to stop the view and detach it from the application
-- framework on shutdown.
procedure Stop_View( this : access Keen_View );
-- Inherited from the Process interface. This will be called regularly after
-- the view is started.
procedure Tick( this : access Keen_View; time : Tick_Time );
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- The following procedures handle direct user actions.
-- Called when the user confirms that they have seen the title screen. The
-- gui will return to the menu.
procedure Action_Title_OK( this : not null access Keen_View'Class );
-- Called when the user attempts to start a new game. This procedure
-- ensures that a new game may be started and then queues a New_Game event.
procedure Action_New_Game( this : not null access Keen_View'Class );
-- Called when the user attempts to resume a game in progress from the menu.
procedure Action_Resume_Game( this : not null access Keen_View'Class );
-- Called when the user attempts to quit the game. This procedure may do
-- something else first, like ask if the game should be saved, etc. When the
-- game should be quit, this procedure will queue a Close_Window event.
procedure Action_Quit( this : not null access Keen_View'Class );
-- Called when the user responds to the retry level dialog.
procedure Action_Retry_Level( this : not null access Keen_View'Class;
again : Boolean );
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- The following procedures update the GUI.
-- Pauses the game automatically if it isn't already paused, or unpauses the
-- game if it was paused automatically and not by the player.
procedure Auto_Pause( this : not null access Keen_View'Class;
pause : Boolean );
-- Queues an event to pause or resume the game. The user must be allowed to
-- pause or resume the game or else 'force' must be set to True. Note that
-- the paused state of the game remains unchanged until Handle_Paused is
-- called.
procedure Pause_Game( this : not null access Keen_View'Class;
pause : Boolean;
force : Boolean := False );
-- Creates all of the widgets required for the game view. This should only
-- be called once as part of Game_View object construction. An exception
-- will be raised if an error occurs creating the widgets.
procedure Populate_View( this : not null access Keen_View'Class;
xres,
yres : Positive;
scale : Positive );
-- Returns the gui to the menu from gameplay, pausing the game automatically.
procedure Return_To_Menu( this : not null access Keen_View'Class );
-- Indicates to the game logic that the view is ready to play. The menu and
-- load screen is hidden and the scene is made visible.
procedure Ready_To_Play( this : not null access Keen_View'Class );
-- Puts 'text' into the loading message box, splitting text into multiple
-- lines on whitespace boundaries as necessary. If visibility of the loading
-- message will not be affected.
procedure Set_Loading_Text( this : not null access Keen_View'Class;
text : String );
-- Shows the game widgets and focuses the scene, or hides the game widgets.
procedure Show_Game( this : not null access Keen_View'Class; show : Boolean );
-- Shows or hides the modal loading dialog. If 'show' is True then 'text'
-- will be the text shown in the dialog.
procedure Show_Loading( this : not null access Keen_View'Class;
show : Boolean;
text : String := "" );
-- Shows or hides the menu widgets.
procedure Show_Menu( this : not null access Keen_View'Class; show : Boolean );
end Game_Views.Keen;