Some other bullshit
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
use bevy::{picking::Pickable, prelude::*, text::FontSourceTemplate, ui::widget::ImageNodeSize};
|
||||
|
||||
use crate::{
|
||||
fighter::{FighterId, manifest::FighterManifest}, menus::{button::FGUiButton, style::FGUiButtonType},
|
||||
fighter::{FighterId, manifest::FighterManifest},
|
||||
menus::{button::FGUiButton, style::FGUiButtonType},
|
||||
};
|
||||
|
||||
#[derive(Component, Clone, FromTemplate)]
|
||||
pub struct CharacterBox {
|
||||
pub fighter_manifest: Handle<FighterManifest>,
|
||||
pub fighter_id: FighterId
|
||||
pub fighter_id: FighterId,
|
||||
}
|
||||
|
||||
impl CharacterBox {
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
pub enum CharacterSelectErrors {
|
||||
|
||||
}
|
||||
pub enum CharacterSelectErrors {}
|
||||
|
||||
@@ -5,8 +5,20 @@ use bevy::{
|
||||
use bevy_egui::egui::accesskit::TextAlign;
|
||||
|
||||
use crate::{
|
||||
AppState, fighter::manifest::{FighterManifest, FighterManifestRegistry}, game_settings::CommonAssets, input::{LocalInputAssignments, LocalInputSource}, menus::{
|
||||
MenuMarker, build_menu_with_props, button::FGUiButton, character_select::{character_box::CharacterBox, token::CharacterSelectToken}, cursor::{FGMenuCursor, MenuCursorInputSource}, errors::MenuErrors::{self, FighterManifestNotFound}, match_config::{MenuMatchConfig, MenuMatchPlayerSlot}, scaling, spawn_menu, style::{FGUiButtonType, FGUiStyle}, wrap_menu,
|
||||
AppState,
|
||||
fighter::manifest::{FighterManifest, FighterManifestRegistry},
|
||||
game_settings::CommonAssets,
|
||||
input::{LocalInputAssignments, LocalInputSource},
|
||||
menus::{
|
||||
MenuMarker, build_menu_with_props,
|
||||
button::FGUiButton,
|
||||
character_select::{character_box::CharacterBox, token::CharacterSelectToken},
|
||||
cursor::{FGMenuCursor, MenuCursorInputSource},
|
||||
errors::MenuErrors::{self, FighterManifestNotFound},
|
||||
match_config::{MenuMatchConfig, MenuMatchPlayerSlot},
|
||||
scaling, spawn_menu,
|
||||
style::{FGUiButtonType, FGUiStyle},
|
||||
wrap_menu,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -142,7 +154,6 @@ pub fn handle_fighter_slot_addition(
|
||||
common_assets: Res<CommonAssets>,
|
||||
styles: Res<Assets<FGUiStyle>>,
|
||||
) {
|
||||
|
||||
for addition in addition.read() {
|
||||
let slot = addition.slot;
|
||||
create_portrait(
|
||||
@@ -155,7 +166,6 @@ pub fn handle_fighter_slot_addition(
|
||||
&addition.input_source,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn css_auto_assign_slots(
|
||||
@@ -220,7 +230,11 @@ pub fn update_start_banner_visibility(
|
||||
config: Res<MenuMatchConfig>,
|
||||
) {
|
||||
let match_ready = config.all_players_ready();
|
||||
commands.entity(banner.into_inner()).insert(if match_ready {Visibility::Visible} else {Visibility::Hidden});
|
||||
commands.entity(banner.into_inner()).insert(if match_ready {
|
||||
Visibility::Visible
|
||||
} else {
|
||||
Visibility::Hidden
|
||||
});
|
||||
}
|
||||
|
||||
pub fn copy_cursor_transform_to_token(
|
||||
@@ -269,4 +283,4 @@ pub fn despawn_tokens(tokens: Query<Entity, With<CharacterSelectToken>>, mut com
|
||||
for token in tokens {
|
||||
commands.entity(token).despawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,16 +7,13 @@ use crate::menus::style::FGUiStyle;
|
||||
#[derive(Component, Clone)]
|
||||
pub struct CharacterSelectToken {
|
||||
pub slot: usize,
|
||||
pub cursor: Entity
|
||||
pub cursor: Entity,
|
||||
}
|
||||
|
||||
impl CharacterSelectToken {
|
||||
pub fn create(cursor: Entity, slot: usize, style: &FGUiStyle) -> impl Bundle {
|
||||
(
|
||||
CharacterSelectToken {
|
||||
slot,
|
||||
cursor
|
||||
},
|
||||
CharacterSelectToken { slot, cursor },
|
||||
Pickable::IGNORE,
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
@@ -26,9 +23,13 @@ impl CharacterSelectToken {
|
||||
},
|
||||
ImageNode {
|
||||
image: style.css_token.handle.handle.clone(),
|
||||
color: style.player_colors.get(slot).copied().unwrap_or(Color::WHITE),
|
||||
color: style
|
||||
.player_colors
|
||||
.get(slot)
|
||||
.copied()
|
||||
.unwrap_or(Color::WHITE),
|
||||
..default()
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+28
-17
@@ -9,7 +9,12 @@ use bevy::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
input::{LocalInputAssignments, LocalInputSource}, menus::{input::{MenuInput, MenuInputState}, scaling, style::FGUiStyle},
|
||||
input::{LocalInputAssignments, LocalInputSource},
|
||||
menus::{
|
||||
input::{MenuInput, MenuInputState},
|
||||
scaling,
|
||||
style::FGUiStyle,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -30,7 +35,7 @@ impl FGMenuCursor {
|
||||
pub fn create_cursor(
|
||||
input_source: MenuCursorInputSource,
|
||||
style: &FGUiStyle,
|
||||
pointer_id: PointerId
|
||||
pointer_id: PointerId,
|
||||
) -> impl Bundle {
|
||||
let circle_icon = style.cursor.handle().clone();
|
||||
(
|
||||
@@ -57,22 +62,22 @@ impl FGMenuCursor {
|
||||
)
|
||||
}
|
||||
pub fn create_shared_cursor(style: &FGUiStyle) -> impl Bundle {
|
||||
Self::create_cursor(
|
||||
MenuCursorInputSource::Any,
|
||||
style,
|
||||
PointerId::Mouse
|
||||
)
|
||||
Self::create_cursor(MenuCursorInputSource::Any, style, PointerId::Mouse)
|
||||
}
|
||||
pub fn create_player_cursor(
|
||||
player_slot: usize,
|
||||
style: &FGUiStyle,
|
||||
input_source: &LocalInputSource,
|
||||
) -> impl Bundle {
|
||||
let pointer_id = if matches!(input_source, LocalInputSource::Keyboard) {PointerId::Mouse} else {PointerId::Custom(Uuid::new_v4())};
|
||||
let pointer_id = if matches!(input_source, LocalInputSource::Keyboard) {
|
||||
PointerId::Mouse
|
||||
} else {
|
||||
PointerId::Custom(Uuid::new_v4())
|
||||
};
|
||||
Self::create_cursor(
|
||||
MenuCursorInputSource::Player(player_slot),
|
||||
style,
|
||||
pointer_id
|
||||
pointer_id,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -81,19 +86,17 @@ impl FGMenuCursor {
|
||||
pub fn copy_mouse_input(
|
||||
mut query: Query<(&FGMenuCursor, &mut PointerLocation, &PointerId)>,
|
||||
assignments: Res<LocalInputAssignments>,
|
||||
mut input_events: MessageReader<Pointer<Move>>
|
||||
mut input_events: MessageReader<Pointer<Move>>,
|
||||
) {
|
||||
|
||||
for event in input_events.read() {
|
||||
if let PointerId::Mouse = event.pointer_id {
|
||||
for (cursor, mut location, _) in query.iter_mut() {
|
||||
let is_mouse = match cursor.input_source {
|
||||
MenuCursorInputSource::Any => true,
|
||||
MenuCursorInputSource::Player(slot) => {
|
||||
assignments.get(slot).map(|(_, source)| {
|
||||
matches!(source, LocalInputSource::Keyboard)
|
||||
}).unwrap_or_default()
|
||||
},
|
||||
MenuCursorInputSource::Player(slot) => assignments
|
||||
.get(slot)
|
||||
.map(|(_, source)| matches!(source, LocalInputSource::Keyboard))
|
||||
.unwrap_or_default(),
|
||||
};
|
||||
|
||||
if is_mouse {
|
||||
@@ -185,7 +188,15 @@ pub fn update_cursor_transform(
|
||||
let camera = camera.into_inner();
|
||||
|
||||
for (mut node, location) in query {
|
||||
let ui_pos = scaling::logical_to_ui_position(location.location.as_ref().map(|d| d.position).unwrap_or_default(), camera, &ui_scale);
|
||||
let ui_pos = scaling::logical_to_ui_position(
|
||||
location
|
||||
.location
|
||||
.as_ref()
|
||||
.map(|d| d.position)
|
||||
.unwrap_or_default(),
|
||||
camera,
|
||||
&ui_scale,
|
||||
);
|
||||
node.left = px(ui_pos.x);
|
||||
node.top = px(ui_pos.y);
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,4 +8,4 @@ pub enum MenuErrors {
|
||||
FighterManifestNotFound,
|
||||
#[error("Match config error: {0:?}")]
|
||||
MatchConfigError(#[from] MenuMatchConfigErrors),
|
||||
}
|
||||
}
|
||||
|
||||
+13
-6
@@ -91,10 +91,14 @@ impl MenuInput {
|
||||
self.accept.accumulate(&other.accept);
|
||||
self.back.accumulate(&other.back);
|
||||
self.start.accumulate(&other.start);
|
||||
self.movement_digital_up.accumulate(&other.movement_digital_up);
|
||||
self.movement_digital_down.accumulate(&other.movement_digital_down);
|
||||
self.movement_digital_left.accumulate(&other.movement_digital_left);
|
||||
self.movement_digital_right.accumulate(&other.movement_digital_right);
|
||||
self.movement_digital_up
|
||||
.accumulate(&other.movement_digital_up);
|
||||
self.movement_digital_down
|
||||
.accumulate(&other.movement_digital_down);
|
||||
self.movement_digital_left
|
||||
.accumulate(&other.movement_digital_left);
|
||||
self.movement_digital_right
|
||||
.accumulate(&other.movement_digital_right);
|
||||
self.movement = self.movement.clamp_length_max(1.0);
|
||||
}
|
||||
}
|
||||
@@ -247,9 +251,12 @@ pub fn sample_menu_inputs(
|
||||
state
|
||||
.inputs
|
||||
.push((LocalInputSource::Keyboard, keyboard_input(&key, &map)));
|
||||
|
||||
|
||||
let mut prev_joystick_states: Vec<(LocalInputSource, MenuJoystickState)> = vec![];
|
||||
std::mem::swap(&mut prev_joystick_states, &mut state.prev_frame_joystick_state);
|
||||
std::mem::swap(
|
||||
&mut prev_joystick_states,
|
||||
&mut state.prev_frame_joystick_state,
|
||||
);
|
||||
|
||||
for (entity, pad) in pads.iter() {
|
||||
let local_source = LocalInputSource::Gamepad(entity);
|
||||
|
||||
+5
-5
@@ -190,7 +190,10 @@ impl Plugin for MenuPlugin {
|
||||
)
|
||||
.add_systems(
|
||||
PreUpdate,
|
||||
(character_select::css_auto_assign_slots, character_select::handle_fighter_slot_addition)
|
||||
(
|
||||
character_select::css_auto_assign_slots,
|
||||
character_select::handle_fighter_slot_addition,
|
||||
)
|
||||
.chain()
|
||||
.run_if(in_state(AppState::CharacterSelect))
|
||||
.run_if(any_with_component::<CharacterSelectScreen>),
|
||||
@@ -214,14 +217,11 @@ impl Plugin for MenuPlugin {
|
||||
OnEnter(AppState::StageSelect),
|
||||
stage_select::setup_stage_select,
|
||||
)
|
||||
.add_observer(stage_select::stage_selected.run_if(in_state(AppState::StageSelect)),
|
||||
)
|
||||
|
||||
.add_observer(stage_select::stage_selected.run_if(in_state(AppState::StageSelect)))
|
||||
.add_systems(
|
||||
OnExit(AppState::StageSelect),
|
||||
(cursor::despawn_cursors, despawn_menu),
|
||||
)
|
||||
|
||||
//---------
|
||||
// STAGE SELECT END
|
||||
//---------
|
||||
|
||||
+26
-6
@@ -48,7 +48,7 @@ pub fn process_inputs(
|
||||
action_state.pressed_actions.clear();
|
||||
let input = menu_inputs.aggregate();
|
||||
let has_direction = input.movement.length() != 0.0;
|
||||
|
||||
|
||||
let mut dir_distances = [
|
||||
(input.movement_digital_up, input.movement.dot(Vec2::Y)),
|
||||
(input.movement_digital_down, input.movement.dot(Vec2::NEG_Y)),
|
||||
@@ -82,12 +82,32 @@ pub fn process_inputs(
|
||||
false
|
||||
};
|
||||
if curr_dir.is_just_pressed() || repeat_press {
|
||||
if input.movement.y > 0.0 { action_state.pressed_actions.insert(DirectionalNavigationAction::Up); }
|
||||
if input.movement.y < 0.0 { action_state.pressed_actions.insert(DirectionalNavigationAction::Down); }
|
||||
if input.movement.x < 0.0 { action_state.pressed_actions.insert(DirectionalNavigationAction::Left); }
|
||||
if input.movement.x > 0.0 { action_state.pressed_actions.insert(DirectionalNavigationAction::Right); }
|
||||
if input.movement.y > 0.0 {
|
||||
action_state
|
||||
.pressed_actions
|
||||
.insert(DirectionalNavigationAction::Up);
|
||||
}
|
||||
if input.movement.y < 0.0 {
|
||||
action_state
|
||||
.pressed_actions
|
||||
.insert(DirectionalNavigationAction::Down);
|
||||
}
|
||||
if input.movement.x < 0.0 {
|
||||
action_state
|
||||
.pressed_actions
|
||||
.insert(DirectionalNavigationAction::Left);
|
||||
}
|
||||
if input.movement.x > 0.0 {
|
||||
action_state
|
||||
.pressed_actions
|
||||
.insert(DirectionalNavigationAction::Right);
|
||||
}
|
||||
}
|
||||
if input.accept.is_pressed() {
|
||||
action_state
|
||||
.pressed_actions
|
||||
.insert(DirectionalNavigationAction::Select);
|
||||
}
|
||||
if input.accept.is_pressed() { action_state.pressed_actions.insert(DirectionalNavigationAction::Select); }
|
||||
}
|
||||
|
||||
const FOCUSED_BORDER: Srgba = bevy::color::palettes::tailwind::BLUE_50;
|
||||
|
||||
+10
-3
@@ -30,8 +30,15 @@ pub fn ui_scaling_system(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn world_to_ui_position(pos: Vec2, camera: &Camera, camera_transform: &GlobalTransform, ui_scale: &UiScale) -> Vec2 {
|
||||
let viewport_position = camera.world_to_viewport(camera_transform, Vec3::new(pos.x, pos.y, 0.0)).unwrap();
|
||||
pub fn world_to_ui_position(
|
||||
pos: Vec2,
|
||||
camera: &Camera,
|
||||
camera_transform: &GlobalTransform,
|
||||
ui_scale: &UiScale,
|
||||
) -> Vec2 {
|
||||
let viewport_position = camera
|
||||
.world_to_viewport(camera_transform, Vec3::new(pos.x, pos.y, 0.0))
|
||||
.unwrap();
|
||||
|
||||
let viewport_rect = camera.logical_viewport_rect().unwrap();
|
||||
|
||||
@@ -46,4 +53,4 @@ pub fn logical_to_ui_position(pos: Vec2, camera: &Camera, ui_scale: &UiScale) ->
|
||||
let ui_position = (pos - viewport_rect.min) / ui_scale.0;
|
||||
|
||||
ui_position
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
AppState, game_settings::CommonAssets, match_loading::initiate_match, menus::{
|
||||
MenuMarker, button::FGUiButton, cursor, match_config::MenuMatchConfig, spawn_menu, stage_select::stage_box::StageBox, style::{FGUiButtonType, FGUiStyle},
|
||||
}, stage::manifest::{StageManifest, StageManifestRegistry},
|
||||
AppState,
|
||||
game_settings::CommonAssets,
|
||||
match_loading::initiate_match,
|
||||
menus::{
|
||||
MenuMarker,
|
||||
button::FGUiButton,
|
||||
cursor,
|
||||
match_config::MenuMatchConfig,
|
||||
spawn_menu,
|
||||
stage_select::stage_box::StageBox,
|
||||
style::{FGUiButtonType, FGUiStyle},
|
||||
},
|
||||
stage::manifest::{StageManifest, StageManifestRegistry},
|
||||
};
|
||||
|
||||
pub mod stage_box;
|
||||
@@ -64,12 +74,16 @@ pub fn stage_selected(
|
||||
query: Query<&StageBox>,
|
||||
mut commands: Commands,
|
||||
mut next_state: ResMut<NextState<AppState>>,
|
||||
mut match_config: ResMut<MenuMatchConfig>
|
||||
mut match_config: ResMut<MenuMatchConfig>,
|
||||
) -> Result {
|
||||
let stage_box = query.get(ev.event_target());
|
||||
if let Ok(stage_box) = stage_box {
|
||||
match_config.stage = Some(stage_box.stage_id);
|
||||
initiate_match(&mut commands, &mut next_state, match_config.to_pending_match()?);
|
||||
initiate_match(
|
||||
&mut commands,
|
||||
&mut next_state,
|
||||
match_config.to_pending_match()?,
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
use bevy::{picking::Pickable, prelude::*, text::FontSourceTemplate, ui::widget::ImageNodeSize};
|
||||
|
||||
use crate::{
|
||||
fighter::{FighterId, manifest::FighterManifest}, menus::{button::FGUiButton, style::FGUiButtonType}, stage::manifest::{StageId, StageManifest},
|
||||
fighter::{FighterId, manifest::FighterManifest},
|
||||
menus::{button::FGUiButton, style::FGUiButtonType},
|
||||
stage::manifest::{StageId, StageManifest},
|
||||
};
|
||||
|
||||
#[derive(Component, Clone, FromTemplate)]
|
||||
pub struct StageBox {
|
||||
pub stage_manifest: Handle<StageManifest>,
|
||||
pub stage_id: StageId
|
||||
pub stage_id: StageId,
|
||||
}
|
||||
|
||||
impl StageBox {
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ron_asset_manager::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::texture_reference::TextureReference;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user