checkboxes functionality

This commit is contained in:
Pfauenauge90 2019-07-26 18:34:00 +02:00 committed by Imbris
parent 041f2565bc
commit d8fac7a995
2 changed files with 77 additions and 40 deletions

@ -167,6 +167,8 @@ pub struct Show {
open_windows: Windows, open_windows: Windows,
map: bool, map: bool,
inventory_test_button: bool, inventory_test_button: bool,
rel_to_win: bool,
absolute: bool,
mini_map: bool, mini_map: bool,
ingame: bool, ingame: bool,
settings_tab: SettingsTab, settings_tab: SettingsTab,
@ -279,9 +281,7 @@ pub struct Hud {
inventory_space: usize, inventory_space: usize,
show: Show, show: Show,
to_focus: Option<Option<widget::Id>>, to_focus: Option<Option<widget::Id>>,
force_ungrab: bool, force_ungrab: bool,
rel_to_win: bool,
absolute: bool,
force_chat_input: Option<String>, force_chat_input: Option<String>,
force_chat_cursor: Option<Index>, force_chat_cursor: Option<Index>,
} }
@ -304,9 +304,7 @@ impl Hud {
ui, ui,
imgs, imgs,
fonts, fonts,
ids, ids,
rel_to_win: true,
absolute: false,
new_messages: VecDeque::new(), new_messages: VecDeque::new(),
inventory_space: 8, inventory_space: 8,
show: Show { show: Show {
@ -322,6 +320,8 @@ impl Hud {
settings_tab: SettingsTab::Interface, settings_tab: SettingsTab::Interface,
want_grab: true, want_grab: true,
ingame: true, ingame: true,
rel_to_win: true,
absolute: false,
}, },
to_focus: None, to_focus: None,
force_ungrab: false, force_ungrab: false,
@ -638,7 +638,7 @@ impl Hud {
// Settings // Settings
if let Windows::Settings = self.show.open_windows { if let Windows::Settings = self.show.open_windows {
for event in SettingsWindow::new(&global_state, &self.show, &self.imgs, &self.fonts, self.rel_to_win, self.absolute) for event in SettingsWindow::new(&global_state, &self.show, &self.imgs, &self.fonts, self.show.rel_to_win, self.show.absolute)
.set(self.ids.settings_window, ui_widgets) .set(self.ids.settings_window, ui_widgets)
{ {
match event { match event {

@ -29,6 +29,7 @@ widget_ids! {
show_help_label, show_help_label,
ui_scale_label, ui_scale_label,
ui_scale_slider, ui_scale_slider,
ui_scale_slider_2,
ui_scale_button, ui_scale_button,
ui_scale_value, ui_scale_value,
relative_to_win_button, relative_to_win_button,
@ -96,10 +97,7 @@ pub struct SettingsWindow<'a> {
show: &'a Show, show: &'a Show,
imgs: &'a Imgs, imgs: &'a Imgs,
fonts: &'a Fonts, fonts: &'a Fonts,
rel_to_win: bool,
absolute: bool,
#[conrod(common_builder)] #[conrod(common_builder)]
common: widget::CommonBuilder, common: widget::CommonBuilder,
@ -119,9 +117,7 @@ impl<'a> SettingsWindow<'a> {
show, show,
imgs, imgs,
fonts, fonts,
common: widget::CommonBuilder::default(), common: widget::CommonBuilder::default(),
rel_to_win,
absolute,
} }
} }
} }
@ -247,7 +243,8 @@ impl<'a> Widget for SettingsWindow<'a> {
if let SettingsTab::Interface = self.show.settings_tab { if let SettingsTab::Interface = self.show.settings_tab {
let crosshair_transp = self.global_state.settings.gameplay.crosshair_transp; let crosshair_transp = self.global_state.settings.gameplay.crosshair_transp;
let crosshair_type = self.global_state.settings.gameplay.crosshair_type; let crosshair_type = self.global_state.settings.gameplay.crosshair_type;
let ui_scale = self.global_state.settings.gameplay.ui_scale; let ui_scale = self.global_state.settings.gameplay.ui_scale;
Text::new("General") Text::new("General")
.top_left_with_margins_on(state.ids.settings_content, 5.0, 5.0) .top_left_with_margins_on(state.ids.settings_content, 5.0, 5.0)
@ -353,21 +350,45 @@ impl<'a> Widget for SettingsWindow<'a> {
events.push(Event::UiScale(ScaleChange::ToAbsolute)) events.push(Event::UiScale(ScaleChange::ToAbsolute))
} }
} }
}*/ }*/
// rel to win button
let rel_to_win = /* Intended function:
ToggleButton::new(self.rel_to_win, self.imgs.check, self.imgs.check_checked) Checking one button unchecks the other one
.w_h(288.0 / 24.0, 288.0 / 24.0) Buttons can't be unchecked by clicking them
.down_from(state.ids.ui_scale_label, 20.0) Slider switches to active state (display of indicator and value) when absolute scaling is checked
.hover_images(self.imgs.check_checked_mo, self.imgs.check_mo) */
.press_images(self.imgs.check_press, self.imgs.check_press)
.set(state.ids.relative_to_win_button, ui);
if self.rel_to_win != rel_to_win { let mut scaling_method = ScaleChange::ToRelative;
events.push(Event::UiScale(ScaleChange::ToRelative));
// Relative Scaling Button
if Button::image(match ui_scale {
ScaleMode::Absolute(_) => self.imgs.check,
ScaleMode::RelativeToWindow(_) => self.imgs.check_checked,
ScaleMode::DpiFactor => self.imgs.check_checked,
})
.w_h(288.0 / 24.0, 288.0 / 24.0)
.down_from(state.ids.ui_scale_label, 20.0)
.hover_image(match ui_scale {
ScaleMode::Absolute(_) => self.imgs.check_mo,
ScaleMode::RelativeToWindow(_) => self.imgs.check_checked,
ScaleMode::DpiFactor => self.imgs.check_checked,
})
.press_image(match ui_scale {
ScaleMode::Absolute(_) => self.imgs.check_press,
ScaleMode::RelativeToWindow(_) => self.imgs.check_checked,
ScaleMode::DpiFactor => self.imgs.check_checked,
})
.set(state.ids.relative_to_win_button, ui)
.was_clicked()
{
events.push(Event::UiScale(ScaleChange::ToRelative));
} }
Text::new("Relative to Window") Text::new("Relative Scaling")
.right_from(state.ids.relative_to_win_button, 10.0) .right_from(state.ids.relative_to_win_button, 10.0)
.font_size(14) .font_size(14)
.font_id(self.fonts.opensans) .font_id(self.fonts.opensans)
@ -375,19 +396,33 @@ impl<'a> Widget for SettingsWindow<'a> {
.color(TEXT_COLOR) .color(TEXT_COLOR)
.set(state.ids.relative_to_win_text, ui); .set(state.ids.relative_to_win_text, ui);
// absolute scale button
let absolute = // Absolute Scaling Button
ToggleButton::new(self.absolute, self.imgs.check, self.imgs.check_checked)
.w_h(288.0 / 24.0, 288.0 / 24.0) if Button::image(match ui_scale {
.down_from(state.ids.relative_to_win_button, 20.0) ScaleMode::Absolute(_) => self.imgs.check_checked,
.hover_images(self.imgs.check_checked_mo, self.imgs.check_mo) ScaleMode::RelativeToWindow(_) => self.imgs.check,
.press_images(self.imgs.check_press, self.imgs.check_press) ScaleMode::DpiFactor => self.imgs.check,
.set(state.ids.absolute_scale_button, ui); })
if self.absolute != absolute { .w_h(288.0 / 24.0, 288.0 / 24.0)
events.push(Event::UiScale(ScaleChange::ToAbsolute)); .down_from(state.ids.relative_to_win_button, 20.0)
.hover_image(match ui_scale {
ScaleMode::Absolute(_) => self.imgs.check_checked,
ScaleMode::RelativeToWindow(_) => self.imgs.check_mo,
ScaleMode::DpiFactor => self.imgs.check_mo,
})
.press_image(match ui_scale {
ScaleMode::Absolute(_) => self.imgs.check_checked,
ScaleMode::RelativeToWindow(_) => self.imgs.check_press,
ScaleMode::DpiFactor => self.imgs.check_press,
})
.set(state.ids.absolute_scale_button, ui)
.was_clicked()
{
events.push(Event::UiScale(ScaleChange::ToAbsolute));
} }
Text::new("Free Scaling") Text::new("Custom Scaling")
.right_from(state.ids.absolute_scale_button, 10.0) .right_from(state.ids.absolute_scale_button, 10.0)
.font_size(14) .font_size(14)
.font_id(self.fonts.opensans) .font_id(self.fonts.opensans)
@ -424,10 +459,12 @@ impl<'a> Widget for SettingsWindow<'a> {
ImageSlider::continuous(5.0, 0.0, 10.0, self.imgs.nothing, self.imgs.slider) ImageSlider::continuous(5.0, 0.0, 10.0, self.imgs.nothing, self.imgs.slider)
.w_h(208.0, 22.0) .w_h(208.0, 22.0)
.right_from(state.ids.absolute_scale_text, 10.0) .right_from(state.ids.absolute_scale_text, 10.0)
.track_breadth(30.0) .track_breadth(12.0)
.slider_length(10.0) .slider_length(10.0)
.track_color(Color::Rgba(1.0, 1.0, 1.0, 0.2))
.slider_color(Color::Rgba(1.0, 1.0, 1.0, 0.2))
.pad_track((5.0, 5.0)) .pad_track((5.0, 5.0))
.set(state.ids.ui_scale_slider, ui) .set(state.ids.ui_scale_slider_2, ui)
{} {}
} }