上海虹口龙之梦项目
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.
 
 
 
 

173 lines
4.7 KiB

using UnityEngine;
using UnityEngine.UI;
using UniRx;
using System.Collections.Generic;
public class CommandTablePanel : UIView
{
/// <summary>
/// 文本框
/// </summary>
public List<Text> Infos = new List<Text>();
/// <summary>
/// 输入框
/// </summary>
public List<InputField> Inputs = new List<InputField>();
/// <summary>
/// 编辑按钮
/// </summary>
public Button EditorButton;
/// <summary>
/// 保存按钮
/// </summary>
public Button SaveButton;
/// <summary>
/// 取消按钮
/// </summary>
public Button CancelButton;
/// <summary>
/// 数据
/// </summary>
public Dictionary<int, StringReactiveProperty> Datas = new Dictionary<int, StringReactiveProperty>();
/// <summary>
/// Text面板
/// </summary>
public GameObject InfoPanel;
/// <summary>
/// Input面板
/// </summary>
public GameObject InputPanel;
/// <summary>
/// 默认面板
/// </summary>
public GameObject DefualtPanel;
/// <summary>
/// 保存面板
/// </summary>
public GameObject SavePanel;
public override void Awake()
{
base.Awake();
InitUI();
InitData();
InitBinding();
}
/// <summary>
/// 显示
/// </summary>
public override void Show()
{
base.Show();
GetData();
}
/// <summary>
/// 初始化UI
/// </summary>
private void InitUI()
{
EditorButton = Find<Button>("Bottom/DefaultPanel/EditorButton");
SaveButton = Find<Button>("Bottom/EditorPanel/SaveButton");
CancelButton = Find<Button>("Bottom/EditorPanel/CancelButton");
InfoPanel = Find("Scroll View/Viewport/Content/Background/InfoPanel");
InputPanel = Find("Scroll View/Viewport/Content/Background/InputPanel");
DefualtPanel = Find("Bottom/DefaultPanel");
SavePanel = Find("Bottom/EditorPanel");
for (int i = 0; i < 165; i++)
{
var t = Find<Text>("Scroll View/Viewport/Content/Background/InfoPanel/Info" + i);
Infos.Add(t);
}
for (int i = 0; i < 165; i++)
{
var t = Find<InputField>("Scroll View/Viewport/Content/Background/InputPanel/Input" + i);
Inputs.Add(t);
}
}
/// <summary>
/// 初始化数据
/// </summary>
private void InitData()
{
//初始化Datas
for (int i = 0; i < 165; i++)
{
Datas.Add(i, new StringReactiveProperty(""));
}
}
/// <summary>
/// 初始化绑定
/// </summary>
private void InitBinding()
{
for (int i = 0; i < Datas.Count; i++)
{
int num = i;
Datas[num].SubscribeToText(Infos[num]).AddTo(gameObject);
Datas[num].SubscribeToText(Inputs[num]).AddTo(gameObject);
Inputs[num].OnEndEditAsObservable().Subscribe(value =>
{
Datas[num].Value = value;
}).AddTo(gameObject);
}
//编辑
EditorButton.OnClickAsObservable()
.Subscribe(_ =>
{
InfoPanel.SetActive(false);
InputPanel.SetActive(true);
DefualtPanel.SetActive(false);
SavePanel.SetActive(true);
});
//取消编辑
CancelButton.OnClickAsObservable()
.Subscribe(_ =>
{
InfoPanel.SetActive(true);
InputPanel.SetActive(false);
DefualtPanel.SetActive(true);
SavePanel.SetActive(false);
});
//保存
SaveButton.OnClickAsObservable()
.Subscribe(_ =>
{
InfoPanel.SetActive(true);
InputPanel.SetActive(false);
DefualtPanel.SetActive(true);
SavePanel.SetActive(false);
SaveData();
});
}
/// <summary>
/// 保存数据
/// </summary>
void SaveData()
{
Dictionary<int, string> postData = new Dictionary<int, string>();
foreach (var item in Datas)
{
postData.Add(item.Key, item.Value.Value);
}
string url = string.Format(HttpManager.Instance.PostOrgCmds);
HttpManager.Instance.Post(url, postData);
}
/// <summary>
/// 获取数据
/// </summary>
void GetData()
{
string url = string.Format(HttpManager.Instance.GetOrgCmds);
HttpManager.Instance.Get<Dictionary<int, string>>(url, datas =>
{
foreach (var item in datas)
{
Datas[item.Key].Value = item.Value;
}
});
}
}