mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-13 17:23:08 +00:00
Add share config button
This commit is contained in:
parent
bd68f3d20b
commit
769bb3dcc7
|
@ -2,6 +2,9 @@
|
|||
extends Node
|
||||
|
||||
signal color_changed(color: Color, button: int)
|
||||
@warning_ignore("unused_signal")
|
||||
signal config_changed(slot_idx: int, config: Dictionary)
|
||||
@warning_ignore("unused_signal")
|
||||
signal flip_rotated(flip_x, flip_y, rotate_90, rotate_180, rotate_270)
|
||||
signal options_reset
|
||||
|
||||
|
@ -12,6 +15,10 @@ var horizontal_mirror := false
|
|||
var vertical_mirror := false
|
||||
var pixel_perfect := false
|
||||
var alpha_locked := false
|
||||
var share_config := false:
|
||||
set(value):
|
||||
share_config = value
|
||||
attempt_config_share(MOUSE_BUTTON_LEFT)
|
||||
|
||||
# Dynamics
|
||||
var stabilizer_enabled := false
|
||||
|
@ -373,6 +380,33 @@ func _ready() -> void:
|
|||
_show_relevant_tools(layer_type)
|
||||
|
||||
|
||||
## Syncs the other tool using the config of tool located at [param from_idx].[br]
|
||||
## NOTE: For optimization, if there is already a ready made config available, then we will use that
|
||||
## instead of re-calculating the config, else we have no choice but to re-generate it
|
||||
func attempt_config_share(from_idx: int, config: Dictionary = {}):
|
||||
if share_config:
|
||||
if config.is_empty() and _slots[from_idx]:
|
||||
var from_slot: Slot = _slots.get(from_idx, null)
|
||||
if from_slot:
|
||||
var from_tool = from_slot.tool_node
|
||||
if from_tool.has_method("get_config"):
|
||||
config = from_tool.get_config()
|
||||
#print(config)
|
||||
var target_slot: Slot = _slots.get(MOUSE_BUTTON_LEFT, null)
|
||||
if from_idx == MOUSE_BUTTON_LEFT:
|
||||
target_slot = _slots.get(MOUSE_BUTTON_RIGHT, null)
|
||||
if target_slot: # FailSafe Check
|
||||
# Using call() to avoid errors in case a tool doesn't contain the method
|
||||
if (
|
||||
target_slot.tool_node.has_method("set_config")
|
||||
and target_slot.tool_node.has_method("update_config")
|
||||
):
|
||||
target_slot.tool_node.set("is_syncing", true)
|
||||
target_slot.tool_node.set_config(config)
|
||||
target_slot.tool_node.update_config()
|
||||
target_slot.tool_node.set("is_syncing", false)
|
||||
|
||||
|
||||
func reset_options() -> void:
|
||||
default_color()
|
||||
assign_tool(get_tool(MOUSE_BUTTON_LEFT).tool_node.name, MOUSE_BUTTON_LEFT, true)
|
||||
|
@ -401,9 +435,12 @@ func remove_tool(t: Tool) -> void:
|
|||
|
||||
|
||||
func set_tool(tool_name: String, button: int) -> void:
|
||||
## To prevent any unintentional syncing, we will temporarily disconnect the signal
|
||||
Tools.config_changed.disconnect(attempt_config_share)
|
||||
var slot: Slot = _slots[button]
|
||||
var panel: Node = _panels[button]
|
||||
var node: Node = tools[tool_name].instantiate_scene()
|
||||
var config_slot := MOUSE_BUTTON_LEFT if button == MOUSE_BUTTON_RIGHT else MOUSE_BUTTON_RIGHT
|
||||
if button == MOUSE_BUTTON_LEFT: # As guides are only moved with left mouse
|
||||
if tool_name == "Pan": # tool you want to give more access at guides
|
||||
Global.move_guides_on_canvas = true
|
||||
|
@ -422,6 +459,11 @@ func set_tool(tool_name: String, button: int) -> void:
|
|||
elif button == MOUSE_BUTTON_RIGHT:
|
||||
_right_tools_per_layer_type[_curr_layer_type] = tool_name
|
||||
|
||||
# Wait for config to get loaded, then re-connect and sync
|
||||
await get_tree().process_frame
|
||||
Tools.config_changed.connect(attempt_config_share)
|
||||
attempt_config_share(config_slot) # Sync it with the other tool
|
||||
|
||||
|
||||
func get_tool(button: int) -> Slot:
|
||||
return _slots[button]
|
||||
|
|
|
@ -113,6 +113,11 @@ func get_config() -> Dictionary:
|
|||
"brush_index": _brush.index,
|
||||
"brush_size": _brush_size,
|
||||
"brush_interpolate": _brush_interpolate,
|
||||
"brush_flip_x": _brush_flip_x,
|
||||
"brush_flip_y": _brush_flip_y,
|
||||
"brush_rotate_90": _brush_rotate_90,
|
||||
"brush_rotate_180": _brush_rotate_180,
|
||||
"brush_rotate_270": _brush_rotate_270,
|
||||
}
|
||||
|
||||
|
||||
|
@ -125,6 +130,11 @@ func set_config(config: Dictionary) -> void:
|
|||
if Tools.dynamics_size != Tools.Dynamics.NONE:
|
||||
_brush_size_dynamics = Tools.brush_size_min
|
||||
_brush_interpolate = config.get("brush_interpolate", _brush_interpolate)
|
||||
_brush_flip_x = config.get("brush_flip_x", _brush_flip_x)
|
||||
_brush_flip_y = config.get("brush_flip_y", _brush_flip_y)
|
||||
_brush_rotate_90 = config.get("brush_rotate_90", _brush_rotate_90)
|
||||
_brush_rotate_180 = config.get("brush_rotate_180", _brush_rotate_180)
|
||||
_brush_rotate_270 = config.get("brush_rotate_270", _brush_rotate_270)
|
||||
|
||||
|
||||
func update_config() -> void:
|
||||
|
@ -743,23 +753,28 @@ func _pick_color(pos: Vector2i) -> void:
|
|||
func _on_flip_x_toggled(button_pressed: bool) -> void:
|
||||
_brush_flip_x = button_pressed
|
||||
update_brush()
|
||||
save_config()
|
||||
|
||||
|
||||
func _on_flip_y_toggled(button_pressed: bool) -> void:
|
||||
_brush_flip_y = button_pressed
|
||||
update_brush()
|
||||
save_config()
|
||||
|
||||
|
||||
func _on_rotate_90_toggled(button_pressed: bool) -> void:
|
||||
_brush_rotate_90 = button_pressed
|
||||
update_brush()
|
||||
save_config()
|
||||
|
||||
|
||||
func _on_rotate_180_toggled(button_pressed: bool) -> void:
|
||||
_brush_rotate_180 = button_pressed
|
||||
update_brush()
|
||||
save_config()
|
||||
|
||||
|
||||
func _on_rotate_270_toggled(button_pressed: bool) -> void:
|
||||
_brush_rotate_270 = button_pressed
|
||||
update_brush()
|
||||
save_config()
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
class_name BaseTool
|
||||
extends VBoxContainer
|
||||
|
||||
signal config_changed(config: Dictionary)
|
||||
|
||||
var is_moving := false
|
||||
var is_syncing := false
|
||||
var kname: String
|
||||
var tool_slot: Tools.Slot = null
|
||||
var cursor_text := ""
|
||||
|
@ -34,6 +37,8 @@ func _ready() -> void:
|
|||
func save_config() -> void:
|
||||
var config := get_config()
|
||||
Global.config_cache.set_value(tool_slot.kname, kname, config)
|
||||
if not is_syncing: # If the tool isn't buzy syncing with another tool
|
||||
Tools.config_changed.emit(tool_slot.button, config)
|
||||
|
||||
|
||||
func load_config() -> void:
|
||||
|
|
|
@ -50,6 +50,7 @@ func _on_SpacingMode_toggled(button_pressed: bool) -> void:
|
|||
|
||||
func _on_Spacing_value_changed(value: Vector2) -> void:
|
||||
_spacing = value
|
||||
save_config()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
|
|
|
@ -6,6 +6,7 @@ extends PanelContainer
|
|||
@onready var pixel_perfect: BaseButton = grid_container.get_node("PixelPerfect")
|
||||
@onready var alpha_lock: BaseButton = grid_container.get_node("AlphaLock")
|
||||
@onready var dynamics: Button = $"%Dynamics"
|
||||
@onready var share_config: BaseButton = grid_container.get_node("ShareConfig")
|
||||
@onready var dynamics_panel: PopupPanel = $DynamicsPanel
|
||||
|
||||
|
||||
|
@ -113,3 +114,13 @@ func _on_vertical_mirror_options_id_pressed(id: int) -> void:
|
|||
project.y_symmetry_point = Global.camera.camera_screen_center.y * 2
|
||||
project.x_symmetry_axis.points[0].y = project.y_symmetry_point / 2 + 0.5
|
||||
project.x_symmetry_axis.points[1].y = project.y_symmetry_point / 2 + 0.5
|
||||
|
||||
|
||||
func _on_share_config_toggled(toggled_on: bool) -> void:
|
||||
Tools.share_config = toggled_on
|
||||
Global.config_cache.set_value("tools", "share_config", toggled_on)
|
||||
var texture_button: TextureRect = share_config.get_node("TextureRect")
|
||||
#var file_name := "share_config_on.png"
|
||||
#if not toggled_on:
|
||||
#file_name = "share_config_off.png"
|
||||
#Global.change_button_texturerect(texture_button, file_name)
|
||||
|
|
|
@ -71,7 +71,7 @@ size_flags_vertical = 3
|
|||
[node name="GridContainer" type="GridContainer" parent="ScrollContainer/CenterContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 0
|
||||
columns = 5
|
||||
columns = 6
|
||||
|
||||
[node name="Horizontal" type="Button" parent="ScrollContainer/CenterContainer/GridContainer" groups=["UIButtons"]]
|
||||
custom_minimum_size = Vector2(44, 32)
|
||||
|
@ -105,6 +105,8 @@ anchor_bottom = 0.5
|
|||
offset_left = -22.0
|
||||
offset_top = -10.0
|
||||
offset_bottom = 10.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 2
|
||||
mouse_default_cursor_shape = 2
|
||||
item_count = 2
|
||||
popup/item_0/text = "Move to canvas center"
|
||||
|
@ -235,6 +237,25 @@ offset_right = 11.0
|
|||
offset_bottom = 10.0
|
||||
texture = ExtResource("6")
|
||||
|
||||
[node name="ShareConfig" type="Button" parent="ScrollContainer/CenterContainer/GridContainer"]
|
||||
custom_minimum_size = Vector2(32, 32)
|
||||
layout_mode = 2
|
||||
tooltip_text = "Lock alpha"
|
||||
mouse_default_cursor_shape = 2
|
||||
toggle_mode = true
|
||||
shortcut = SubResource("Shortcut_vcyug")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="ScrollContainer/CenterContainer/GridContainer/ShareConfig"]
|
||||
layout_mode = 0
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -11.0
|
||||
offset_top = -10.0
|
||||
offset_right = 11.0
|
||||
offset_bottom = 10.0
|
||||
|
||||
[node name="DynamicsPanel" type="PopupPanel" parent="."]
|
||||
canvas_item_default_texture_filter = 0
|
||||
size = Vector2i(300, 334)
|
||||
|
@ -545,6 +566,7 @@ offset_bottom = 23.0
|
|||
[connection signal="toggled" from="ScrollContainer/CenterContainer/GridContainer/PixelPerfect" to="." method="_on_PixelPerfect_toggled"]
|
||||
[connection signal="toggled" from="ScrollContainer/CenterContainer/GridContainer/AlphaLock" to="." method="_on_alpha_lock_toggled"]
|
||||
[connection signal="pressed" from="ScrollContainer/CenterContainer/GridContainer/Dynamics" to="." method="_on_Dynamics_pressed"]
|
||||
[connection signal="toggled" from="ScrollContainer/CenterContainer/GridContainer/ShareConfig" to="." method="_on_share_config_toggled"]
|
||||
[connection signal="toggled" from="DynamicsPanel/VBoxContainer/StabilizerContainer/EnableStabilizer" to="DynamicsPanel" method="_on_enable_stabilizer_toggled"]
|
||||
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/StabilizerContainer/StabilizerValue" to="DynamicsPanel" method="_on_stabilizer_value_value_changed"]
|
||||
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/AlphaMin" to="DynamicsPanel" method="_on_alpha_min_value_changed"]
|
||||
|
|
Loading…
Reference in a new issue