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