1. private with Ada.Real_Time; 
  2. private with Ada.Strings.Unbounded; 
  3. private with Allegro.Keyboard; 
  4. private with Entities; 
  5. private with Events.Game; 
  6. private with Events.Keen; 
  7. private with Events.World; 
  8.  
  9. package Game_Views.Keen is 
  10.  
  11. private 
  12.  
  13.     use Ada.Real_Time; 
  14.     use Ada.Strings.Unbounded; 
  15.     use Allegro.Keyboard; 
  16.     use Entities; 
  17.     use Events.Game; 
  18.     use Events.Keen; 
  19.     use Events.World; 
  20.  
  21.     type Boolean_Key_Array is array (1..KEY_MAX) of Boolean; 
  22.  
  23.     type Keen_View is new Game_View with 
  24.         record 
  25.             -- true if a game is currently in-session 
  26.             gameInProgress : Boolean := False; 
  27.  
  28.             -- paused automatically by the gui. this indicates that the gui 
  29.             -- should resume the game because the pause command was not given by 
  30.             -- the user. (ex: auto pause when showing progress board or entering 
  31.             -- the menu) 
  32.             autoPaused : Boolean := False; 
  33.  
  34.             -- player can pause/resume the game. the gui may lock the pause 
  35.             -- feature temporarily so the user can't directly pause/resume. 
  36.             pauseEnabled : Boolean := True; 
  37.  
  38.             -- the id of the player entity, for sending impulses. 
  39.             playerId : Entity_Id := INVALID_ID; 
  40.  
  41.             -- events from these keys sent to the scene should be ignored until 
  42.             -- the next key press event. 
  43.             ignoreKey : Boolean_Key_Array := Boolean_Key_Array'(others => False); 
  44.  
  45.             -- time when the loading screen was shown; the time is set when 
  46.             -- the world introduction text is put into it, not when the message 
  47.             -- box is first displayed. this allows a minimum time to pass where 
  48.             -- the player can read the text before it is hidden again. 
  49.             loadScreenStarted : Time := Time_Last; 
  50.  
  51.             -- true when loading is in progress. 
  52.             loading : Boolean := False; 
  53.  
  54.             -- the name of the music for the current world. this is set when the 
  55.             -- 'music' world property changes and played when the world loading 
  56.             -- dialog is closed. 
  57.             worldMusic : Unbounded_String; 
  58.  
  59.             -- the id of the most recent dialog event pending a response. 
  60.             dialogId : Integer := 0; 
  61.         end record; 
  62.     type A_Keen_View is access all Keen_View'Class; 
  63.  
  64.     procedure Construct( this : access Keen_View ); 
  65.  
  66.     procedure Handle( this : not null access Keen_View'Class; 
  67.                       evt  : not null A_Dialog_Event ); 
  68.  
  69.     procedure Handle( this : not null access Keen_View'Class; 
  70.                       evt  : not null A_Game_State_Event ); 
  71.  
  72.     procedure Handle( this : not null access Keen_View'Class; 
  73.                       evt  : not null A_Game_Var_Changed_Event ); 
  74.  
  75.     procedure Handle( this : not null access Keen_View'Class; 
  76.                       evt  : not null A_Scroll_View_Event ); 
  77.  
  78.     procedure Handle( this : not null access Keen_View'Class; 
  79.                       evt  : not null A_World_Property_Changed_Event ); 
  80.  
  81.     procedure Handle_Close_Request( this : access Keen_View ); 
  82.  
  83.     -- Inherited from the Event_Listener interface. Handles events that the view 
  84.     -- is registered to receive. 
  85.     procedure Handle_Event( this : access Keen_View; 
  86.                             evt  : in out A_Event; 
  87.                             resp : out Response_Type ); 
  88.     pragma Precondition( evt /= null ); 
  89.  
  90.     -- This is called when the application starts and stops loading resources. 
  91.     procedure Handle_Loading( this : access Keen_View; loading : Boolean ); 
  92.  
  93.     -- This is called when a new world is loaded by the Game. 
  94.     procedure Handle( this : not null access Keen_View'Class; 
  95.                       evt  : not null A_New_World_Event ); 
  96.  
  97.     -- This is called when the paused state of the Game changes. 
  98.     procedure Handle_Paused( this : access Keen_View; paused : Boolean ); 
  99.  
  100.     -- This is called to start the view and attach it to the application 
  101.     -- framework on startup. 
  102.     procedure Start_View( this : access Keen_View ); 
  103.  
  104.     -- This is called to stop the view and detach it from the application 
  105.     -- framework on shutdown. 
  106.     procedure Stop_View( this : access Keen_View ); 
  107.  
  108.     -- Inherited from the Process interface. This will be called regularly after 
  109.     -- the view is started. 
  110.     procedure Tick( this : access Keen_View; time : Tick_Time ); 
  111.  
  112.     -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  113.     -- The following procedures handle direct user actions. 
  114.  
  115.     -- Called when the user confirms that they have seen the title screen. The 
  116.     -- gui will return to the menu. 
  117.     procedure Action_Title_OK( this : not null access Keen_View'Class ); 
  118.  
  119.     -- Called when the user attempts to start a new game. This procedure 
  120.     -- ensures that a new game may be started and then queues a New_Game event. 
  121.     procedure Action_New_Game( this : not null access Keen_View'Class ); 
  122.  
  123.     -- Called when the user attempts to resume a game in progress from the menu. 
  124.     procedure Action_Resume_Game( this : not null access Keen_View'Class ); 
  125.  
  126.    -- Called when the user attempts to quit the game. This procedure may do 
  127.    -- something else first, like ask if the game should be saved, etc. When the 
  128.    -- game should be quit, this procedure will queue a Close_Window event. 
  129.     procedure Action_Quit( this : not null access Keen_View'Class ); 
  130.  
  131.     -- Called when the user responds to the retry level dialog. 
  132.     procedure Action_Retry_Level( this  : not null access Keen_View'Class; 
  133.                                   again : Boolean ); 
  134.  
  135.     -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  136.     -- The following procedures update the GUI. 
  137.  
  138.     -- Pauses the game automatically if it isn't already paused, or unpauses the 
  139.     -- game if it was paused automatically and not by the player. 
  140.     procedure Auto_Pause( this  : not null access Keen_View'Class; 
  141.                           pause : Boolean ); 
  142.  
  143.     -- Queues an event to pause or resume the game. The user must be allowed to 
  144.     -- pause or resume the game or else 'force' must be set to True. Note that 
  145.     -- the paused state of the game remains unchanged until Handle_Paused is 
  146.     -- called. 
  147.     procedure Pause_Game( this  : not null access Keen_View'Class; 
  148.                           pause : Boolean; 
  149.                           force : Boolean := False ); 
  150.  
  151.     -- Creates all of the widgets required for the game view. This should only 
  152.     -- be called once as part of Game_View object construction. An exception 
  153.     -- will be raised if an error occurs creating the widgets. 
  154.     procedure Populate_View( this  : not null access Keen_View'Class; 
  155.                              xres, 
  156.                              yres  : Positive; 
  157.                              scale : Positive ); 
  158.  
  159.     -- Returns the gui to the menu from gameplay, pausing the game automatically. 
  160.     procedure Return_To_Menu( this : not null access Keen_View'Class ); 
  161.  
  162.     -- Indicates to the game logic that the view is ready to play. The menu and 
  163.     -- load screen is hidden and the scene is made visible. 
  164.     procedure Ready_To_Play( this : not null access Keen_View'Class ); 
  165.  
  166.     -- Puts 'text' into the loading message box, splitting text into multiple 
  167.     -- lines on whitespace boundaries as necessary. If visibility of the loading 
  168.     -- message will not be affected. 
  169.     procedure Set_Loading_Text( this : not null access Keen_View'Class; 
  170.                                 text : String ); 
  171.  
  172.     -- Shows the game widgets and focuses the scene, or hides the game widgets. 
  173.     procedure Show_Game( this : not null access Keen_View'Class; show : Boolean ); 
  174.  
  175.     -- Shows or hides the modal loading dialog. If 'show' is True then 'text' 
  176.     -- will be the text shown in the dialog. 
  177.     procedure Show_Loading( this : not null access Keen_View'Class; 
  178.                             show : Boolean; 
  179.                             text : String := "" ); 
  180.  
  181.     -- Shows or hides the menu widgets. 
  182.     procedure Show_Menu( this : not null access Keen_View'Class; show : Boolean ); 
  183.  
  184. end Game_Views.Keen;