From e3fd358e800ef18f27d44c6eb499275d561bdef8 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 2 Feb 2024 22:19:06 -0800 Subject: [PATCH] Added more ui scenes --- content/config.toml | 2 + content/flying.rhai | 3 + content/landed.rhai | 14 ++- content/outfitter.rhai | 187 ++++++++++++++++++++++++++++++ crates/content/src/part/config.rs | 20 +++- 5 files changed, 220 insertions(+), 6 deletions(-) create mode 100644 content/flying.rhai create mode 100644 content/outfitter.rhai diff --git a/content/config.toml b/content/config.toml index 7d7c45e..4bcdef6 100644 --- a/content/config.toml +++ b/content/config.toml @@ -40,3 +40,5 @@ zoom_max = 2000.0 # TODO: move to user config file ui_scale = 2 ui_landed_scene = "landed.rhai" +ui_flying_scene = "flying.rhai" +ui_outfitter_scene = "outfitter.rhai" diff --git a/content/flying.rhai b/content/flying.rhai new file mode 100644 index 0000000..d14bbd1 --- /dev/null +++ b/content/flying.rhai @@ -0,0 +1,3 @@ +fn init(state) { return []; } +fn hover(element, hover_state) {} +fn click(element, click_state) {} \ No newline at end of file diff --git a/content/landed.rhai b/content/landed.rhai index e59a39f..3b4b1e8 100644 --- a/content/landed.rhai +++ b/content/landed.rhai @@ -60,8 +60,12 @@ fn hover(element, hover_state) { } } -//fn click(scene, name) { -// if name = "button" { -// return SceneAction::Outfitter(); -// } -//} \ No newline at end of file +fn click(element, click_state) { + if !click_state { + return SceneAction::None; + } + + if element.has_name("button") { + return SceneAction::SceneOutfitter; + } +} \ No newline at end of file diff --git a/content/outfitter.rhai b/content/outfitter.rhai new file mode 100644 index 0000000..b66d312 --- /dev/null +++ b/content/outfitter.rhai @@ -0,0 +1,187 @@ + +fn init(state) { + let se_box = SpriteBuilder( + "se_box", + "ui::outfitterbox", + Rect( + -1.0, -1.0, 202.345, 133.409, + SpriteAnchor::SouthWest, + SpriteAnchor::SouthWest + ) + ); + + let exit_text = TextBoxBuilder( + "exit_text", + 10.0, 10.0, TextBoxFont::Serif, TextBoxJustify::Center, + Rect( + 122.71, 48.0, 51.0, 12.0, + SpriteAnchor::NorthWest, + SpriteAnchor::SouthWest + ) + ); + exit_text.set_text(state.planet_name); + + let exit_button = SpriteBuilder( + "exit_button", + "ui::button", + Rect( + 113.35, 52.0, 69.8, 18.924, + SpriteAnchor::NorthWest, + SpriteAnchor::SouthWest + ) + ); + + + + + + let ship_bg = SpriteBuilder( + "ship_bg", + "ui::outfitter-ship-bg", + Rect( + 16.0, -16.0, 190.0, 353.0, + SpriteAnchor::NorthWest, + SpriteAnchor::NorthWest + ) + ); + + let ship_thumb = SpriteBuilder( + "ship_thumb", + "icon::gypsum", + Rect( + 111.0, -95.45, 90.0, 90.0, + SpriteAnchor::Center, + SpriteAnchor::NorthWest + ) + ); + + let ship_name = TextBoxBuilder( + "ship_name", + 10.0, 10.0, TextBoxFont::Serif, TextBoxJustify::Center, + Rect( + 111.0, -167.27, 145.0, 10.0, + SpriteAnchor::Center, + SpriteAnchor::NorthWest + ) + ); + ship_name.set_text(state.planet_name); + + let ship_type = TextBoxBuilder( + "ship_type", + 7.0, 8.5, TextBoxFont::SansSerif, TextBoxJustify::Center, + Rect( + 111.0, -178.0, 145.0, 8.5, + SpriteAnchor::Center, + SpriteAnchor::NorthWest + ) + ); + ship_type.set_text(state.planet_name); + + let ship_stats = TextBoxBuilder( + "ship_stats", + 7.0, 8.5, TextBoxFont::Monospace, TextBoxJustify::Left, + Rect( + 38.526, -192.332, 144.948, 154.5, + SpriteAnchor::NorthWest, + SpriteAnchor::NorthWest, + ) + ); + ship_stats.set_text(state.planet_name); + + + + + + + + let outfit_bg = SpriteBuilder( + "outfit_bg", + "ui::outfitter-outfit-bg", + Rect( + -16.0, -16.0, 300.0, 480.0, + SpriteAnchor::NorthEast, + SpriteAnchor::NorthEast + ) + ); + + let outfit_thumb = SpriteBuilder( + "outfit_thumb", + "icon::engine", + Rect( + -166.0, -109.0, 90.0, 90.0, + SpriteAnchor::Center, + SpriteAnchor::NorthEast + ) + ); + + let outfit_name = TextBoxBuilder( + "outfit_name", + 16.0, 16.0, TextBoxFont::Serif, TextBoxJustify::Left, + Rect( + -312.0, -20.0, 200.0, 16.0, + SpriteAnchor::NorthWest, + SpriteAnchor::NorthEast, + ) + ); + outfit_name.set_text(state.planet_name); + + let outfit_desc = TextBoxBuilder( + "outfit_desc", + 7.0, 8.5, TextBoxFont::SansSerif, TextBoxJustify::Left, + Rect( + -166.0, -219.0, 260.0, 78.0, + SpriteAnchor::Center, + SpriteAnchor::NorthEast, + ) + ); + outfit_desc.set_text(state.planet_name); + + let outfit_stats = TextBoxBuilder( + "outfit_stats", + 7.0, 8.5, TextBoxFont::Monospace, TextBoxJustify::Left, + Rect( + -295.0, -271.0, 164.0, 216.0, + SpriteAnchor::NorthWest, + SpriteAnchor::NorthEast, + ) + ); + outfit_stats.set_text(state.planet_name); + + return [ + ship_bg, + ship_thumb, + ship_name, + ship_type, + ship_stats, + + outfit_bg, + outfit_thumb, + outfit_name, + outfit_desc, + outfit_stats, + + se_box, + exit_button, + exit_text + ]; +} + +fn hover(element, hover_state) { + if element.has_name("exit_button") { + if hover_state { + element.take_edge("on:top", 0.1); + } else { + element.take_edge("off:top", 0.1); + } + } +} + +fn click(element, click_state) { + if !click_state { + return SceneAction::None; + } + + if element.has_name("exit_button") { + return SceneAction::SceneLanded; + } +} \ No newline at end of file diff --git a/crates/content/src/part/config.rs b/crates/content/src/part/config.rs index 5822271..451360d 100644 --- a/crates/content/src/part/config.rs +++ b/crates/content/src/part/config.rs @@ -20,7 +20,9 @@ pub(crate) mod syntax { pub zoom_min: f32, pub zoom_max: f32, pub ui_scale: f32, + pub ui_flying_scene: PathBuf, pub ui_landed_scene: PathBuf, + pub ui_outfitter_scene: PathBuf, } impl Config { @@ -61,6 +63,14 @@ pub(crate) mod syntax { .compile_file(content_root.join(self.ui_landed_scene)) .with_context(|| format!("while loading `landed` scene")) .with_context(|| format!("while loading config"))?; + let ui_outfitter_scene = engine + .compile_file(content_root.join(self.ui_outfitter_scene)) + .with_context(|| format!("while loading `outfitter` scene")) + .with_context(|| format!("while loading config"))?; + let ui_flying_scene = engine + .compile_file(content_root.join(self.ui_flying_scene)) + .with_context(|| format!("while loading `flying` scene")) + .with_context(|| format!("while loading config"))?; return Ok(super::Config { sprite_root: asset_root.join(self.sprite_root), @@ -89,6 +99,8 @@ pub(crate) mod syntax { zoom_min: self.zoom_min, ui_scale: self.ui_scale, ui_landed_scene, + ui_flying_scene, + ui_outfitter_scene, }); } } @@ -175,6 +187,12 @@ pub struct Config { /// Ui scale factor pub ui_scale: f32, - /// Ui landed scene + /// Ui landed scene script pub ui_landed_scene: AST, + + /// Ui flying scene script + pub ui_flying_scene: AST, + + /// Ui outfitter scene script + pub ui_outfitter_scene: AST, }