From 9f1c64bafd891cfbf0ba819d03d01337196cb92c Mon Sep 17 00:00:00 2001 From: QueenOfSquiggles <8940604+QueenOfSquiggles@users.noreply.github.com> Date: Fri, 29 Mar 2024 09:12:14 -0500 Subject: [PATCH] Updating for new project, slight ergonomic improvements --- .gitignore | 3 ++ Cargo.toml | 2 +- .../sqore_options_menu.tscn | 4 +-- sqore.gdextension | 12 ++++--- src/editor/editor_plugin.rs | 35 +++++++++++++++---- src/scene/gui/collapsable_container.rs | 2 +- src/scene/state_machine.rs | 5 +++ 7 files changed, 49 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 76d1684..298d7fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ assets/ doc/ +!doc/.gdignore + debug/ target/ + Cargo.lock sqore_release.zip *.json diff --git a/Cargo.toml b/Cargo.toml index d397bf3..7f7f56e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqore" -version = "0.2.0" +version = "0.2.1" edition = "2021" [lib] diff --git a/scenes/prefabs/sqore_options_menu/sqore_options_menu.tscn b/scenes/prefabs/sqore_options_menu/sqore_options_menu.tscn index 8e6fa3a..9ec45bf 100644 --- a/scenes/prefabs/sqore_options_menu/sqore_options_menu.tscn +++ b/scenes/prefabs/sqore_options_menu/sqore_options_menu.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=3 uid="uid://dnbbxlomwl1pr"] -[ext_resource type="Script" path="res://addons/sqore/scenes/prefabs/sqore_options_menu/sqore_options_menu.gd" id="1_6met4"] -[ext_resource type="Script" path="res://addons/sqore/scenes/prefabs/sqore_options_menu/gameplay.gd" id="2_n73id"] +[ext_resource type="Script" path="res://addons/squiggles-core/scenes/prefabs/sqore_options_menu/sqore_options_menu.gd" id="1_6met4"] +[ext_resource type="Script" path="res://addons/squiggles-core/scenes/prefabs/sqore_options_menu/gameplay.gd" id="2_n73id"] [node name="SqoreOptionsMenu" type="VBoxContainer"] anchors_preset = 15 diff --git a/sqore.gdextension b/sqore.gdextension index c0c42a5..fea254a 100644 --- a/sqore.gdextension +++ b/sqore.gdextension @@ -22,13 +22,11 @@ macos.release.arm64 = "res://addons/sqore/target/release/libsqore.dylib" [icons] -;; camera.rs +;; scene/camera.rs CameraBrain3D = "res://addons/sqore/assets/icons/camera_brain.svg" VirtualCamera3D = "res://addons/sqore/assets/icons/virtual_camera.svg" -;; interaction.rs - InteractRaycast3D = "res://addons/sqore/assets/icons/interaction_raycast3d.svg" InteractArea3D = "res://addons/sqore/assets/icons/interaction_area3d.svg" InteractionObjectArea3D = "res://addons/sqore/assets/icons/interact_object_area3d.svg" @@ -41,6 +39,12 @@ FiniteStateMachine = "res://addons/sqore/assets/icons/fsm.svg" FiniteState = "res://addons/sqore/assets/icons/fsm_state.svg" FiniteSubStateMachine = "res://addons/sqore/assets/icons/fsm_sub_state.svg" -;; utility_nodes/gui_interact.rs +;; scene/utility_nodes GuiInteract = "res://addons/sqore/assets/icons/gui_interact.svg" + +;; scene/gui + +CollapsingVBoxContainer = "res://addons/sqore/assets/icons/collapseable_panel.svg" +LabelledHSlider = "res://addons/sqore/assets/icons/labelled_hslider.svg" + diff --git a/src/editor/editor_plugin.rs b/src/editor/editor_plugin.rs index 8e7e93c..2745b76 100644 --- a/src/editor/editor_plugin.rs +++ b/src/editor/editor_plugin.rs @@ -11,12 +11,17 @@ use crate::scene::serialization::SqoreSerialized; struct SqoreEditorUtils { tool_items: Option>, base: Base, + menu_callbacks: Vec, } #[godot_api] impl IEditorPlugin for SqoreEditorUtils { fn enter_tree(&mut self) { - let menu = PopupMenu::new_alloc(); + let mut menu = PopupMenu::new_alloc(); + menu.connect( + StringName::from("id_pressed"), + Callable::from_object_method(&self.to_gd(), "on_menu_item"), + ); self.base_mut() .add_tool_submenu_item("Sqore".to_godot(), menu.clone()); self.tool_items = Some(menu); @@ -54,10 +59,17 @@ impl IEditorPlugin for SqoreEditorUtils { fn exit_tree(&mut self) {} } - +#[godot_api] impl SqoreEditorUtils { const DOC_ENTRY_INDEX: &'static str = "res://addons/sqore/doc/sqore/index.html"; + fn humanize_text(input: &str) -> String { + let (f, b) = input.split_at(1); + let front: String = f.to_uppercase(); + let back: String = b.replace('_', " "); + front + back.as_str() + } + /// registers a callable command in both the tools dropdown pane of the editor and the command palette for quick access fn register_tool_item( &mut self, @@ -67,13 +79,24 @@ impl SqoreEditorUtils { command_palette: &mut Gd, ) { let fname = ("sqore_core/".to_string() + name).to_godot(); + let hname = Self::humanize_text(name); if let Some(mut menu_items) = self.tool_items.clone() { menu_items.add_item(name.to_godot()); let index = menu_items.get_item_count() - 1; - menu_items.set_item_tooltip(index, description.to_godot()) + menu_items.set_item_text(index, hname.clone().into()); + menu_items.set_item_tooltip(index, description.to_godot()); + self.menu_callbacks.push(func.clone()); + } else { + self.base_mut() + .add_tool_menu_item(fname.clone(), func.clone()); + } + command_palette.add_command(hname.to_godot(), fname, func); + } + + #[func] + fn on_menu_item(&mut self, index: u32) { + if let Some(callable) = self.menu_callbacks.get(index as usize) { + callable.callv(Array::new()); } - self.base_mut() - .add_tool_menu_item(fname.clone(), func.clone()); - command_palette.add_command(name.to_godot(), fname, func); } } diff --git a/src/scene/gui/collapsable_container.rs b/src/scene/gui/collapsable_container.rs index 08c8d3e..884969a 100644 --- a/src/scene/gui/collapsable_container.rs +++ b/src/scene/gui/collapsable_container.rs @@ -56,7 +56,7 @@ impl CollapsingVBoxContainer { let mut children: Vec> = self.base_mut().get_children().iter_shared().collect(); if let Some(btn) = &self.heading { let btn_base = &btn.clone().upcast::(); - children = children.into_iter().filter(|p| p != btn_base).collect(); + children.retain(|p| p != btn_base); } for child in children { if let Ok(control) = &mut child.clone().try_cast::() { diff --git a/src/scene/state_machine.rs b/src/scene/state_machine.rs index 3ae7261..01bc239 100644 --- a/src/scene/state_machine.rs +++ b/src/scene/state_machine.rs @@ -1,3 +1,8 @@ +//! # State Machines +//! For Godot 4.2 earlier, you have to manually remember the functions "tick", "on_enter", and "on_exit" as those are the string name values that are checked for in the states. +//! > From Godot 4.3+, support for virtual functions will have been reached which will allow a refactor that makes extending the base class functions significantly easier. +//! +//! For now just remember to keep your function names in order and everything should be fine use godot::prelude::*; const METHOD_TICK: &str = "tick";