上海虹口龙之梦项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

125 lines
4.3 KiB

using UnityEngine;
using UnityEngine.UI;
using UniRx;
public class FirePumpAttributePanel : UIView<FirePump,FirePumpReactive>
{
//类型
public Text TypeText;
public InputField TypeInput;
//型号
public Text ModeText;
public InputField ModeInput;
//功率
public Text PowerText;
public InputField PowerInput;
//扬程
public Text LiftText;
public InputField LiftInput;
//流量
public Text FlowText;
public InputField FlowInput;
//压力
public Text PressureText;
public InputField PressureInput;
//保存按钮
public Button SaveButton;
public Button CancelButton;
public Button EditorButton;
public GameObject InfosPanel;
public GameObject InputsPanel;
public GameObject DefaultPanel;
public GameObject EditorPanel;
public override void Awake()
{
base.Awake();
#region DataSource Bind
//类型
DataSource.Type.SubscribeToText(TypeText).AddTo(gameObject);
DataSource.Type.SubscribeToText(TypeInput).AddTo(gameObject);
TypeInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Type.Value = s);
//型号
DataSource.Mode.SubscribeToText(ModeText).AddTo(gameObject);
DataSource.Mode.SubscribeToText(ModeInput).AddTo(gameObject);
ModeInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Mode.Value = s);
//功率
DataSource.Power.SubscribeToText(PowerText).AddTo(gameObject);
DataSource.Power.SubscribeToText(PowerInput).AddTo(gameObject);
PowerInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Power.Value = s);
//扬程
DataSource.Lift.SubscribeToText(LiftText).AddTo(gameObject);
DataSource.Lift.SubscribeToText(LiftInput).AddTo(gameObject);
LiftInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Lift.Value = s);
//流量
DataSource.Flow.SubscribeToText(FlowText).AddTo(gameObject);
DataSource.Flow.SubscribeToText(FlowInput).AddTo(gameObject);
FlowInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Flow.Value = s);
//压力
DataSource.Pressure.SubscribeToText(PressureText).AddTo(gameObject);
DataSource.Pressure.SubscribeToText(PressureInput).AddTo(gameObject);
PressureInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Pressure.Value = s);
#endregion
#region Button Click
//编辑
EditorButton.onClick.AsObservable().Subscribe(onClick =>
{
InfosPanel.SetActive(false);
InputsPanel.SetActive(true);
DefaultPanel.SetActive(false);
EditorPanel.SetActive(true);
}).AddTo(gameObject);
//保存
SaveButton.onClick.AsObservable().Subscribe(onClick =>
{
InfosPanel.SetActive(true);
InputsPanel.SetActive(false);
DefaultPanel.SetActive(true);
EditorPanel.SetActive(false);
SaveData();
}).AddTo(gameObject);
//取消
CancelButton.onClick.AsObservable().Subscribe(onClick =>
{
InfosPanel.SetActive(true);
InputsPanel.SetActive(false);
DefaultPanel.SetActive(true);
EditorPanel.SetActive(false);
}).AddTo(gameObject);
transform.Find("TitleBar/CloseButton").GetComponent<Button>().OnClickAsObservable()
.Subscribe(_ => Hide());
Observable.EveryLateUpdate()
.Where(_ => Input.GetMouseButtonDown(1))
.Subscribe(_ => Hide());
#endregion
}
public override void Show()
{
base.Show();
Vector2 pos = MainMenu.Instance.GetMousePosition(gameObject);
gameObject.GetComponent<RectTransform>().anchoredPosition = new Vector2(pos.x, pos.y);
LoadData();
}
/// <summary>
/// 加载数据
/// <summary>
private void LoadData()
{
string url = string.Format(HttpManager.Instance.GetPumpById,DataSource.Id);
HttpManager.Instance.Get<FirePump>(url, d =>
{
DataSource.SetData(d);
});
}
/// <summary>
/// 保存数据
/// <summary>
private void SaveData()
{
string url = string.Format(HttpManager.Instance.PostPumpById, DataSource.Id);
HttpManager.Instance.Post(url, DataSource.GetData());
}
}