From 60d05782bd08e19244b25df2a707cb3414dd39f6 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Wed, 22 Nov 2023 19:03:17 +0100 Subject: [PATCH] drop legacy ui system --- kubi/src/guiv2_integration.rs | 7 +-- kubi/src/legacy_gui.rs | 78 ------------------------------ kubi/src/legacy_gui/progressbar.rs | 46 ------------------ kubi/src/legacy_gui/text_widget.rs | 1 - kubi/src/lib.rs | 5 -- 5 files changed, 1 insertion(+), 136 deletions(-) delete mode 100644 kubi/src/legacy_gui.rs delete mode 100644 kubi/src/legacy_gui/progressbar.rs delete mode 100644 kubi/src/legacy_gui/text_widget.rs diff --git a/kubi/src/guiv2_integration.rs b/kubi/src/guiv2_integration.rs index 988a22f..562d892 100644 --- a/kubi/src/guiv2_integration.rs +++ b/kubi/src/guiv2_integration.rs @@ -1,5 +1,4 @@ -use glam::vec2; -use kubi_ui::{KubiUi, backend::glium::GliumUiRenderer, element::{progress_bar::ProgressBar, UiElement}, UiSize}; +use kubi_ui::{KubiUi, backend::glium::GliumUiRenderer}; use shipyard::{AllStoragesView, Unique, UniqueView, NonSendSync, UniqueViewMut}; use crate::rendering::{Renderer, RenderTarget, WindowSize}; @@ -23,10 +22,6 @@ pub fn kubi_ui_begin( mut ui: NonSendSync> ) { ui.ui.begin(); - ui.ui.add(ProgressBar { - size: (UiSize::Pixels(300.), UiSize::Auto), - ..Default::default() - }, vec2(999., 999.)); } pub fn kubi_ui_end( diff --git a/kubi/src/legacy_gui.rs b/kubi/src/legacy_gui.rs deleted file mode 100644 index 29561c5..0000000 --- a/kubi/src/legacy_gui.rs +++ /dev/null @@ -1,78 +0,0 @@ -use shipyard::{Component, Unique, Workload, IntoWorkload, AllStoragesView, View, UniqueViewMut, IntoIter}; -use glam::{Vec4, Mat4}; -use crate::{color::color_hex, events::WindowResizedEvent}; - -pub mod text_widget; -pub mod progressbar; - -use progressbar::render_progressbars; - -//TODO compute gui scale on window resize -#[derive(Unique, Clone, Copy, Debug, Default)] -pub struct LegacyGuiView(pub Mat4); - -#[derive(Component, Clone, Copy, Debug, Default)] -pub struct LegacyGuiComponent; - -#[derive(Component, Clone, Copy, Debug)] -pub struct LegacyPrimaryColor(pub Vec4); -impl Default for LegacyPrimaryColor { - fn default() -> Self { - Self(color_hex(0x156cddff)) - } -} - -#[derive(Component, Clone, Copy, Debug)] -pub struct LegacySecondaryColor(pub Vec4); -impl Default for LegacySecondaryColor { - fn default() -> Self { - Self(color_hex(0xc9d5e4ff)) - } -} - -fn update_legacy_gui_view( - mut view: UniqueViewMut, - resize: View, -) { - let Some(&size) = resize.iter().next() else { - return - }; - let [w, h] = size.0.to_array(); - view.0 = Mat4::orthographic_rh_gl(0.0, w as f32, h as f32, 0.0, -1.0, 1.0); -} - -pub fn legacy_ui_init( - storages: AllStoragesView -) { - storages.add_unique(LegacyGuiView::default()); -} - -pub fn legacy_ui_update() -> Workload { - ( - update_legacy_gui_view - ).into_sequential_workload() -} - -pub fn legacy_ui_render() -> Workload { - ( - render_progressbars - ).into_sequential_workload() -} - -// pub fn gui_testing( -// mut storages: AllStoragesViewMut, -// ) { -// storages.add_entity(( -// GuiComponent, -// Transform2d(Mat3::from_scale_angle_translation( -// vec2(1920., 16.), -// 0., -// vec2(0., 0.) -// )), -// ProgressbarComponent { -// progress: 0.33 -// }, -// PrimaryColor::default(), -// SecondaryColor::default(), -// )); -// } diff --git a/kubi/src/legacy_gui/progressbar.rs b/kubi/src/legacy_gui/progressbar.rs deleted file mode 100644 index c88f80f..0000000 --- a/kubi/src/legacy_gui/progressbar.rs +++ /dev/null @@ -1,46 +0,0 @@ -use shipyard::{UniqueView, UniqueViewMut, NonSendSync, View, Component, IntoIter, IntoWithId, Get, track}; -use glium::{Surface, uniform, DrawParameters}; -use crate::{ - prefabs::ProgressbarShaderPrefab, - rendering::{ - RenderTarget, - primitives::rect::RectPrimitive - }, - transform::Transform2d, -}; -use super::{LegacyGuiComponent, LegacyPrimaryColor, LegacySecondaryColor, LegacyGuiView}; - -#[derive(Component, Debug, Clone, Copy, Default)] -pub struct ProgressbarComponent { - pub progress: f32 -} - -pub fn render_progressbars( - mut target: NonSendSync>, - rect: NonSendSync>, - program: NonSendSync>, - view: UniqueView, - components: View, - transforms: View, - progressbars: View, - primary: View, - secondary: View, -) { - for (eid, (_, transform, progress)) in (&components, &transforms, &progressbars).iter().with_id() { - let primary_color = primary.get(eid).copied().unwrap_or_default(); - let secondary_color = secondary.get(eid).copied().unwrap_or_default(); - target.0.draw( - &rect.0, - &rect.1, - &program.0, - &uniform! { - transform: transform.0.to_cols_array_2d(), - ui_view: view.0.to_cols_array_2d(), - progress: progress.progress, - color: primary_color.0.to_array(), - bg_color: secondary_color.0.to_array(), - }, - &DrawParameters::default() - ).unwrap(); - } -} diff --git a/kubi/src/legacy_gui/text_widget.rs b/kubi/src/legacy_gui/text_widget.rs deleted file mode 100644 index 31c4422..0000000 --- a/kubi/src/legacy_gui/text_widget.rs +++ /dev/null @@ -1 +0,0 @@ -//TODO text widget diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index 796719a..d5a06b1 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -29,7 +29,6 @@ pub(crate) mod delta_time; pub(crate) mod cursor_lock; pub(crate) mod control_flow; pub(crate) mod state; -pub(crate) mod legacy_gui; pub(crate) mod guiv2_integration; pub(crate) mod networking; pub(crate) mod init; @@ -77,7 +76,6 @@ use control_flow::{exit_on_esc, insert_control_flow_unique, RequestExit}; use state::{is_ingame, is_ingame_or_loading, is_loading, init_state, update_state, is_connecting}; use networking::{update_networking, update_networking_late, is_multiplayer, disconnect_on_exit, is_singleplayer}; use init::initialize_from_args; -use legacy_gui::{legacy_ui_render, legacy_ui_init, legacy_ui_update}; use guiv2_integration::{kubi_ui_init, kubi_ui_begin, kubi_ui_end, kubi_ui_draw}; use loading_screen::update_loading_screen; use connecting_screen::switch_to_loading_if_connected; @@ -104,7 +102,6 @@ fn startup() -> Workload { initialize_from_args, lock_cursor_now, init_input, - legacy_ui_init, insert_control_flow_unique, init_delta_time, ).into_sequential_workload() @@ -141,7 +138,6 @@ fn update() -> Workload { ).into_sequential_workload().run_if(is_ingame), update_networking_late.run_if(is_multiplayer), compute_cameras, - legacy_ui_update, kubi_ui_end, update_state, exit_on_esc, @@ -158,7 +154,6 @@ fn render() -> Workload { render_selection_box, render_entities, ).into_sequential_workload().run_if(is_ingame), - legacy_ui_render, kubi_ui_draw, ).into_sequential_workload() }