|
@@ -1,5 +1,6 @@
|
1
|
1
|
use std::cmp;
|
2
|
2
|
use std::collections::HashMap;
|
|
3
|
+use std::f32::consts::FRAC_PI_2;
|
3
|
4
|
|
4
|
5
|
use ggez::event::MouseButton;
|
5
|
6
|
use ggez::graphics::{DrawMode, MeshBuilder, StrokeOptions};
|
|
@@ -23,10 +24,10 @@ use crate::physics::{util, MetaEvent, PhysicEvent};
|
23
|
24
|
use crate::scene::item::{
|
24
|
25
|
apply_scene_item_modifier, ItemState, SceneItem, SceneItemModifier, SceneItemType,
|
25
|
26
|
};
|
26
|
|
-use crate::ui::scene_item_menu::SceneItemMenuItem;
|
27
|
|
-use crate::ui::{SceneItemPrepareOrder, UiItem, UiSpriteInfo, UserEvent};
|
|
27
|
+use crate::ui::vertical_menu::{vertical_menu_sprite_info, VerticalMenuSpriteInfo};
|
|
28
|
+use crate::ui::MenuItem;
|
|
29
|
+use crate::ui::{SceneItemPrepareOrder, UiComponent, UserEvent};
|
28
|
30
|
use crate::{Offset, ScenePoint, WindowPoint};
|
29
|
|
-use std::f32::consts::FRAC_PI_2;
|
30
|
31
|
|
31
|
32
|
pub struct MainState {
|
32
|
33
|
// time
|
|
@@ -158,10 +159,12 @@ impl MainState {
|
158
|
159
|
}
|
159
|
160
|
|
160
|
161
|
fn digest_click(&mut self, window_click_point: WindowPoint) {
|
161
|
|
- let scene_position =
|
|
162
|
+ let scene_click_point =
|
162
|
163
|
scene_point_from_window_point(&window_click_point, &self.display_offset);
|
163
|
164
|
self.selected_scene_items.drain(..);
|
164
|
|
- if let Some(scene_item_usize) = self.get_first_scene_item_for_scene_point(&scene_position) {
|
|
165
|
+ if let Some(scene_item_usize) =
|
|
166
|
+ self.get_first_scene_item_for_scene_point(&scene_click_point)
|
|
167
|
+ {
|
165
|
168
|
self.selected_scene_items.push(scene_item_usize);
|
166
|
169
|
}
|
167
|
170
|
|
|
@@ -170,40 +173,29 @@ impl MainState {
|
170
|
173
|
match scene_item_prepare_order {
|
171
|
174
|
SceneItemPrepareOrder::Move(scene_item_usize) => {
|
172
|
175
|
let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
|
173
|
|
- scene_item.next_order = Some(Order::MoveTo(scene_position));
|
|
176
|
+ scene_item.next_order = Some(Order::MoveTo(scene_click_point));
|
174
|
177
|
}
|
175
|
178
|
}
|
176
|
179
|
|
177
|
180
|
self.scene_item_prepare_order = None;
|
178
|
181
|
}
|
179
|
182
|
|
180
|
|
- // FIXME BS NOW: interpreter sur quel element du menu on a click ...
|
181
|
183
|
if let Some((scene_item_usize, scene_menu_point)) = self.scene_item_menu {
|
182
|
|
- let window_menu_point =
|
183
|
|
- window_point_from_scene_point(&scene_menu_point, &self.display_offset);
|
184
|
|
- let menu_sprite_info = UiSpriteInfo::from_type(UiItem::SceneItemMenu);
|
185
|
|
- let scene_item = self.get_scene_item(scene_item_usize);
|
186
|
|
- if window_click_point.x >= window_menu_point.x
|
187
|
|
- && window_click_point.x <= window_menu_point.x + menu_sprite_info.width
|
188
|
|
- && window_click_point.y >= window_menu_point.y
|
189
|
|
- && window_click_point.y <= window_menu_point.y + menu_sprite_info.height
|
|
184
|
+ let menu_sprite_info = vertical_menu_sprite_info(UiComponent::SceneItemMenu);
|
|
185
|
+ if let Some(menu_item) =
|
|
186
|
+ menu_sprite_info.item_clicked(&scene_menu_point, &scene_click_point)
|
190
|
187
|
{
|
191
|
|
- if let Some(menu_item) = menu_sprite_info.which_item_clicked(
|
192
|
|
- window_menu_point,
|
193
|
|
- window_click_point,
|
194
|
|
- scene_item,
|
195
|
|
- ) {
|
196
|
|
- match menu_item {
|
197
|
|
- SceneItemMenuItem::Move => {
|
198
|
|
- self.scene_item_prepare_order =
|
199
|
|
- Some(SceneItemPrepareOrder::Move(scene_item_usize));
|
200
|
|
- self.scene_item_menu = None;
|
201
|
|
- }
|
|
188
|
+ match menu_item {
|
|
189
|
+ MenuItem::Move => {
|
|
190
|
+ self.scene_item_prepare_order =
|
|
191
|
+ Some(SceneItemPrepareOrder::Move(scene_item_usize));
|
|
192
|
+ self.scene_item_menu = None;
|
202
|
193
|
}
|
|
194
|
+ MenuItem::MoveFast => {}
|
|
195
|
+ MenuItem::Hide => {}
|
203
|
196
|
}
|
204
|
|
- } else {
|
205
|
|
- self.scene_item_menu = None;
|
206
|
|
- }
|
|
197
|
+ };
|
|
198
|
+ self.scene_item_menu = None;
|
207
|
199
|
};
|
208
|
200
|
}
|
209
|
201
|
|
|
@@ -329,7 +321,7 @@ impl MainState {
|
329
|
321
|
|
330
|
322
|
fn generate_scene_item_menu_sprites(&mut self) -> GameResult {
|
331
|
323
|
if let Some((_, scene_point)) = self.scene_item_menu {
|
332
|
|
- for draw_param in UiSpriteInfo::from_type(UiItem::SceneItemMenu)
|
|
324
|
+ for draw_param in vertical_menu_sprite_info(UiComponent::SceneItemMenu)
|
333
|
325
|
.as_draw_params(&scene_point, &self.current_cursor_position)
|
334
|
326
|
{
|
335
|
327
|
self.ui_batch.add(draw_param);
|