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