using UnityEngine;
using System.Collections;
public class LocalNotifCallbacks : MonoBehaviour {
public AppSettings settings;
public WeightRegistrationManager WRM;
public SlideMenuManager SMM;
public DatabaseEventManager DEM;
public GameObject[] PanelWidgets;
public UIButton[] WMButtons,
MotivButtons;
private GameObject activePanel;
private Vector3 panelVector;
private EventDelegate evi,
WMEvi;
private void Start()
{
if(!PanelWidgets[30].gameObject.activeSelf)
panelVector = PanelWidgets[30].transform.localPosition;
else
panelVector = PanelWidgets[29].transform.localPosition;
evi
= new EventDelegate
(this,
"TurnOff"); evi.oneShot = true;
WMEvi
= new EventDelegate
(this,
"TurnOffWM"); evi.oneShot = true;
}
#if UNITY_IPHONE
public void OnEnable() {
LocalNotifs.OnLocalNotificationFired += OnLocalNotificationFired;
LocalNotifs.OnSetLocalNotification += OnSetLocalNotification;
}
public void OnDisable() {
LocalNotifs.OnLocalNotificationFired -= OnLocalNotificationFired;
LocalNotifs.OnSetLocalNotification -= OnSetLocalNotification;
}
#endif
public void OnSetLocalNotification()
{
//Does nothing atm
}
//Fires when returning from suspended and responded to localnotification
public void OnLocalNotificationFired(string id)
{
switch(id)
{
case "MP01": SetMPPanelOptions();
break;
case "MP02": SetMPPanelOptions();
break;
case "WMoment": SetWMPanelOptions();
break;
}
}
public void WMBack()
{
activePanel.SetActive(true);
TweenPosition.Begin(PanelWidgets[23], settings.SpeedOfTweens, panelVector);
TweenPosition.Begin(activePanel, settings.SpeedOfTweens, Vector3.zero).onFinished.Add(WMEvi);
}
private void SetMPPanelOptions()
{
activePanel = CheckActive();
if(activePanel != null)
{
MotivButtons[0].gameObject.SetActive(false);
MotivButtons[1].gameObject.SetActive(false);
PanelWidgets[4].SetActive(true);
}
}
private void SetWMPanelOptions()
{
activePanel = CheckActive();
if(activePanel != null)
{
WMButtons[0].gameObject.SetActive(false);
WMButtons[1].gameObject.SetActive(true);
DEM.GetWeightMoment();
PanelWidgets[23].SetActive(true);
TweenPosition.Begin(activePanel, 0, -panelVector);
TweenPosition.Begin(PanelWidgets[23], 0, Vector3.zero).onFinished.Add(evi);
}
else
{
Debug.Log ("ActivePanel = null :(");
}
}
private GameObject CheckActive()
{
foreach(GameObject obj in PanelWidgets)
{
if(obj.activeSelf)
{
return obj;
break;
}
}
return null;
}
private void TurnOff()
{
activePanel.gameObject.SetActive(false);
}
private void TurnOffWM()
{
WMButtons[1].gameObject.SetActive(false);
WMButtons[0].gameObject.SetActive(true);
PanelWidgets[23].gameObject.SetActive(false);
}
}