mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add ui scale setting and slider
This commit is contained in:
@ -132,10 +132,15 @@ impl<'a> Widget for Buttons<'a> {
|
|||||||
return Some(Event::ToggleSettings);
|
return Some(Event::ToggleSettings);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Image::new(self.imgs.social_button)
|
||||||
|
.w_h(25.0, 25.0)
|
||||||
|
.left_from(state.ids.settings_button, 10.0)
|
||||||
|
.set(state.ids.social_button_bg, ui);
|
||||||
|
|
||||||
// 2 Map
|
// 2 Map
|
||||||
if Button::image(self.imgs.map_button)
|
if Button::image(self.imgs.map_button)
|
||||||
.w_h(22.0, 25.0)
|
.w_h(22.0, 25.0)
|
||||||
.left_from(state.ids.social_button, 10.0)
|
.left_from(state.ids.social_button_bg, 10.0)
|
||||||
.hover_image(self.imgs.map_hover)
|
.hover_image(self.imgs.map_hover)
|
||||||
.press_image(self.imgs.map_press)
|
.press_image(self.imgs.map_press)
|
||||||
.label("M")
|
.label("M")
|
||||||
@ -149,26 +154,22 @@ impl<'a> Widget for Buttons<'a> {
|
|||||||
return Some(Event::ToggleMap);
|
return Some(Event::ToggleMap);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Other Windows can only be accessed when `Settings` is closed.
|
|
||||||
// Opening `Settings` will close all other Windows, including the `Bag`.
|
|
||||||
// Opening the `Map` won't close the previously displayed windows.
|
|
||||||
Image::new(self.imgs.social_button)
|
|
||||||
.w_h(25.0, 25.0)
|
|
||||||
.left_from(state.ids.settings_button, 10.0)
|
|
||||||
.set(state.ids.social_button_bg, ui);
|
|
||||||
Image::new(self.imgs.spellbook_button)
|
Image::new(self.imgs.spellbook_button)
|
||||||
.w_h(28.0, 25.0)
|
.w_h(28.0, 25.0)
|
||||||
.left_from(state.ids.map_button, 10.0)
|
.left_from(state.ids.map_button, 10.0)
|
||||||
.set(state.ids.spellbook_button_bg, ui);
|
.set(state.ids.spellbook_button_bg, ui);
|
||||||
Image::new(self.imgs.character_button)
|
Image::new(self.imgs.character_button)
|
||||||
.w_h(27.0, 25.0)
|
.w_h(27.0, 25.0)
|
||||||
.left_from(state.ids.spellbook_button, 10.0)
|
.left_from(state.ids.spellbook_button_bg, 10.0)
|
||||||
.set(state.ids.character_button_bg, ui);
|
.set(state.ids.character_button_bg, ui);
|
||||||
Image::new(self.imgs.qlog_button)
|
Image::new(self.imgs.qlog_button)
|
||||||
.w_h(23.0, 25.0)
|
.w_h(23.0, 25.0)
|
||||||
.left_from(state.ids.character_button, 10.0)
|
.left_from(state.ids.character_button_bg, 10.0)
|
||||||
.set(state.ids.qlog_button_bg, ui);
|
.set(state.ids.qlog_button_bg, ui);
|
||||||
|
|
||||||
|
// Other Windows can only be accessed when `Settings` is closed.
|
||||||
|
// Opening `Settings` will close all other Windows, including the `Bag`.
|
||||||
|
// Opening the `Map` won't close the previously displayed windows.
|
||||||
if !(*self.open_windows == Windows::Settings) && self.show_map == false {
|
if !(*self.open_windows == Windows::Settings) && self.show_map == false {
|
||||||
// 1 Social
|
// 1 Social
|
||||||
if Button::image(self.imgs.social_button)
|
if Button::image(self.imgs.social_button)
|
||||||
|
@ -10,6 +10,8 @@ mod settings_window;
|
|||||||
mod skillbar;
|
mod skillbar;
|
||||||
mod small_window;
|
mod small_window;
|
||||||
|
|
||||||
|
pub use settings_window::ScaleChange;
|
||||||
|
|
||||||
use bag::Bag;
|
use bag::Bag;
|
||||||
use buttons::Buttons;
|
use buttons::Buttons;
|
||||||
use character_window::CharacterWindow;
|
use character_window::CharacterWindow;
|
||||||
@ -28,7 +30,7 @@ use crate::{
|
|||||||
scene::camera::Camera,
|
scene::camera::Camera,
|
||||||
settings::ControlSettings,
|
settings::ControlSettings,
|
||||||
ui::{Ingameable, ScaleMode, Ui},
|
ui::{Ingameable, ScaleMode, Ui},
|
||||||
window::{Event as WinEvent, GameInput, Window},
|
window::{Event as WinEvent, GameInput},
|
||||||
GlobalState,
|
GlobalState,
|
||||||
};
|
};
|
||||||
use client::{Client, Event as ClientEvent};
|
use client::{Client, Event as ClientEvent};
|
||||||
@ -121,7 +123,7 @@ pub struct DebugInfo {
|
|||||||
pub ping_ms: f64,
|
pub ping_ms: f64,
|
||||||
pub coordinates: Option<comp::Pos>,
|
pub coordinates: Option<comp::Pos>,
|
||||||
}
|
}
|
||||||
#[derive(Serialize, Deserialize)]
|
//#[derive(Serialize, Deserialize)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
SendMessage(String),
|
SendMessage(String),
|
||||||
AdjustMousePan(u32),
|
AdjustMousePan(u32),
|
||||||
@ -132,7 +134,7 @@ pub enum Event {
|
|||||||
ChangeMaxFPS(u32),
|
ChangeMaxFPS(u32),
|
||||||
CrosshairTransp(f32),
|
CrosshairTransp(f32),
|
||||||
CrosshairType(CrosshairType),
|
CrosshairType(CrosshairType),
|
||||||
//UiScale(f32),
|
UiScale(ScaleChange),
|
||||||
CharacterSelection,
|
CharacterSelection,
|
||||||
Logout,
|
Logout,
|
||||||
Quit,
|
Quit,
|
||||||
@ -283,13 +285,12 @@ pub struct Hud {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Hud {
|
impl Hud {
|
||||||
pub fn new(window: &mut Window) -> Self {
|
pub fn new(global_state: &mut GlobalState) -> Self {
|
||||||
|
let window = &mut global_state.window;
|
||||||
|
let settings = &global_state.settings;
|
||||||
|
|
||||||
let mut ui = Ui::new(window).unwrap();
|
let mut ui = Ui::new(window).unwrap();
|
||||||
// TODO: Adjust/remove this, right now it is used to demonstrate window scaling functionality.
|
ui.set_scaling_mode(settings.gameplay.ui_scale);
|
||||||
let ui_scale = 0.7;
|
|
||||||
ui.scaling_mode(ScaleMode::RelativeToWindow(
|
|
||||||
window.renderer().get_resolution().map(|e| e as f64) / ui_scale as f64,
|
|
||||||
));
|
|
||||||
// Generate ids.
|
// Generate ids.
|
||||||
let ids = Ids::new(ui.id_generator());
|
let ids = Ids::new(ui.id_generator());
|
||||||
// Load images.
|
// Load images.
|
||||||
@ -668,6 +669,9 @@ impl Hud {
|
|||||||
settings_window::Event::CrosshairType(crosshair_type) => {
|
settings_window::Event::CrosshairType(crosshair_type) => {
|
||||||
events.push(Event::CrosshairType(crosshair_type));
|
events.push(Event::CrosshairType(crosshair_type));
|
||||||
}
|
}
|
||||||
|
settings_window::Event::UiScale(scale_change) => {
|
||||||
|
events.push(Event::UiScale(scale_change));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -754,6 +758,16 @@ impl Hud {
|
|||||||
self.new_messages.push_back(msg);
|
self.new_messages.push_back(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn scale_change(&mut self, scale_change: ScaleChange) -> ScaleMode {
|
||||||
|
let scale_mode = match scale_change {
|
||||||
|
ScaleChange::Adjust(scale) => ScaleMode::Absolute(scale),
|
||||||
|
ScaleChange::ToAbsolute => self.ui.scale().scaling_mode_as_absolute(),
|
||||||
|
ScaleChange::ToRelative => self.ui.scale().scaling_mode_as_relative(),
|
||||||
|
};
|
||||||
|
self.ui.set_scaling_mode(scale_mode);
|
||||||
|
scale_mode
|
||||||
|
}
|
||||||
|
|
||||||
// Checks if a TextEdit widget has the keyboard captured.
|
// Checks if a TextEdit widget has the keyboard captured.
|
||||||
fn typing(&self) -> bool {
|
fn typing(&self) -> bool {
|
||||||
if let Some(id) = self.ui.widget_capturing_keyboard() {
|
if let Some(id) = self.ui.widget_capturing_keyboard() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::{img_ids::Imgs, CrosshairType, Fonts, Show, TEXT_COLOR};
|
use super::{img_ids::Imgs, CrosshairType, Fonts, Show, TEXT_COLOR};
|
||||||
use crate::{
|
use crate::{
|
||||||
audio::base::Genre,
|
audio::base::Genre,
|
||||||
ui::{ImageSlider, ToggleButton},
|
ui::{ImageSlider, ScaleMode, ToggleButton},
|
||||||
GlobalState,
|
GlobalState,
|
||||||
};
|
};
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
@ -27,6 +27,9 @@ widget_ids! {
|
|||||||
button_help,
|
button_help,
|
||||||
button_help2,
|
button_help2,
|
||||||
show_help_label,
|
show_help_label,
|
||||||
|
ui_scale_label,
|
||||||
|
ui_scale_slider,
|
||||||
|
ui_scale_button,
|
||||||
gameplay,
|
gameplay,
|
||||||
controls,
|
controls,
|
||||||
rectangle,
|
rectangle,
|
||||||
@ -129,6 +132,13 @@ pub enum Event {
|
|||||||
MaximumFPS(u32),
|
MaximumFPS(u32),
|
||||||
CrosshairTransp(f32),
|
CrosshairTransp(f32),
|
||||||
CrosshairType(CrosshairType),
|
CrosshairType(CrosshairType),
|
||||||
|
UiScale(ScaleChange),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ScaleChange {
|
||||||
|
ToAbsolute,
|
||||||
|
ToRelative,
|
||||||
|
Adjust(f64),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Widget for SettingsWindow<'a> {
|
impl<'a> Widget for SettingsWindow<'a> {
|
||||||
@ -225,6 +235,7 @@ 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;
|
||||||
|
|
||||||
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)
|
||||||
@ -299,10 +310,66 @@ impl<'a> Widget for SettingsWindow<'a> {
|
|||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.set(state.ids.debug_button_label, ui);
|
.set(state.ids.debug_button_label, ui);
|
||||||
|
|
||||||
|
// Ui Scale
|
||||||
|
Text::new(match ui_scale {
|
||||||
|
ScaleMode::Absolute(_) => "Ui Scale (Absolute)",
|
||||||
|
ScaleMode::DpiFactor => "Ui Scale (Dpi based)",
|
||||||
|
ScaleMode::RelativeToWindow(_) => "Ui Scale (Relative to window size)",
|
||||||
|
})
|
||||||
|
.down_from(state.ids.debug_button, 15.0)
|
||||||
|
.font_size(18)
|
||||||
|
.font_id(self.fonts.opensans)
|
||||||
|
.color(TEXT_COLOR)
|
||||||
|
.set(state.ids.ui_scale_label, ui);
|
||||||
|
|
||||||
|
// TODO: change button image
|
||||||
|
if Button::image(self.imgs.settings_button)
|
||||||
|
.w_h(31.0 * 6.0, 12.0 * 3.0)
|
||||||
|
.hover_image(self.imgs.settings_button_hover)
|
||||||
|
.press_image(self.imgs.settings_button_press)
|
||||||
|
.down_from(state.ids.ui_scale_label, 10.0)
|
||||||
|
.label(match ui_scale {
|
||||||
|
ScaleMode::Absolute(_) => "Make relative to current window",
|
||||||
|
ScaleMode::DpiFactor => "Switch to absolute scaling",
|
||||||
|
ScaleMode::RelativeToWindow(_) => "Switch to absolute scaling",
|
||||||
|
})
|
||||||
|
.label_font_size(8)
|
||||||
|
.label_color(TEXT_COLOR)
|
||||||
|
.set(state.ids.ui_scale_button, ui)
|
||||||
|
.was_clicked()
|
||||||
|
{
|
||||||
|
match ui_scale {
|
||||||
|
ScaleMode::Absolute(_) => events.push(Event::UiScale(ScaleChange::ToRelative)),
|
||||||
|
ScaleMode::DpiFactor => events.push(Event::UiScale(ScaleChange::ToAbsolute)),
|
||||||
|
ScaleMode::RelativeToWindow(_) => {
|
||||||
|
events.push(Event::UiScale(ScaleChange::ToAbsolute))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let ScaleMode::Absolute(scale) = ui_scale {
|
||||||
|
if let Some(new_val) = ImageSlider::continuous(
|
||||||
|
scale.log(2.0),
|
||||||
|
-1.0,
|
||||||
|
2.0,
|
||||||
|
self.imgs.slider_indicator,
|
||||||
|
self.imgs.slider,
|
||||||
|
)
|
||||||
|
.w_h(550.0, 22.0)
|
||||||
|
.down_from(state.ids.ui_scale_button, 10.0)
|
||||||
|
.track_breadth(30.0)
|
||||||
|
.slider_length(10.0)
|
||||||
|
.pad_track((5.0, 5.0))
|
||||||
|
.set(state.ids.ui_scale_slider, ui)
|
||||||
|
{
|
||||||
|
events.push(Event::UiScale(ScaleChange::Adjust(2.0f64.powf(new_val))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Crosshair Options
|
// Crosshair Options
|
||||||
// Crosshair Transparency
|
// Crosshair Transparency
|
||||||
Text::new("Crosshair")
|
Text::new("Crosshair")
|
||||||
.down_from(state.ids.debug_button, 15.0)
|
.down(15.0)
|
||||||
.font_size(18)
|
.font_size(18)
|
||||||
.font_id(self.fonts.opensans)
|
.font_id(self.fonts.opensans)
|
||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
|
@ -2,9 +2,7 @@ mod scene;
|
|||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
session::SessionState,
|
session::SessionState, window::Event, Direction, GlobalState, PlayState, PlayStateResult,
|
||||||
window::{Event, Window},
|
|
||||||
Direction, GlobalState, PlayState, PlayStateResult,
|
|
||||||
};
|
};
|
||||||
use client::{self, Client};
|
use client::{self, Client};
|
||||||
use common::{clock::Clock, comp, msg::ClientState};
|
use common::{clock::Clock, comp, msg::ClientState};
|
||||||
@ -21,11 +19,11 @@ pub struct CharSelectionState {
|
|||||||
|
|
||||||
impl CharSelectionState {
|
impl CharSelectionState {
|
||||||
/// Create a new `CharSelectionState`.
|
/// Create a new `CharSelectionState`.
|
||||||
pub fn new(window: &mut Window, client: Rc<RefCell<Client>>) -> Self {
|
pub fn new(global_state: &mut GlobalState, client: Rc<RefCell<Client>>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
char_selection_ui: CharSelectionUi::new(window),
|
char_selection_ui: CharSelectionUi::new(global_state),
|
||||||
client,
|
client,
|
||||||
scene: Scene::new(window.renderer_mut()),
|
scene: Scene::new(global_state.window.renderer_mut()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,9 +67,8 @@ impl PlayState for CharSelectionState {
|
|||||||
comp::Body::Humanoid(self.char_selection_ui.character_body),
|
comp::Body::Humanoid(self.char_selection_ui.character_body),
|
||||||
);
|
);
|
||||||
return PlayStateResult::Push(Box::new(SessionState::new(
|
return PlayStateResult::Push(Box::new(SessionState::new(
|
||||||
&mut global_state.window,
|
global_state,
|
||||||
self.client.clone(),
|
self.client.clone(),
|
||||||
global_state.settings.clone(),
|
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ use crate::{
|
|||||||
ui::{
|
ui::{
|
||||||
self,
|
self,
|
||||||
img_ids::{ImageGraphic, VoxelGraphic},
|
img_ids::{ImageGraphic, VoxelGraphic},
|
||||||
ImageSlider, ScaleMode, Ui,
|
ImageSlider, Ui,
|
||||||
},
|
},
|
||||||
window::Window,
|
GlobalState,
|
||||||
};
|
};
|
||||||
use client::Client;
|
use client::Client;
|
||||||
use common::comp::{humanoid, item::Weapon};
|
use common::comp::{humanoid, item::Weapon};
|
||||||
@ -211,10 +211,12 @@ pub struct CharSelectionUi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CharSelectionUi {
|
impl CharSelectionUi {
|
||||||
pub fn new(window: &mut Window) -> Self {
|
pub fn new(global_state: &mut GlobalState) -> Self {
|
||||||
|
let window = &mut global_state.window;
|
||||||
|
let settings = &global_state.settings;
|
||||||
|
|
||||||
let mut ui = Ui::new(window).unwrap();
|
let mut ui = Ui::new(window).unwrap();
|
||||||
// TODO: Adjust/remove this, right now it is used to demonstrate window scaling functionality.
|
ui.set_scaling_mode(settings.gameplay.ui_scale);
|
||||||
ui.scaling_mode(ScaleMode::RelativeToWindow([1920.0, 1080.0].into()));
|
|
||||||
// Generate ids
|
// Generate ids
|
||||||
let ids = Ids::new(ui.id_generator());
|
let ids = Ids::new(ui.id_generator());
|
||||||
// Load images
|
// Load images
|
||||||
|
@ -55,7 +55,7 @@ impl PlayState for MainMenuState {
|
|||||||
Some(Ok(client)) => {
|
Some(Ok(client)) => {
|
||||||
self.main_menu_ui.connected();
|
self.main_menu_ui.connected();
|
||||||
return PlayStateResult::Push(Box::new(CharSelectionState::new(
|
return PlayStateResult::Push(Box::new(CharSelectionState::new(
|
||||||
&mut global_state.window,
|
global_state,
|
||||||
std::rc::Rc::new(std::cell::RefCell::new(client)),
|
std::rc::Rc::new(std::cell::RefCell::new(client)),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ impl PlayState for StartSingleplayerState {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PlayStateResult::Push(Box::new(CharSelectionState::new(
|
PlayStateResult::Push(Box::new(CharSelectionState::new(
|
||||||
&mut global_state.window,
|
global_state,
|
||||||
std::rc::Rc::new(std::cell::RefCell::new(client)),
|
std::rc::Rc::new(std::cell::RefCell::new(client)),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use crate::{
|
|||||||
ui::{
|
ui::{
|
||||||
self,
|
self,
|
||||||
img_ids::{ImageGraphic, VoxelGraphic},
|
img_ids::{ImageGraphic, VoxelGraphic},
|
||||||
ScaleMode, Ui,
|
Ui,
|
||||||
},
|
},
|
||||||
GlobalState,
|
GlobalState,
|
||||||
};
|
};
|
||||||
@ -110,9 +110,10 @@ impl MainMenuUi {
|
|||||||
pub fn new(global_state: &mut GlobalState) -> Self {
|
pub fn new(global_state: &mut GlobalState) -> Self {
|
||||||
let window = &mut global_state.window;
|
let window = &mut global_state.window;
|
||||||
let networking = &global_state.settings.networking;
|
let networking = &global_state.settings.networking;
|
||||||
|
let gameplay = &global_state.settings.gameplay;
|
||||||
|
|
||||||
let mut ui = Ui::new(window).unwrap();
|
let mut ui = Ui::new(window).unwrap();
|
||||||
// TODO: adjust/remove this, right now it is used to demonstrate window scaling functionality
|
ui.set_scaling_mode(gameplay.ui_scale);
|
||||||
ui.scaling_mode(ScaleMode::RelativeToWindow([1920.0, 1080.0].into()));
|
|
||||||
// Generate ids
|
// Generate ids
|
||||||
let ids = Ids::new(ui.id_generator());
|
let ids = Ids::new(ui.id_generator());
|
||||||
// Load images
|
// Load images
|
||||||
|
@ -3,13 +3,12 @@ use crate::{
|
|||||||
key_state::KeyState,
|
key_state::KeyState,
|
||||||
render::Renderer,
|
render::Renderer,
|
||||||
scene::{camera::Camera, Scene},
|
scene::{camera::Camera, Scene},
|
||||||
settings::Settings,
|
window::{Event, GameInput},
|
||||||
window::{Event, GameInput, Window},
|
|
||||||
Direction, Error, GlobalState, PlayState, PlayStateResult,
|
Direction, Error, GlobalState, PlayState, PlayStateResult,
|
||||||
};
|
};
|
||||||
use client::{self, Client};
|
use client::{self, Client};
|
||||||
use common::{clock::Clock, comp, comp::Pos, msg::ClientState, terrain::Block, vol::ReadVol};
|
use common::{clock::Clock, comp, comp::Pos, msg::ClientState, terrain::Block, vol::ReadVol};
|
||||||
use log::{error, warn};
|
use log::error;
|
||||||
use std::{cell::RefCell, rc::Rc, time::Duration};
|
use std::{cell::RefCell, rc::Rc, time::Duration};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -25,15 +24,15 @@ pub struct SessionState {
|
|||||||
/// Represents an active game session (i.e., the one being played).
|
/// Represents an active game session (i.e., the one being played).
|
||||||
impl SessionState {
|
impl SessionState {
|
||||||
/// Create a new `SessionState`.
|
/// Create a new `SessionState`.
|
||||||
pub fn new(window: &mut Window, client: Rc<RefCell<Client>>, _settings: Settings) -> Self {
|
pub fn new(global_state: &mut GlobalState, client: Rc<RefCell<Client>>) -> Self {
|
||||||
// Create a scene for this session. The scene handles visible elements of the game world.
|
// Create a scene for this session. The scene handles visible elements of the game world.
|
||||||
let scene = Scene::new(window.renderer_mut());
|
let scene = Scene::new(global_state.window.renderer_mut());
|
||||||
Self {
|
Self {
|
||||||
scene,
|
scene,
|
||||||
client,
|
client,
|
||||||
key_state: KeyState::new(),
|
key_state: KeyState::new(),
|
||||||
controller: comp::Controller::default(),
|
controller: comp::Controller::default(),
|
||||||
hud: Hud::new(window),
|
hud: Hud::new(global_state),
|
||||||
selected_block: Block::new(1, Rgb::broadcast(255)),
|
selected_block: Block::new(1, Rgb::broadcast(255)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,59 +275,48 @@ impl PlayState for SessionState {
|
|||||||
HudEvent::AdjustMousePan(sensitivity) => {
|
HudEvent::AdjustMousePan(sensitivity) => {
|
||||||
global_state.window.pan_sensitivity = sensitivity;
|
global_state.window.pan_sensitivity = sensitivity;
|
||||||
global_state.settings.gameplay.pan_sensitivity = sensitivity;
|
global_state.settings.gameplay.pan_sensitivity = sensitivity;
|
||||||
if let Err(err) = global_state.settings.save_to_file() {
|
global_state.settings.save_to_file_warn();
|
||||||
warn!("Failed to save settings: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
HudEvent::AdjustMouseZoom(sensitivity) => {
|
HudEvent::AdjustMouseZoom(sensitivity) => {
|
||||||
global_state.window.zoom_sensitivity = sensitivity;
|
global_state.window.zoom_sensitivity = sensitivity;
|
||||||
global_state.settings.gameplay.zoom_sensitivity = sensitivity;
|
global_state.settings.gameplay.zoom_sensitivity = sensitivity;
|
||||||
if let Err(err) = global_state.settings.save_to_file() {
|
global_state.settings.save_to_file_warn();
|
||||||
warn!("Failed to save settings: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
HudEvent::AdjustViewDistance(view_distance) => {
|
HudEvent::AdjustViewDistance(view_distance) => {
|
||||||
self.client.borrow_mut().set_view_distance(view_distance);
|
self.client.borrow_mut().set_view_distance(view_distance);
|
||||||
|
|
||||||
global_state.settings.graphics.view_distance = view_distance;
|
global_state.settings.graphics.view_distance = view_distance;
|
||||||
if let Err(err) = global_state.settings.save_to_file() {
|
global_state.settings.save_to_file_warn();
|
||||||
warn!("Failed to save settings: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
HudEvent::CrosshairTransp(crosshair_transp) => {
|
HudEvent::CrosshairTransp(crosshair_transp) => {
|
||||||
global_state.settings.gameplay.crosshair_transp = crosshair_transp;
|
global_state.settings.gameplay.crosshair_transp = crosshair_transp;
|
||||||
if let Err(err) = global_state.settings.save_to_file() {
|
global_state.settings.save_to_file_warn();
|
||||||
warn!("Failed to save settings: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
HudEvent::CrosshairType(crosshair_type) => {
|
HudEvent::CrosshairType(crosshair_type) => {
|
||||||
global_state.settings.gameplay.crosshair_type = crosshair_type;
|
global_state.settings.gameplay.crosshair_type = crosshair_type;
|
||||||
if let Err(err) = global_state.settings.save_to_file() {
|
global_state.settings.save_to_file_warn();
|
||||||
warn!("Failed to save settings: {:?}", err);
|
}
|
||||||
}
|
HudEvent::UiScale(scale_change) => {
|
||||||
|
global_state.settings.gameplay.ui_scale =
|
||||||
|
self.hud.scale_change(scale_change);
|
||||||
|
global_state.settings.save_to_file_warn();
|
||||||
}
|
}
|
||||||
|
|
||||||
HudEvent::AdjustVolume(volume) => {
|
HudEvent::AdjustVolume(volume) => {
|
||||||
global_state.audio.model.player.set_volume(volume);
|
global_state.audio.model.player.set_volume(volume);
|
||||||
|
|
||||||
global_state.settings.audio.music_volume = volume;
|
global_state.settings.audio.music_volume = volume;
|
||||||
if let Err(err) = global_state.settings.save_to_file() {
|
global_state.settings.save_to_file_warn();
|
||||||
warn!("Failed to save settings: {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
HudEvent::ChangeAudioDevice(name) => {
|
HudEvent::ChangeAudioDevice(name) => {
|
||||||
global_state.audio.model.player.set_device(&name.clone());
|
global_state.audio.model.player.set_device(&name.clone());
|
||||||
|
|
||||||
global_state.settings.audio.audio_device = Some(name);
|
global_state.settings.audio.audio_device = Some(name);
|
||||||
if let Err(err) = global_state.settings.save_to_file() {
|
global_state.settings.save_to_file_warn();
|
||||||
warn!("Failed to save settings!\n{:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
HudEvent::ChangeMaxFPS(fps) => {
|
HudEvent::ChangeMaxFPS(fps) => {
|
||||||
global_state.settings.graphics.max_fps = fps;
|
global_state.settings.graphics.max_fps = fps;
|
||||||
if let Err(err) = global_state.settings.save_to_file() {
|
global_state.settings.save_to_file_warn();
|
||||||
warn!("Failed to save settings!\n{:?}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::{hud::CrosshairType, window::KeyMouse};
|
use crate::{hud::CrosshairType, ui::ScaleMode, window::KeyMouse};
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use glutin::{MouseButton, VirtualKeyCode};
|
use glutin::{MouseButton, VirtualKeyCode};
|
||||||
|
use log::warn;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::{fs, io::prelude::*, path::PathBuf};
|
use std::{fs, io::prelude::*, path::PathBuf};
|
||||||
|
|
||||||
@ -77,6 +78,7 @@ pub struct GameplaySettings {
|
|||||||
pub zoom_sensitivity: u32,
|
pub zoom_sensitivity: u32,
|
||||||
pub crosshair_transp: f32,
|
pub crosshair_transp: f32,
|
||||||
pub crosshair_type: CrosshairType,
|
pub crosshair_type: CrosshairType,
|
||||||
|
pub ui_scale: ScaleMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for GameplaySettings {
|
impl Default for GameplaySettings {
|
||||||
@ -86,6 +88,7 @@ impl Default for GameplaySettings {
|
|||||||
zoom_sensitivity: 100,
|
zoom_sensitivity: 100,
|
||||||
crosshair_transp: 0.6,
|
crosshair_transp: 0.6,
|
||||||
crosshair_type: CrosshairType::Round,
|
crosshair_type: CrosshairType::Round,
|
||||||
|
ui_scale: ScaleMode::RelativeToWindow([1920.0, 1080.0].into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,6 +214,12 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn save_to_file_warn(&self) {
|
||||||
|
if let Err(err) = self.save_to_file() {
|
||||||
|
warn!("Failed to save settings: {:?}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn save_to_file(&self) -> std::io::Result<()> {
|
pub fn save_to_file(&self) -> std::io::Result<()> {
|
||||||
let path = Settings::get_settings_path();
|
let path = Settings::get_settings_path();
|
||||||
if let Some(dir) = path.parent() {
|
if let Some(dir) = path.parent() {
|
||||||
|
@ -175,9 +175,13 @@ impl GraphicCache {
|
|||||||
// Deallocate
|
// Deallocate
|
||||||
self.atlas.deallocate(alloc_id);
|
self.atlas.deallocate(alloc_id);
|
||||||
// Try to allocate
|
// Try to allocate
|
||||||
allocation = self
|
if let Some(alloc) = self
|
||||||
.atlas
|
.atlas
|
||||||
.allocate(size2(i32::from(dims.x), i32::from(dims.y)));
|
.allocate(size2(i32::from(dims.x), i32::from(dims.y)))
|
||||||
|
{
|
||||||
|
allocation = Some(alloc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ mod font_ids;
|
|||||||
|
|
||||||
pub use event::Event;
|
pub use event::Event;
|
||||||
pub use graphic::Graphic;
|
pub use graphic::Graphic;
|
||||||
pub use scale::ScaleMode;
|
pub use scale::{Scale, ScaleMode};
|
||||||
pub use widgets::{
|
pub use widgets::{
|
||||||
image_slider::ImageSlider,
|
image_slider::ImageSlider,
|
||||||
ingame::{Ingame, IngameAnchor, Ingameable},
|
ingame::{Ingame, IngameAnchor, Ingameable},
|
||||||
@ -40,7 +40,6 @@ use conrod_core::{
|
|||||||
};
|
};
|
||||||
use graphic::Id as GraphicId;
|
use graphic::Id as GraphicId;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use scale::Scale;
|
|
||||||
use std::{
|
use std::{
|
||||||
io::{BufReader, Read},
|
io::{BufReader, Read},
|
||||||
ops::Range,
|
ops::Range,
|
||||||
@ -132,13 +131,20 @@ impl Ui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the scaling mode of the ui.
|
// Set the scaling mode of the ui.
|
||||||
pub fn scaling_mode(&mut self, mode: ScaleMode) {
|
pub fn set_scaling_mode(&mut self, mode: ScaleMode) {
|
||||||
self.scale.scaling_mode(mode);
|
self.scale.set_scaling_mode(mode);
|
||||||
|
// To clear the cache (it won't be resized in this case)
|
||||||
|
self.need_cache_resize = true;
|
||||||
// Give conrod the new size.
|
// Give conrod the new size.
|
||||||
let (w, h) = self.scale.scaled_window_size().into_tuple();
|
let (w, h) = self.scale.scaled_window_size().into_tuple();
|
||||||
self.ui.handle_event(Input::Resize(w, h));
|
self.ui.handle_event(Input::Resize(w, h));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get a copy of Scale
|
||||||
|
pub fn scale(&self) -> Scale {
|
||||||
|
self.scale
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_graphic(&mut self, graphic: Graphic) -> image::Id {
|
pub fn add_graphic(&mut self, graphic: Graphic) -> image::Id {
|
||||||
self.image_map.insert(self.cache.add_graphic(graphic))
|
self.image_map.insert(self.cache.add_graphic(graphic))
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
use crate::{render::Renderer, window::Window};
|
use crate::{render::Renderer, window::Window};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
/// Type of scaling to use.
|
/// Type of scaling to use.
|
||||||
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||||
pub enum ScaleMode {
|
pub enum ScaleMode {
|
||||||
// Scale against physical size.
|
// Scale against physical size.
|
||||||
Absolute(f64),
|
Absolute(f64),
|
||||||
@ -12,6 +14,7 @@ pub enum ScaleMode {
|
|||||||
RelativeToWindow(Vec2<f64>),
|
RelativeToWindow(Vec2<f64>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct Scale {
|
pub struct Scale {
|
||||||
mode: ScaleMode,
|
mode: ScaleMode,
|
||||||
// Current dpi factor
|
// Current dpi factor
|
||||||
@ -31,9 +34,18 @@ impl Scale {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Change the scaling mode.
|
// Change the scaling mode.
|
||||||
pub fn scaling_mode(&mut self, mode: ScaleMode) {
|
pub fn set_scaling_mode(&mut self, mode: ScaleMode) {
|
||||||
self.mode = mode;
|
self.mode = mode;
|
||||||
}
|
}
|
||||||
|
// Get scaling mode transformed into absolute scaling
|
||||||
|
pub fn scaling_mode_as_absolute(&self) -> ScaleMode {
|
||||||
|
ScaleMode::Absolute(self.scale_factor_physical())
|
||||||
|
}
|
||||||
|
// Get scaling mode transformed to be relative to the window with the same aspect ratio as the current window
|
||||||
|
pub fn scaling_mode_as_relative(&self) -> ScaleMode {
|
||||||
|
let scale = self.scale_factor_logical();
|
||||||
|
ScaleMode::RelativeToWindow(self.window_dims.map(|e| e / scale))
|
||||||
|
}
|
||||||
// Calculate factor to transform between logical coordinates and our scaled coordinates.
|
// Calculate factor to transform between logical coordinates and our scaled coordinates.
|
||||||
pub fn scale_factor_logical(&self) -> f64 {
|
pub fn scale_factor_logical(&self) -> f64 {
|
||||||
match self.mode {
|
match self.mode {
|
||||||
|
Reference in New Issue
Block a user