|
@@ -21,6 +21,7 @@ use crate::scene::item::{ItemState, SceneItem, SceneItemType};
|
21
|
21
|
use crate::ui::scene_item_menu::SceneItemMenuItem;
|
22
|
22
|
use crate::ui::{SceneItemPrepareOrder, UiItem, UiSpriteInfo, UserEvent};
|
23
|
23
|
use crate::{Offset, ScenePoint, WindowPoint};
|
|
24
|
+use std::f32::consts::FRAC_PI_2;
|
24
|
25
|
|
25
|
26
|
pub struct MainState {
|
26
|
27
|
// time
|
|
@@ -105,6 +106,18 @@ impl MainState {
|
105
|
106
|
Ok(main_state)
|
106
|
107
|
}
|
107
|
108
|
|
|
109
|
+ fn get_scene_item(&self, index: usize) -> &SceneItem {
|
|
110
|
+ self.scene_items
|
|
111
|
+ .get(index)
|
|
112
|
+ .expect(SCENE_ITEMS_CHANGE_ERR_MSG)
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ fn get_scene_item_mut(&mut self, index: usize) -> &SceneItem {
|
|
116
|
+ self.scene_items
|
|
117
|
+ .get_mut(index)
|
|
118
|
+ .expect(SCENE_ITEMS_CHANGE_ERR_MSG)
|
|
119
|
+ }
|
|
120
|
+
|
108
|
121
|
fn inputs(&mut self, ctx: &Context) {
|
109
|
122
|
let display_offset_by =
|
110
|
123
|
if input::keyboard::is_mod_active(ctx, input::keyboard::KeyMods::SHIFT) {
|
|
@@ -151,8 +164,12 @@ impl MainState {
|
151
|
164
|
// TODO: Add order to scene_item
|
152
|
165
|
match scene_item_prepare_order {
|
153
|
166
|
SceneItemPrepareOrder::Move(scene_item_usize) => {
|
154
|
|
- let scene_item = self.scene_items.get_mut(*scene_item_usize).expect(SCENE_ITEMS_CHANGE_ERR_MSG);
|
155
|
|
- let angle = f32::atan2(scene_position.y - scene_item.position.y, scene_position.x - scene_item.position.x) + f32::consts::FRAC_PI_2;
|
|
167
|
+ let scene_item = self.get_scene_item(*scene_item_usize);
|
|
168
|
+ // TODO: remove this code when used in right place
|
|
169
|
+ let angle = f32::atan2(
|
|
170
|
+ scene_position.y - scene_item.position.y,
|
|
171
|
+ scene_position.x - scene_item.position.x,
|
|
172
|
+ ) + FRAC_PI_2;
|
156
|
173
|
println!("{:?}", angle);
|
157
|
174
|
}
|
158
|
175
|
}
|
|
@@ -165,10 +182,7 @@ impl MainState {
|
165
|
182
|
let window_menu_point =
|
166
|
183
|
window_point_from_scene_point(&scene_menu_point, &self.display_offset);
|
167
|
184
|
let menu_sprite_info = UiSpriteInfo::from_type(UiItem::SceneItemMenu);
|
168
|
|
- let scene_item = self
|
169
|
|
- .scene_items
|
170
|
|
- .get(scene_item_usize)
|
171
|
|
- .expect(SCENE_ITEMS_CHANGE_ERR_MSG);
|
|
185
|
+ let scene_item = self.get_scene_item(scene_item_usize);
|
172
|
186
|
if window_click_point.x >= window_menu_point.x
|
173
|
187
|
&& window_click_point.x <= window_menu_point.x + menu_sprite_info.width
|
174
|
188
|
&& window_click_point.y >= window_menu_point.y
|
|
@@ -205,10 +219,7 @@ impl MainState {
|
205
|
219
|
self.get_first_scene_item_for_scene_point(&scene_right_click_point)
|
206
|
220
|
{
|
207
|
221
|
if self.selected_scene_items.contains(&scene_item_usize) {
|
208
|
|
- let scene_item = self
|
209
|
|
- .scene_items
|
210
|
|
- .get(scene_item_usize)
|
211
|
|
- .expect(SCENE_ITEMS_CHANGE_ERR_MSG);
|
|
222
|
+ let scene_item = self.get_scene_item(scene_item_usize);
|
212
|
223
|
self.scene_item_menu = Some((scene_item_usize, scene_item.position))
|
213
|
224
|
}
|
214
|
225
|
}
|
|
@@ -227,7 +238,7 @@ impl MainState {
|
227
|
238
|
// Scene items movements
|
228
|
239
|
for scene_item in self.scene_items.iter_mut() {
|
229
|
240
|
match scene_item.state.current_behavior {
|
230
|
|
- ItemBehavior::Walking(vector) => {
|
|
241
|
+ ItemBehavior::Walking(_vector) => {
|
231
|
242
|
// TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)
|
232
|
243
|
scene_item.position.x += 1.0;
|
233
|
244
|
scene_item.grid_position =
|
|
@@ -408,7 +419,7 @@ impl MainState {
|
408
|
419
|
mut mesh_builder: MeshBuilder,
|
409
|
420
|
) -> GameResult<MeshBuilder> {
|
410
|
421
|
for i in &self.selected_scene_items {
|
411
|
|
- let selected_scene_item = self.scene_items.get(*i).expect(SCENE_ITEMS_CHANGE_ERR_MSG);
|
|
422
|
+ let selected_scene_item = self.get_scene_item(*i);
|
412
|
423
|
mesh_builder.rectangle(
|
413
|
424
|
DrawMode::Stroke(StrokeOptions::default()),
|
414
|
425
|
graphics::Rect::new(
|
|
@@ -457,10 +468,7 @@ impl MainState {
|
457
|
468
|
if let Some(scene_item_prepare_order) = &self.scene_item_prepare_order {
|
458
|
469
|
match scene_item_prepare_order {
|
459
|
470
|
SceneItemPrepareOrder::Move(scene_item_usize) => {
|
460
|
|
- let scene_item = self
|
461
|
|
- .scene_items
|
462
|
|
- .get(*scene_item_usize)
|
463
|
|
- .expect(SCENE_ITEMS_CHANGE_ERR_MSG);
|
|
471
|
+ let scene_item = self.get_scene_item(*scene_item_usize);
|
464
|
472
|
mesh_builder.line(
|
465
|
473
|
&vec![
|
466
|
474
|
scene_item.position.clone(),
|