123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- using Cysharp.Threading.Tasks;
- using ET.EventType;
- using FairyGUI;
- using Sirenix.Utilities;
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- namespace ET.Client
- {
- [Event]
- public class ShowLoginUIEventHandle : BEvent<EventType.ShowLoginUIEvent>
- {
- private string mIP;
- private int mPort;
- private string strRoomToken;
- private bool bEnd = false;
- private bool bIsCloud = false;
- private bool bIsMobile = false;
- private bool bIsFullScreen = false;
- private int iScreenHeight = 0;
- private int iScreenWidth = 0;
- protected override async ETTask OnEvent(ShowLoginUIEvent a)
- {
- InitArgs();
- UIHelper.RemoveAllUiExceptSth();
- try
- {
- UIPackage.RemovePackage("CheckForResUpdate");
- }
- catch
- { }
- var view = await UIHelper.Create( "Login" );
- bEnd = false;
- InitLogin(view);
- }
- private void InitArgs()
- {
- var args = Environment.GetCommandLineArgs();
- for (var i = 0; i < args.Length; i++)
- {
- var arg = args[i];
- bool hasNext = args.Length > i + 1;
- if (arg.StartsWith("-token="))
- {
- strRoomToken = args[i][7..];
- Log.Debug($"env token: {strRoomToken}");
- continue;
- }
- switch(arg)
- {
- case "-cloud-game":
- bIsCloud = hasNext && args[i + 1] == "1";
- Log.Debug($"args: -cloud-game: {bIsCloud}");
- ++i;
- break;
- case "-mobile":
- bIsMobile = hasNext && args[i + 1] == "1";
- Log.Debug($"args: -mobile: {bIsMobile}");
- ++i;
- break;
- case "-screen-fullscreen":
- bIsFullScreen = hasNext && args[i + 1] == "1";
- Log.Debug($"args: -screen-fullscreen: {bIsFullScreen}");
- ++i;
- break;
- case "-screen-height":
- try
- {
- if(hasNext)
- {
- iScreenHeight = int.Parse(args[i + 1]);
- Log.Debug($"args: -screen-height: {iScreenHeight}");
- }
- }
- catch { }
- ++i;
- break;
- case "-screen-width":
- try
- {
- if (hasNext)
- {
- iScreenWidth = int.Parse(args[i + 1]);
- Log.Debug($"args: -screen-width: {iScreenWidth}");
- }
- }
- catch { }
- ++i;
- break;
- }
- }
- }
- private void InitServerList(GComboBox list)
- {
- var saveip = GameSetting.Instance.GetString(GameSetting.Sets.Server_str);
- int select = -1;
- List<string> servers = new();
- foreach (var info in ServerInfo.ServerList)
- {
- servers.Add(info.ShowName);
- if (select < 0 && !saveip.IsNullOrWhitespace())
- {
- if (saveip == info.HostStr)
- {
- select = servers.Count - 1;
- }
- }
- }
- if(select < 0 && !saveip.IsNullOrWhitespace())
- {
- try
- {
- var ipendpoint = NetworkHelper.ToIPEndPoint(saveip);
- servers.Add($"Custom[{saveip}]");
- ServerInfo.ServerList.Add(new ServerInfo()
- {
- ShowName = $"Custom[{saveip}]",
- Ip = ipendpoint.Address.ToString(),
- Port = ipendpoint.Port,
- }) ;
- select = servers.Count - 1;
- }
- catch(Exception)
- {
- Log.Error($"error save ip: {saveip}");
- }
- }
- if(select < 0)
- {
- select = 0;
- }
- var cur = ServerInfo.ServerList[select];
- mIP = cur.Ip;
- mPort = cur.Port;
- list.items = servers.ToArray();
- list.selectedIndex = select;
- list.onChanged.Set(() =>
- {
- var info = ServerInfo.ServerList[list.selectedIndex];
- GameSetting.Instance.SetString(GameSetting.Sets.Server_str, info.HostStr);
- mIP = info.Ip;
- mPort = info.Port;
- });
- list.visible = false;
- }
- private void InitResolutionList(GComboBox list)
- {
- list.visible = !bIsCloud;
- if(bIsFullScreen)
- {
- if(iScreenHeight == 0) iScreenHeight = Screen.height;
- if(iScreenWidth == 0) iScreenWidth = iScreenHeight * 9 / 16;
- Log.Debug($"fullscreen : {iScreenWidth}X{iScreenHeight}");
- }
-
- int val = GameSetting.Instance.GetInt(GameSetting.Sets.Resolution_int, iScreenHeight);
- int select = -1;
- List<string> showlist = new();
- foreach (var info in ResolutionInfo.ResolutionList)
- {
- showlist.Add(info.ShowName);
- if (select < 0 && val == info.Y)
- {
- select = showlist.Count - 1;
- }
- }
- if (select < 0)
- {
- select = 0;
- }
- list.items = showlist.ToArray();
- list.selectedIndex = select;
- list.onChanged.Set(() =>
- {
- var info = ResolutionInfo.ResolutionList[list.selectedIndex];
- GameSetting.Instance.SetInt(GameSetting.Sets.Resolution_int, info.Y);
- Screen.SetResolution(info.X, info.Y, false);
- Log.Debug($"SetResolution x:{info.X}, y:{info.Y}");
- });
- if (iScreenWidth == 0 || iScreenHeight == 0)
- {
- var cur = ResolutionInfo.ResolutionList[select];
- iScreenWidth = cur.X;
- iScreenHeight = cur.Y;
- }
- Screen.SetResolution(iScreenWidth, iScreenHeight, bIsFullScreen);
- }
- private async ETTask FakeUpdate(GComboBox listsvr, GComboBox listResolution)
- {
- while(!bEnd)
- {
- await TimerComponent.Instance.WaitAsync(100);
- if(Input.GetKey(KeyCode.F11))
- {
- listsvr.visible = true;
- listResolution.visible = true;
- break;
- }
- }
- }
- private void InitLogin(GComponent view)
- {
- var globalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
- var field = typeof(GlobalConfig).GetField("ExeVersion");
- string exeVersion = "first";
- if (field != null)
- {
- exeVersion = field.GetValue(globalConfig).ToString();
- }
- var txtVer = view.GetChild("Text_Version");
-
- txtVer.text = $"Main({exeVersion}) Res({YooAsset.YooAssets.GetResourceVersion()})@{globalConfig.Version}";
- var comp = view.GetChild("comp_login") as GComponent;
- var listSvr = view.GetChild("listServer").asComboBox;
- var listResolution = view.GetChild("listResolution").asComboBox;
- InitServerList(listSvr);
- InitResolutionList(listResolution);
- FakeUpdate(listSvr, listResolution).Coroutine();
- var tips = comp.GetChild( "txt_tips" );
- var inputID = comp.GetChild("txtID").asTextInput;
- var imgtips = comp.GetChild("img_tips");
- inputID.text = strRoomToken;
- var btn = comp.GetChild("btn_go").asButton;
- btn.onClick.Add(async () =>
- {
- tips.visible = false;
- imgtips.visible = true;
- btn.visible = false;
- var ret = await LoginHelper.Login(mIP, mPort, strRoomToken);
- if (ret != ErrorCode.ERR_Success)
- {
- imgtips.visible = false;
- tips.visible = true;
- btn.visible = true;
- if (ret == ErrorCode.ERR_UserNameOrPasswordFormatError ||
- ret == ErrorCode.ERR_UserNameOrPasswordError)
- {
- tips.text = "用户名或密码错误";
- }
- else
- {
- tips.text = "连接服务器过程中出现了问题\n" +
- "如重试后还是不行,请与客服联系" +
- "\n抖音:[color=#FF0000]奥陌陌网络科技[/color]" +
- "\n微信:[color=#FF0000]omm_wh[/color]";
- }
- listSvr.visible = true;
- }
- else
- {
- bEnd = true;
- imgtips.visible = false;
- }
- });
- if (strRoomToken.IsNullOrWhitespace())
- {
- tips.visible = true;
- tips.text = "获得直播间token失败,请重新启动\n" +
- "如重试后还是不行,请与客服联系" +
- "\n抖音:[color=#FF0000]奥陌陌网络科技[/color]" +
- "\n微信:[color=#FF0000]omm_wh[/color]";
- }
-
-
-
-
-
- }
- }
- }
|