summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/UI/CustomBattle/CustomBattlePasswordSettingHandler.cs
blob: e45ce9a781043266bc64f4e29c4890199672db72 (plain)
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
using System;
using UILib;
using XMainClient.UI.UICommon;

namespace XMainClient.UI.CustomBattle
{
	internal class CustomBattlePasswordSettingHandler : DlgHandlerBase
	{
		protected override string FileName
		{
			get
			{
				return "GameSystem/CustomBattle/PasswordSettingFrame";
			}
		}

		private XCustomBattleDocument _doc = null;

		private IXUIButton _ok;

		private IXUIButton _cancel;

		private IXUIInput _password;

		private bool passwordForJoin = false;

		protected override void Init()
		{
			base.Init();
			this._doc = XDocuments.GetSpecificDocument<XCustomBattleDocument>(XCustomBattleDocument.uuID);
			this._ok = (base.transform.Find("OK").GetComponent("XUIButton") as IXUIButton);
			this._cancel = (base.transform.Find("Cancel").GetComponent("XUIButton") as IXUIButton);
			this._password = (base.transform.Find("Password").GetComponent("XUIInput") as IXUIInput);
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			this._ok.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnOKButtonClicked));
			this._cancel.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnCancelButtonClicked));
		}

		protected override void OnShow()
		{
			base.OnShow();
			this.passwordForJoin = this._doc.passwordForJoin;
			this._doc.passwordForJoin = false;
			this.RefreshData();
		}

		public override void RefreshData()
		{
			base.RefreshData();
			bool flag = DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeCreateHandler != null && DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeCreateHandler.IsVisible();
			if (flag)
			{
				bool flag2 = this._doc.CustomCreateData.hasPassword && !string.IsNullOrEmpty(this._doc.CustomCreateData.password);
				if (flag2)
				{
					this._password.SetText(this._doc.CustomCreateData.password);
				}
			}
		}

		private bool OnOKButtonClicked(IXUIButton button)
		{
			bool flag = this.passwordForJoin;
			bool result;
			if (flag)
			{
				bool flag2 = this._password.GetText() == this._password.GetDefault();
				if (flag2)
				{
					this._doc.SendCustomBattleJoin(this._doc.CurrentCustomData.gameID, false, "");
				}
				else
				{
					this._doc.SendCustomBattleJoin(this._doc.CurrentCustomData.gameID, false, this._password.GetText());
				}
				base.SetVisible(false);
				result = true;
			}
			else
			{
				bool flag3 = this._password.GetText() == "" || this._password.GetText() == this._password.GetDefault();
				if (flag3)
				{
					bool flag4 = DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeCreateHandler != null && DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeCreateHandler.IsVisible();
					if (flag4)
					{
						this._doc.CustomCreateData.hasPassword = false;
						this._doc.CustomCreateData.password = "";
						DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeCreateHandler.SetPasswordSwitchSprite(false);
					}
				}
				else
				{
					bool flag5 = DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeCreateHandler != null && DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeCreateHandler.IsVisible();
					if (flag5)
					{
						this._doc.CustomCreateData.hasPassword = true;
						this._doc.CustomCreateData.password = this._password.GetText();
						DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeCreateHandler.SetPasswordSwitchSprite(true);
					}
				}
				bool flag6 = DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeBriefHandler != null && DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeBriefHandler.IsVisible();
				if (flag6)
				{
					this._doc.SendCustomBattleModifyPassword(this._doc.CurrentCustomData.gameID, this._password.GetText());
				}
				base.SetVisible(false);
				result = true;
			}
			return result;
		}

		private bool OnCancelButtonClicked(IXUIButton button)
		{
			bool flag = DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeCreateHandler != null && DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeCreateHandler.IsVisible();
			if (flag)
			{
				this._doc.CustomCreateData.hasPassword = false;
				this._doc.CustomCreateData.password = "";
				DlgBase<CustomBattleView, TabDlgBehaviour>.singleton._CustomModeCreateHandler.SetPasswordSwitchSprite(false);
			}
			base.SetVisible(false);
			return true;
		}
	}
}