aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/fparkan-game/src/factory_menu.rs254
-rw-r--r--apps/fparkan-game/src/main.rs10
-rw-r--r--apps/fparkan-game/src/mission_overlay.rs12
-rw-r--r--apps/fparkan-game/src/robot_designer.rs74
4 files changed, 314 insertions, 36 deletions
diff --git a/apps/fparkan-game/src/factory_menu.rs b/apps/fparkan-game/src/factory_menu.rs
index 8f307cfc..743a438a 100644
--- a/apps/fparkan-game/src/factory_menu.rs
+++ b/apps/fparkan-game/src/factory_menu.rs
@@ -1,16 +1,20 @@
+#[cfg(windows)]
+use super::robot_designer::RobotDesignerPanel;
use super::{
append_environment_gradient_material, append_environment_range, quad_indices,
screen_tl_quad_vertices_pixels, world_pipeline_state, DirectoryVfs, EnvironmentGpuRange,
LegacyBlendMode, LegacyDepthMode, StaticPreviewScene, StaticVulkanApp, VulkanSmokeRenderer,
VulkanStaticTexture,
};
+use fparkan_assets::designer_screen::{self, DesignerAction, PART_ROWS};
use fparkan_assets::factory_projects::{
hit_test, FactoryProjectAction, FactoryProjectImages, EXTENT, ORIGIN, PROJECT_SLOTS,
};
+use fparkan_runtime::{factory_project_components, Engine};
use fparkan_world::ObjectHandle;
use std::{ops::Range, path::Path};
use winit::{
- event::{ElementState, MouseButton, WindowEvent},
+ event::{ElementState, MouseButton, MouseScrollDelta, WindowEvent},
keyboard::KeyCode,
};
@@ -22,10 +26,27 @@ pub(super) struct FactoryChoice {
}
pub(super) struct FactoryMenu {
- choices: Vec<FactoryChoice>,
+ pub(super) choices: Vec<FactoryChoice>,
selected: usize,
cursor: [f32; 2],
pressed: Option<usize>,
+ pub(super) designer: Option<DesignerSession>,
+}
+
+pub(super) struct DesignerSession {
+ pub(super) slots: Range<usize>,
+ pub(super) selected: Option<usize>,
+ pub(super) first_part: usize,
+ pub(super) hover: Option<DesignerAction>,
+ pub(super) dirty: bool,
+}
+
+impl DesignerSession {
+ fn point(&mut self, cursor: [f32; 2]) {
+ let next = designer_screen::hit_test(cursor, self.slots.len(), self.selected.is_some());
+ self.dirty |= next != self.hover;
+ self.hover = next;
+ }
}
impl FactoryMenu {
@@ -36,6 +57,7 @@ impl FactoryMenu {
selected: 0,
cursor: [f32::NAN; 2],
pressed: None,
+ designer: None,
}
}
@@ -64,6 +86,39 @@ impl FactoryMenu {
start..start + count
}
+ fn open_designer(&mut self) {
+ let mut designer = DesignerSession {
+ slots: self.visible_slots(),
+ selected: None,
+ first_part: 0,
+ hover: None,
+ dirty: true,
+ };
+ designer.point(self.cursor);
+ self.designer = Some(designer);
+ }
+
+ fn designer_action(&mut self, action: DesignerAction) {
+ let Some(designer) = &mut self.designer else {
+ return;
+ };
+ match action {
+ DesignerAction::Project(slot) if slot < designer.slots.len() => {
+ designer.selected = Some(slot);
+ designer.first_part = 0;
+ designer.dirty = true;
+ }
+ DesignerAction::Send => {
+ if let Some(slot) = designer.selected {
+ self.selected = designer.slots.start + slot;
+ self.designer = None;
+ }
+ }
+ DesignerAction::Exit => self.designer = None,
+ _ => {}
+ }
+ }
+
pub(super) fn title(&self) -> String {
let choice = self.selected();
let factory = choice.factory.map_or_else(
@@ -83,6 +138,8 @@ pub(super) struct FactoryProjectPanel {
images: FactoryProjectImages,
range: EnvironmentGpuRange,
displayed: Option<ProjectPicture>,
+ #[cfg(windows)]
+ designer: Option<RobotDesignerPanel>,
}
#[derive(PartialEq, Eq)]
@@ -96,45 +153,64 @@ struct ProjectPicture {
impl FactoryProjectPanel {
pub(super) fn load(root: &Path, preview: &mut StaticPreviewScene) -> Result<Self, String> {
let images = FactoryProjectImages::load(&DirectoryVfs::new(root))?;
- let material = append_environment_gradient_material(&mut preview.materials)?;
- preview.materials[material].screen_tl = true;
- preview.materials[material].sky_far_depth = false;
- preview.materials[material].texture =
- texture(vec![0; (EXTENT[0] * EXTENT[1] * 4) as usize]);
- let half = EXTENT.map(|dimension| dimension as f32 * 0.5);
- let vertices = screen_tl_quad_vertices_pixels(
- [ORIGIN[0] as f32 + half[0], ORIGIN[1] as f32 + half[1]],
- half[0],
- half[1],
- [640.0, 480.0],
- [1.0; 3],
- 1.0,
- [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]],
- );
- let range = append_environment_range(
- &mut preview.mesh,
- material,
- vertices.to_vec(),
- quad_indices(1)?,
- world_pipeline_state(LegacyBlendMode::SourceAlpha, LegacyDepthMode::Disabled),
+ let range = append_picture(
+ preview,
+ EXTENT,
+ [
+ ORIGIN[0] as f32,
+ ORIGIN[1] as f32,
+ EXTENT[0] as f32,
+ EXTENT[1] as f32,
+ ],
)?;
+ #[cfg(windows)]
+ let designer = RobotDesignerPanel::load(root, preview)
+ .map(Some)
+ .unwrap_or_else(|error| {
+ eprintln!("robot_designer_unavailable reason={error}");
+ None
+ });
Ok(Self {
images,
range,
displayed: None,
+ #[cfg(windows)]
+ designer,
})
}
- pub(super) fn range_index(&self) -> usize {
- self.range.range_index
+ pub(super) fn designer_available(&self) -> bool {
+ #[cfg(windows)]
+ {
+ self.designer.is_some()
+ }
+ #[cfg(not(windows))]
+ {
+ false
+ }
+ }
+
+ pub(super) fn ranges(&self) -> impl Iterator<Item = usize> {
+ #[cfg(windows)]
+ let designer = self.designer.as_ref().map(RobotDesignerPanel::range_index);
+ #[cfg(not(windows))]
+ let designer = None;
+ std::iter::once(self.range.range_index).chain(designer)
}
pub(super) fn draw(
&mut self,
renderer: &mut VulkanSmokeRenderer,
- menu: Option<&mut FactoryMenu>,
+ mut menu: Option<&mut FactoryMenu>,
+ engine: Option<&Engine>,
) -> Result<(), String> {
- if let Some(menu) = menu {
+ #[cfg(windows)]
+ if let Some(designer) = &mut self.designer {
+ designer.draw(renderer, menu.as_deref_mut(), engine)?;
+ }
+ #[cfg(not(windows))]
+ let _ = (&mut menu, engine);
+ if let Some(menu) = menu.filter(|menu| menu.designer.is_none()) {
let slots = menu.visible_slots();
let count = slots.len();
let selected = menu.selected - slots.start;
@@ -147,9 +223,15 @@ impl FactoryProjectPanel {
&& picture.name == *name
});
if !unchanged {
- let image = self.images.paint(count, selected, pressed, name)?;
+ let image =
+ self.images
+ .paint(count, selected, pressed, name, self.designer_available())?;
renderer
- .update_material_texture(self.range.material_index, 0, &texture(image.rgba8))
+ .update_material_texture(
+ self.range.material_index,
+ 0,
+ &picture_texture(EXTENT, image.rgba8),
+ )
.map_err(|error| error.to_string())?;
self.displayed = Some(ProjectPicture {
count,
@@ -180,6 +262,17 @@ impl StaticVulkanApp {
return false;
};
if state == ElementState::Pressed && !repeat && !self.mission_paused {
+ if menu.designer.is_some() {
+ match code {
+ KeyCode::Escape => menu.designer_action(DesignerAction::Exit),
+ KeyCode::Enter | KeyCode::NumpadEnter => {
+ menu.designer_action(DesignerAction::Send)
+ }
+ _ => {}
+ }
+ self.update_mission_title();
+ return true;
+ }
match code {
KeyCode::ArrowUp => menu.navigate(true),
KeyCode::ArrowDown => menu.navigate(false),
@@ -198,6 +291,11 @@ impl StaticVulkanApp {
}
pub(super) fn handle_factory_pointer(&mut self, event: &WindowEvent) -> bool {
+ let designer_available = self
+ .overlay
+ .factory_projects
+ .as_ref()
+ .is_some_and(FactoryProjectPanel::designer_available);
let Some(menu) = &mut self.factory_menu else {
return false;
};
@@ -210,19 +308,54 @@ impl StaticVulkanApp {
position.x as f32 * 640.0 / size.width as f32,
position.y as f32 * 480.0 / size.height as f32,
];
+ if let Some(designer) = &mut menu.designer {
+ designer.point(menu.cursor);
+ }
}
}
true
}
WindowEvent::CursorLeft { .. } | WindowEvent::Focused(false) => {
menu.cursor = [f32::NAN; 2];
+ if let Some(designer) = &mut menu.designer {
+ designer.point(menu.cursor);
+ }
false
}
+ WindowEvent::MouseWheel { delta, .. } if menu.designer.is_some() => {
+ let designer = menu.designer.as_mut().expect("the designer is open");
+ if let Some(parts) = designer.selected.and_then(|slot| {
+ let choice = &menu.choices[designer.slots.start + slot];
+ factory_project_components(self.mission_engine.as_ref()?, choice.scheme)
+ }) {
+ let y = match delta {
+ MouseScrollDelta::LineDelta(_, y) => *y,
+ MouseScrollDelta::PixelDelta(point) => point.y as f32,
+ };
+ if y == 0.0 {
+ return true;
+ }
+ let first_part = designer
+ .first_part
+ .saturating_add_signed(-y.signum() as isize)
+ .min(parts.len().saturating_sub(PART_ROWS));
+ designer.dirty |= designer.first_part != first_part;
+ designer.first_part = first_part;
+ }
+ true
+ }
WindowEvent::MouseInput { state, button, .. } => {
if *state == ElementState::Pressed
&& *button == MouseButton::Left
&& !self.mission_paused
{
+ if let Some(designer) = &menu.designer {
+ if let Some(action) = designer.hover {
+ menu.designer_action(action);
+ self.update_mission_title();
+ }
+ return true;
+ }
let slots = menu.visible_slots();
match hit_test(menu.cursor, slots.len()) {
Some(FactoryProjectAction::Select(index)) => {
@@ -231,6 +364,10 @@ impl StaticVulkanApp {
self.update_mission_title();
}
Some(FactoryProjectAction::Build) => self.player_build_pressed = true,
+ Some(FactoryProjectAction::Designer) if designer_available => {
+ menu.open_designer()
+ }
+ Some(FactoryProjectAction::Designer) => {}
None => {}
}
}
@@ -241,10 +378,38 @@ impl StaticVulkanApp {
}
}
-fn texture(rgba8: Vec<u8>) -> VulkanStaticTexture {
+pub(super) fn append_picture(
+ preview: &mut StaticPreviewScene,
+ extent: [u32; 2],
+ [x, y, width, height]: [f32; 4],
+) -> Result<EnvironmentGpuRange, String> {
+ let material = append_environment_gradient_material(&mut preview.materials)?;
+ preview.materials[material].screen_tl = true;
+ preview.materials[material].sky_far_depth = false;
+ preview.materials[material].texture =
+ picture_texture(extent, vec![0; (extent[0] * extent[1] * 4) as usize]);
+ let vertices = screen_tl_quad_vertices_pixels(
+ [x + width * 0.5, y + height * 0.5],
+ width * 0.5,
+ height * 0.5,
+ [640.0, 480.0],
+ [1.0; 3],
+ 1.0,
+ [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]],
+ );
+ append_environment_range(
+ &mut preview.mesh,
+ material,
+ vertices.to_vec(),
+ quad_indices(1)?,
+ world_pipeline_state(LegacyBlendMode::SourceAlpha, LegacyDepthMode::Disabled),
+ )
+}
+
+pub(super) fn picture_texture([width, height]: [u32; 2], rgba8: Vec<u8>) -> VulkanStaticTexture {
VulkanStaticTexture {
- width: EXTENT[0],
- height: EXTENT[1],
+ width,
+ height,
rgba8,
mip_levels: Vec::new(),
}
@@ -273,4 +438,29 @@ mod tests {
menu.navigate(false);
assert_eq!(menu.visible_slots(), 6..8);
}
+
+ #[test]
+ fn previewing_a_project_changes_the_factory_selection_only_on_transfer() {
+ let mut menu = FactoryMenu::new(
+ (0..2)
+ .map(|scheme| FactoryChoice {
+ factory: None,
+ scheme,
+ name: format!("{scheme}.dat"),
+ })
+ .collect(),
+ );
+ menu.open_designer();
+ menu.designer_action(DesignerAction::Send);
+ assert!(menu.designer.is_some());
+ menu.designer_action(DesignerAction::Project(1));
+ menu.designer_action(DesignerAction::Exit);
+ assert_eq!(menu.selected().scheme, 0);
+
+ menu.open_designer();
+ menu.designer_action(DesignerAction::Project(1));
+ menu.designer_action(DesignerAction::Send);
+ assert!(menu.designer.is_none());
+ assert_eq!(menu.selected().scheme, 1);
+ }
}
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs
index 65f8bc59..4b5734b0 100644
--- a/apps/fparkan-game/src/main.rs
+++ b/apps/fparkan-game/src/main.rs
@@ -42,6 +42,8 @@ mod player_service;
mod projectile_render;
mod projectile_sound;
mod projectile_trail;
+#[cfg(windows)]
+mod robot_designer;
mod shield_effects;
mod shot_sound;
use mission_loading::{MissionLoading, Stage as LoadingStage};
@@ -10830,7 +10832,13 @@ impl StaticVulkanApp {
Some("Завод — нет подходящих схем".into());
None
}
- 1 if !remote => choices.pop(),
+ 1 if !remote
+ && !self.overlay.factory_projects.as_ref().is_some_and(
+ factory_menu::FactoryProjectPanel::designer_available,
+ ) =>
+ {
+ choices.pop()
+ }
_ => {
self.factory_menu = Some(FactoryMenu::new(choices));
self.pressed_keys.clear();
diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs
index d6c0a242..ee3c2425 100644
--- a/apps/fparkan-game/src/mission_overlay.rs
+++ b/apps/fparkan-game/src/mission_overlay.rs
@@ -18,7 +18,7 @@ pub(super) use fparkan_assets::ui_sprite::source_over;
pub(super) struct MissionOverlay {
pub(super) satellite_map: Option<SatelliteMap>,
dial: Option<CockpitDial>,
- factory_projects: Option<FactoryProjectPanel>,
+ pub(super) factory_projects: Option<FactoryProjectPanel>,
pub(super) radar: Option<CockpitRadarHud>,
#[cfg(windows)]
pub(super) hints: Option<MissionHints>,
@@ -138,7 +138,9 @@ impl MissionOverlay {
}
}
if let Some(panel) = &self.factory_projects {
- remove(panel.range_index(), ranges, counts);
+ for range in panel.ranges() {
+ remove(range, ranges, counts);
+ }
}
#[cfg(windows)]
if let Some(hints) = &self.hints {
@@ -230,7 +232,11 @@ impl StaticVulkanApp {
help.draw(renderer, &mut self.mesh, frame.viewport)?;
}
if let Some(panel) = &mut self.overlay.factory_projects {
- panel.draw(renderer, self.factory_menu.as_mut())?;
+ panel.draw(
+ renderer,
+ self.factory_menu.as_mut(),
+ self.mission_engine.as_ref(),
+ )?;
}
Ok(())
}
diff --git a/apps/fparkan-game/src/robot_designer.rs b/apps/fparkan-game/src/robot_designer.rs
new file mode 100644
index 00000000..80005b89
--- /dev/null
+++ b/apps/fparkan-game/src/robot_designer.rs
@@ -0,0 +1,74 @@
+use super::{
+ factory_menu::{append_picture, picture_texture, FactoryMenu},
+ DirectoryVfs, EnvironmentGpuRange, StaticPreviewScene, VulkanSmokeRenderer,
+};
+use fparkan_assets::designer_screen::{DesignerLabels, DesignerPicture, DesignerScreen, EXTENT};
+use fparkan_platform_winit::text::StringResources;
+use fparkan_runtime::{factory_project_components, Engine};
+use std::path::Path;
+
+pub(super) struct RobotDesignerPanel {
+ assets: DesignerScreen,
+ range: EnvironmentGpuRange,
+}
+
+impl RobotDesignerPanel {
+ pub(super) fn load(root: &Path, preview: &mut StaticPreviewScene) -> Result<Self, String> {
+ let strings = StringResources::open(&root.join("iron3d.dll"))?;
+ let read = |id| {
+ strings
+ .get(id)
+ .ok_or_else(|| format!("missing designer label {id:#06x}"))
+ };
+ let assets = DesignerScreen::load(
+ &DirectoryVfs::new(root),
+ DesignerLabels {
+ title: read(0x5e7)?,
+ recent: read(0x616)?,
+ send: read(0x184e)?,
+ exit: read(0x615)?,
+ },
+ )?;
+ let range = append_picture(preview, EXTENT, [0.0, 0.0, 640.0, 480.0])?;
+ Ok(Self { assets, range })
+ }
+
+ pub(super) fn range_index(&self) -> usize {
+ self.range.range_index
+ }
+
+ pub(super) fn draw(
+ &mut self,
+ renderer: &mut VulkanSmokeRenderer,
+ menu: Option<&mut FactoryMenu>,
+ engine: Option<&Engine>,
+ ) -> Result<(), String> {
+ let visible = menu.as_ref().is_some_and(|menu| menu.designer.is_some());
+ if let Some(menu) = menu {
+ if let Some(designer) = menu.designer.as_mut().filter(|view| view.dirty) {
+ let project = designer.selected.and_then(|slot| {
+ let choice = &menu.choices[designer.slots.start + slot];
+ let parts = factory_project_components(engine?, choice.scheme)?;
+ Some((slot, choice.name.as_str(), parts))
+ });
+ let image = self.assets.paint(DesignerPicture {
+ count: designer.slots.len(),
+ project,
+ first_part: designer.first_part,
+ hover: designer.hover,
+ })?;
+ renderer
+ .update_material_texture(
+ self.range.material_index,
+ 0,
+ &picture_texture(EXTENT, image.rgba8),
+ )
+ .map_err(|error| error.to_string())?;
+ designer.dirty = false;
+ }
+ }
+ renderer
+ .set_draw_range_index_count(self.range.range_index, if visible { 6 } else { 0 })
+ .map_err(|error| error.to_string())
+ }
+}