2021-02-02 17:48:17 +02:00
|
|
|
extends BaseTool
|
2020-07-09 20:22:17 +08:00
|
|
|
|
2021-11-11 03:21:34 +02:00
|
|
|
var _prev_mode := 0
|
2020-07-09 20:22:17 +08:00
|
|
|
var _color_slot := 0
|
|
|
|
|
|
|
|
|
2021-11-11 03:21:34 +02:00
|
|
|
func _input(event: InputEvent) -> void:
|
2021-11-25 14:48:30 +02:00
|
|
|
var options: OptionButton = $ColorPicker/Options
|
2021-11-11 03:21:34 +02:00
|
|
|
|
|
|
|
if event.is_action_pressed("ctrl"):
|
|
|
|
_prev_mode = options.selected
|
|
|
|
if event.is_action("ctrl"):
|
|
|
|
options.selected = _prev_mode ^ 1
|
|
|
|
_color_slot = options.selected
|
|
|
|
if event.is_action_released("ctrl"):
|
|
|
|
options.selected = _prev_mode
|
|
|
|
_color_slot = options.selected
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func _on_Options_item_selected(id: int) -> void:
|
2020-07-09 20:22:17 +08:00
|
|
|
_color_slot = id
|
|
|
|
update_config()
|
|
|
|
save_config()
|
|
|
|
|
|
|
|
|
|
|
|
func get_config() -> Dictionary:
|
|
|
|
return {
|
2021-11-25 14:48:30 +02:00
|
|
|
"color_slot": _color_slot,
|
2020-07-09 20:22:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func set_config(config: Dictionary) -> void:
|
2020-07-09 20:22:17 +08:00
|
|
|
_color_slot = config.get("color_slot", _color_slot)
|
|
|
|
|
|
|
|
|
|
|
|
func update_config() -> void:
|
|
|
|
$ColorPicker/Options.selected = _color_slot
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func draw_start(position: Vector2) -> void:
|
2020-07-09 20:22:17 +08:00
|
|
|
_pick_color(position)
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func draw_move(position: Vector2) -> void:
|
2020-07-09 20:22:17 +08:00
|
|
|
_pick_color(position)
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func draw_end(_position: Vector2) -> void:
|
2020-07-09 20:22:17 +08:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func _pick_color(position: Vector2) -> void:
|
|
|
|
var project: Project = Global.current_project
|
2021-07-14 18:06:07 +03:00
|
|
|
if project.tile_mode and project.get_tile_mode_rect().has_point(position):
|
|
|
|
position = position.posmodv(project.size)
|
|
|
|
|
2020-08-06 06:13:45 -03:00
|
|
|
if position.x < 0 or position.y < 0:
|
|
|
|
return
|
|
|
|
|
2020-07-09 20:22:17 +08:00
|
|
|
var image := Image.new()
|
|
|
|
image.copy_from(_get_draw_image())
|
2020-08-06 06:13:45 -03:00
|
|
|
if position.x > image.get_width() - 1 or position.y > image.get_height() - 1:
|
|
|
|
return
|
|
|
|
|
2020-07-09 20:22:17 +08:00
|
|
|
image.lock()
|
|
|
|
var color := image.get_pixelv(position)
|
2021-05-12 15:51:31 +03:00
|
|
|
image.unlock()
|
2020-07-09 20:22:17 +08:00
|
|
|
var button := BUTTON_LEFT if _color_slot == 0 else BUTTON_RIGHT
|
2020-10-23 20:18:39 +03:00
|
|
|
Tools.assign_color(color, button, false)
|