Interface size in finer percent steps; fixed sizes no longer double the interface
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d8aa0e5fc1
commit
361e1e4108
4 files changed
+52
-24
No files matched your search
+40
-2
@@ -148,7 +148,8 @@ pub struct Settings {
|
||||
pub outlines: bool,
|
||||
pub wall_detail: u8, // 1 low, 2 medium, 3 high
|
||||
pub max_lights: u8, // 8, 16 or 24
|
||||
pub ui_factor: u8, // interface size: 0 = automatic, 2 large, 3 medium, 4 small (interface pixels per world pixel)
|
||||
pub ui_factor: u8, // old interface size (2 large, 3 medium, 4 small; only read to carry old settings over)
|
||||
pub ui_size: u16, // interface size in percent of the standard (100 = 1080 interface rows), 0 = automatic
|
||||
pub render_scale: u8, // old pixel-look divisor (no longer used, kept for old settings files)
|
||||
pub pixel_rows: u16, // pixel look: rows of the world on every screen (270, 360, 480)
|
||||
pub touch_ui: u8, // touch interface: 0 = automatic (after the first touch), 1 = on, 2 = off
|
||||
@@ -189,6 +190,7 @@ impl Default for Settings {
|
||||
wall_detail: 2,
|
||||
max_lights: 24,
|
||||
ui_factor: 0,
|
||||
ui_size: 0,
|
||||
render_scale: 1,
|
||||
pixel_rows: 360,
|
||||
touch_ui: 0,
|
||||
@@ -244,10 +246,32 @@ impl Settings {
|
||||
}
|
||||
|
||||
pub fn from_json(s: &str) -> Option<Settings> {
|
||||
serde_json::from_str(s).ok()
|
||||
let mut st: Settings = serde_json::from_str(s).ok()?;
|
||||
// old interface sizes (pixels per world pixel) become percentages
|
||||
if st.ui_size == 0 {
|
||||
st.ui_size = match st.ui_factor {
|
||||
2 => 150,
|
||||
3 => 100,
|
||||
4 => 75,
|
||||
_ => 0,
|
||||
};
|
||||
}
|
||||
st.ui_factor = 0;
|
||||
if st.ui_size != 0 && !UI_SIZES.contains(&st.ui_size) {
|
||||
st.ui_size = 0;
|
||||
}
|
||||
Some(st)
|
||||
}
|
||||
}
|
||||
|
||||
// the interface sizes of the settings menu in percent (0 = automatic), from small to large
|
||||
pub const UI_SIZES: [u16; 9] = [0, 75, 85, 100, 115, 130, 150, 175, 200];
|
||||
|
||||
// interface rows of the virtual screen for a size in percent (100% = 1080 rows)
|
||||
pub fn ui_size_rows(percent: u16) -> u32 {
|
||||
(1080.0 * 100.0 / percent.max(1) as f32).round() as u32
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -273,4 +297,18 @@ mod tests {
|
||||
assert!(!old.debug_trigger_zones);
|
||||
assert!(!old.debug_command_markers);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interface_size_percent() {
|
||||
let old = Settings::from_json(r#"{"ui_factor":2}"#).unwrap();
|
||||
assert_eq!(old.ui_size, 150);
|
||||
assert_eq!(old.ui_factor, 0);
|
||||
let mut s = Settings::default();
|
||||
s.ui_size = 115;
|
||||
assert_eq!(Settings::from_json(&s.to_json()).unwrap().ui_size, 115);
|
||||
assert_eq!(Settings::from_json(r#"{"ui_size":123}"#).unwrap().ui_size, 0);
|
||||
assert_eq!(ui_size_rows(100), 1080);
|
||||
assert_eq!(ui_size_rows(150), 720);
|
||||
assert!(ui_size_rows(200) < ui_size_rows(175));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user