Settings for Si prefixes in the interface menu

This commit is contained in:
Evgen Kot 2023-08-17 15:24:05 +00:00 committed by Isse
parent 237d13dbce
commit 9f213019d1
6 changed files with 157 additions and 8 deletions

View File

@ -16,9 +16,12 @@ hud-settings-custom_scaling = Custom Scaling
hud-settings-crosshair = Crosshair
hud-settings-opacity = Opacity
hud-settings-hotbar = Hotbar
hud-settings-slots = Slots
hud-settings-toggle_shortcuts = Toggle Shortcuts
hud-settings-buffs_skillbar = Buffs at Skillbar
hud-settings-buffs_mmap = Buffs at Minimap
hud-settings-use_prefixes = Use SI prefixes for quantities
hud-settings-prefix_switch_point = Digit limit for SI prefix switch
hud-settings-toggle_bar_experience = Toggle Experience Bar
hud-settings-scrolling_combat_text = Scrolling Combat Text
hud-settings-damage_accumulation_duration = Damage Accumulation Duration

View File

@ -1363,6 +1363,8 @@ impl Hud {
let slot_manager = slots::SlotManager::new(
ui.id_generator(),
Vec2::broadcast(40.0),
global_state.settings.interface.slots_use_prefixes,
global_state.settings.interface.slots_prefix_switch_point,
// TODO(heyzoos) Will be useful for whoever works on rendering the number of items
// "in hand".
// fonts.cyri.conrod_id,
@ -1454,6 +1456,15 @@ impl Hud {
self.fonts = Fonts::load(i18n.fonts(), &mut self.ui).expect("Impossible to load fonts!");
}
pub fn set_slots_use_prefixes(&mut self, use_prefixes: bool) {
self.slot_manager.set_use_prefixes(use_prefixes);
}
pub fn set_slots_prefix_switch_point(&mut self, prefix_switch_point: u32) {
self.slot_manager
.set_prefix_switch_point(prefix_switch_point);
}
#[allow(clippy::single_match)] // TODO: Pending review in #587
fn update_layout(
&mut self,

View File

@ -78,6 +78,13 @@ widget_ids! {
buff_pos_map_button,
buff_pos_map_text,
//
slots_title,
slots_use_prefixes_text,
slots_use_prefixes_radio,
slots_prefix_switch_point_slider,
slots_prefix_switch_point_text,
slots_prefix_switch_point_value,
//
sct_title,
sct_show_text,
sct_show_radio,
@ -755,6 +762,78 @@ impl<'a> Widget for Interface<'a> {
.graphics_for(state.ids.show_shortcuts_button)
.color(TEXT_COLOR)
.set(state.ids.buff_pos_map_text, ui);
// Slots text
Text::new(&self.localized_strings.get_msg("hud-settings-slots"))
.down_from(state.ids.buff_pos_map_button, 20.0)
.font_size(self.fonts.cyri.scale(18))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
.set(state.ids.slots_title, ui);
// Prefix switch checkbox
let slots_use_prefixes = ToggleButton::new(
self.global_state.settings.interface.slots_use_prefixes,
self.imgs.checkbox,
self.imgs.checkbox_checked,
)
.w_h(18.0, 18.0)
.down_from(state.ids.slots_title, 20.0)
.hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
.set(state.ids.slots_use_prefixes_radio, ui);
if self.global_state.settings.interface.slots_use_prefixes != slots_use_prefixes {
events.push(SlotsUsePrefixes(
!self.global_state.settings.interface.slots_use_prefixes,
));
}
Text::new(&self.localized_strings.get_msg("hud-settings-use_prefixes"))
.right_from(state.ids.slots_use_prefixes_radio, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.graphics_for(state.ids.slots_use_prefixes_radio)
.color(TEXT_COLOR)
.set(state.ids.slots_use_prefixes_text, ui);
if self.global_state.settings.interface.slots_use_prefixes {
let prefix_switch_point = self
.global_state
.settings
.interface
.slots_prefix_switch_point;
Text::new(
&self
.localized_strings
.get_msg("hud-settings-prefix_switch_point"),
)
.down_from(state.ids.slots_use_prefixes_radio, 8.0)
.right_from(state.ids.slots_use_prefixes_radio, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
.set(state.ids.slots_prefix_switch_point_text, ui);
if let Some(new_val) = ImageSlider::discrete(
prefix_switch_point,
4,
7,
self.imgs.slider_indicator,
self.imgs.slider,
)
.w_h(208.0, 22.0)
.down_from(state.ids.slots_prefix_switch_point_text, 8.0)
.track_breadth(30.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.slots_prefix_switch_point_slider, ui)
{
events.push(SlotsPrefixSwitchPoint(new_val));
}
Text::new(&format!("{prefix_switch_point}"))
.right_from(state.ids.slots_prefix_switch_point_slider, 10.0)
.font_size(self.fonts.cyri.scale(14))
.graphics_for(state.ids.slots_prefix_switch_point_slider)
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
.set(state.ids.slots_prefix_switch_point_value, ui);
}
// Content Right Side
@ -1253,7 +1332,15 @@ impl<'a> Widget for Interface<'a> {
.w_h(RESET_BUTTONS_WIDTH, RESET_BUTTONS_HEIGHT)
.hover_image(self.imgs.button_hover)
.press_image(self.imgs.button_press)
.down_from(state.ids.buff_pos_map_button, 12.0)
.down_from(
if self.global_state.settings.interface.slots_use_prefixes {
state.ids.slots_prefix_switch_point_slider
} else {
state.ids.slots_use_prefixes_radio
},
12.0,
)
.x_align_to(state.ids.slots_use_prefixes_radio, Align::Start)
.label(
&self
.localized_strings

View File

@ -150,6 +150,9 @@ pub enum Interface {
MapShowBiomes(bool),
MapShowVoxelMap(bool),
AccumExperience(bool),
//Slots
SlotsUsePrefixes(bool),
SlotsPrefixSwitchPoint(u32),
ResetInterfaceSettings,
}
@ -668,6 +671,16 @@ impl SettingsChange {
Interface::AccumExperience(accum_experience) => {
settings.interface.accum_experience = accum_experience;
},
Interface::SlotsUsePrefixes(slots_use_prefixes) => {
settings.interface.slots_use_prefixes = slots_use_prefixes;
session_state.hud.set_slots_use_prefixes(slots_use_prefixes);
},
Interface::SlotsPrefixSwitchPoint(slots_prefix_switch_point) => {
settings.interface.slots_prefix_switch_point = slots_prefix_switch_point;
session_state
.hud
.set_slots_prefix_switch_point(slots_prefix_switch_point);
},
Interface::ResetInterfaceSettings => {
// Reset Interface Settings
let tmp = settings.interface.intro_show;

View File

@ -14,6 +14,8 @@ pub struct InterfaceSettings {
pub toggle_hitboxes: bool,
pub toggle_chat: bool,
pub toggle_hotkey_hints: bool,
pub slots_use_prefixes: bool,
pub slots_prefix_switch_point: u32,
pub sct: bool,
pub sct_damage_rounding: bool,
pub sct_dmg_accum_duration: f32,
@ -60,6 +62,8 @@ impl Default for InterfaceSettings {
toggle_hitboxes: false,
toggle_chat: true,
toggle_hotkey_hints: true,
slots_use_prefixes: true,
slots_prefix_switch_point: 5,
sct: true,
sct_damage_rounding: false,
sct_dmg_accum_duration: 0.45,

View File

@ -141,6 +141,9 @@ pub struct SlotManager<S: SumSlot> {
// Note: could potentially be specialized for each slot if needed
drag_img_size: Vec2<f32>,
pub mouse_over_slot: Option<S>,
// Si prefixes settings
use_prefixes: bool,
prefix_switch_point: u32,
/* TODO(heyzoos) Will be useful for whoever works on rendering the number of items "in
* hand".
*
@ -170,6 +173,8 @@ where
pub fn new(
mut gen: widget::id::Generator,
drag_img_size: Vec2<f32>,
use_prefixes: bool,
prefix_switch_point: u32,
/* TODO(heyzoos) Will be useful for whoever works on rendering the number of items "in
* hand". amount_font: font::Id,
* amount_margins: Vec2<f32>,
@ -183,6 +188,8 @@ where
events: Vec::new(),
drag_id: gen.next(),
mouse_over_slot: None,
use_prefixes,
prefix_switch_point,
// TODO(heyzoos) Will be useful for whoever works on rendering the number of items "in
// hand". drag_amount_id: gen.next(),
// drag_amount_shadow_id: gen.next(),
@ -305,6 +312,12 @@ where
core::mem::take(&mut self.events)
}
pub fn set_use_prefixes(&mut self, use_prefixes: bool) { self.use_prefixes = use_prefixes; }
pub fn set_prefix_switch_point(&mut self, prefix_switch_point: u32) {
self.prefix_switch_point = prefix_switch_point;
}
fn update(
&mut self,
widget: widget::Id,
@ -580,7 +593,7 @@ where
fn style(&self) -> Self::Style {}
/// Update the state of the Slot.
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
fn update(mut self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs {
id,
state,
@ -622,7 +635,7 @@ where
// Get image ids
let content_images = state.cached_images.as_ref().map(|c| c.1.clone());
// Get whether this slot is selected
let interaction = self.slot_manager.map_or(Interaction::None, |m| {
let interaction = self.slot_manager.as_mut().map_or(Interaction::None, |m| {
m.update(
id,
slot_key.into(),
@ -698,11 +711,29 @@ where
// Draw amount
if let Some(amount) = amount {
let amount = match amount {
amount if amount > 1_000_000_000 => format!("{}G", amount / 1_000_000_000),
amount if amount > 1_000_000 => format!("{}M", amount / 1_000_000),
amount if amount > 1_000 => format!("{}K", amount / 1_000),
amount => format!("{}", amount),
let amount = match self
.slot_manager
.as_ref()
.map_or(true, |sm| sm.use_prefixes)
{
true => {
let threshold = amount
/ (u32::pow(
10,
self.slot_manager
.map_or(4, |sm| sm.prefix_switch_point)
.saturating_sub(4),
));
match amount {
amount if threshold >= 1_000_000_000 => {
format!("{}G", amount / 1_000_000_000)
},
amount if threshold >= 1_000_000 => format!("{}M", amount / 1_000_000),
amount if threshold >= 1_000 => format!("{}K", amount / 1_000),
amount => format!("{}", amount),
}
},
false => format!("{}", amount),
};
// Text shadow
Text::new(&amount)