summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/PetSkillLearnHandler.cs
blob: c632675dc4a0b6047dbc57607716c4f331520df1 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using UILib;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	internal class PetSkillLearnHandler : DlgHandlerBase
	{
		protected override string FileName
		{
			get
			{
				return "GameSystem/PetSkillLearn";
			}
		}

		private XPetDocument doc;

		private IXUIButton m_Close;

		private IXUIButton m_Help;

		private IXUIButton m_BtnGetSkillBook;

		private IXUIScrollView m_PetListScrollView;

		private IXUIWrapContent m_WrapContent;

		protected override void Init()
		{
			XSingleton<XDebug>.singleton.AddGreenLog("Init", null, null, null, null, null);
			base.Init();
			this.doc = XDocuments.GetSpecificDocument<XPetDocument>(XPetDocument.uuID);
			this.m_Close = (base.transform.Find("Bg/Close").GetComponent("XUIButton") as IXUIButton);
			this.m_Help = (base.transform.Find("Bg/Help").GetComponent("XUIButton") as IXUIButton);
			this.m_PetListScrollView = (base.transform.Find("Bg/SkillBookPanel").GetComponent("XUIScrollView") as IXUIScrollView);
			this.m_WrapContent = (base.transform.Find("Bg/SkillBookPanel/WrapContent").GetComponent("XUIWrapContent") as IXUIWrapContent);
			this.m_BtnGetSkillBook = (base.transform.Find("Bg/BtnGetSkillBook").GetComponent("XUIButton") as IXUIButton);
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			this.m_Close.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnCloseClicked));
			this.m_WrapContent.RegisterItemUpdateEventHandler(new WrapItemUpdateEventHandler(this.OnSkillBookListUpdated));
			this.m_Help.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnHelpClicked));
			this.m_BtnGetSkillBook.ID = ulong.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("PetGoBuySkillBook"));
			this.m_BtnGetSkillBook.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnGoClick));
		}

		public bool OnCloseClicked(IXUIButton btn)
		{
			base.SetVisible(false);
			return true;
		}

		private bool OnHelpClicked(IXUIButton btn)
		{
			DlgBase<XCommonHelpTipView, XCommonHelpTipBehaviour>.singleton.ShowHelp(XSysDefine.XSys_Horse_LearnSkill);
			return true;
		}

		protected override void OnShow()
		{
			base.OnShow();
			this.RefreshList(true);
			XSingleton<XDebug>.singleton.AddGreenLog("OnShow", null, null, null, null, null);
		}

		protected override void OnHide()
		{
			XSingleton<XDebug>.singleton.AddGreenLog("OnHide", null, null, null, null, null);
			base.OnHide();
		}

		public override void OnUnload()
		{
			XSingleton<XDebug>.singleton.AddGreenLog("OnUnload", null, null, null, null, null);
			this.doc = null;
			base.OnUnload();
		}

		public void RefreshList(bool bResetPosition = true)
		{
			int count = this.doc.GetSkillBook().Count;
			this.m_WrapContent.SetContentCount(count, false);
			if (bResetPosition)
			{
				this.m_PetListScrollView.ResetPosition();
			}
			else
			{
				this.m_WrapContent.RefreshAllVisibleContents();
			}
		}

		private void OnSkillBookListUpdated(Transform t, int index)
		{
			bool flag = index < 0 || index >= this.doc.SkillBookList.Count;
			if (flag)
			{
				XSingleton<XDebug>.singleton.AddErrorLog("index:" + index, null, null, null, null, null);
			}
			else
			{
				Transform transform = t.Find("Item");
				IXUISprite ixuisprite = transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
				IXUIButton ixuibutton = t.Find("BtnLearn").GetComponent("XUIButton") as IXUIButton;
				XItem xitem = this.doc.SkillBookList[index];
				XSingleton<XItemDrawerMgr>.singleton.DrawItem(transform.gameObject, xitem);
				ixuisprite.ID = (ulong)((long)xitem.itemID);
				ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnItemClick));
				ixuibutton.ID = xitem.uid;
				ixuibutton.RegisterClickEventHandler(new ButtonClickEventHandler(this._OnLearnSkillClick));
				PetSkillBook.RowData petSkillBook = XPetDocument.GetPetSkillBook((uint)xitem.itemID);
				IXUILabel ixuilabel = t.Find("Description").GetComponent("XUILabel") as IXUILabel;
				ixuilabel.SetText(petSkillBook.Description);
			}
		}

		private void _OnItemClick(IXUISprite iSp)
		{
			XSingleton<UiUtility>.singleton.ShowTooltipDialog((int)iSp.ID, null);
		}

		private bool _OnLearnSkillClick(IXUIButton btn)
		{
			this.ReqRecentMount(btn.ID, this.doc.CurSelectedPet.UID);
			return true;
		}

		private bool OnGoClick(IXUIButton btn)
		{
			XSingleton<XGameSysMgr>.singleton.OpenSystem((XSysDefine)btn.ID, 0UL);
			return true;
		}

		public void ReqRecentMount(ulong itemuid, ulong petuid)
		{
			RpcC2G_UseItem rpcC2G_UseItem = new RpcC2G_UseItem();
			rpcC2G_UseItem.oArg.uid = itemuid;
			rpcC2G_UseItem.oArg.petid = petuid;
			XSingleton<XClientNetwork>.singleton.Send(rpcC2G_UseItem);
		}
	}
}