mirror of
https://github.com/litruv/PNGTuber-Plus.git
synced 2026-07-24 02:26:02 +10:00
Added renaming layers on right click, removed a lot of old debug logging
This commit is contained in:
@@ -2,9 +2,9 @@ extends NinePatchRect
|
||||
|
||||
@onready var spritePreview = $SpritePreview/Sprite2D
|
||||
@onready var outline = $Selected
|
||||
|
||||
|
||||
@onready var fade = $Fade
|
||||
@onready var button = $Button
|
||||
@onready var label = $Label
|
||||
|
||||
var sprite = null
|
||||
var parent = null
|
||||
@@ -14,9 +14,23 @@ var indent = 0
|
||||
var childrenTags = []
|
||||
var parentTag = null
|
||||
|
||||
## Context menu for right-click actions
|
||||
var context_menu: PopupMenu = null
|
||||
## Line edit for renaming
|
||||
var rename_edit: LineEdit = null
|
||||
## Track if we're currently in rename mode
|
||||
var is_renaming: bool = false
|
||||
|
||||
func _ready():
|
||||
var count = spritePath.get_slice_count("/") - 1
|
||||
$Label.text = spritePath.get_slice("/",count)
|
||||
# Use displayName if available, otherwise fallback to path
|
||||
var display_text = ""
|
||||
if sprite.displayName != "":
|
||||
display_text = sprite.displayName
|
||||
else:
|
||||
var count = spritePath.get_slice_count("/") - 1
|
||||
display_text = spritePath.get_slice("/",count)
|
||||
|
||||
label.text = display_text
|
||||
$Line2D.visible = false
|
||||
|
||||
spritePreview.texture = sprite.sprite.texture
|
||||
@@ -25,6 +39,105 @@ func _ready():
|
||||
spritePreview.scale = Vector2(1,1) * (60.0/displaySize)
|
||||
spritePreview.offset = sprite.sprite.offset
|
||||
|
||||
# Set up right-click detection
|
||||
button.gui_input.connect(_on_button_gui_input)
|
||||
|
||||
# Create context menu
|
||||
_setup_context_menu()
|
||||
|
||||
## Set up the right-click context menu
|
||||
func _setup_context_menu():
|
||||
context_menu = PopupMenu.new()
|
||||
add_child(context_menu)
|
||||
|
||||
# Add rename option
|
||||
context_menu.add_item("Rename", 0)
|
||||
context_menu.id_pressed.connect(_on_context_menu_selected)
|
||||
|
||||
## Handle GUI input events on the button
|
||||
func _on_button_gui_input(event: InputEvent):
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
|
||||
# Show context menu at cursor position
|
||||
var global_pos = get_global_mouse_position()
|
||||
context_menu.position = Vector2i(global_pos)
|
||||
context_menu.popup()
|
||||
|
||||
## Handle context menu selections
|
||||
func _on_context_menu_selected(id: int):
|
||||
match id:
|
||||
0: # Rename
|
||||
_start_rename()
|
||||
|
||||
## Start the rename process
|
||||
func _start_rename():
|
||||
if is_renaming:
|
||||
return
|
||||
|
||||
is_renaming = true
|
||||
|
||||
# Create line edit for renaming
|
||||
rename_edit = LineEdit.new()
|
||||
add_child(rename_edit)
|
||||
|
||||
# Position and size the line edit over the label
|
||||
rename_edit.position = label.position
|
||||
rename_edit.size = label.size
|
||||
rename_edit.text = label.text
|
||||
|
||||
# Hide the original label
|
||||
label.visible = false
|
||||
|
||||
# Focus the line edit and select all text
|
||||
rename_edit.grab_focus()
|
||||
rename_edit.select_all()
|
||||
|
||||
# Connect signals
|
||||
rename_edit.text_submitted.connect(_on_rename_submitted)
|
||||
rename_edit.focus_exited.connect(_on_rename_focus_lost)
|
||||
|
||||
## Handle rename submission (Enter key)
|
||||
func _on_rename_submitted(new_name: String):
|
||||
if rename_edit != null:
|
||||
_finish_rename(new_name)
|
||||
|
||||
## Handle losing focus (clicking elsewhere)
|
||||
func _on_rename_focus_lost():
|
||||
if rename_edit != null:
|
||||
_finish_rename(rename_edit.text)
|
||||
|
||||
## Finish the rename process
|
||||
func _finish_rename(new_name: String):
|
||||
if not is_renaming:
|
||||
return
|
||||
|
||||
is_renaming = false
|
||||
|
||||
# Clean up the line edit
|
||||
if rename_edit:
|
||||
rename_edit.queue_free()
|
||||
rename_edit = null
|
||||
|
||||
# Show the label again
|
||||
label.visible = true
|
||||
|
||||
# Validate and apply the new name
|
||||
new_name = new_name.strip_edges()
|
||||
if new_name != "" and new_name != label.text:
|
||||
_apply_rename(new_name)
|
||||
|
||||
## Apply the rename to the sprite
|
||||
func _apply_rename(new_name: String):
|
||||
# Update the display name (without file extension)
|
||||
label.text = new_name
|
||||
sprite.displayName = new_name # Store display name separately
|
||||
|
||||
# Update the global sprite list
|
||||
Global.spriteList.updateData()
|
||||
|
||||
# Show feedback to user
|
||||
Global.pushUpdate("Renamed sprite to: " + new_name)
|
||||
|
||||
|
||||
func updateChildren():
|
||||
for child in childrenTags:
|
||||
|
||||
Reference in New Issue
Block a user