123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using Sfs2X.Entities;
- using Sfs2X.Entities.Data;
- using UnityEngine;
- using UnityEngine.UI;
- public class RoomData
- {
- #region Config
- private static string IDLabel = "i";
- private static string OwnerLabel = "o";
- private static string DurationLabel = "d";
- private static string MaxPlayerLabel = "m";
- private static string NameLabel = "n";
- private static string StartTimeLabel = "s";
- private static string EndTimeLabel = "e";
- public TimeSpan RemainTime
- {
- get
- {
- if (IsSystemRoom)
- {
- return new TimeSpan(1, 0, 0, 0);
- }
- else
- {
- return EndTime.Subtract(StartTime);
- }
- }
- }
- public int ID;
- public int Duration;
- public int MaxPlayer;
- public long Owner;
- public bool IsSystemRoom;
- public string Name;
- public DateTime StartTime;
- public DateTime EndTime;
- #endregion
- public RoomData(ISFSObject arg)
- {
- ID = arg.GetInt(IDLabel);
- Owner = arg.GetLong(OwnerLabel);
- Duration = arg.GetInt(DurationLabel);
- MaxPlayer = arg.GetInt(MaxPlayerLabel);
- Name = arg.GetUtfString(NameLabel);
- StartTime = DateUtil.GetTime(arg.GetClass(StartTimeLabel).ToString().TrimEnd('0'));
- EndTime = DateUtil.GetTime(arg.GetClass(EndTimeLabel).ToString().TrimEnd('0'));
- if (ID == 1)
- IsSystemRoom = true;
- //Debug.Log(ID);
- //Debug.Log(Owner);
- //Debug.Log(Duration);
- //Debug.Log(MaxPlayer);
- //Debug.Log(Name);
- //Debug.Log(StartTime);
- //Debug.Log(EndTime);
- //Debug.Log(RemainHour);
- //Debug.Log(IsSystemRoom);
- }
- public PlazaRoomItem CreateItem()
- {
- PlazaRoomItem plazaRoomItem = ManaReso.Get("PlazaRoomItem", Folder.UI, false, ManaReso.Get("Z_Grid"), false, ObjType.PlazaRoomItem, typeof(PlazaRoomItem)).GetComponent<PlazaRoomItem>();
- plazaRoomItem.Regist();
- return plazaRoomItem;
- }
- public static bool operator ==(RoomData r1, RoomData r2)
- {
- if (r1.ID == r2.ID)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public static bool operator !=(RoomData r1, RoomData r2)
- {
- return !(r1 == r2);
- }
- public override bool Equals(object obj)
- {
- return this == (RoomData) obj;
- }
- public override int GetHashCode()
- {
- return ID.GetHashCode();
- }
- }
- public class PlazaRoomItem : MonoBehaviour
- {
- #region Config
- public bool Registed;
- public RoomData RoomData;
- public Text ID;
- public Text Name;
- public Text Status;
- public Text Duration;
- public Text People;
- public Text ButtonLab;
- public Image Img0;
- public Button Button;
- #endregion
- public void Regist()
- {
- if (Registed)
- return;
- else
- Registed = true;
- Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>();
- Auxiliary.CompileDic(transform, dictionary);
- ID = dictionary["ID"].GetComponent<Text>();
- Name = dictionary["Name"].GetComponent<Text>();
- Status = dictionary["Status"].GetComponent<Text>();
- Duration = dictionary["Duration"].GetComponent<Text>();
- People = dictionary["People"].GetComponent<Text>();
- Img0 = dictionary["Img0"].GetComponent<Image>();
- Button = dictionary["Btn"].GetComponent<Button>();
- ButtonLab = dictionary["BtnLab"].GetComponent<Text>();
- }
- public PlazaRoomItem Init(RoomData roomData)
- {
- RoomData = roomData;
- if (RoomData.IsSystemRoom)
- {
- ID.SetActive(false);
- Img0.SetActive(true);
- }
- else
- {
- ID.SetActive(true);
- Img0.SetActive(false);
- ID.text = RoomData.ID.ToString();
- }
- if (RoomData.RemainTime.TotalMinutes > 10)
- {
- ManaLan.Add(Status, new LanStr("UI", "Z_Running"));
- Status.color = Lib.RoomRunning;
- }
- else
- {
- ManaLan.Add(Status, new LanStr("UI", "Z_Closing"));
- Status.color = Lib.RoomClosing;
- }
- Name.text = RoomData.Name;
- Duration.text = RoomData.Duration.ToString();
- //foreach (var VARIABLE in GardenSmartFoxManager.GardenSmartFox.SmartFox.GetRoomListFromGroup("default"))
- //{
- // Debug.Log(VARIABLE.Id);
- //}
- Room room = GardenSmartFoxManager.GardenSmartFox.SmartFox.GetRoomById(RoomData.ID);
- if (room == null || room.UserCount < room.MaxUsers)
- {
- ManaLan.Add(People, new LanStr("UI", "Z_Available"));
- People.color = Lib.RoomRunning;
- Button.image.material = null;
- ManaLan.Add(ButtonLab, new LanStr("UI", "Z_Join"));
- }
- else
- {
- ManaLan.Add(People, new LanStr("UI", "Z_Full"));
- People.color = Lib.RoomClosing;
- Button.image.material = Lib.GrayMat;
- ManaLan.Add(ButtonLab, new LanStr("UI", "Z_Full"));
- }
- return this;
- }
- }
|