薛之猫大王
17 hours ago da45ccae4c4b03fa50308b442a04ccfd3de160e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// =============================================================================== 
// Author              :    薛之猫
// Create Time         :    Sunday, January 11, 2026
// Update Time         :    Sunday, January 11, 2026
// Class Description   :    LoginMediator
// Copyright 虚幻骑士科技 All rights reserved.
// ===============================================================================
 
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using Skyunion;
using Client;
using PureMVC.Interfaces;
using SprotoType;
using UnityEngine.UI;
 
namespace Game {
    /// <summary>
    /// 登录视图控制器中介者
    /// </summary>
    public class LoginMediator : GameMediator {
        #region 成员
        /// <summary>
        /// 中介者名称,作为视图中介者的唯一标识符,用于在AppFacade中查找和注册,或者移除中介者
        /// </summary>
        public static string NameMediator = "LoginMediator";
 
        /// <summary>
        /// 玩家代理
        /// </summary>
        private PlayerProxy _playerProxy;
        /// <summary>
        /// 上次登录名称
        /// </summary>
        private string _lastLoginName;
        /// <summary>
        /// 网络代理
        /// </summary>
        private NetProxy m_netProxy;
        
        #endregion
 
        /// <summary>
        /// 构造函数,构造的视图组件交给中介者管理
        /// </summary>
        /// <param name="viewComponent">视图组件</param>
        public LoginMediator(object viewComponent ):base(NameMediator, viewComponent ) {}
 
 
        /// <summary>
        /// 登录视图
        /// </summary>
        public LoginView view;
 
        private string m_serverIP;
 
        public override string[] ListNotificationInterests()
        {
            return new List<string>(){
                CmdConstant.AuthEvent,
                Role_GetRoleList.TagName,
                Role_RoleLogin.TagName,
            }.ToArray();
        }
 
        public override void HandleNotification(INotification notification)
        {
            
        }
 
       
 
        #region UI 模板方法
 
        public override void OpenAniEnd(){
 
        }
 
        public override void WinFocus(){
            
        }
 
        public override void WinClose(){
            
        }
 
        public override void PrewarmComplete(){
            
        }   
 
        public override void Update()
        {
            
        }        
 
        protected override void InitData()
        {
            _playerProxy = AppFacade.GetInstance().RetrieveProxy(PlayerProxy.ProxyNAME) as PlayerProxy;
            
            m_netProxy = AppFacade.GetInstance().RetrieveProxy(NetProxy.ProxyNAME) as NetProxy;
                        
            view.m_btn_login_Button.enabled = true;
            _lastLoginName = PlayerPrefs.GetString("lastLoginName", RmdName());
            view.m_ipt_username_GameInput.text = _lastLoginName;
            view.m_btn_login_Button.enabled = true;
        }
 
        protected override void BindUIEvent()
        {
            view.m_btn_login_Button.onClick.AddListener(OnLogin);
            view.m_btn_rmdname_GameButton.onClick.AddListener(OnRmdName);
            view.m_dd_serverip_Dropdown.onValueChanged.AddListener(  onSelectedServer);
 
            int serverIndex = PlayerPrefs.GetInt("serverindex", 0);
            
            view.m_dd_serverip_Dropdown.value = serverIndex;
            onSelectedServer(serverIndex);
        }
 
        private void onSelectedServer(int change)
        {
            m_serverIP = view.m_dd_serverip_Dropdown.options[change].text;
            
            PlayerPrefs.SetInt("serverindex",change);
            Debug.Log("服务器ip index:"+change+"  "+m_serverIP);
        }
 
        protected override void BindUIData()
        {
//            CoreUtils.audioService.SetMusicVolume(0);
//            CoreUtils.audioService.SetSfxVolume(0);
        }
       
        #endregion
 
        private string RmdName()
        {
            return "ID" + Random.Range(1, 2000000).ToString();
        }
        
        //随机名字
        private void OnRmdName()
        {
            _lastLoginName = RmdName();
            view.m_ipt_username_GameInput.text = _lastLoginName;
        }
 
        //登录处理
        private void OnLogin()
        {
            view.m_btn_login_Button.enabled = false;
            
            if (view.m_ipt_username_GameInput.text.Length>0)
            {
                view.m_lbl_error_LanguageText.text = "";
                
                _lastLoginName = view.m_ipt_username_GameInput.text;
                PlayerPrefs.SetString("lastLoginName",_lastLoginName);
 
                string ip = "127.0.0.1";
                string pwd = view.m_ipt_password_GameInput.text;
                var pwds = pwd.Split('|');
                if(pwds.Length == 2)
                {
                    ip = pwds[0];
                    pwd = pwds[1];
                }
                IGGSDKConstant.IGGDefault.AppConfigIP = ip;
                IGGSDKConstant.IGGDefault.IGGID = _lastLoginName;
                IGGSDKConstant.IGGDefault.Token = pwd;
                m_netProxy.SaveLoginInfo(m_serverIP, 10000, _lastLoginName, pwd, view.m_ipt_serverGameNode_GameInput.text);
                CoreUtils.uiManager.CloseUI(UI.s_LoginView);
                // m_netProxy.Connection();
                AppFacade.GetInstance().SendNotification(CmdConstant.LoginToServer);
            }
            else
            {
                Tip.CreateTip("请输入账号").Show();
            }
        }
    }
}