153 lines
4.9 KiB
C#
153 lines
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using ZXKFramework;
|
|
public class ImagePanel : UIBase
|
|
{
|
|
public override string Name => "ImagePanel";
|
|
public override string GroupName => UIGroupLiao.Image.ToString();
|
|
Button left;
|
|
Button right;
|
|
Text imageName;
|
|
Button closeBtn;
|
|
Image image;
|
|
Image maxImage;
|
|
List<int> list = new();
|
|
GameModel gameModel;
|
|
int imageId = 0;
|
|
int id;
|
|
public override void HandleEvent(string name, object data) { }
|
|
public override void Init(IUIManager uictrl)
|
|
{
|
|
base.Init(uictrl);
|
|
left = transform.FindFirst<Button>("Left");
|
|
left.onClick.AddListener(TurnLeft);
|
|
right = transform.FindFirst<Button>("Right");
|
|
right.onClick.AddListener(TurnRight);
|
|
closeBtn = transform.FindFirst<Button>("Close");
|
|
closeBtn.onClick.AddListener(() => {
|
|
SetActive(false);
|
|
Game.Instance.eventManager.Raise(new CloseImageEvent() { id = id });
|
|
});
|
|
imageName = transform.FindFirst<Text>("Name");
|
|
image = transform.FindFirst<Image>("Image");
|
|
maxImage = transform.FindFirst<Image>("MaxImage");
|
|
gameModel = GetModel<GameModel>();
|
|
}
|
|
public override void ShowData(params object[] obj)
|
|
{
|
|
base.ShowData(obj);
|
|
id = (int)obj[0];
|
|
for (int i = 0; i < gameModel.imageData.GetImageDataList().Count; i++)
|
|
{
|
|
if (gameModel.imageData.GetImageDataList()[i].Group == gameModel.mainData.GetImageGroup(id))
|
|
{
|
|
list.Add(gameModel.imageData.GetImageDataList()[i].id);
|
|
}
|
|
}
|
|
}
|
|
public override void Show()
|
|
{
|
|
base.Show();
|
|
if (list.Count == 1)
|
|
{
|
|
left.gameObject.SetActive(false);
|
|
right.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
left.gameObject.SetActive(false);
|
|
right.gameObject.SetActive(true);
|
|
}
|
|
ChangeImage(imageId);
|
|
}
|
|
public override void Hide()
|
|
{
|
|
base.Hide();
|
|
list.Clear();
|
|
imageId = 0;
|
|
}
|
|
private void TurnLeft()
|
|
{
|
|
imageId--;
|
|
if (imageId == 0)
|
|
{
|
|
left.gameObject.SetActive(false);
|
|
right.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
right.gameObject.SetActive(true);
|
|
left.gameObject.SetActive(true);
|
|
}
|
|
ChangeImage(imageId);
|
|
}
|
|
private void TurnRight()
|
|
{
|
|
imageId++;
|
|
if (imageId == list.Count - 1)
|
|
{
|
|
right.gameObject.SetActive(false);
|
|
left.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
right.gameObject.SetActive(true);
|
|
left.gameObject.SetActive(true);
|
|
}
|
|
ChangeImage(imageId);
|
|
}
|
|
private void ChangeImage(int value)
|
|
{
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
if (i == value)
|
|
{
|
|
Game.Instance.res.Load<Texture2D>(gameModel.imageData.GetImagePath(list[i]), m => {
|
|
image.sprite = UnityTools.ToSprite(m);
|
|
float w = m.width;
|
|
float h = m.height;
|
|
if(w < 1000)
|
|
{
|
|
h = (float)Math.Round(1000f / w, 2) * h;
|
|
w = 1000;
|
|
}
|
|
if (w > 1000)
|
|
{
|
|
h = (float)Math.Round(1000f / w, 2) * h;
|
|
w = 1000;
|
|
}
|
|
if (h > 800)
|
|
{
|
|
w = (float)Math.Round(800f / h, 2) * w;
|
|
h = 800;
|
|
}
|
|
image.rectTransform.sizeDelta = new Vector2(w, h);
|
|
maxImage.sprite = UnityTools.ToSprite(m);
|
|
float w2 = m.width;
|
|
float h2 = m.height;
|
|
if (w2 < 1920)
|
|
{
|
|
h2 = (float)Math.Round(1920 / w2, 2) * h2;
|
|
w2 = 1920;
|
|
}
|
|
if (w2 > 1920)
|
|
{
|
|
h2 = (float)Math.Round(1920 / w2, 2) * h2;
|
|
w2 = 1920;
|
|
}
|
|
if (h2 > 1080)
|
|
{
|
|
w2 = (float)Math.Round(1080 / h2, 2) * w2;
|
|
h2 = 1080;
|
|
}
|
|
maxImage.rectTransform.sizeDelta = new Vector2(w2, h2);
|
|
imageName.text = gameModel.imageData.GetImageName(list[i]);
|
|
Game.Instance.eventManager.Raise(new ImageChangeEvent() { id = list[i] });
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|