1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. private with Ada.Real_Time; 
  10. private with Ada.Strings.Unbounded; 
  11.  
  12. package Game_Views.Keen is 
  13.  
  14.     type Keen_View is new Game_View with private; 
  15.     type A_Keen_View is access all Keen_View'Class; 
  16.  
  17.     -- Pauses or resumes the game, in the context of a menu or dialog on the 
  18.     -- screen. For every pause by a menu, there must be a corresponding resume 
  19.     -- as a menu. 
  20.     -- 
  21.     -- Nested menus may all pause the game, so a menu pause count is preserved 
  22.     -- and tracked by this procedure. The first time a menu calls 
  23.     -- Pause_By_Menu(True), the game play will be paused (if it wasn't already 
  24.     -- paused by the player.) When the same menu calls the corresponding 
  25.     -- Pause_By_Menu(False), the menu pause count is decremented. When the count 
  26.     -- reaches zero, play will resume (again, if it wasn't already paused by the 
  27.     -- player.) 
  28.     procedure Pause_By_Menu( this    : not null access Keen_View'Class; 
  29.                              enabled : Boolean ); 
  30.  
  31.     -- Pauses or resumes the game, in the context of the player. If game has 
  32.     -- already been paused by a menu (via Pause_By_Menu) then the player will 
  33.     -- not be allowed to pause or resume play. 
  34.     procedure Pause_By_Player( this    : not null access Keen_View'Class; 
  35.                                enabled : Boolean ); 
  36.  
  37. private 
  38.  
  39.     use Ada.Real_Time; 
  40.     use Ada.Strings.Unbounded; 
  41.  
  42.     type Keen_View is new Game_View with 
  43.         record 
  44.             -- game play was paused explicitly by the player 
  45.             pausedByPlayer : Boolean := False; 
  46.  
  47.             -- a count of the number of times the game as been automatically 
  48.             -- paused by the menu system. the menus must unpause the same number 
  49.             -- of times before game play may resume. the is a count instead of a 
  50.             -- boolean because of nested pause situations (e.g. the status board 
  51.             -- is being shown (pausedByMenu=1) and the player exits back to the 
  52.             -- menu (pausedByMenu=2). 
  53.             pausedByMenu : Integer := 0; 
  54.  
  55.             -- true when loading is in progress. this occurs between levels. 
  56.             loading : Boolean := False; 
  57.  
  58.             -- loading screen is being displayed. 
  59.             loadingScreen : Boolean := False; 
  60.  
  61.             -- time when the loading screen is to be hidden, if loading has 
  62.             -- finished. if this equals Time_First, loading has not begun. 
  63.             loadingScreenComplete : Time := Time_First; 
  64.  
  65.             -- the name of the music for the current world. this is set when the 
  66.             -- 'music' world property changes and played when the world loading 
  67.             -- dialog is closed. 
  68.             worldMusic : Unbounded_String; 
  69.         end record; 
  70.  
  71.     -- This is called when the user clicks the X window button on the window. 
  72.     procedure On_Close_Window( this    : access Keen_View; 
  73.                                allowed : in out Boolean ); 
  74.  
  75.     -- Inherited from the Event_Listener interface. Handles events that the view 
  76.     -- is registered to receive. 
  77.     procedure Handle_Event( this : access Keen_View; 
  78.                             evt  : in out A_Event; 
  79.                             resp : out Response_Type ); 
  80.     pragma Precondition( evt /= null ); 
  81.  
  82.     -- Creates all of the widgets required for the game view. An exception will 
  83.     -- be raised if an error occurs creating the widgets. 
  84.     procedure Initialize_Widgets( this : access Keen_View; 
  85.                                   win  : not null A_Window ); 
  86.  
  87.     -- This is called once, just after the view has been initialized at startup. 
  88.     procedure On_Initialize( this : access Keen_View ); 
  89.  
  90.     -- This is called once, just before the view is finalized at shutdown. 
  91.     procedure On_Finalize( this : access Keen_View ); 
  92.  
  93.     -- This is called when the paused state of the Game changes. 
  94.     procedure On_Game_Paused( this : access Keen_View; paused : Boolean ); 
  95.  
  96.     -- This is called when a game session begins or ends. 'isInterrupted" 
  97.     -- indicates if the game session was aborted before the player won or lost. 
  98.     procedure On_Game_State_Changed( this          : access Keen_View; 
  99.                                      isPlaying     : Boolean; 
  100.                                      isInterrupted : Boolean ); 
  101.  
  102.     -- Called when loading begins. Stops any music currently being played, and 
  103.     -- shows the loading screen. 
  104.     procedure On_Loading_Begin( this : access Keen_View ); 
  105.  
  106.     -- Called when loading ends. Hides the loading screen and begins playing the 
  107.     -- world's music. 
  108.     procedure On_Loading_End( this    : access Keen_View; 
  109.                               success : Boolean; 
  110.                               message : String ); 
  111.  
  112.     -- This is called when a property of the current world changes. 
  113.     procedure On_World_Property_Changed( this  : access Keen_View; 
  114.                                          name  : String; 
  115.                                          value : Value_Ptr'Class ); 
  116.  
  117.     -- Inherited from the Process interface. This will be called regularly after 
  118.     -- the view is started. 
  119.     procedure Tick( this : access Keen_View; time : Tick_Time ); 
  120.  
  121. end Game_Views.Keen;