mirror of
https://github.com/litruv/PNGTuber-Plus.git
synced 2026-07-24 02:26:02 +10:00
Fixed up edit menu. now is more modular + uses extensive use of v+hbox's !build
This commit is contained in:
73
ui_scenes/components/LABEL_FIX.md
Normal file
73
ui_scenes/components/LABEL_FIX.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# 🔧 Fixed: Slider Labels Now Show Correct Text
|
||||
|
||||
## ✅ **Problem Solved**
|
||||
|
||||
The issue was that slider labels were showing "Value" instead of the actual `label_text` property (like "X Frequency", "Drag", etc.) in the Godot editor.
|
||||
|
||||
## 🎯 **Root Cause**
|
||||
|
||||
1. **Editor Execution**: Components needed `@tool` to work properly in the editor
|
||||
2. **Initialization Timing**: Label updates happened before exported properties were set
|
||||
3. **Property Setter Timing**: Label wasn't updated when properties were set by the editor
|
||||
|
||||
## 🔧 **Solution Applied**
|
||||
|
||||
### **1. Added `@tool` Directive**
|
||||
Added `@tool` to all component scripts to enable editor execution:
|
||||
- `LabeledSlider.gd`
|
||||
- `WobbleSlider.gd`
|
||||
- `ParameterSlider.gd`
|
||||
|
||||
### **2. Improved Property Setters**
|
||||
Updated all export property setters to check if the node is ready:
|
||||
```gdscript
|
||||
func set_label_text(new_text: String):
|
||||
label_text = new_text
|
||||
if is_inside_tree():
|
||||
_update_label()
|
||||
else:
|
||||
call_deferred("_update_label")
|
||||
```
|
||||
|
||||
### **3. Enhanced Initialization**
|
||||
- Added `NOTIFICATION_SCENE_INSTANTIATED` handler
|
||||
- Improved `_ready()` function timing
|
||||
- Added deferred label updates for proper timing
|
||||
|
||||
### **4. Fixed Base Template**
|
||||
Updated `LabeledSlider.tscn` to have cleaner default text:
|
||||
```
|
||||
text = "Value" # Instead of "Value: 0"
|
||||
```
|
||||
|
||||
### **5. Robust Label Updates**
|
||||
Enhanced `_update_label()` to handle missing nodes gracefully:
|
||||
```gdscript
|
||||
func _update_label():
|
||||
if not label:
|
||||
label = get_node_or_null("Label")
|
||||
if not label:
|
||||
call_deferred("_update_label")
|
||||
return
|
||||
# ... update logic
|
||||
```
|
||||
|
||||
## 🎉 **Result**
|
||||
|
||||
Now in the Godot editor, all slider labels should properly display:
|
||||
- ✅ "X Frequency: 0.000 Hz"
|
||||
- ✅ "Y Amplitude: 0"
|
||||
- ✅ "Drag: 0.0"
|
||||
- ✅ "Opacity: 100%"
|
||||
- ✅ "Rotational Limit Min: -180°"
|
||||
|
||||
Instead of just "Value" everywhere!
|
||||
|
||||
## 🔄 **How to Test**
|
||||
|
||||
1. Open `sprite_viewer.tscn` in the Godot editor
|
||||
2. Check the slider components in the scene tree
|
||||
3. Labels should now show the correct text for each parameter
|
||||
4. Properties can be modified in the inspector and labels update immediately
|
||||
|
||||
The components now work properly both in the editor preview and at runtime! 🚀
|
||||
Reference in New Issue
Block a user