Skip to content

Commit

Permalink
Update theming and add pick list element
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li committed Feb 28, 2024
1 parent e77cd03 commit f3f30b2
Show file tree
Hide file tree
Showing 73 changed files with 1,475 additions and 521 deletions.
2 changes: 1 addition & 1 deletion src/graphics/renderers/deferred/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl DeferredRenderer {
}
}

#[profile("recreate deferred pipeline")]
#[profile("re-create deferred pipeline")]
pub fn recreate_pipeline(&mut self, viewport: Viewport, dimensions: [u32; 2], #[cfg(feature = "debug")] wireframe: bool) {
let device = self.memory_allocator.device().clone();
let geometry_subpass = Subpass::from(self.render_pass.clone(), 0).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/renderers/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl InterfaceRenderer {
self.font_loader.borrow().get_text_dimensions(text, font_size, available_width)
}

#[profile("recreate interface pipeline")]
#[profile("re-create interface pipeline")]
pub fn recreate_pipeline(&mut self, viewport: Viewport, dimensions: [u32; 2]) {
let device = self.memory_allocator.device().clone();
let subpass = self.render_pass.clone().first_subpass();
Expand Down
17 changes: 11 additions & 6 deletions src/graphics/renderers/interface/rectangle/fragment_shader.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ layout(push_constant) uniform Constants {
vec4 clip_size;
vec4 corner_radius;
vec4 color;
float aspect_ratio;
} constants;

void main() {

vec2 coords = fragment_position * constants.screen_size;
vec2 screen_size = constants.screen_size;

coords.x /= constants.aspect_ratio;
screen_size.x /= constants.aspect_ratio;

// top-left
if (length(coords - constants.corner_radius.x) > constants.corner_radius.x && coords.x < constants.corner_radius.x &&
Expand All @@ -23,20 +28,20 @@ void main() {
}

// top-right
if (length(coords - vec2(constants.screen_size.x - constants.corner_radius.y, constants.corner_radius.y)) > constants.corner_radius.y &&
constants.screen_size.x - coords.x < constants.corner_radius.y && coords.y < constants.corner_radius.y) {
if (length(coords - vec2(screen_size.x - constants.corner_radius.y, constants.corner_radius.y)) > constants.corner_radius.y &&
screen_size.x - coords.x < constants.corner_radius.y && coords.y < constants.corner_radius.y) {
discard;
}

// bottom-right
if (length(coords - constants.screen_size + constants.corner_radius.z) > constants.corner_radius.z &&
constants.screen_size.x - coords.x < constants.corner_radius.z && constants.screen_size.y - coords.y < constants.corner_radius.z) {
if (length(coords - screen_size + constants.corner_radius.z) > constants.corner_radius.z &&
screen_size.x - coords.x < constants.corner_radius.z && screen_size.y - coords.y < constants.corner_radius.z) {
discard;
}

// bottom_left
if (length(coords - vec2(constants.corner_radius.w, constants.screen_size.y - constants.corner_radius.w)) > constants.corner_radius.w &&
coords.x < constants.corner_radius.w && constants.screen_size.y - coords.y < constants.corner_radius.w) {
if (length(coords - vec2(constants.corner_radius.w, screen_size.y - constants.corner_radius.w)) > constants.corner_radius.w &&
coords.x < constants.corner_radius.w && screen_size.y - coords.y < constants.corner_radius.w) {
discard;
}

Expand Down
1 change: 1 addition & 0 deletions src/graphics/renderers/interface/rectangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl RectangleRenderer {
clip_size: clip_size.into(),
corner_radius: corner_radius.into(),
color: [color.red_f32(), color.green_f32(), color.blue_f32(), color.alpha_f32()],
aspect_ratio: window_size.y as f32 / window_size.x as f32,
};

render_target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ layout(push_constant) uniform Constants {
vec4 clip_size;
vec4 corner_radius;
vec4 color;
float aspect_ratio;
} constants;

const vec2 data[6] = vec2[]
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/renderers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use self::picker::PickerSubrenderer;
pub use self::picker::{PickerRenderer, PickerTarget};
#[cfg(feature = "debug")]
pub use self::settings::RenderSettings;
pub use self::shadow::ShadowRenderer;
pub use self::shadow::{ShadowDetail, ShadowRenderer};
pub use self::swapchain::{PresentModeInfo, SwapchainHolder};
use super::{Color, MemoryAllocator, ModelVertex};
#[cfg(feature = "debug")]
Expand Down
20 changes: 20 additions & 0 deletions src/graphics/renderers/shadow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod indicator;
use std::sync::Arc;

use cgmath::{Matrix4, Vector2, Vector3};
use serde::{Deserialize, Serialize};
use vulkano::device::{DeviceOwned, Queue};
use vulkano::format::{ClearValue, Format};
use vulkano::image::{ImageUsage, SampleCount};
Expand All @@ -20,6 +21,25 @@ use crate::graphics::{
use crate::loaders::{GameFileLoader, TextureLoader};
use crate::network::EntityId;

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum ShadowDetail {
Low,
Medium,
High,
Ultra,
}

impl ShadowDetail {
pub fn into_resolution(self) -> u32 {
match self {
ShadowDetail::Low => 512,
ShadowDetail::Medium => 1024,
ShadowDetail::High => 2048,
ShadowDetail::Ultra => 8192,
}
}
}

#[derive(PartialEq, Eq)]
pub enum ShadowSubrenderer {
Geometry,
Expand Down
56 changes: 52 additions & 4 deletions src/graphics/settings.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
use derive_new::new;
use procedural::toggle;
use ron::ser::PrettyConfig;
use serde::{Deserialize, Serialize};

#[derive(toggle, new)]
use super::ShadowDetail;
#[cfg(feature = "debug")]
use crate::debug::*;

#[derive(Serialize, Deserialize, toggle)]
pub struct GraphicsSettings {
#[toggle]
#[new(value = "true")]
pub frame_limit: bool,
#[toggle]
#[new(value = "true")]
pub show_interface: bool,
pub shadow_detail: ShadowDetail,
}

impl Default for GraphicsSettings {
fn default() -> Self {
Self {
frame_limit: true,
show_interface: true,
shadow_detail: ShadowDetail::Medium,
}
}
}

impl GraphicsSettings {
pub fn new() -> Self {
Self::load().unwrap_or_else(|| {
#[cfg(feature = "debug")]
print_debug!("failed to load graphics settings from {}filename{}", MAGENTA, NONE);

Default::default()
})
}

pub fn load() -> Option<Self> {
#[cfg(feature = "debug")]
print_debug!("loading graphics settings from {}filename{}", MAGENTA, NONE);

std::fs::read_to_string("client/graphics_settings.ron")
.ok()
.and_then(|data| ron::from_str(&data).ok())
}

pub fn save(&self) {
#[cfg(feature = "debug")]
print_debug!("saving graphics settings to {}filename{}", MAGENTA, NONE);

let data = ron::ser::to_string_pretty(self, PrettyConfig::new()).unwrap();
std::fs::write("client/graphics_settings.ron", data).expect("unable to write file");
}
}

impl Drop for GraphicsSettings {
fn drop(&mut self) {
self.save();
}
}
27 changes: 18 additions & 9 deletions src/input/event.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
use cgmath::Vector2;

use super::HotbarSlot;
use crate::interface::{ItemMove, SkillMove};
use crate::loaders::Service;
use crate::interface::{ItemMove, SkillMove, ThemeKind};
use crate::loaders::ServiceId;
use crate::network::{AccountId, CharacterId, CharacterServerInformation, EntityId};
#[cfg(feature = "debug")]
use crate::world::MarkerIdentifier;

#[derive(Clone, Debug)]
// TODO: A lot of these are not user events, just a element events
pub enum UserEvent {
SelectService(Service),
LogIn(Service, String, String),
LogIn {
service_id: ServiceId,
username: String,
password: String,
},
SelectServer(CharacterServerInformation),
LogOut,
Exit,
ToggleRemeberUsername,
ToggleRemeberPassword,
CameraZoom(f32),
CameraRotate(f32),
ToggleFrameLimit,
Expand All @@ -27,9 +29,16 @@ pub enum UserEvent {
OpenGraphicsSettingsWindow,
OpenAudioSettingsWindow,
OpenFriendsWindow,
SetThemeFile(String),
SaveTheme,
ReloadTheme,
SetThemeFile {
theme_file: String,
theme_kind: ThemeKind,
},
SaveTheme {
theme_kind: ThemeKind,
},
ReloadTheme {
theme_kind: ThemeKind,
},
SelectCharacter(usize),
OpenCharacterCreationWindow(usize),
CreateCharacter(usize, String),
Expand Down
26 changes: 21 additions & 5 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,12 @@ impl InputSystem {
self.mouse_input_mode = MouseInputMode::ClickInterface;

if let Some(hovered_element) = &hovered_element {
let action = match self.left_mouse_button.pressed() {
let actions = match self.left_mouse_button.pressed() {
true => interface.left_click_element(hovered_element, *window_index),
false => interface.right_click_element(hovered_element, *window_index),
};

if let Some(action) = action {
for action in actions {
match action {
ClickAction::ChangeEvent(..) => {}

Expand Down Expand Up @@ -302,6 +302,14 @@ impl InputSystem {
ClickAction::OpenWindow(prototype_window) => interface.open_window(focus_state, prototype_window.as_ref()),

ClickAction::CloseWindow => interface.close_window(focus_state, *window_index),

ClickAction::OpenPopup {
element,
position_tracker,
size_tracker,
} => interface.open_popup(element, position_tracker, size_tracker, *window_index),

ClickAction::ClosePopup => interface.close_popup(*window_index),
}
}
}
Expand Down Expand Up @@ -414,9 +422,9 @@ impl InputSystem {
}

if self.get_key(VirtualKeyCode::Return).pressed() {
let action = interface.left_click_element(focused_element, *focused_window);
let actions = interface.left_click_element(focused_element, *focused_window);

if let Some(action) = action {
for action in actions {
// TODO: remove and replace with proper event
match action {
ClickAction::Event(event) => events.push(event),
Expand All @@ -442,7 +450,9 @@ impl InputSystem {
'\t' => {}
'\x1b' => {}
valid => {
if let Some(action) = interface.input_character_element(focused_element, *focused_window, valid) {
let actions = interface.input_character_element(focused_element, *focused_window, valid);

for action in actions {
match action {
// is handled in the interface
ClickAction::ChangeEvent(..) => {}
Expand All @@ -469,6 +479,12 @@ impl InputSystem {
ClickAction::MoveSkill(..) => {}
ClickAction::OpenWindow(prototype_window) => interface.open_window(focus_state, prototype_window.as_ref()),
ClickAction::CloseWindow => interface.close_window(focus_state, *focused_window),
ClickAction::OpenPopup {
element,
position_tracker,
size_tracker,
} => interface.open_popup(element, position_tracker, size_tracker, *focused_window),
ClickAction::ClosePopup => interface.close_popup(*focused_window),
}
}
}
Expand Down
Loading

0 comments on commit f3f30b2

Please sign in to comment.