1- // GameFrameX 组织下的以及组织衍生的项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
2- //
3- // 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE 文件。
4- //
5- // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
6-
7- using System . Collections . Generic ;
8- using FairyGUI ;
9- using GameFrameX . Event . Runtime ;
10- using Hotfix . Config ;
11- using Hotfix . Config . Tables ;
12- using Hotfix . Events ;
13- using Hotfix . Manager ;
14- using Hotfix . Proto ;
15-
16- namespace Hotfix . UI
17- {
18- public partial class UIBag
19- {
20- private class ItemTypeData
21- {
22- /// <summary>
23- /// 道具类型
24- /// </summary>
25- public ItemType Type { get ; }
26-
27- /// <summary>
28- /// 分类名称
29- /// </summary>
30- public string Name { get ; }
31-
32- public ItemTypeData ( ItemType type , string name )
33- {
34- Type = type ;
35- Name = name ;
36- }
37- }
38-
39- private List < ItemTypeData > Tabs = new List < ItemTypeData > ( ) ;
40- List < object > _bagItems = new List < object > ( ) ;
41- private BagItem _selectBagItem = null ;
42-
43- public override void OnOpen ( object userData )
44- {
45- _bagItems = new List < object > ( ) ;
46- Tabs = new List < ItemTypeData >
47- {
48- new ItemTypeData ( ItemType . Item , "道具" ) ,
49- new ItemTypeData ( ItemType . Equip , "装备" ) ,
50- new ItemTypeData ( ItemType . Fragment , "碎片" ) ,
51- new ItemTypeData ( ItemType . Material , "材料" ) ,
52- new ItemTypeData ( ItemType . Expendable , "消耗品" ) ,
53- } ;
54-
55- GameApp . Event . CheckSubscribe ( BagChangedEventArgs . EventId , OnBagChangedEventArgs ) ;
56-
57- base . OnOpen ( userData ) ;
58- m_content . m_list . onClickItem . Set ( OnBagItemClick ) ;
59- m_content . m_list . itemRenderer = BagItemRenderer ;
60- m_content . m_type_list . itemRenderer = TypeItemRenderer ;
61- m_content . m_type_list . onClickItem . Set ( OnTabTypeClick ) ;
62- m_content . m_type_list . DataList = new List < object > ( Tabs ) ;
63- m_content . m_type_list . GetChildAt ( 0 ) . onClick . Call ( ) ;
64-
65- m_content . m_info . m_use_button . onClick . Add ( OnUseButtonClick ) ;
66- this . m_bg . onClick . Set ( OnCloseClick ) ;
67- }
68-
69-
70- private void OnBagChangedEventArgs ( object sender , GameEventArgs e )
71- {
72- m_content . m_type_list . GetChildAt ( m_content . m_type_list . selectedIndex ) . onClick . Call ( ) ;
73- }
74-
75- /// <summary>
76- /// 使用道具
77- /// </summary>
78- private async void OnUseButtonClick ( )
79- {
80- if ( _selectBagItem . IsNull ( ) )
81- {
82- return ;
83- }
84-
85- await BagManager . Instance . RequestUseItem ( _selectBagItem . ItemId , _selectBagItem . Count ) ;
86- }
87-
88- private void OnBagItemClick ( EventContext context )
89- {
90- var data = UIBagItem . GetFormPool ( ( GObject ) context . data ) ;
91- var itemTypeData = ( BagItem ) data . self . dataSource ;
92- UpdateSelectItem ( itemTypeData ) ;
93- }
94-
95-
96- private void UpdateSelectItem ( BagItem bagItem )
97- {
98- _selectBagItem = bagItem ;
99- UIGoodItem . GetFormPool ( m_content . m_info . m_good_item ) . SetCount ( bagItem . Count ) . SetIcon ( bagItem . ItemId ) ;
100- var itemConfig = GameApp . Config . GetConfig < TbItemConfig > ( ) . Get ( bagItem . ItemId ) ;
101- if ( itemConfig . CanUse == ItemCanUse . CanNot )
102- {
103- m_content . m_info . m_IsCanUse . SetSelectedIndex ( 0 ) ;
104- }
105- else
106- {
107- m_content . m_info . m_IsCanUse . SetSelectedIndex ( 1 ) ;
108- }
109-
110- m_content . m_info . m_name_text . text = itemConfig . Name ;
111- m_content . m_info . m_desc_text . text = itemConfig . Description ;
112- }
113-
114-
115- private void BagItemRenderer ( int index , GObject item )
116- {
117- var bagItemData = ( BagItem ) item . dataSource ;
118- var uiBagItem = UIBagItem . GetFormPool ( item ) ;
119- var uiGoodItem = UIGoodItem . GetFormPool ( uiBagItem . m_good_item ) ;
120- uiGoodItem . SetCount ( bagItemData . Count ) ;
121- uiGoodItem . SetIcon ( bagItemData . ItemId ) ;
122- }
123-
124- #region Tab
125-
126- private void OnTabTypeClick ( EventContext context )
127- {
128- var data = UIBagTypeItem . GetFormPool ( ( GButton ) context . data ) ;
129- var itemTypeData = ( ItemTypeData ) data . self . dataSource ;
130- _bagItems . Clear ( ) ;
131- _bagItems . AddRange ( BagManager . Instance . GetBagItemsByType ( itemTypeData . Type ) ) ;
132- m_content . m_list . DataList = _bagItems ;
133- if ( _bagItems . Count > 0 )
134- {
135- m_content . m_list . selectedIndex = 0 ;
136- m_content . m_IsSelectedItem . SetSelectedIndex ( 1 ) ;
137- var bagItem = ( BagItem ) _bagItems [ 0 ] ;
138- UpdateSelectItem ( bagItem ) ;
139- }
140- else
141- {
142- m_content . m_IsSelectedItem . SetSelectedIndex ( 0 ) ;
143- _selectBagItem = null ;
144- }
145- }
146-
147- private void TypeItemRenderer ( int index , GObject item )
148- {
149- var itemTypeData = ( ItemTypeData ) item . dataSource ;
150- item . asButton . title = itemTypeData . Name ;
151- }
152-
153- #endregion
154-
155- private void OnCloseClick ( )
156- {
157- GameApp . UI . CloseUIForm < UIBag > ( ) ;
158- }
159- }
160- }
1+ // GameFrameX 组织下的以及组织衍生的项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
2+ //
3+ // 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE 文件。
4+ //
5+ // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
6+
7+ #if ENABLE_UI_FAIRYGUI
8+ using System . Collections . Generic ;
9+ using FairyGUI ;
10+ using GameFrameX . Event . Runtime ;
11+ using Hotfix . Config ;
12+ using Hotfix . Config . Tables ;
13+ using Hotfix . Events ;
14+ using Hotfix . Manager ;
15+ using Hotfix . Proto ;
16+
17+ namespace Hotfix . UI
18+ {
19+ public partial class UIBag
20+ {
21+ private class ItemTypeData
22+ {
23+ /// <summary>
24+ /// 道具类型
25+ /// </summary>
26+ public ItemType Type { get ; }
27+
28+ /// <summary>
29+ /// 分类名称
30+ /// </summary>
31+ public string Name { get ; }
32+
33+ public ItemTypeData ( ItemType type , string name )
34+ {
35+ Type = type ;
36+ Name = name ;
37+ }
38+ }
39+
40+ private List < ItemTypeData > Tabs = new List < ItemTypeData > ( ) ;
41+ List < object > _bagItems = new List < object > ( ) ;
42+ private BagItem _selectBagItem = null ;
43+
44+ public override void OnOpen ( object userData )
45+ {
46+ _bagItems = new List < object > ( ) ;
47+ Tabs = new List < ItemTypeData >
48+ {
49+ new ItemTypeData ( ItemType . Item , "道具" ) ,
50+ new ItemTypeData ( ItemType . Equip , "装备" ) ,
51+ new ItemTypeData ( ItemType . Fragment , "碎片" ) ,
52+ new ItemTypeData ( ItemType . Material , "材料" ) ,
53+ new ItemTypeData ( ItemType . Expendable , "消耗品" ) ,
54+ } ;
55+
56+ GameApp . Event . CheckSubscribe ( BagChangedEventArgs . EventId , OnBagChangedEventArgs ) ;
57+
58+ base . OnOpen ( userData ) ;
59+ m_content . m_list . onClickItem . Set ( OnBagItemClick ) ;
60+ m_content . m_list . itemRenderer = BagItemRenderer ;
61+ m_content . m_type_list . itemRenderer = TypeItemRenderer ;
62+ m_content . m_type_list . onClickItem . Set ( OnTabTypeClick ) ;
63+ m_content . m_type_list . DataList = new List < object > ( Tabs ) ;
64+ m_content . m_type_list . GetChildAt ( 0 ) . onClick . Call ( ) ;
65+
66+ m_content . m_info . m_use_button . onClick . Add ( OnUseButtonClick ) ;
67+ this . m_bg . onClick . Set ( OnCloseClick ) ;
68+ }
69+
70+
71+ private void OnBagChangedEventArgs ( object sender , GameEventArgs e )
72+ {
73+ m_content . m_type_list . GetChildAt ( m_content . m_type_list . selectedIndex ) . onClick . Call ( ) ;
74+ }
75+
76+ /// <summary>
77+ /// 使用道具
78+ /// </summary>
79+ private async void OnUseButtonClick ( )
80+ {
81+ if ( _selectBagItem . IsNull ( ) )
82+ {
83+ return ;
84+ }
85+
86+ await BagManager . Instance . RequestUseItem ( _selectBagItem . ItemId , _selectBagItem . Count ) ;
87+ }
88+
89+ private void OnBagItemClick ( EventContext context )
90+ {
91+ var data = UIBagItem . GetFormPool ( ( GObject ) context . data ) ;
92+ var itemTypeData = ( BagItem ) data . self . dataSource ;
93+ UpdateSelectItem ( itemTypeData ) ;
94+ }
95+
96+
97+ private void UpdateSelectItem ( BagItem bagItem )
98+ {
99+ _selectBagItem = bagItem ;
100+ UIGoodItem . GetFormPool ( m_content . m_info . m_good_item ) . SetCount ( bagItem . Count ) . SetIcon ( bagItem . ItemId ) ;
101+ var itemConfig = GameApp . Config . GetConfig < TbItemConfig > ( ) . Get ( bagItem . ItemId ) ;
102+ if ( itemConfig . CanUse == ItemCanUse . CanNot )
103+ {
104+ m_content . m_info . m_IsCanUse . SetSelectedIndex ( 0 ) ;
105+ }
106+ else
107+ {
108+ m_content . m_info . m_IsCanUse . SetSelectedIndex ( 1 ) ;
109+ }
110+
111+ m_content . m_info . m_name_text . text = itemConfig . Name ;
112+ m_content . m_info . m_desc_text . text = itemConfig . Description ;
113+ }
114+
115+
116+ private void BagItemRenderer ( int index , GObject item )
117+ {
118+ var bagItemData = ( BagItem ) item . dataSource ;
119+ var uiBagItem = UIBagItem . GetFormPool ( item ) ;
120+ var uiGoodItem = UIGoodItem . GetFormPool ( uiBagItem . m_good_item ) ;
121+ uiGoodItem . SetCount ( bagItemData . Count ) ;
122+ uiGoodItem . SetIcon ( bagItemData . ItemId ) ;
123+ }
124+
125+ #region Tab
126+
127+ private void OnTabTypeClick ( EventContext context )
128+ {
129+ var data = UIBagTypeItem . GetFormPool ( ( GButton ) context . data ) ;
130+ var itemTypeData = ( ItemTypeData ) data . self . dataSource ;
131+ _bagItems . Clear ( ) ;
132+ _bagItems . AddRange ( BagManager . Instance . GetBagItemsByType ( itemTypeData . Type ) ) ;
133+ m_content . m_list . DataList = _bagItems ;
134+ if ( _bagItems . Count > 0 )
135+ {
136+ m_content . m_list . selectedIndex = 0 ;
137+ m_content . m_IsSelectedItem . SetSelectedIndex ( 1 ) ;
138+ var bagItem = ( BagItem ) _bagItems [ 0 ] ;
139+ UpdateSelectItem ( bagItem ) ;
140+ }
141+ else
142+ {
143+ m_content . m_IsSelectedItem . SetSelectedIndex ( 0 ) ;
144+ _selectBagItem = null ;
145+ }
146+ }
147+
148+ private void TypeItemRenderer ( int index , GObject item )
149+ {
150+ var itemTypeData = ( ItemTypeData ) item . dataSource ;
151+ item . asButton . title = itemTypeData . Name ;
152+ }
153+
154+ #endregion
155+
156+ private void OnCloseClick ( )
157+ {
158+ GameApp . UI . CloseUIForm < UIBag > ( ) ;
159+ }
160+ }
161+ }
162+ #endif
0 commit comments