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.
177 lines
5.3 KiB
177 lines
5.3 KiB
12 months ago
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using UniRx;
|
||
|
using AX.ImageViewer;
|
||
|
|
||
|
public class FireStationPanel : UIView<FireStation, FireStationReactive>
|
||
|
{
|
||
|
#region Variables
|
||
|
//位置
|
||
|
public Text LocationText;
|
||
|
public InputField LocationInput;
|
||
|
//联系人
|
||
|
public Text ContactText;
|
||
|
public InputField ContactInput;
|
||
|
//电话
|
||
|
public Text PhoneText;
|
||
|
public InputField PhoneInput;
|
||
|
//装备
|
||
|
public Text EquipsText;
|
||
|
public InputField EquipsInput;
|
||
|
//图片类型
|
||
|
public OriginalImageType ImageType;
|
||
|
//图片面板
|
||
|
public Image ImagePanel;
|
||
|
//全景开关
|
||
|
public Toggle ImageTypeToggle;
|
||
|
//查看原图
|
||
|
public Button ViewButton;
|
||
|
public OpenImage OpenImageFile;
|
||
|
//保存按钮
|
||
|
public Button SaveButton;
|
||
|
|
||
|
#endregion
|
||
|
public override void Awake()
|
||
|
{
|
||
|
base.Awake();
|
||
|
|
||
|
#region DataSource Bind]
|
||
|
DataSource.Location.SubscribeToText(LocationText).AddTo(gameObject);
|
||
|
DataSource.Location.SubscribeToText(LocationInput).AddTo(gameObject);
|
||
|
|
||
|
DataSource.Contact.SubscribeToText(ContactText).AddTo(gameObject);
|
||
|
DataSource.Contact.SubscribeToText(ContactInput).AddTo(gameObject);
|
||
|
|
||
|
DataSource.Phone.SubscribeToText(PhoneText).AddTo(gameObject);
|
||
|
DataSource.Phone.SubscribeToText(PhoneInput).AddTo(gameObject);
|
||
|
|
||
|
DataSource.Equips.SubscribeToText(EquipsText).AddTo(gameObject);
|
||
|
DataSource.Equips.SubscribeToText(EquipsInput).AddTo(gameObject);
|
||
|
DataSource.ImageType.Subscribe(data =>
|
||
|
{
|
||
|
switch (data)
|
||
|
{
|
||
|
case OriginalImageType.Normal:
|
||
|
ImageTypeToggle.isOn = false;
|
||
|
break;
|
||
|
case OriginalImageType.Panorama:
|
||
|
ImageTypeToggle.isOn = true;
|
||
|
break;
|
||
|
}
|
||
|
}).AddTo(gameObject);
|
||
|
ImageTypeToggle.OnValueChangedAsObservable().Subscribe(b =>
|
||
|
{
|
||
|
DataSource.ImageType.Value = b ? OriginalImageType.Panorama : OriginalImageType.Normal;
|
||
|
}).AddTo(gameObject);
|
||
|
|
||
|
LocationInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Location.Value = s).AddTo(gameObject);
|
||
|
ContactInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Contact.Value = s).AddTo(gameObject);
|
||
|
PhoneInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Phone.Value = s).AddTo(gameObject);
|
||
|
EquipsInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Equips.Value = s).AddTo(gameObject);
|
||
|
#endregion
|
||
|
|
||
|
#region Button Click
|
||
|
|
||
|
//保存
|
||
|
SaveButton.onClick.AsObservable().Subscribe(onClick =>
|
||
|
{
|
||
|
SaveData();
|
||
|
}).AddTo(gameObject);
|
||
|
//查看原图
|
||
|
ViewButton.onClick.AsObservable().Subscribe(onClick =>
|
||
|
{
|
||
|
ViewImage();
|
||
|
});
|
||
|
//关闭
|
||
|
transform.Find("TitleBar/CloseButton").GetComponent<Button>().OnClickAsObservable()
|
||
|
.Subscribe(_ => Hide());
|
||
|
//上传图片
|
||
|
OpenImageFile.OnLoadTextureFinished = texture =>
|
||
|
{
|
||
|
UploadImage(texture);
|
||
|
};
|
||
|
#endregion
|
||
|
|
||
|
}
|
||
|
public override void Show()
|
||
|
{
|
||
|
base.Show();
|
||
|
LoadData();
|
||
|
GetComponent<AttributePanelControl>().ResetPanel();
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 加载数据
|
||
|
/// </summary>
|
||
|
public void LoadData()
|
||
|
{
|
||
|
string url = string.Format(HttpManager.Instance.GetMiniFireStations);
|
||
|
HttpManager.Instance.Get<FireStation>(url, d =>
|
||
|
{
|
||
|
DataSource.SetData(d);
|
||
|
GetImage();
|
||
|
});
|
||
|
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 保存数据
|
||
|
/// </summary>
|
||
|
public void SaveData()
|
||
|
{
|
||
|
string url = string.Format(HttpManager.Instance.PostMiniFireStations);
|
||
|
HttpManager.Instance.Post(url, DataSource.GetData());
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 上传图片
|
||
|
/// </summary>
|
||
|
public void UploadImage(Texture2D texture)
|
||
|
{
|
||
|
HttpManager.Instance.PostImage($"FireStation.jpg", texture, a =>
|
||
|
{
|
||
|
DataSource.ImageUrl.Value = a?.ObjectName;
|
||
|
});
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 获取图片
|
||
|
/// </summary>
|
||
|
void GetImage()
|
||
|
{
|
||
|
if (!string.IsNullOrEmpty(DataSource.ImageUrl.Value))
|
||
|
{
|
||
|
HttpManager.Instance.GetImage($"{ DataSource.ImageUrl.Value}?x-oss-process=image/resize,h_200", texture =>
|
||
|
{
|
||
|
ImagePanel.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
|
||
|
ImagePanel.preserveAspect = true;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 查看原图
|
||
|
/// </summary>
|
||
|
public void ViewImage()
|
||
|
{
|
||
|
if (!string.IsNullOrEmpty(DataSource.ImageUrl.Value))
|
||
|
{
|
||
|
HttpManager.Instance.GetImage(DataSource.ImageUrl.Value, texture =>
|
||
|
{
|
||
|
switch (DataSource.ImageType.Value)
|
||
|
{
|
||
|
case OriginalImageType.Normal:
|
||
|
ImageViewer.Load(texture);
|
||
|
break;
|
||
|
case OriginalImageType.Panorama:
|
||
|
PanoramicViewer.Load(texture);
|
||
|
break;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
MessageBox.Show("未上传图片!", Color.white, 3f);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|