BotNavSim  v0.4.3
Mobile Robot Simulation
UI_Toolbar Class Reference

UI Toolbar provides controls for choosing which UI windows to display More...

Inheritance diagram for UI_Toolbar:
Collaboration diagram for UI_Toolbar:

Public Attributes

float width
 The width of the toolbar in screen px. More...
 
List< IWindowFunctionadditionalWindows = new List<IWindowFunction>()
 The additional windows to be drawn outside the toolbar. used for classes like UI_SimulationSettings More...
 

Static Public Attributes

static UI_Toolbar I
 Singleton pattern. More...
 

Properties

Rect rect [get, private set]
 
float innerWidth [get]
 

Private Member Functions

void Awake ()
 
void OnGUI ()
 Draw GUI elements More...
 
void ToolbarWindow (int windowID)
 Toolbar window GUI.WindowFunction (a list of buttons for showing/hiding tools) More...
 

Private Attributes

List< IToolbar_tools = new List<IToolbar>()
 
GUISkin _skin
 
Vector2 _scrollPos
 
int winId
 
UI_Credits _credits
 

Detailed Description

UI Toolbar provides controls for choosing which UI windows to display

Definition at line 11 of file UI_Toolbar.cs.

Member Function Documentation

void UI_Toolbar.Awake ( )
private

Definition at line 45 of file UI_Toolbar.cs.

45  {
46  // singleton pattern
47  if (I == null) {
48  I = this;
49  }
50  else {
51  Destroy(this);
52  }
53 
54  // instantiate all classes that implement IToolbar
55  Type ti = typeof(IToolbar);
56  foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) {
57  Type[] types;
58  try {
59  types = asm.GetTypes();
60  }
61  catch(ReflectionTypeLoadException e) {
62  foreach (Exception le in e.LoaderExceptions) {
63  Debug.LogException(le);
64  }
65  types = e.Types;
66  }
67  foreach(Type t in types) {
68  if (t == null) continue;
69  Type toolbarType = t.GetInterface(ti.FullName);
70  if (toolbarType != null) {
71  _tools.Add((IToolbar)Activator.CreateInstance(t));
72  }
73  }
74  }
75 
76  // get GUISkin
77  _skin = Resources.Load<GUISkin>("GUI_style");
78  _scrollPos = new Vector2();
79  _credits = GetComponent<UI_Credits>();
80  }
static UI_Toolbar I
Singleton pattern.
Definition: UI_Toolbar.cs:16
UI_Credits _credits
Definition: UI_Toolbar.cs:43
GUISkin _skin
Definition: UI_Toolbar.cs:40
Vector2 _scrollPos
Definition: UI_Toolbar.cs:41
List< IToolbar > _tools
Definition: UI_Toolbar.cs:39
Interface for classes that implement a toolbar item
Definition: IToolbar.cs:7
void UI_Toolbar.OnGUI ( )
private

Draw GUI elements

Definition at line 86 of file UI_Toolbar.cs.

86  {
87  // set skin object
88  GUI.skin = _skin;
89  winId = 1;
90  // set toolbar size and position
91  rect = new Rect(Screen.width-width,0,width,Screen.height);
92  // display toolbar window
93  rect = GUILayout.Window(winId++, rect, ToolbarWindow, Strings.projectTitle + "-" + Strings.projectVersion);
94 
95  // display any additional windows
96  for(int i = 0; i < additionalWindows.Count; i++) {
98  if (w.windowFunction == null) {
99  Debug.LogWarning("Null window removed.");
100  additionalWindows.Remove(w);
101  } else {
102  w.windowRect = GUILayout.Window(winId++, w.windowRect, w.windowFunction, w.windowTitle);
103  }
104  }
105  }
GUI.WindowFunction windowFunction
Gets the window function definition for GUILayout.Window()
const string projectTitle
The project title.
Definition: Strings.cs:14
Rect rect
Definition: UI_Toolbar.cs:29
GUISkin _skin
Definition: UI_Toolbar.cs:40
const string projectVersion
The project version.
Definition: Strings.cs:19
Rect windowRect
Gets or sets the window rect (window size and position).
void ToolbarWindow(int windowID)
Toolbar window GUI.WindowFunction (a list of buttons for showing/hiding tools)
Definition: UI_Toolbar.cs:110
float width
The width of the toolbar in screen px.
Definition: UI_Toolbar.cs:21
Interface for classes that implement a GUI.WindowFunction
List< IWindowFunction > additionalWindows
The additional windows to be drawn outside the toolbar. used for classes like UI_SimulationSettings ...
Definition: UI_Toolbar.cs:27
string windowTitle
Gets the window title.
A utility class for strings used in this project.
Definition: Strings.cs:9

Here is the call graph for this function:

void UI_Toolbar.ToolbarWindow ( int  windowID)
private

Toolbar window GUI.WindowFunction (a list of buttons for showing/hiding tools)

Definition at line 110 of file UI_Toolbar.cs.

110  {
111  _scrollPos = GUILayout.BeginScrollView(_scrollPos, true, false);
112  // about button
113  if (GUILayout.Button("About", GUILayout.Width(innerWidth))) {
114  _credits.close = false;
116 
117  }
118 
119  // horizontal separator
120  GUILayout.Box("", GUILayout.Width(innerWidth), GUILayout.Height(5));
121  if (!BotNavSim.isIdle) {
122  if (GUILayout.Button("Back", GUILayout.Width(innerWidth))) {
124  }
125  // horizontal separator
126  GUILayout.Box("", GUILayout.Width(innerWidth), GUILayout.Height(5));
127  }
128  foreach(IToolbar t in _tools) {
129  // only handle windows that are contextual
130  if (t.contextual) {
131  // toggle window show/hide if button pressed
132  if (GUILayout.Button(t.windowTitle, GUILayout.Width(innerWidth))) {
133  t.hidden = !t.hidden;
134  }
135  if (!t.hidden) t.windowFunction(0);
136  // horizontal separator
137  GUILayout.Box("", GUILayout.Width(innerWidth), GUILayout.Height(5));
138  }
139  }
140  GUILayout.EndScrollView();
141  }
GUI.WindowFunction windowFunction
Gets the window function definition for GUILayout.Window()
bool hidden
Gets or sets a value indicating whether this IToolbar is hidden.
Definition: IToolbar.cs:19
float innerWidth
Definition: UI_Toolbar.cs:33
static bool isIdle
Gets a value indicating whether BotNavSim is idle.
Definition: BotNavSim.cs:58
UI_Credits _credits
Definition: UI_Toolbar.cs:43
bool contextual
Gets a value indicating whether this IToolbar is contextual.
Definition: IToolbar.cs:13
static State state
Gets or sets the state.
Definition: BotNavSim.cs:45
List< IWindowFunction > additionalWindows
The additional windows to be drawn outside the toolbar. used for classes like UI_SimulationSettings ...
Definition: UI_Toolbar.cs:27
string windowTitle
Gets the window title.
Vector2 _scrollPos
Definition: UI_Toolbar.cs:41
List< IToolbar > _tools
Definition: UI_Toolbar.cs:39
BotNavSim high-level manager class. Holds BotNavSim.State and controls state transition behaviour...
Definition: BotNavSim.cs:7
bool close
Definition: UI_Credits.cs:64
Interface for classes that implement a toolbar item
Definition: IToolbar.cs:7

Here is the caller graph for this function:

Member Data Documentation

UI_Credits UI_Toolbar._credits
private

Definition at line 43 of file UI_Toolbar.cs.

Vector2 UI_Toolbar._scrollPos
private

Definition at line 41 of file UI_Toolbar.cs.

GUISkin UI_Toolbar._skin
private

Definition at line 40 of file UI_Toolbar.cs.

List<IToolbar> UI_Toolbar._tools = new List<IToolbar>()
private

Definition at line 39 of file UI_Toolbar.cs.

List<IWindowFunction> UI_Toolbar.additionalWindows = new List<IWindowFunction>()

The additional windows to be drawn outside the toolbar. used for classes like UI_SimulationSettings

Definition at line 27 of file UI_Toolbar.cs.

UI_Toolbar UI_Toolbar.I
static

Singleton pattern.

Definition at line 16 of file UI_Toolbar.cs.

float UI_Toolbar.width

The width of the toolbar in screen px.

Definition at line 21 of file UI_Toolbar.cs.

int UI_Toolbar.winId
private

Definition at line 42 of file UI_Toolbar.cs.

Property Documentation

float UI_Toolbar.innerWidth
get

Definition at line 33 of file UI_Toolbar.cs.

Rect UI_Toolbar.rect
getprivate set

Definition at line 29 of file UI_Toolbar.cs.


The documentation for this class was generated from the following file: