--
-- Copyright (c) 2012 Kevin Wellwood
-- All rights reserved.
--
-- This source code is distributed under the Modified BSD License. For terms and
-- conditions, see license.txt.
--
package Widgets.Containers.Game_Screens is
-- A Game_Screen is a simple abstract container for multiple widgets,
-- intended to be used with a Screen_Manager object. It fills the entire
-- window and is intended to represent one "state" of a game's GUI, managing
-- input and logic, and transitions to other screens. A screen can have an
-- optional background image or color or it can have a transparent
-- background.
--
-- This class is abstract with the intention that it be instantiated
-- specifically for each screen in a game's interface (e.g. title screen,
-- main menu, loading screen, game play, etc.)
--
-- A screen populates its child widgets at construction and also handles all
-- Actions dispatched by its children.
type Game_Screen is abstract new Container with private;
type A_Game_Screen is access all Game_Screen'Class;
-- Activates the screen when it hits the front of the screen manager and
-- begins accepting user input. This procedure should be overriden to focus
-- an input widget, if necessary. It is possible for Activate to be called
-- multiple times without deactivation, so if its important that this only
-- happens once, check Is_Active. When overriding this procedure, call this
-- base implementation first.
procedure Activate( this : access Game_Screen );
-- Deactivates the screen when becomes hidden by another screen in the
-- screen manager, or when it is removed from the screen manager. When
-- overriding this procedure, call this base implementation first.
procedure Deactivate( this : access Game_Screen );
-- Indicates the screen will now begin exiting. On the screen manager's next
-- tick after this screen has finished exiting, the screen will be removed
-- and destroyed. Deactivate will be called just before the screen is
-- removed from its manager.
procedure Exit_Screen( this : not null access Game_Screen'Class );
-- Returns True if the game screen has been activated by a call from the
-- screen manager to Activate. This remains True until the screen is
-- deactivated.
function Is_Active( this : not null access Game_Screen'Class ) return Boolean;
-- Returns True if the screen is in the processing of exiting.
function Is_Exiting( this : not null access Game_Screen'Class ) return Boolean;
-- Returns True if the game screen is a light-weight popup screen with a
-- transparent screen.
function Is_Popup( this : not null access Game_Screen'Class ) return Boolean;
private
type Game_Screen is abstract new Container with
record
background : Natural := 0; -- background image's tile id
popup : Boolean := False; -- screen is a popup (transparent background)
active : Boolean := False; -- screen has been activated
exiting : Boolean := False; -- in the process of exiting?
end record;
procedure Construct( this : access Game_Screen;
view : not null access Game_Views.Game_View'Class;
id : String;
popup : Boolean );
-- Draws the screen's background image, if it has one, or background color
-- if it's not transparent.
procedure Draw_Content( this : access Game_Screen );
-- Sets the background image name to display behind all the child widgets.
-- If the background image is not found in the interface's tile library, or
-- an empty string is given, the background will be transparent.
procedure Set_Background( this : not null access Game_Screen'Class;
background : String );
end Widgets.Containers.Game_Screens;