Bastien Sevajol преди 3 години
родител
ревизия
b6f6294786
променени са 1 файла, в които са добавени 76 реда и са изтрити 71 реда
  1. 76 71
      src/scene/main.rs

+ 76 - 71
src/scene/main.rs Целия файл

@@ -127,87 +127,92 @@ impl MainState {
127 127
 
128 128
         while let Some(user_event) = self.user_events.pop() {
129 129
             match user_event {
130
-                UserEvent::Click(window_click_point) => {
131
-                    let scene_position =
132
-                        scene_point_from_window_point(&window_click_point, &self.display_offset);
133
-                    self.selected_scene_items.drain(..);
134
-                    if let Some(scene_item_usize) =
135
-                        self.get_first_scene_item_for_scene_point(&scene_position)
136
-                    {
137
-                        self.selected_scene_items.push(scene_item_usize);
138
-                    }
139
-
140
-                    if let Some(scene_item_prepare_order) = &self.scene_item_prepare_order {
141
-                        // TODO: Add order to scene_item
142
-                        self.scene_item_prepare_order = None;
143
-                    }
144
-
145
-                    // FIXME BS NOW: interpreter sur quel element du menu on a click ...
146
-                    if let Some((scene_item_usize, scene_menu_point)) = self.scene_item_menu {
147
-                        let window_menu_point =
148
-                            window_point_from_scene_point(&scene_menu_point, &self.display_offset);
149
-                        let menu_sprite_info = UiSpriteInfo::from_type(UiItem::SceneItemMenu);
150
-                        let scene_item = self
151
-                            .scene_items
152
-                            .get(scene_item_usize)
153
-                            .expect(SCENE_ITEMS_CHANGE_ERR_MSG);
154
-                        if window_click_point.x >= window_menu_point.x
155
-                            && window_click_point.x <= window_menu_point.x + menu_sprite_info.width
156
-                            && window_click_point.y >= window_menu_point.y
157
-                            && window_click_point.y <= window_menu_point.y + menu_sprite_info.height
158
-                        {
159
-                            if let Some(menu_item) = menu_sprite_info.which_item_clicked(
160
-                                window_menu_point,
161
-                                window_click_point,
162
-                                scene_item,
163
-                            ) {
164
-                                match menu_item {
165
-                                    SceneItemMenuItem::Move => {
166
-                                        self.scene_item_prepare_order =
167
-                                            Some(SceneItemPrepareOrder::Move(scene_item_usize));
168
-                                        self.scene_item_menu = None;
169
-                                    }
170
-                                }
171
-                            }
172
-                        } else {
173
-                            self.scene_item_menu = None;
174
-                        }
175
-                    };
176
-                }
130
+                UserEvent::Click(window_click_point) => self.digest_click(window_click_point),
177 131
                 UserEvent::AreaSelection(window_from, window_to) => {
178
-                    let scene_from =
179
-                        scene_point_from_window_point(&window_from, &self.display_offset);
180
-                    let scene_to = scene_point_from_window_point(&window_to, &self.display_offset);
181
-                    self.selected_scene_items.drain(..);
182
-                    self.selected_scene_items
183
-                        .extend(self.get_scene_items_for_scene_area(&scene_from, &scene_to));
132
+                    self.digest_area_selection(window_from, window_to)
184 133
                 }
185 134
                 UserEvent::RightClick(window_right_click_point) => {
186
-                    let scene_right_click_point = scene_point_from_window_point(
187
-                        &window_right_click_point,
188
-                        &self.display_offset,
189
-                    );
190
-
191
-                    // TODO: aucune selection et right click sur un item: scene_item_menu sur un item
192
-                    // TODO: selection et right click sur un item de la selection: scene_item_menu sur un TOUS les item de la selection
193
-                    // TODO: selection et right click sur un item PAS dans la selection: scene_item_menu sur un item
194
-
195
-                    if let Some(scene_item_usize) =
196
-                        self.get_first_scene_item_for_scene_point(&scene_right_click_point)
197
-                    {
198
-                        if self.selected_scene_items.contains(&scene_item_usize) {
199
-                            let scene_item = self
200
-                                .scene_items
201
-                                .get(scene_item_usize)
202
-                                .expect(SCENE_ITEMS_CHANGE_ERR_MSG);
203
-                            self.scene_item_menu = Some((scene_item_usize, scene_item.position))
135
+                    self.digest_right_click(window_right_click_point)
136
+                }
137
+            }
138
+        }
139
+    }
140
+
141
+    fn digest_click(&mut self, window_click_point: WindowPoint) {
142
+        let scene_position =
143
+            scene_point_from_window_point(&window_click_point, &self.display_offset);
144
+        self.selected_scene_items.drain(..);
145
+        if let Some(scene_item_usize) = self.get_first_scene_item_for_scene_point(&scene_position) {
146
+            self.selected_scene_items.push(scene_item_usize);
147
+        }
148
+
149
+        if let Some(scene_item_prepare_order) = &self.scene_item_prepare_order {
150
+            // TODO: Add order to scene_item
151
+            self.scene_item_prepare_order = None;
152
+        }
153
+
154
+        // FIXME BS NOW: interpreter sur quel element du menu on a click ...
155
+        if let Some((scene_item_usize, scene_menu_point)) = self.scene_item_menu {
156
+            let window_menu_point =
157
+                window_point_from_scene_point(&scene_menu_point, &self.display_offset);
158
+            let menu_sprite_info = UiSpriteInfo::from_type(UiItem::SceneItemMenu);
159
+            let scene_item = self
160
+                .scene_items
161
+                .get(scene_item_usize)
162
+                .expect(SCENE_ITEMS_CHANGE_ERR_MSG);
163
+            if window_click_point.x >= window_menu_point.x
164
+                && window_click_point.x <= window_menu_point.x + menu_sprite_info.width
165
+                && window_click_point.y >= window_menu_point.y
166
+                && window_click_point.y <= window_menu_point.y + menu_sprite_info.height
167
+            {
168
+                if let Some(menu_item) = menu_sprite_info.which_item_clicked(
169
+                    window_menu_point,
170
+                    window_click_point,
171
+                    scene_item,
172
+                ) {
173
+                    match menu_item {
174
+                        SceneItemMenuItem::Move => {
175
+                            self.scene_item_prepare_order =
176
+                                Some(SceneItemPrepareOrder::Move(scene_item_usize));
177
+                            self.scene_item_menu = None;
204 178
                         }
205 179
                     }
206 180
                 }
181
+            } else {
182
+                self.scene_item_menu = None;
183
+            }
184
+        };
185
+    }
186
+
187
+    fn digest_right_click(&mut self, window_right_click_point: WindowPoint) {
188
+        let scene_right_click_point =
189
+            scene_point_from_window_point(&window_right_click_point, &self.display_offset);
190
+
191
+        // TODO: aucune selection et right click sur un item: scene_item_menu sur un item
192
+        // TODO: selection et right click sur un item de la selection: scene_item_menu sur un TOUS les item de la selection
193
+        // TODO: selection et right click sur un item PAS dans la selection: scene_item_menu sur un item
194
+
195
+        if let Some(scene_item_usize) =
196
+            self.get_first_scene_item_for_scene_point(&scene_right_click_point)
197
+        {
198
+            if self.selected_scene_items.contains(&scene_item_usize) {
199
+                let scene_item = self
200
+                    .scene_items
201
+                    .get(scene_item_usize)
202
+                    .expect(SCENE_ITEMS_CHANGE_ERR_MSG);
203
+                self.scene_item_menu = Some((scene_item_usize, scene_item.position))
207 204
             }
208 205
         }
209 206
     }
210 207
 
208
+    fn digest_area_selection(&mut self, window_from: WindowPoint, window_to: WindowPoint) {
209
+        let scene_from = scene_point_from_window_point(&window_from, &self.display_offset);
210
+        let scene_to = scene_point_from_window_point(&window_to, &self.display_offset);
211
+        self.selected_scene_items.drain(..);
212
+        self.selected_scene_items
213
+            .extend(self.get_scene_items_for_scene_area(&scene_from, &scene_to));
214
+    }
215
+
211 216
     // TODO: manage errors
212 217
     fn physics(&mut self) {
213 218
         // Scene items movements