Files
rusty-path-of-building/src/stage.rs
T
faumaray 4118c3943f
CI / check (push) Failing after 7s
Native release / linux (push) Successful in 1m33s
Native release / windows (push) Failing after 9s
Native release / publish (push) Skipped
Release 0.3.6 with a game chooser and native installers
2026-11-27 21:48:45 +03:00

99 lines
2.5 KiB
Rust

use std::sync::Arc;
use winit::window::Window;
use crate::{
args::Game,
chooser::Chooser,
dpi::{PhysicalPoint, PhysicalSize, ScaleFactor},
draw_commands::DrawCommand,
input::{Key, ModifiersState, MouseButton},
installer::Installer,
pob::PathOfBuilding,
};
pub enum StageEvent {
KeyDown { key: Key },
KeyUp { key: Key },
CharacterInput { ch: char },
ModifiersChanged { state: ModifiersState },
MouseDown { button: MouseButton },
MouseUp { button: MouseButton },
MouseWheel { delta: f32 },
MouseMoved { pos: PhysicalPoint<f32> },
Exit,
Resized(PhysicalSize<u32>),
ScaleFactorChanged(f64),
FocusChanged(bool),
HoverChanged(bool),
}
pub enum StageTransition {
StartGame(Game),
ToMain,
ToShutdown,
}
pub struct StageFrameOutput {
pub draw_commands: Vec<DrawCommand>,
pub can_elide: bool,
pub request_redraw: bool,
pub scale_factor: ScaleFactor<f32>,
}
pub enum ActiveStage {
Chooser(Box<Chooser>),
Startup(Installer),
Main(PathOfBuilding),
}
impl ActiveStage {
pub fn update(&mut self) -> anyhow::Result<Option<StageTransition>> {
match self {
Self::Chooser(s) => s.update(),
Self::Startup(s) => s.update(),
Self::Main(s) => s.update(),
}
}
pub fn frame(&mut self) -> anyhow::Result<StageFrameOutput> {
match self {
Self::Chooser(s) => s.frame(),
Self::Startup(s) => s.frame(),
Self::Main(s) => s.frame(),
}
}
pub fn handle_event(&mut self, event: StageEvent) -> anyhow::Result<Option<StageTransition>> {
match self {
Self::Chooser(s) => s.handle_event(event),
Self::Startup(s) => s.handle_event(event),
Self::Main(s) => s.handle_event(event),
}
}
pub fn set_window(&mut self, window: Arc<Window>) {
match self {
Self::Chooser(s) => s.set_window(window),
Self::Startup(s) => s.set_window(window),
Self::Main(s) => s.set_window(window),
}
}
pub fn can_exit(&mut self) -> bool {
match self {
Self::Chooser(_) => true,
Self::Startup(_) => true,
Self::Main(s) => s.can_exit(),
}
}
pub fn clear_pressed(&mut self) {
match self {
Self::Chooser(s) => s.clear_pressed(),
Self::Startup(_) => {}
Self::Main(s) => s.clear_pressed(),
}
}
}