Skip to content

Commit

Permalink
move character_selection to file instead of a folder, limit visibilit…
Browse files Browse the repository at this point in the history
…y of functions in button
  • Loading branch information
cdsupina committed May 26, 2024
1 parent 99d3aae commit 826e4cf
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 1,386 deletions.
2 changes: 1 addition & 1 deletion crates/thetawave_interface/src/character.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::VecDeque, default};
use std::collections::VecDeque;

use bevy_math::Vec2;
use serde::Deserialize;
Expand Down
34 changes: 0 additions & 34 deletions src/states/game.rs

This file was deleted.

3 changes: 0 additions & 3 deletions src/states/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use bevy_asset_loader::standard_dynamic_asset::StandardDynamicAssetCollection;
use leafwing_input_manager::prelude::ActionState;
use thetawave_interface::input::MainMenuExplorer;
use thetawave_interface::input::MenuAction;
use thetawave_interface::input::MenuExplorer;
use thetawave_interface::states::CharacterSelectionCleanup;
use thetawave_interface::states::GameCleanup;
use thetawave_interface::states::GameOverCleanup;
Expand All @@ -20,7 +19,6 @@ use thetawave_interface::states::PauseCleanup;
use thetawave_interface::states::VictoryCleanup;
use thetawave_interface::states::{AppStates, GameStates};

mod game;
mod pause_menu;

use crate::assets::ConsumableAssets;
Expand All @@ -34,7 +32,6 @@ use crate::assets::UiAssets;
use crate::GameEnterSet;
use crate::GameUpdateSet;

use self::game::start_game_system;
use self::pause_menu::{close_pause_menu_system, open_pause_menu_system};
/// Includes systems that handle state transitions for `AppStates` and `GameStates`. Also includes
/// an asset loading state.
Expand Down
23 changes: 12 additions & 11 deletions src/ui/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::assets::UiAssets;
/// `AppStates::MainMenu` to `AppStates::CharacterSelection`, plus possibly a few digressions and
/// sprinkles.
#[derive(Component, Event, Clone, PartialEq, Eq, Copy, Debug)]
pub enum ButtonActionComponent {
pub(super) enum ButtonActionComponent {
CharacterSelectReady(u8),
CharacterSelectJoin,
CharacterSelectRight(u8),
Expand All @@ -37,12 +37,12 @@ pub enum ButtonActionComponent {
QuitGame,
}

pub type ButtonActionEvent = ButtonActionComponent;
pub(super) type ButtonActionEvent = ButtonActionComponent;

impl ButtonActionComponent {
/// The label that will show on the main menu screen for the button representing this
/// option/action
pub fn text(&self) -> Option<&'static str> {
fn text(&self) -> Option<&'static str> {
match self {
Self::EnterCharacterSelection => Some("Start Game"),
Self::EnterOptions => Some("Options"),
Expand All @@ -56,7 +56,7 @@ impl ButtonActionComponent {
}

/// Get input button animations to show on the button
pub fn inputs(
fn get_input_images(
&self,
ui_assets: &UiAssets,
player_input: Option<PlayerInput>, // optional input method (keyboard/gamepad) of the player that the button belongs to
Expand Down Expand Up @@ -92,7 +92,7 @@ impl ButtonActionComponent {

/// External style applied to buttons
/// Returns different styles based the based on the button action
fn external_style(&self) -> Style {
fn get_external_style(&self) -> Style {
match self {
Self::EnterCharacterSelection
| Self::EnterOptions
Expand Down Expand Up @@ -129,7 +129,7 @@ impl ButtonActionComponent {

/// Internal style of the ui inside of the button
/// such as the text and the input symbols
fn internal_style(&self) -> Style {
fn get_internal_style(&self) -> Style {
match self {
Self::EnterCharacterSelection
| Self::EnterOptions
Expand Down Expand Up @@ -192,7 +192,7 @@ impl ButtonActionComponent {

// Handles state changes for buttons. This runs when a user actually
// clicks/whacks enter on a button in the main menu
pub fn button_action_change_state_system(
pub(super) fn button_action_change_state_system(
mut button_event_reader: EventReader<ButtonActionEvent>,
mut next_app_state: ResMut<NextState<AppStates>>,
mut exit: EventWriter<AppExit>,
Expand All @@ -213,7 +213,7 @@ pub fn button_action_change_state_system(
}

/// Extension trait for spawning customized UI elements for Thetawave
pub trait UiButtonChildBuilderExt {
pub(super) trait UiButtonChildBuilderExt {
/// Spawn a Thetawave-stylized menu button
fn spawn_button(
&mut self,
Expand All @@ -234,7 +234,7 @@ impl UiButtonChildBuilderExt for ChildBuilder<'_> {
) {
// Spawn button bundle entity, with a child entity containing the texture
self.spawn(ButtonBundle {
style: action.external_style(),
style: action.get_external_style(),
background_color: BackgroundColor(Color::NONE),
..default()
})
Expand All @@ -246,7 +246,7 @@ impl UiButtonChildBuilderExt for ChildBuilder<'_> {
.spawn(AtlasImageBundle {
image: button_asset.0.into(),
texture_atlas: button_asset.1.into(),
style: action.internal_style(),
style: action.get_internal_style(),
..default()
})
.with_children(|parent| {
Expand All @@ -264,7 +264,8 @@ impl UiButtonChildBuilderExt for ChildBuilder<'_> {
);
}

if let Some(inputs) = action.inputs(ui_assets, player_input.copied()) {
if let Some(inputs) = action.get_input_images(ui_assets, player_input.copied())
{
// Row for all button inputs
parent
.spawn(NodeBundle {
Expand Down
Loading

0 comments on commit 826e4cf

Please sign in to comment.