1
+ use matches:: matches;
1
2
use std:: rc:: Rc ;
2
3
use std:: cell:: RefCell ;
3
4
use std:: time:: { Duration , Instant } ;
@@ -21,7 +22,13 @@ use super::action_menu::{Action, Placement};
21
22
#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
22
23
enum PickMode {
23
24
Hex ,
24
- Object ,
25
+ Object ( ObjectPickMode ) ,
26
+ }
27
+
28
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
29
+ enum ObjectPickMode {
30
+ Action ,
31
+ Skill ( crate :: asset:: Skill ) ,
25
32
}
26
33
27
34
#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
@@ -42,6 +49,7 @@ enum PickState {
42
49
pub struct WorldView {
43
50
world : Rc < RefCell < World > > ,
44
51
pick_mode : PickMode ,
52
+ saved_pick_mode : Option < PickMode > ,
45
53
hex_cursor : object:: Handle ,
46
54
pub hex_cursor_style : HexCursorStyle ,
47
55
pub roof_visible : bool ,
@@ -59,6 +67,7 @@ impl WorldView {
59
67
Self {
60
68
world,
61
69
pick_mode : PickMode :: Hex ,
70
+ saved_pick_mode : None ,
62
71
hex_cursor,
63
72
hex_cursor_style : HexCursorStyle :: Normal ,
64
73
roof_visible : false ,
@@ -85,6 +94,11 @@ impl WorldView {
85
94
}
86
95
}
87
96
97
+ pub fn enter_skill_target_pick_mode ( & mut self , skill : crate :: asset:: Skill ) {
98
+ self . saved_pick_mode = Some ( self . pick_mode ) ;
99
+ self . pick_mode = PickMode :: Object ( ObjectPickMode :: Skill ( skill) ) ;
100
+ }
101
+
88
102
fn insert_hex_cursor ( world : & mut World ) -> object:: Handle {
89
103
let mut hex_cursor = Object :: new ( FrameId :: MOUSE_HEX_OUTLINE , None ,
90
104
Some ( Default :: default ( ) ) , SubObject :: None ) ;
@@ -125,10 +139,6 @@ impl WorldView {
125
139
}
126
140
127
141
impl Widget for WorldView {
128
- fn init ( & mut self , ctx : Init ) {
129
- ctx. base . set_cursor ( Some ( Cursor :: Hidden ) ) ;
130
- }
131
-
132
142
fn handle_event ( & mut self , mut ctx : HandleEvent ) {
133
143
match ctx. event {
134
144
Event :: MouseMove { pos } => {
@@ -139,15 +149,18 @@ impl Widget for WorldView {
139
149
ctx. out ( UiCommandData :: HexPick { action : false , pos } ) ;
140
150
}
141
151
}
142
- PickMode :: Object => {
152
+ PickMode :: Object ( ObjectPickMode :: Action ) => {
143
153
self . pick_state = PickState :: Pending { start : ctx. now , pos } ;
144
154
self . default_action_icon = None ;
145
155
}
156
+ PickMode :: Object ( ObjectPickMode :: Skill ( _) ) => { }
146
157
}
147
158
self . update_hex_cursor_visibility ( None ) ;
148
159
}
149
160
Event :: MouseDown { pos, button } => {
150
- if button == MouseButton :: Left && self . pick_mode == PickMode :: Object {
161
+ if button == MouseButton :: Left &&
162
+ matches ! ( self . pick_mode, PickMode :: Object ( ObjectPickMode :: Action ) )
163
+ {
151
164
let world = self . world . borrow ( ) ;
152
165
if let Some ( obj) = world. pick_object ( pos, true ) {
153
166
self . action_menu_state = Some ( ( ctx. now , obj) ) ;
@@ -163,25 +176,34 @@ impl Widget for WorldView {
163
176
let ( pos, _) = self . update_hex_cursor_pos ( pos) ;
164
177
ctx. out ( UiCommandData :: HexPick { action : true , pos } ) ;
165
178
}
166
- PickMode :: Object => {
167
- let world = self . world . borrow ( ) ;
168
- if let Some ( obj) = world. pick_object ( pos, true ) {
169
- ctx. out ( UiCommandData :: ObjectPick {
170
- kind : ObjectPickKind :: DefaultAction ,
171
- obj,
172
- } ) ;
179
+ PickMode :: Object ( mode) => {
180
+ let picked_obj = self . world . borrow ( ) . pick_object ( pos, true ) ;
181
+ if let Some ( obj) = picked_obj {
182
+ let kind = match mode {
183
+ ObjectPickMode :: Action => ObjectPickKind :: DefaultAction ,
184
+ ObjectPickMode :: Skill ( skill) => {
185
+ self . pick_mode = self . saved_pick_mode . take ( ) . unwrap ( ) ;
186
+ ObjectPickKind :: Skill ( skill)
187
+ }
188
+ } ;
189
+ ctx. out ( UiCommandData :: ObjectPick { kind, obj } ) ;
190
+ if self . pick_mode == PickMode :: Hex {
191
+ self . update_hex_cursor_visibility ( None ) ;
192
+ let ( pos, changed) = self . update_hex_cursor_pos ( pos) ;
193
+ if changed {
194
+ ctx. out ( UiCommandData :: HexPick { action : false , pos } ) ;
195
+ }
196
+ }
173
197
}
174
198
}
175
199
}
176
200
}
177
201
MouseButton :: Right => {
178
202
self . pick_mode = match self . pick_mode {
179
203
PickMode :: Hex => {
180
- ctx. base . set_cursor ( Some ( Cursor :: ActionArrow ) ) ;
181
- PickMode :: Object
204
+ PickMode :: Object ( ObjectPickMode :: Action )
182
205
}
183
- PickMode :: Object => {
184
- ctx. base . set_cursor ( Some ( Cursor :: Hidden ) ) ;
206
+ PickMode :: Object ( _) => {
185
207
let ( pos, changed) = self . update_hex_cursor_pos ( pos) ;
186
208
if changed {
187
209
ctx. out ( UiCommandData :: HexPick { action : false , pos } ) ;
@@ -233,14 +255,16 @@ impl Widget for WorldView {
233
255
}
234
256
235
257
fn sync ( & mut self , ctx : Sync ) {
236
- if ctx. base . cursor ( ) != Some ( Cursor :: Hidden ) {
237
- ctx. base . set_cursor ( Some (
238
- if self . default_action_icon . is_some ( ) {
239
- Placement :: new ( 1 , ctx. cursor_pos , ctx. base . rect ( ) ) . cursor
240
- } else {
241
- Cursor :: ActionArrow
242
- } ) )
243
- }
258
+ ctx. base . set_cursor ( Some (
259
+ if self . default_action_icon . is_some ( ) {
260
+ Placement :: new ( 1 , ctx. cursor_pos , ctx. base . rect ( ) ) . cursor
261
+ } else {
262
+ match self . pick_mode {
263
+ PickMode :: Hex => Cursor :: Hidden ,
264
+ PickMode :: Object ( ObjectPickMode :: Action ) => Cursor :: ActionArrow ,
265
+ PickMode :: Object ( ObjectPickMode :: Skill ( _) ) => Cursor :: CrosshairUse ,
266
+ }
267
+ } ) ) ;
244
268
}
245
269
246
270
fn render ( & mut self , ctx : Render ) {
@@ -267,7 +291,7 @@ impl Widget for WorldView {
267
291
} ) ;
268
292
}
269
293
}
270
- PickMode :: Object => if let Some ( action) = self . default_action_icon {
294
+ PickMode :: Object ( ObjectPickMode :: Action ) => if let Some ( action) = self . default_action_icon {
271
295
let fid = action. icons ( ) . 0 ;
272
296
let pos = Placement :: new ( 1 , ctx. cursor_pos , ctx. base . unwrap ( ) . rect ( ) ) . rect . top_left ( ) ;
273
297
Sprite {
@@ -280,6 +304,7 @@ impl Widget for WorldView {
280
304
effect : None ,
281
305
} . render ( ctx. canvas , ctx. frm_db ) ;
282
306
}
307
+ PickMode :: Object ( ObjectPickMode :: Skill ( _) ) => { }
283
308
}
284
309
}
285
310
}
0 commit comments