Skip to content

Commit

Permalink
feat: permit move map with mouse middle ckick
Browse files Browse the repository at this point in the history
  • Loading branch information
buxx committed Apr 4, 2024
1 parent abc329f commit 9165290
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 40 deletions.
99 changes: 59 additions & 40 deletions battle_gui/src/engine/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ impl Engine {
}
}

if self.gui_state.middle_click_down_window_point().is_some() {
let last_cursor_point = self.gui_state.current_cursor_window_point();
messages.push(EngineMessage::GuiState(
GuiStateMessage::ApplyOnDisplaySceneOffset(Offset::from_vec2(
cursor_point.to_vec2() - last_cursor_point.to_vec2(),
)),
))
}

let point = self.gui_state.current_cursor_window_point();
let cursor_in_control = self.hud.contains(ctx, &[point]);
messages.push(EngineMessage::GuiState(GuiStateMessage::SetCursorInHud(
Expand All @@ -258,54 +267,64 @@ impl Engine {
let opened_squad_menu = self.gui_state.squad_menu().is_some();
let have_pending_order = !self.gui_state.pending_order().is_empty();

if let MouseButton::Left = button {
// Update cursor down position
messages.push(EngineMessage::GuiState(GuiStateMessage::SetLeftClickDown(
Some(cursor),
)));
match button {
MouseButton::Left => {
// Update cursor down position
messages.push(EngineMessage::GuiState(GuiStateMessage::SetLeftClickDown(
Some(cursor),
)));

// Check if any order under the cursor
if self.gui_state.is_controlling(&Control::Soldiers)
&& !self.gui_state.cursor_in_hud()
&& !opened_squad_menu
&& !have_pending_order
{
for (order, order_marker, squad_id, world_point, order_marker_i) in
self.battle_state.order_markers(self.gui_state.side())
// Check if any order under the cursor
if self.gui_state.is_controlling(&Control::Soldiers)
&& !self.gui_state.cursor_in_hud()
&& !opened_squad_menu
&& !have_pending_order
{
let world_shape =
self.order_marker_selection_shape(&order, &order_marker, &world_point);
if self
.gui_state
.window_shape_from_world_shape(&world_shape)
.contains(&cursor)
for (order, order_marker, squad_id, world_point, order_marker_i) in
self.battle_state.order_markers(self.gui_state.side())
{
let pending_order = self.create_pending_order_from_order_marker(
&order_marker,
&squad_id,
&Some(order_marker_i),
&[],
);
messages.push(EngineMessage::GuiState(GuiStateMessage::SetPendingOrders(
vec![pending_order],
)));
let world_shape =
self.order_marker_selection_shape(&order, &order_marker, &world_point);
if self
.gui_state
.window_shape_from_world_shape(&world_shape)
.contains(&cursor)
{
let pending_order = self.create_pending_order_from_order_marker(
&order_marker,
&squad_id,
&Some(order_marker_i),
&[],
);
messages.push(EngineMessage::GuiState(
GuiStateMessage::SetPendingOrders(vec![pending_order]),
));
}
}
}

if self.battle_state.phase().is_placement() && !self.gui_state.cursor_in_hud() {
let world_point = self.gui_state.current_cursor_world_point();
if let Some(soldier) = self
.soldiers_at_point(world_point, Some(self.gui_state.side()))
.first()
{
messages.push(EngineMessage::GuiState(
GuiStateMessage::SetBeginClickOnSoldier(Some(soldier.uuid())),
));
if self.battle_state.phase().is_placement() && !self.gui_state.cursor_in_hud() {
let world_point = self.gui_state.current_cursor_world_point();
if let Some(soldier) = self
.soldiers_at_point(world_point, Some(self.gui_state.side()))
.first()
{
messages.push(EngineMessage::GuiState(
GuiStateMessage::SetBeginClickOnSoldier(Some(soldier.uuid())),
));
}
}
}
}
MouseButton::Right => {}
MouseButton::Middle => {
if self.gui_state.middle_click_down_window_point().is_none() {
messages.push(EngineMessage::GuiState(
GuiStateMessage::SetMiddleClickDown(Some(cursor)),
));
}
}
MouseButton::Other(_) => {}
}

messages
}

Expand Down Expand Up @@ -376,7 +395,7 @@ impl Engine {
)));
}
MouseButton::Middle => messages.push(EngineMessage::GuiState(
GuiStateMessage::CenterSceneOn(self.gui_state.current_cursor_world_point()),
GuiStateMessage::SetMiddleClickDown(None),
)),
_ => {}
}
Expand Down
1 change: 1 addition & 0 deletions battle_gui/src/engine/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum EngineMessage {
pub enum GuiStateMessage {
SetCursorPoint(WindowPoint),
SetLeftClickDown(Option<WindowPoint>),
SetMiddleClickDown(Option<WindowPoint>),
SetCurrentCursorVector(Option<(WindowPoint, WindowPoint)>),
ApplyOnDisplaySceneOffset(Offset),
SetDisplaySceneOffset(Offset),
Expand Down
11 changes: 11 additions & 0 deletions battle_gui/src/engine/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct GuiState {
last_cursor_move_frame: u64,
/// WindowPoint where left click was down, if left click currently down
left_click_down: Option<WindowPoint>,
/// WindowPoint where middle click was down, if middle click currently down
middle_click_down: Option<WindowPoint>,
/// Vector representing current cursor drag
current_cursor_vector: Option<(WindowPoint, WindowPoint)>,
/// Vector of UIEvent (will be consumed)
Expand Down Expand Up @@ -107,6 +109,7 @@ impl GuiState {
current_cursor_point: WindowPoint::new(0., 0.),
last_cursor_move_frame: 0,
left_click_down: None,
middle_click_down: None,
current_cursor_vector: None,
ui_events: vec![],
selected_squads: (None, vec![]),
Expand Down Expand Up @@ -170,6 +173,10 @@ impl GuiState {
&self.left_click_down
}

pub fn middle_click_down_window_point(&self) -> &Option<WindowPoint> {
&self.middle_click_down
}

pub fn _left_click_down_world_point(&self) -> Option<WorldPoint> {
self.left_click_down
.map(|left_click_down| self.world_point_from_window_point(left_click_down))
Expand Down Expand Up @@ -403,6 +410,10 @@ impl GuiState {
self.set_scene_offset_to(ctx, point);
self.ensure_correct_scene_offset(ctx);
}
GuiStateMessage::SetMiddleClickDown(point) => {
//
self.middle_click_down = *point
}
}
}

Expand Down

0 comments on commit 9165290

Please sign in to comment.