mirror of
https://github.com/Theaninova/mhlib.git
synced 2026-01-21 09:22:57 +00:00
ui
This commit is contained in:
@@ -2,7 +2,7 @@ use crate::formats::datafile::FileEntry;
|
||||
use crate::formats::level::LevelLayer;
|
||||
use crate::formats::rle::RleImage;
|
||||
use crate::formats::sprites::Sprites;
|
||||
use crate::formats::txt::{decrypt_txt, DecryptError};
|
||||
use crate::formats::txt::{decrypt_exposed_txt, decrypt_txt, DecryptError};
|
||||
use crate::formats::ui_xml::UiTag;
|
||||
use binrw::BinRead;
|
||||
use encoding_rs::WINDOWS_1252;
|
||||
@@ -93,6 +93,10 @@ where
|
||||
Ok(DatafileFile::Sprites(
|
||||
Sprites::parse(decr.as_str()).map_err(custom_err)?,
|
||||
))
|
||||
} else if stem.starts_with("profile") || stem.starts_with("highscores") {
|
||||
Ok(DatafileFile::Txt(
|
||||
decrypt_exposed_txt(decr).map_err(custom_err)?,
|
||||
))
|
||||
} else {
|
||||
Ok(DatafileFile::Txt(decr))
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ pub enum UiTag {
|
||||
Image(UiImage),
|
||||
TextButton(UiTextButton),
|
||||
TextArea(UiTextArea),
|
||||
TextField(UiTextField),
|
||||
StaticText(UiStaticText),
|
||||
ToggleButton(UiToggleButton),
|
||||
}
|
||||
@@ -20,6 +21,24 @@ pub struct UiMenu {
|
||||
pub children: Vec<UiTag>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct UiTextField {
|
||||
pub name: Option<String>,
|
||||
pub text: String,
|
||||
#[serde(deserialize_with = "deserialize_vec2")]
|
||||
pub position: [i32; 2],
|
||||
#[serde(rename = "bufferVar")]
|
||||
pub buffer_var: String,
|
||||
#[serde(deserialize_with = "deserialize_vec4")]
|
||||
pub area: [i32; 4],
|
||||
#[serde(rename = "halign", default)]
|
||||
pub horizontal_align: HorizontalAlign,
|
||||
#[serde(rename = "fademode")]
|
||||
pub fade_mode: FadeMode,
|
||||
#[serde(rename = "OnSelect")]
|
||||
pub on_select: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct UiImage {
|
||||
pub texture: String,
|
||||
@@ -172,12 +191,18 @@ where
|
||||
to_vec2::<D>(String::deserialize(deserializer)?)
|
||||
}
|
||||
|
||||
fn to_vec2<'de, D>(buf: String) -> Result<[i32; 2], D::Error>
|
||||
fn deserialize_vec4<'de, D>(deserializer: D) -> Result<[i32; 4], D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let mut values: Vec<Result<i32, D::Error>> = buf
|
||||
.split(',')
|
||||
to_vec4::<D>(String::deserialize(deserializer)?)
|
||||
}
|
||||
|
||||
fn to_vec<'de, D>(buf: String) -> Result<Vec<i32>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
buf.split(',')
|
||||
.into_iter()
|
||||
.map(|value| {
|
||||
// there's some typos so we have to cover that...
|
||||
@@ -186,9 +211,29 @@ where
|
||||
.parse::<i32>()
|
||||
.map_err(|err| Error::custom(err.to_string()))
|
||||
})
|
||||
.collect();
|
||||
let y = values.pop().ok_or(Error::custom("InvalidField"))??;
|
||||
let x = values.pop().ok_or(Error::custom("InvalidField"))??;
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn to_vec4<'de, D>(buf: String) -> Result<[i32; 4], D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let mut values = to_vec::<D>(buf)?;
|
||||
let w = values.pop().ok_or(Error::custom("InvalidField"))?;
|
||||
let z = values.pop().ok_or(Error::custom("InvalidField"))?;
|
||||
let y = values.pop().ok_or(Error::custom("InvalidField"))?;
|
||||
let x = values.pop().ok_or(Error::custom("InvalidField"))?;
|
||||
|
||||
Ok([x, y, z, w])
|
||||
}
|
||||
|
||||
fn to_vec2<'de, D>(buf: String) -> Result<[i32; 2], D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let mut values = to_vec::<D>(buf)?;
|
||||
let y = values.pop().ok_or(Error::custom("InvalidField"))?;
|
||||
let x = values.pop().ok_or(Error::custom("InvalidField"))?;
|
||||
|
||||
Ok([x, y])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user