Compare commits
6 commits
8ad53e456f
...
8ff523d50c
Author | SHA1 | Date | |
---|---|---|---|
8ff523d50c | |||
bffec81ad3 | |||
f384959fc6 | |||
5ed9a42f8e | |||
8b20c92bbb | |||
17dd562408 |
6 changed files with 91 additions and 97 deletions
|
@ -5,7 +5,7 @@ authors = ["hodasemi <michaelh.95@t-online.de>"]
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
quick-xml = "0.31.0"
|
||||
quick-xml = "0.37.0"
|
||||
serde = { version = "1.0.203", features = ["derive"] }
|
||||
serde_json = { version = "1.0.120" }
|
||||
vulkan-rs = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
||||
|
|
|
@ -54,10 +54,10 @@ pub struct ButtonInfo {
|
|||
background_fill_type: DisplayableFillType,
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
pub click_sound: AssetPath,
|
||||
pub click_sound: Option<AssetPath>,
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
pub hover_sound: AssetPath,
|
||||
pub hover_sound: Option<AssetPath>,
|
||||
|
||||
pub text: RwLock<String>,
|
||||
pub text_color: Color,
|
||||
|
@ -98,16 +98,12 @@ impl ButtonInfo {
|
|||
background_fill_type: DisplayableFillType::Expand,
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
click_sound: match Self::find_click_sound(grid) {
|
||||
Some(sound) => sound,
|
||||
None => gui_handler.click_sound().clone(),
|
||||
},
|
||||
click_sound: Self::find_click_sound(grid)
|
||||
.or(gui_handler.click_sound().map(|p| p.clone())),
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
hover_sound: match Self::find_hover_sound(grid) {
|
||||
Some(sound) => sound,
|
||||
None => gui_handler.hover_sound().clone(),
|
||||
},
|
||||
hover_sound: Self::find_hover_sound(grid)
|
||||
.or(gui_handler.hover_sound().map(|p| p.clone())),
|
||||
|
||||
text: RwLock::default(),
|
||||
text_color: Color::Black,
|
||||
|
@ -143,10 +139,10 @@ impl ButtonInfo {
|
|||
}
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
b"click_sound" => button_info.click_sound = cow_to_path(attribute.value),
|
||||
b"click_sound" => button_info.click_sound = Some(cow_to_path(attribute.value)),
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
b"hover_sound" => button_info.hover_sound = cow_to_path(attribute.value),
|
||||
b"hover_sound" => button_info.hover_sound = Some(cow_to_path(attribute.value)),
|
||||
|
||||
b"select_mode" => {
|
||||
button_info.select_mode = cow_to_button_select_mode(attribute.value)?
|
||||
|
@ -176,7 +172,7 @@ impl ButtonInfo {
|
|||
return Err(anyhow::Error::msg(format!(
|
||||
"Unsupported attribute in Button: {}",
|
||||
from_utf8(attribute.key.into_inner())?
|
||||
)))
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,23 +3,23 @@ use crate::{
|
|||
gui_handler::gui::iconizable::IconizablePositioning, prelude::*,
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use anyhow::{Result, anyhow};
|
||||
use assetpath::AssetPath;
|
||||
use utilities::prelude::*;
|
||||
use vulkan_rs::prelude::*;
|
||||
|
||||
use super::{
|
||||
IconBuilderType,
|
||||
fill_type::{FillType, InnerFillType},
|
||||
wrapper::{IconizableWrapper, TextableWrapper},
|
||||
IconBuilderType,
|
||||
};
|
||||
use cgmath::{vec2, vec4};
|
||||
|
||||
use std::{
|
||||
ops::Deref,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicBool, Ordering::SeqCst},
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -121,18 +121,14 @@ impl ButtonBuilder {
|
|||
|
||||
let normal = FillType::new(
|
||||
framable.clone(),
|
||||
match self.normal {
|
||||
Some(info) => info,
|
||||
None => FillTypeInfo::from(gui_handler.menu_button().clone()),
|
||||
},
|
||||
self.normal
|
||||
.ok_or(anyhow!("normal button layout not set!"))?,
|
||||
)?;
|
||||
|
||||
let selected = FillType::new(
|
||||
framable.clone(),
|
||||
match self.selected {
|
||||
Some(info) => info,
|
||||
None => FillTypeInfo::from(gui_handler.menu_button_selected().clone()),
|
||||
},
|
||||
self.selected
|
||||
.ok_or(anyhow!("selected button layout not set!"))?,
|
||||
)?;
|
||||
|
||||
let click_executable = Executable::new(&gui_handler);
|
||||
|
@ -393,13 +389,13 @@ impl Button {
|
|||
}
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
if !button_info.click_sound.is_empty() {
|
||||
button_builder = button_builder.set_click_sound(button_info.click_sound.clone());
|
||||
if let Some(click_sound) = &button_info.click_sound {
|
||||
button_builder = button_builder.set_click_sound(click_sound.clone());
|
||||
}
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
if !button_info.hover_sound.is_empty() {
|
||||
button_builder = button_builder.set_hover_sound(button_info.hover_sound.clone());
|
||||
if let Some(hover_sound) = &button_info.hover_sound {
|
||||
button_builder = button_builder.set_hover_sound(hover_sound.clone());
|
||||
}
|
||||
|
||||
button_builder = button_builder.set_icon(
|
||||
|
@ -408,7 +404,10 @@ impl Button {
|
|||
.clone()
|
||||
.map(|icon| {
|
||||
Image::from_file(AssetPath::from((
|
||||
gui_handler.resource_base_path().full_path(),
|
||||
gui_handler
|
||||
.resource_base_path()
|
||||
.ok_or(anyhow!("resource base path not set!"))?
|
||||
.full_path(),
|
||||
icon,
|
||||
)))?
|
||||
.attach_sampler(Sampler::nearest_sampler().build(gui_handler.device())?)
|
||||
|
|
BIN
src/gui_handler/default_font.png
Normal file
BIN
src/gui_handler/default_font.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
|
@ -1,7 +1,7 @@
|
|||
//! `Audible` is a property to play a sound
|
||||
|
||||
use crate::prelude::*;
|
||||
use anyhow::Result;
|
||||
use anyhow::{Result, anyhow};
|
||||
use assetpath::AssetPath;
|
||||
|
||||
// #[cfg(feature = "audio")]
|
||||
|
@ -18,7 +18,12 @@ pub struct Audible {
|
|||
impl Audible {
|
||||
pub fn new(gui_handler: Arc<GuiHandler>, mut path: AssetPath) -> Result<Arc<Self>> {
|
||||
if !path.has_prefix() {
|
||||
path.set_prefix(&gui_handler.resource_base_path().full_path());
|
||||
path.set_prefix(
|
||||
&gui_handler
|
||||
.resource_base_path()
|
||||
.ok_or(anyhow!("resource base path not set!"))?
|
||||
.full_path(),
|
||||
);
|
||||
}
|
||||
|
||||
// TODO:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
use anyhow::Result;
|
||||
use anyhow::{Result, anyhow};
|
||||
use assetpath::AssetPath;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utilities::{impl_reprc, prelude::*};
|
||||
|
@ -35,44 +35,36 @@ impl Default for Font<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug, Default)]
|
||||
#[derive(Deserialize, Serialize, Clone, Debug)]
|
||||
pub struct GuiHandlerCreateInfo<'a> {
|
||||
// default button textures
|
||||
pub menu_button: AssetPath,
|
||||
pub menu_button_selected: AssetPath,
|
||||
|
||||
// path to the alphabet image
|
||||
#[serde(borrow)]
|
||||
pub font: Font<'a>,
|
||||
|
||||
// sound info
|
||||
#[cfg(feature = "audio")]
|
||||
pub click_sound: AssetPath,
|
||||
pub click_sound: Option<AssetPath>,
|
||||
#[cfg(feature = "audio")]
|
||||
pub hover_sound: AssetPath,
|
||||
pub hover_sound: Option<AssetPath>,
|
||||
|
||||
// resource base directory
|
||||
pub resource_directory: AssetPath,
|
||||
pub resource_directory: Option<AssetPath>,
|
||||
}
|
||||
|
||||
impl<'a> GuiHandlerCreateInfo<'a> {
|
||||
pub const fn new() -> Self {
|
||||
GuiHandlerCreateInfo {
|
||||
// default button textures
|
||||
menu_button: AssetPath::new(),
|
||||
menu_button_selected: AssetPath::new(),
|
||||
|
||||
// path to the alphabet image
|
||||
font: Font::Path(AssetPath::new()),
|
||||
font: Font::Bytes(include_bytes!("default_font.png")),
|
||||
|
||||
// sound info
|
||||
#[cfg(feature = "audio")]
|
||||
click_sound: AssetPath::new(),
|
||||
click_sound: None,
|
||||
#[cfg(feature = "audio")]
|
||||
hover_sound: AssetPath::new(),
|
||||
hover_sound: None,
|
||||
|
||||
// resource base directory
|
||||
resource_directory: AssetPath::new(),
|
||||
resource_directory: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -197,7 +189,7 @@ pub struct GuiHandler {
|
|||
width: AtomicU32,
|
||||
height: AtomicU32,
|
||||
|
||||
resource_base_path: AssetPath,
|
||||
resource_base_path: Option<AssetPath>,
|
||||
|
||||
top_ui: RwLock<Option<Arc<dyn TopGui>>>,
|
||||
tooltip_ui: RwLock<Option<Arc<dyn TopGui>>>,
|
||||
|
@ -232,14 +224,11 @@ pub struct GuiHandler {
|
|||
|
||||
on_selected: RwLock<Option<Box<dyn Fn() -> Result<()> + Send + Sync>>>,
|
||||
|
||||
menu_button: AssetPath,
|
||||
menu_button_selected: AssetPath,
|
||||
#[cfg(feature = "audio")]
|
||||
click_sound: Option<AssetPath>,
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
click_sound: AssetPath,
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
hover_sound: AssetPath,
|
||||
hover_sound: Option<AssetPath>,
|
||||
|
||||
// ----- gui handling -----
|
||||
layers: Mutex<Vec<(i32, Elements)>>,
|
||||
|
@ -296,7 +285,7 @@ impl GuiHandler {
|
|||
}
|
||||
._descriptor_layout
|
||||
.clone(),
|
||||
gui_handler_create_info.font.clone(),
|
||||
gui_handler_create_info.font,
|
||||
)?;
|
||||
|
||||
let icon_descriptor_layout = DescriptorSetLayout::builder()
|
||||
|
@ -315,36 +304,31 @@ impl GuiHandler {
|
|||
width: AtomicU32::new(context.width()),
|
||||
height: AtomicU32::new(context.height()),
|
||||
|
||||
menu_button: {
|
||||
let mut menu_button = gui_handler_create_info.menu_button;
|
||||
menu_button.set_prefix(&gui_handler_create_info.resource_directory.full_path());
|
||||
|
||||
menu_button
|
||||
},
|
||||
|
||||
menu_button_selected: {
|
||||
let mut menu_button_selected = gui_handler_create_info.menu_button_selected;
|
||||
menu_button_selected
|
||||
.set_prefix(&gui_handler_create_info.resource_directory.full_path());
|
||||
|
||||
menu_button_selected
|
||||
},
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
click_sound: {
|
||||
let mut click_sound = gui_handler_create_info.click_sound;
|
||||
click_sound.set_prefix(&gui_handler_create_info.resource_directory.full_path());
|
||||
click_sound: gui_handler_create_info.click_sound.map(|mut click_sound| {
|
||||
click_sound.set_prefix(
|
||||
&gui_handler_create_info
|
||||
.resource_directory
|
||||
.as_ref()
|
||||
.expect("missing resource directory")
|
||||
.full_path(),
|
||||
);
|
||||
|
||||
click_sound
|
||||
},
|
||||
}),
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
hover_sound: {
|
||||
let mut hover_sound = gui_handler_create_info.hover_sound;
|
||||
hover_sound.set_prefix(&gui_handler_create_info.resource_directory.full_path());
|
||||
hover_sound: gui_handler_create_info.hover_sound.map(|mut hover_sound| {
|
||||
hover_sound.set_prefix(
|
||||
&gui_handler_create_info
|
||||
.resource_directory
|
||||
.as_ref()
|
||||
.expect("missing resource directory")
|
||||
.full_path(),
|
||||
);
|
||||
|
||||
hover_sound
|
||||
},
|
||||
}),
|
||||
|
||||
resource_base_path: gui_handler_create_info.resource_directory,
|
||||
|
||||
|
@ -451,7 +435,13 @@ impl GuiHandler {
|
|||
Some(image) => Ok(image),
|
||||
None => {
|
||||
if !path.has_prefix() {
|
||||
path.set_prefix(&self.resource_base_path().full_path());
|
||||
path.set_prefix(
|
||||
&self
|
||||
.resource_base_path
|
||||
.as_ref()
|
||||
.ok_or(anyhow!("resource base path not set!"))?
|
||||
.full_path(),
|
||||
);
|
||||
}
|
||||
|
||||
let image = Image::from_file(path)?
|
||||
|
@ -466,7 +456,13 @@ impl GuiHandler {
|
|||
},
|
||||
None => {
|
||||
if !path.has_prefix() {
|
||||
path.set_prefix(&self.resource_base_path().full_path());
|
||||
path.set_prefix(
|
||||
&self
|
||||
.resource_base_path
|
||||
.as_ref()
|
||||
.ok_or(anyhow!("resource base path not set!"))?
|
||||
.full_path(),
|
||||
);
|
||||
}
|
||||
|
||||
let image = Image::from_file(path.clone())?
|
||||
|
@ -513,7 +509,13 @@ impl GuiHandler {
|
|||
|
||||
pub(crate) fn displayable_image_from_path(&self, mut path: AssetPath) -> Result<Arc<Image>> {
|
||||
if !path.has_prefix() {
|
||||
path.set_prefix(&self.resource_base_path.full_path());
|
||||
path.set_prefix(
|
||||
&self
|
||||
.resource_base_path
|
||||
.as_ref()
|
||||
.ok_or(anyhow!("resource base path not set!"))?
|
||||
.full_path(),
|
||||
);
|
||||
}
|
||||
|
||||
if self.internal_textures.read().unwrap().contains_key(&path) {
|
||||
|
@ -585,26 +587,18 @@ impl GuiHandler {
|
|||
*self.ortho.read().unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn resource_base_path(&self) -> &AssetPath {
|
||||
&self.resource_base_path
|
||||
}
|
||||
|
||||
pub fn menu_button(&self) -> &AssetPath {
|
||||
&self.menu_button
|
||||
}
|
||||
|
||||
pub fn menu_button_selected(&self) -> &AssetPath {
|
||||
&self.menu_button_selected
|
||||
pub(crate) fn resource_base_path(&self) -> Option<&AssetPath> {
|
||||
self.resource_base_path.as_ref()
|
||||
}
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
pub fn click_sound(&self) -> &AssetPath {
|
||||
&self.click_sound
|
||||
pub fn click_sound(&self) -> Option<&AssetPath> {
|
||||
self.click_sound.as_ref()
|
||||
}
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
pub fn hover_sound(&self) -> &AssetPath {
|
||||
&self.hover_sound
|
||||
pub fn hover_sound(&self) -> Option<&AssetPath> {
|
||||
self.hover_sound.as_ref()
|
||||
}
|
||||
|
||||
pub fn set_on_selected_event<F>(&self, f: F) -> Result<()>
|
||||
|
|
Loading…
Reference in a new issue