2 using UnityEngine.EventSystems;
3 using System.Collections;
4 using System.Collections.Generic;
9 public class Core : MonoBehaviour
17 public static Core instance {
private set;
get; }
19 public Camera UICamera;
21 public LayoutSystem layoutSystem {
private set;
get; }
25 public float pixelsPerMeter = 500f;
26 public float aspectRatio = 1f;
28 public Color TabHighlightColor;
29 public Color ButtonBaseColor;
30 public Color ButtonHighlightColor;
32 public Sprite normalTabImage;
33 public Sprite selectedTabImage;
35 public GameObject indicatorLeft;
36 public GameObject indicatorRight;
40 private GameObject closePatientButton;
41 private GameObject savePatientButton;
43 private List<GameObject> activeIndicators =
new List<GameObject> ();
44 private int indicationID = 0;
51 if( instance != null )
52 throw(
new System.Exception (
"Error: Cannot create more than one instance of UI.Core!"));
56 public void OnEnable()
60 indicatorLeft.SetActive (
false);
61 indicatorRight.SetActive (
false);
62 statusBar.SetActive (
true);
64 Transform tf = statusBar.transform.Find (
"ButtonClose");
66 closePatientButton = tf.gameObject;
67 closePatientButton.GetComponent<Button> ().onClick.AddListener (() => closePatient ());
68 closePatientButton.SetActive (
false);
70 Debug.LogWarning (
"ButtonClose not found on Status Bar!");
73 tf = statusBar.transform.Find (
"ButtonSave");
75 savePatientButton = tf.gameObject;
76 savePatientButton.GetComponent<Button> ().onClick.AddListener (() => savePatient ());
77 savePatientButton.SetActive (
false);
79 Debug.LogWarning (
"ButtonSave not found on Status Bar!");
82 PatientEventSystem.startListening (PatientEventSystem.Event.PATIENT_FinishedLoading, patientLoaded );
85 public void OnDisable()
91 public void setPointerIsOnUI(
bool onUI )
95 public void setPointerIsOnPlatformUI(
bool onUI )
100 public void setCamera( Camera cam )
103 aspectRatio = (float)UICamera.targetTexture.width / (
float)UICamera.targetTexture.height;
104 layoutSystem.updateDimensions ();
107 Rect newRect = layoutSystem.getStatusBarPosition ();
108 RectTransform widgetRect = statusBar.GetComponent<RectTransform> ();
109 widgetRect.localPosition = newRect.position;
110 widgetRect.sizeDelta = newRect.size;
113 public Widget getWidgetByName(
string name )
115 foreach (Transform child
in transform) {
116 if (child.name == name) {
117 if (child.GetComponent<Widget> () != null) {
118 return child.GetComponent<Widget> ();
125 public void selectTab( Button b )
127 ColorBlock colors = b.colors;
128 colors.normalColor = TabHighlightColor;
129 colors.highlightedColor = TabHighlightColor;
131 b.image.sprite = selectedTabImage;
134 public void unselectTab( Button b )
136 ColorBlock colors = b.colors;
137 colors.normalColor = ButtonBaseColor;
138 colors.highlightedColor = ButtonBaseColor;
140 b.image.sprite = normalTabImage;
143 public int addIndication( UI.Screen screen,
string message )
145 if (activeIndicators.Count > 0) {
146 clearIndication (indicationID);
149 if (screen == UI.Screen.left) {
150 GameObject indicator1 = Instantiate (indicatorLeft) as GameObject;
151 indicator1.GetComponent<Widget> ().layoutScreen = UI.Screen.right;
152 indicator1.GetComponent<Widget> ().layoutAlignHorizontal = AlignmentH.center;
153 indicator1.GetComponent<Widget> ().layoutAlignVertical = AlignmentV.center;
154 indicator1.SetActive (true);
155 Text t = indicator1.GetComponentInChildren<Text> ();
157 indicator1.transform.SetParent (transform, false);
158 activeIndicators.Add (indicator1);
160 GameObject indicator2 = Instantiate (indicatorLeft) as GameObject;
161 indicator2.GetComponent<Widget> ().layoutScreen = UI.Screen.center;
162 indicator2.GetComponent<Widget> ().layoutAlignHorizontal = AlignmentH.center;
163 indicator2.GetComponent<Widget> ().layoutAlignVertical = AlignmentV.center;
164 indicator2.SetActive (true);
165 t = indicator2.GetComponentInChildren<Text> ();
167 indicator2.transform.SetParent (transform, false);
168 activeIndicators.Add (indicator2);
169 } else if (screen == UI.Screen.center) {
170 GameObject indicator1 = Instantiate (indicatorLeft) as GameObject;
171 indicator1.GetComponent<Widget> ().layoutScreen = UI.Screen.right;
172 indicator1.GetComponent<Widget> ().layoutAlignHorizontal = AlignmentH.center;
173 indicator1.GetComponent<Widget> ().layoutAlignVertical = AlignmentV.center;
174 indicator1.SetActive (true);
175 Text t = indicator1.GetComponentInChildren<Text> ();
177 indicator1.transform.SetParent (transform, false);
178 activeIndicators.Add (indicator1);
180 GameObject indicator2 = Instantiate (indicatorRight) as GameObject;
181 indicator2.GetComponent<Widget> ().layoutScreen = UI.Screen.left;
182 indicator2.GetComponent<Widget> ().layoutAlignHorizontal = AlignmentH.center;
183 indicator2.GetComponent<Widget> ().layoutAlignVertical = AlignmentV.center;
184 indicator2.SetActive (true);
185 t = indicator2.GetComponentInChildren<Text> ();
187 indicator2.transform.SetParent (transform, false);
188 activeIndicators.Add (indicator2);
189 } else if (screen == UI.Screen.right) {
190 GameObject indicator1 = Instantiate (indicatorRight) as GameObject;
191 indicator1.GetComponent<Widget> ().layoutScreen = UI.Screen.left;
192 indicator1.GetComponent<Widget> ().layoutAlignHorizontal = AlignmentH.center;
193 indicator1.GetComponent<Widget> ().layoutAlignVertical = AlignmentV.center;
194 indicator1.SetActive (true);
195 Text t = indicator1.GetComponentInChildren<Text> ();
197 indicator1.transform.SetParent (transform, false);
198 activeIndicators.Add (indicator1);
200 GameObject indicator2 = Instantiate (indicatorRight) as GameObject;
201 indicator2.GetComponent<Widget> ().layoutScreen = UI.Screen.center;
202 indicator2.GetComponent<Widget> ().layoutAlignHorizontal = AlignmentH.center;
203 indicator2.GetComponent<Widget> ().layoutAlignVertical = AlignmentV.center;
204 indicator2.SetActive (true);
205 t = indicator2.GetComponentInChildren<Text> ();
207 indicator2.transform.SetParent (transform, false);
208 activeIndicators.Add (indicator2);
210 return (++indicationID);
213 public
void clearIndication(
int id )
215 if (indicationID !=
id)
218 foreach (GameObject go
in activeIndicators) {
221 activeIndicators.Clear ();
224 public void closePatient()
227 PatientEventSystem.triggerEvent (PatientEventSystem.Event.PATIENT_Closed);
228 layoutSystem.closeAllWidgets ();
229 closePatientButton.SetActive (
false);
230 savePatientButton.SetActive (
false);
231 PatientSelector.SetActive (
true);
233 public void savePatient()
235 if (
Patient.getLoadedPatient () != null) {
236 Patient.getLoadedPatient ().save ();
237 NotificationControl.instance.createNotification (
"Patient saved.",
new System.TimeSpan (0, 0, 5));
241 public void patientLoaded(
object obj = null )
243 closePatientButton.SetActive (
true);
244 savePatientButton.SetActive (
true);
float UIScale
The scale with which all the UI elements are scaled (i.e. pixels to meters)
GameObject statusBar
A bar on the lower end of the screen (for close button etc.)
bool pointerIsOverPlatformUIObject
bool pointerIsOverUIObject
Is set to true whenever the mouse is over a UI elemnt.