11return {
22
3+ selected_unit : null ,
4+ active_item : null ,
5+
6+ set_active_item : ( object ) => {
7+ if ( this . active_item != null ) {
8+ this . active_item . class = 'bottombar-objects-list-item' ;
9+ this . active_item . border = #undefined; // TODO: fix class switching logic to also apply modifier styles correctly
10+ }
11+ this . active_item = object ;
12+ if ( this . active_item != null ) {
13+ this . active_item . class = 'bottombar-objects-list-item-active' ;
14+ }
15+ } ,
16+
317 add_object : ( object , left ) => {
418 const cls = #classof( object ) ;
519 let type = null ;
@@ -33,25 +47,51 @@ return {
3347 class : 'bottombar-objects-list-item-preview' ,
3448 top : top ,
3549 } ) ;
36- if ( cls == 'Unit' ) {
37- const p = this . p ; // TODO: make this work within object
38- item . text ( {
39- class : 'bottombar-objects-list-item-text' ,
40- text : p . get_stats_str ( object ) ,
41- } ) ;
50+ switch ( cls ) {
51+ case 'Unit' : {
52+ const p = this . p ; // TODO: make this work within object
53+ item . text ( {
54+ class : 'bottombar-objects-list-item-text' ,
55+ text : p . get_stats_str ( object ) ,
56+ } ) ;
57+ if ( object == this . selected_unit ) {
58+ this . set_active_item ( item ) ;
59+ }
60+ item . on ( 'mousedown' , ( e ) => {
61+ this . p . game . select_unit ( object ) ;
62+ return true ;
63+ } ) ;
64+ item . on ( 'mouseover' , ( e ) => {
65+ this . p . sections . object_preview . show ( object ) ;
66+ return true ;
67+ } ) ;
68+ item . on ( 'mouseout' , ( e ) => {
69+ this . p . sections . object_preview . show ( this . selected_unit ) ;
70+ return true ;
71+ } ) ;
72+ break ;
73+ }
74+ case 'Base' : {
75+ // TODO:
76+ break ;
77+ }
4278 }
4379 } ,
4480
45- update_units : ( tile ) => {
81+ update_tile : ( tile ) => {
82+
4683 if ( #is_defined( this . list ) ) {
4784 this . list . remove ( ) ;
85+ this . set_active_item ( null ) ;
4886 }
4987 this . list = this . frame . scrollview ( {
5088 left : 2 ,
5189 right : 2 ,
5290 top : - 8 ,
53- bottom : - 6 ,
91+ bottom : - 8 ,
5492 padding : 10 ,
93+ has_hscroll : false ,
94+ has_vscroll : false ,
5595 } ) ;
5696
5797 let left = 0 ;
@@ -67,6 +107,7 @@ return {
67107 this . add_object ( unit , left ) ;
68108 left += this . object_width ;
69109 }
110+
70111 } ,
71112
72113 init : ( p ) => {
@@ -79,7 +120,16 @@ return {
79120
80121 p . ui . class ( 'bottombar-objects-list-item' ) . set ( {
81122 width : width ,
82- height : 48 ,
123+ height : 52 ,
124+ _hover : {
125+ border : 'rgb(14,40,49),1' ,
126+ } ,
127+ } ) ;
128+ p . ui . class ( 'bottombar-objects-list-item-active' ) . extend ( 'bottombar-objects-list-item' ) . set ( {
129+ border : 'rgb(28,80,99),1' ,
130+ _hover : {
131+ border : 'rgb(28,80,99),1' ,
132+ } ,
83133 } ) ;
84134
85135 p . ui . class ( 'bottombar-objects-list-item-preview' ) . set ( {
@@ -91,6 +141,7 @@ return {
91141 font : 'arialnb.ttf:12' ,
92142 color : 'rgb(235,235,235)' ,
93143 align : 'bottom center' ,
144+ bottom : 3 ,
94145 } ) ;
95146
96147 this . frame = p . el . panel ( {
@@ -102,8 +153,17 @@ return {
102153 height : 58 ,
103154 } ) ;
104155
156+ p . map . on ( 'unit_preview' , ( e ) => {
157+ if ( e . unit != this . selected_unit ) {
158+ this . selected_unit = e . unit ;
159+ if ( this . selected_unit != null ) {
160+ this . update_tile ( this . selected_unit . get_tile ( ) ) ;
161+ }
162+ }
163+ } ) ;
164+
105165 p . map . on ( 'tile_preview' , ( e ) => {
106- this . update_units ( e . tile ) ;
166+ this . update_tile ( e . tile ) ;
107167 } ) ;
108168
109169 } ,
0 commit comments