diff --git a/src/Tools/DesignTools/Shading.gd b/src/Tools/DesignTools/Shading.gd index 1a964430b..4dda20c0e 100644 --- a/src/Tools/DesignTools/Shading.gd +++ b/src/Tools/DesignTools/Shading.gd @@ -1,6 +1,6 @@ extends "res://src/Tools/BaseDraw.gd" -enum ShadingMode { SIMPLE, HUE_SHIFTING } +enum ShadingMode { SIMPLE, HUE_SHIFTING, COLOR_REPLACE } enum LightenDarken { LIGHTEN, DARKEN } var _prev_mode := 0 @@ -12,6 +12,8 @@ var _amount := 10 var _hue_amount := 10 var _sat_amount := 10 var _value_amount := 10 +var _colors_right := 10 +var _old_palette: Palette class LightenDarkenOp: @@ -28,17 +30,18 @@ class LightenDarkenOp: var sat_lighten_limit := 10.0 / 100.0 var value_darken_limit := 10.0 / 100.0 + var color_array := PackedStringArray() func process(_src: Color, dst: Color) -> Color: changed = true - if dst.a == 0: + if dst.a == 0 and shading_mode != ShadingMode.COLOR_REPLACE: return dst if shading_mode == ShadingMode.SIMPLE: if lighten_or_darken == LightenDarken.LIGHTEN: dst = dst.lightened(strength) else: dst = dst.darkened(strength) - else: + elif shading_mode == ShadingMode.HUE_SHIFTING: var hue_shift := hue_amount / 360.0 var sat_shift := sat_amount / 100.0 var value_shift := value_amount / 100.0 @@ -61,6 +64,18 @@ class LightenDarkenOp: dst.s += sat_shift if dst.v > value_darken_limit: dst.v = maxf(dst.v - minf(value_shift, dst.v), value_darken_limit) + else: + if not color_array.is_empty(): + var index = color_array.find(dst.to_html()) + if index != -1: + if lighten_or_darken == LightenDarken.LIGHTEN: + ## Moving to Right + if index < color_array.size() - 1: + dst = Color(color_array[index + 1]) + else: + ## Moving to Left + if index > 0: + dst = Color(color_array[index - 1]) return dst @@ -106,6 +121,8 @@ class LightenDarkenOp: func _init() -> void: _drawer.color_op = LightenDarkenOp.new() + Tools.color_changed.connect(_refresh_colors_array) + Palettes.palette_selected.connect(palette_changed) func _input(event: InputEvent) -> void: @@ -161,6 +178,12 @@ func _on_LightenDarken_value_value_changed(value: float) -> void: save_config() +func _on_LightenDarken_colors_right_changed(value: float) -> void: + _colors_right = int(value) + update_config() + save_config() + + func get_config() -> Dictionary: var config := super.get_config() config["shading_mode"] = _shading_mode @@ -169,6 +192,7 @@ func get_config() -> Dictionary: config["hue_amount"] = _hue_amount config["sat_amount"] = _sat_amount config["value_amount"] = _value_amount + config["colors_right"] = _colors_right return config @@ -182,6 +206,7 @@ func set_config(config: Dictionary) -> void: _hue_amount = config.get("hue_amount", _hue_amount) _sat_amount = config.get("sat_amount", _sat_amount) _value_amount = config.get("value_amount", _value_amount) + _colors_right = config.get("colors_right", _colors_right) func update_config() -> void: @@ -192,8 +217,11 @@ func update_config() -> void: $HueShiftingOptions/HueSlider.value = _hue_amount $HueShiftingOptions/SatSlider.value = _sat_amount $HueShiftingOptions/ValueSlider.value = _value_amount + $ColorReplaceOptions/Settings/ColorsRight.value = _colors_right $AmountSlider.visible = _shading_mode == ShadingMode.SIMPLE $HueShiftingOptions.visible = _shading_mode == ShadingMode.HUE_SHIFTING + $ColorReplaceOptions.visible = _shading_mode == ShadingMode.COLOR_REPLACE + _refresh_colors_array() update_strength() @@ -293,3 +321,54 @@ func _draw_brush_image(image: Image, src_rect: Rect2i, dst: Vector2i) -> void: func update_brush() -> void: super.update_brush() $ColorInterpolation.visible = false + + +## this function is also used by a signal, this is why there is _color = Color.TRANSPARENT in here. +func _refresh_colors_array(_color = Color.TRANSPARENT, mouse_button := tool_slot.button) -> void: + if mouse_button != tool_slot.button: + return + if _shading_mode == ShadingMode.COLOR_REPLACE: + await get_tree().process_frame + var index = Palettes.current_palette_get_selected_color_index(mouse_button) + if index > -1: + $ColorReplaceOptions/Settings.visible = true + $ColorReplaceOptions/Label.visible = false + var color_array := PackedStringArray() + for i in _colors_right + 1: + var next_color = Palettes.current_palette.get_color(index + i) + if next_color != null: + color_array.append(next_color.to_html()) + _drawer.color_op.color_array = color_array + construct_preview() + else: + $ColorReplaceOptions/Settings.visible = false + $ColorReplaceOptions/Label.visible = true + _drawer.color_op.color_array.clear() + + +func construct_preview() -> void: + var colors_container: HFlowContainer = $ColorReplaceOptions/Settings/Colors + for i in colors_container.get_child_count(): + if i >= _drawer.color_op.color_array.size(): + colors_container.get_child(i).queue_free() + for i in _drawer.color_op.color_array.size(): + var color = _drawer.color_op.color_array[i] + if i < colors_container.get_child_count(): + colors_container.get_child(i).color = color + else: + var color_rect := ColorRect.new() + color_rect.color = color + color_rect.custom_minimum_size = Vector2(20, 20) + var checker = preload("res://src/UI/Nodes/TransparentChecker.tscn").instantiate() + checker.show_behind_parent = true + checker.set_anchors_preset(Control.PRESET_FULL_RECT) + color_rect.add_child(checker) + colors_container.add_child(color_rect) + + +func palette_changed(_palette_name): + if _old_palette: + _old_palette.data_changed.disconnect(_refresh_colors_array) + Palettes.current_palette.data_changed.connect(_refresh_colors_array) + _old_palette = Palettes.current_palette + _refresh_colors_array() diff --git a/src/Tools/DesignTools/Shading.tscn b/src/Tools/DesignTools/Shading.tscn index 21fd4c309..b78e383a1 100644 --- a/src/Tools/DesignTools/Shading.tscn +++ b/src/Tools/DesignTools/Shading.tscn @@ -24,22 +24,22 @@ button_group = SubResource("ButtonGroup_se02m") custom_minimum_size = Vector2(92, 0) layout_mode = 2 mouse_default_cursor_shape = 2 -item_count = 2 selected = 0 +item_count = 2 popup/item_0/text = "Lighten" -popup/item_0/id = 0 popup/item_1/text = "Darken" popup/item_1/id = 1 [node name="ShadingMode" type="OptionButton" parent="." index="6"] layout_mode = 2 mouse_default_cursor_shape = 2 -item_count = 2 selected = 0 +item_count = 3 popup/item_0/text = "Simple Shading" -popup/item_0/id = 0 popup/item_1/text = "Hue Shifting" popup/item_1/id = 1 +popup/item_2/text = "Color Replace" +popup/item_2/id = 2 [node name="AmountSlider" parent="." index="7" instance=ExtResource("3")] layout_mode = 2 @@ -71,9 +71,50 @@ min_value = -100.0 value = 10.0 prefix = "Value:" +[node name="ColorReplaceOptions" type="VBoxContainer" parent="." index="9"] +visible = false +layout_mode = 2 + +[node name="Settings" type="VBoxContainer" parent="ColorReplaceOptions" index="0"] +visible = false +layout_mode = 2 + +[node name="ColorsRight" parent="ColorReplaceOptions/Settings" index="0" instance=ExtResource("3")] +layout_mode = 2 +max_value = 10.0 +allow_greater = true +prefix = "Colors Right" + +[node name="HBoxContainer" type="HBoxContainer" parent="ColorReplaceOptions/Settings" index="1"] +layout_mode = 2 + +[node name="DarkenLabel" type="Label" parent="ColorReplaceOptions/Settings/HBoxContainer" index="0"] +layout_mode = 2 +text = "Darken" + +[node name="HSeparator" type="HSeparator" parent="ColorReplaceOptions/Settings/HBoxContainer" index="1"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="LightenLabel" type="Label" parent="ColorReplaceOptions/Settings/HBoxContainer" index="2"] +layout_mode = 2 +text = "Lighten" +horizontal_alignment = 2 + +[node name="Colors" type="HFlowContainer" parent="ColorReplaceOptions/Settings" index="2"] +layout_mode = 2 + +[node name="Label" type="Label" parent="ColorReplaceOptions" index="1"] +custom_minimum_size = Vector2(0, 75) +layout_mode = 2 +text = "Please Select a color from the palette." +horizontal_alignment = 1 +autowrap_mode = 3 + [connection signal="item_selected" from="LightenDarken" to="." method="_on_LightenDarken_item_selected"] [connection signal="item_selected" from="ShadingMode" to="." method="_on_ShadingMode_item_selected"] [connection signal="value_changed" from="AmountSlider" to="." method="_on_LightenDarken_value_changed"] [connection signal="value_changed" from="HueShiftingOptions/HueSlider" to="." method="_on_LightenDarken_hue_value_changed"] [connection signal="value_changed" from="HueShiftingOptions/SatSlider" to="." method="_on_LightenDarken_sat_value_changed"] [connection signal="value_changed" from="HueShiftingOptions/ValueSlider" to="." method="_on_LightenDarken_value_value_changed"] +[connection signal="value_changed" from="ColorReplaceOptions/Settings/ColorsRight" to="." method="_on_LightenDarken_colors_right_changed"]