using System;
using System.Collections.Generic;
using System.Diagnostics;
using Chernobyl.Collections.Generic.Event;
using Chernobyl.Dependency;
using Chernobyl.Graphics.Drawing;
using Chernobyl.Graphics.Texture;
using Chernobyl.Graphics.Writing;
using Chernobyl.Input.Controls;
using Chernobyl.Interface.Input;
using Chernobyl.Interface.Tool;
using Chernobyl.Mathematics;
using Chernobyl.Mathematics.Movement;
using Chernobyl.Mathematics.Vectors;
using Chernobyl.Plugin;
using Chernobyl.Utility;
namespace Chernobyl.Interface
{
///
/// The main class for the Chernobyl.Interface plug-in module. This class
/// provides Chernobyl.Interface specific parent for the rest of Chernobyl
/// and other client code.
///
public class Interface : DecoratingEventList, IPlugin
{
///
/// Initializes a new instance of the class.
///
/// The instance that is the parent to this
/// instance.
public Interface(IEventCollection parent)
{
Trace = new TraceSource("Chernobyl.Interface");
_parent = parent;
parent.Add(this);
parent.Inject(this);
}
///
/// A used to output errors, warnings, information,
/// etc., that are specific to Chernobyl.Interface. This
/// will have the name "Chernobyl.Interface".
///
public static TraceSource Trace { get; private set; }
///
/// Setting the instance here will add the
/// Chernobyl.Interface specific search paths to the
/// instance.
///
[Inject]
public ISearchPaths SearchPaths
{
set
{
value.Add("../../Chernobyl.Interface");
}
}
///
/// The that the will attach
/// to so that the cursor can be moved around the screen.
///
[Inject]
public IMouse Mouse
{
set
{
_mouse = value;
_mouseCursor = new Cursor(_parent, "data/images/cursor.tga", _mouse);
}
}
///
/// The class that holds interface factory collections.
///
[Provide]
public IInterfaceFactoryCollectionServices InterfaceFactoriesCollections
{
get
{
if(_interfaceFactoriesCollections == null)
{
_interfaceFactoriesCollections = new InterfaceFactoryCollectionServices();
//////////////////////////////////////////////////////////////////////////
// set some default interface factory collection into the interface
// factory collection services instance
//////////////////////////////////////////////////////////////////////////
// IStandardInterfaceFactoryCollection
{
IStandardInterfaceFactoryCollection standardInterfaceFactories = new StandardInterfaceFactoryCollection();
InterfaceFactoriesCollections.Add(standardInterfaceFactories);
standardInterfaceFactories.Add(new KeyValuePair(typeof(object), item => new Text(_parent, item.ToString())));
}
// IIconInterfaceFactoryCollection
{
IIconInterfaceFactoryCollection iconInterfaceFactories = new IconInterfaceFactoryCollection();
InterfaceFactoriesCollections.Add(iconInterfaceFactories);
iconInterfaceFactories.Add(new KeyValuePair(typeof(string), item => new Sprite(_parent, new Texture2D(_parent, "interface/images/icons/text.tga"))));
}
}
return _interfaceFactoriesCollections;
}
}
///
/// The instance that determines where instance are placed for the
/// layering of controls.
///
[Provide]
public LayerBucket Layers
{
get
{
return _layers ?? (_layers = new LayerBucket(_parent));
}
}
///
/// The instance that is used by the user to control pointer interaction
/// with the Chernobyl interface.
///
[Provide]
public PointerControlCollection PointerControl
{
get { return _pointerControl ?? (_pointerControl = new PointerController(_parent)); }
}
///
/// The instance that is the parent to this
/// instance.
///
readonly IEventCollection _parent;
///
/// The instance that is displayed on the screen for the mouse pointer.
/// Other cursors, such as those for the gamepads, are not created because
/// client code may not want a gamepad cursor while a mouse cursor is likely
/// needed if a mouse is plugged in. If this value is null then an IMouse
/// was not provided to this instance.
///
ICursor _mouseCursor;
///
/// The backing field to
///
IMouse _mouse;
///
/// The backing field to
///
IInterfaceFactoryCollectionServices _interfaceFactoriesCollections;
///
/// The backing field to .
///
LayerBucket _layers;
///
/// The backing field to .
///
PointerControlCollection _pointerControl;
///
/// The holder for the interface s used for adding
/// interface layers.
///
public class LayerBucket
{
///
/// Initializes a new instance of the struct.
///
/// The instance that gives out services for
/// use by this type and takes services from this type for use by
/// other systems.
public LayerBucket(IEventCollection services)
: this(services, DefaultLayerOffsetAmount)
{ }
///
/// Initializes a new instance of the struct.
///
/// The instance that gives out services for
/// use by this type and takes services from this type for use by
/// other systems.
/// The layer offset amount.
public LayerBucket(IEventCollection services, Vector3 layerOffsetAmount)
{
LayerOffsetAmount = layerOffsetAmount;
services.Inject(this);
}
///
/// A transform that is responsible for layering 2D interface widgets.
/// This is the layer farthest away from the screen. It is where the
/// bottom most widgets lie.
///
/// The bottom most layer of the widgets. By default, the value
/// of this property is a whose
/// has been set to a
/// vector denoted by .
public Layout BottomLayerTransform { get; set; }
///
/// A transform that is responsible for layering 2D interface widgets.
/// This is the layer between the bottom and top layers. It is where
/// the middle widgets lie.
///
/// The middle layer of the widgets. By default, the value
/// of this property is a whose
/// has been set to a
/// vector denoted by .
public Layout MiddleLayerTransform { get; set; }
///
/// A transform that is responsible for layering 2D interface widgets.
/// This is the layer closest to the screen. It is where the top most
/// widgets lie.
///
/// The top most layer of the widgets. By default, the value
/// of this property is a whose
/// has been set to a
/// vector denoted by .
public Layout TopLayerTransform { get; set; }
///
/// The default amount to offset the interface layers by. This
/// field has the value of Vector3(0.0f, 0.0f, 0.001f).
///
///
///
///
public static readonly Vector3 DefaultLayerOffsetAmount = new Vector3(0.0f, 0.0f, 0.001f);
///
/// The amount that each interface transform will
/// offset it's children transforms by. The default value of this property
/// is given by the field .
///
Vector3 LayerOffsetAmount { get; set; }
///
/// The transform that will become the root
/// transform for the interface
/// transforms.
///
[Inject]
public Layout LayersTransform
{
set
{
//////////////////////////////////////////////////////////////////////////
// Setup the layers - give each of them a layer offset amount and
// attach them to the root layers transform
//////////////////////////////////////////////////////////////////////////
TopLayerTransform = new Layout(LayerOffsetAmount, Axis.Z);
value.Add(TopLayerTransform);
MiddleLayerTransform = new Layout(LayerOffsetAmount, Axis.Z);
value.Add(MiddleLayerTransform);
BottomLayerTransform = new Layout(LayerOffsetAmount, Axis.Z);
value.Add(BottomLayerTransform);
}
}
}
///
/// A type that gathers together the controls used for controlling
/// aspects of the Chernobyl interface.
///
class PointerController : PointerControlCollection
{
///
/// Initializes a new instance of the
/// class.
///
/// The instance that gives out services for
/// use by this type and takes services from this type for use by
/// other systems.
public PointerController(IEventCollection services)
{
services.OfType(service => Mouse = service);
}
///
/// The that is to interact with the GUI.
///
IMouse Mouse
{
set
{
value.ThrowIfNull("value");
if (_mouse != null)
Remove(_mouse);
_mouse = new MousePointerControl(value);
Add(_mouse);
}
}
///
/// The mouse GUI interaction method.
///
MousePointerControl _mouse;
}
}
}