aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/launch_menu.rs
diff options
context:
space:
mode:
Diffstat (limited to 'apps/fparkan-game/src/launch_menu.rs')
-rw-r--r--apps/fparkan-game/src/launch_menu.rs156
1 files changed, 120 insertions, 36 deletions
diff --git a/apps/fparkan-game/src/launch_menu.rs b/apps/fparkan-game/src/launch_menu.rs
index f11fa954..93b539bc 100644
--- a/apps/fparkan-game/src/launch_menu.rs
+++ b/apps/fparkan-game/src/launch_menu.rs
@@ -13,7 +13,10 @@ use winit::{
window::Window,
};
+mod graphics;
+mod profile;
mod sound;
+use graphics::{GraphicsControl, GraphicsSettings};
use sound::{SoundSettings, Volume};
const EXTENT: [u32; 2] = [960, 540];
@@ -26,6 +29,8 @@ const GAP: usize = 6;
const BACKGROUND: u32 = 0x141c24;
const VOLUME_LEFT: usize = 480;
const VOLUME_WIDTH: usize = 300;
+const GRAPHICS_VALUE_LEFT: usize = 480;
+const RESOLUTION_STEP_WIDTH: usize = 180;
pub(super) struct LaunchMenu {
catalog: MissionCatalog,
@@ -35,6 +40,7 @@ pub(super) struct LaunchMenu {
selected: usize,
pointer: Option<PhysicalPosition<f64>>,
sound: Option<SoundSettings>,
+ graphics: Option<GraphicsSettings>,
}
#[derive(Clone, Copy)]
@@ -46,6 +52,7 @@ enum Screen {
Single,
Settings,
Sound,
+ Graphics,
}
struct Row<'a> {
@@ -60,6 +67,8 @@ enum Action<'a> {
Volume(Volume),
ToggleMusic,
ApplySound,
+ Graphics(GraphicsControl),
+ ApplyGraphics,
Exit,
}
@@ -87,6 +96,7 @@ impl LaunchMenu {
selected: 0,
pointer: None,
sound: None,
+ graphics: None,
})
}
@@ -158,10 +168,16 @@ impl LaunchMenu {
action: Action::Launch(&mission.key),
}));
}
- Screen::Settings => rows.push(Row {
- label: "Звук",
- action: Action::Open(Screen::Sound),
- }),
+ Screen::Settings => rows.extend([
+ Row {
+ label: "Графика",
+ action: Action::Open(Screen::Graphics),
+ },
+ Row {
+ label: "Звук",
+ action: Action::Open(Screen::Sound),
+ },
+ ]),
Screen::Sound => {
if self.sound.is_some() {
rows.extend([
@@ -184,6 +200,28 @@ impl LaunchMenu {
]);
}
}
+ Screen::Graphics => {
+ if self.graphics.is_some() {
+ rows.extend([
+ Row {
+ label: "Разрешение",
+ action: Action::Graphics(GraphicsControl::Resolution),
+ },
+ Row {
+ label: "Режим экрана",
+ action: Action::Graphics(GraphicsControl::WindowMode),
+ },
+ Row {
+ label: "Отражения на воде",
+ action: Action::Graphics(GraphicsControl::Reflections),
+ },
+ Row {
+ label: "Применить",
+ action: Action::ApplyGraphics,
+ },
+ ]);
+ }
+ }
}
if let Some(parent) = self.parent() {
rows.push(Row {
@@ -200,11 +238,11 @@ impl LaunchMenu {
Screen::Start | Screen::Settings => Some(Screen::Main),
Screen::Campaigns | Screen::Single => Some(Screen::Start),
Screen::Campaign(_) => Some(Screen::Campaigns),
- Screen::Sound => Some(Screen::Settings),
+ Screen::Sound | Screen::Graphics => Some(Screen::Settings),
}
}
- fn enter(&mut self, screen: Screen) -> MenuEvent {
+ fn enter(&mut self, screen: Screen, window: &Window) -> MenuEvent {
self.sound = if matches!(screen, Screen::Sound) {
SoundSettings::open(&self.root)
.map_err(|error| eprintln!("read Iron_3D.ini: {error}"))
@@ -212,14 +250,21 @@ impl LaunchMenu {
} else {
None
};
+ self.graphics = if matches!(screen, Screen::Graphics) {
+ GraphicsSettings::open(&self.root, window)
+ .map_err(|error| eprintln!("read Iron_3D.ini: {error}"))
+ .ok()
+ } else {
+ None
+ };
self.screen = screen;
self.selected = 0;
MenuEvent::Redraw
}
- fn activate(&mut self, index: usize) -> MenuEvent {
+ fn activate(&mut self, index: usize, window: &Window) -> MenuEvent {
match self.rows().get(index).map(|row| row.action) {
- Some(Action::Open(screen)) => self.enter(screen),
+ Some(Action::Open(screen)) => self.enter(screen, window),
Some(Action::Launch(key)) => MenuEvent::Launch(key.to_string()),
Some(Action::ToggleMusic) => {
if let Some(sound) = &mut self.sound {
@@ -236,12 +281,30 @@ impl LaunchMenu {
}
MenuEvent::Redraw
}
+ Some(Action::Graphics(control)) => self.change_graphics(control, true),
+ Some(Action::ApplyGraphics) => {
+ if let Some(graphics) = &mut self.graphics {
+ if let Err(error) = graphics.apply(&self.root, window) {
+ eprintln!("apply graphics settings: {error}");
+ graphics.status = "Не удалось применить настройки";
+ }
+ }
+ MenuEvent::Redraw
+ }
Some(Action::Exit) => MenuEvent::Exit,
Some(Action::Volume(_)) | None => MenuEvent::None,
}
}
- pub(super) fn input(&mut self, event: &WindowEvent, size: PhysicalSize<u32>) -> MenuEvent {
+ fn change_graphics(&mut self, control: GraphicsControl, forward: bool) -> MenuEvent {
+ if let Some(graphics) = &mut self.graphics {
+ graphics.change(control, forward);
+ }
+ MenuEvent::Redraw
+ }
+
+ pub(super) fn input(&mut self, event: &WindowEvent, window: &Window) -> MenuEvent {
+ let size = window.inner_size();
match event {
WindowEvent::KeyboardInput { event, .. } if event.state == ElementState::Pressed => {
match event.logical_key {
@@ -255,28 +318,30 @@ impl LaunchMenu {
self.selected = (self.selected + step) % count;
MenuEvent::Redraw
}
- Key::Named(NamedKey::Enter) if !event.repeat => self.activate(self.selected),
+ Key::Named(NamedKey::Enter) if !event.repeat => {
+ self.activate(self.selected, window)
+ }
Key::Named(NamedKey::ArrowLeft | NamedKey::ArrowRight) => {
- let Some(Action::Volume(volume)) =
- self.rows().get(self.selected).map(|row| row.action)
- else {
- return MenuEvent::None;
- };
- if let Some(sound) = &mut self.sound {
- let step = if event.logical_key == Key::Named(NamedKey::ArrowLeft) {
- -1
- } else {
- 1
- };
- sound.set_volume(
- volume,
- sound.volume(volume).saturating_add_signed(step),
- );
+ let forward = event.logical_key == Key::Named(NamedKey::ArrowRight);
+ match self.rows().get(self.selected).map(|row| row.action) {
+ Some(Action::Volume(volume)) => {
+ if let Some(sound) = &mut self.sound {
+ let step = if forward { 1 } else { -1 };
+ sound.set_volume(
+ volume,
+ sound.volume(volume).saturating_add_signed(step),
+ );
+ }
+ MenuEvent::Redraw
+ }
+ Some(Action::Graphics(control)) => {
+ self.change_graphics(control, forward)
+ }
+ _ => MenuEvent::None,
}
- MenuEvent::Redraw
}
Key::Named(NamedKey::Escape) if !event.repeat => match self.parent() {
- Some(parent) => self.enter(parent),
+ Some(parent) => self.enter(parent, window),
None => MenuEvent::Exit,
},
_ => MenuEvent::None,
@@ -323,7 +388,16 @@ impl LaunchMenu {
}
return MenuEvent::None;
}
- self.activate(index)
+ if let Some(Action::Graphics(GraphicsControl::Resolution)) =
+ self.rows().get(index).map(|row| row.action)
+ {
+ let center = (GRAPHICS_VALUE_LEFT + RESOLUTION_STEP_WIDTH / 2) as f64;
+ return self.change_graphics(
+ GraphicsControl::Resolution,
+ self.pointer_x(size).is_some_and(|x| x >= center),
+ );
+ }
+ self.activate(index, window)
}
WindowEvent::MouseInput {
state: ElementState::Released,
@@ -389,6 +463,7 @@ impl LaunchMenu {
Screen::Single => "Одиночные миссии",
Screen::Settings => "Настройки",
Screen::Sound => "Звук",
+ Screen::Graphics => "Графика",
};
self.text(&mut frame, title, [LEFT, 57], 2)?;
let rows = self.rows();
@@ -427,16 +502,25 @@ impl LaunchMenu {
_ => {}
}
}
- }
- if matches!(self.screen, Screen::Sound) {
- let status = self
- .sound
- .as_ref()
- .map_or("Не удалось прочитать настройки", |sound| sound.status);
- if !status.is_empty() {
- self.text(&mut frame, status, [LEFT + 20, TOP + ROW_HEIGHT * 5 + 9], 1)?;
+ if let (Some(graphics), Action::Graphics(control)) = (&self.graphics, row.action) {
+ let mut left = GRAPHICS_VALUE_LEFT;
+ if matches!(control, GraphicsControl::Resolution) {
+ self.text(&mut frame, "<", [left, top + 9], 1)?;
+ self.text(&mut frame, ">", [left + RESOLUTION_STEP_WIDTH, top + 9], 1)?;
+ left += 32;
+ }
+ self.text(&mut frame, &graphics.value(control), [left, top + 9], 1)?;
}
}
+ let status = match self.screen {
+ Screen::Sound => self.sound.as_ref().map(|sound| sound.status),
+ Screen::Graphics => self.graphics.as_ref().map(|graphics| graphics.status),
+ _ => Some(""),
+ }
+ .unwrap_or("Не удалось прочитать настройки");
+ if !status.is_empty() {
+ self.text(&mut frame, status, [LEFT + 20, TOP + ROW_HEIGHT * 5 + 9], 1)?;
+ }
Ok(frame)
}