mirror of
https://github.com/Relintai/pandemonium_paint_experimental.git
synced 2024-11-07 16:52:10 +01:00
Initial action implementation.
This commit is contained in:
parent
a58c95caaf
commit
0c6ed1316a
2
HEADS
2
HEADS
@ -1 +1 @@
|
|||||||
{"engine": {"3.2": "64a9e86c5c20bd4bd5833f0563457d0126617489", "3.x": "9b512dd510207d32911064a1bbe15b80c91b006b"}, "world_generator": {"master": "260c430f11b0b591eaf4714516419aa327d2842c"}, "entity_spell_system": {"master": "3536f01bacf5f54cefb32b768cd020a1f94d0ade"}, "ui_extensions": {"master": "80a3b96fc56991a0f88a1d441ed1e3cebaf3307a"}, "texture_packer": {"master": "ae4d222fbaade063ed6f0bc9f3aaa53df68a7fed"}, "fastnoise": {"master": "46bb1f610bfb7171613b5c708d312bcf94e89356"}, "thread_pool": {"master": "0917511d04bb1aa308385b63ec88d3c182990628"}, "mesh_data_resource": {"master": "a062d871d49d954c5466b9de54b4075cb61cbef4"}, "mesh_utils": {"master": "b52a261c31f04fad624e5cfbcdcc4a45d61136da"}, "props": {"master": "2afd6eff45f9a921bdf4090ff3029def86df5cb5"}, "terraman_2d": {"master": "60a7e84a5dc2fc252b0c582dd8f877685d28d74a"}, "broken_seals_module": {"master": "52c5a81350db1c29d375c63d95010260911ec034"}, "rtile_map": {"master": "389070cfef387b69902e23e6c4ac53997b69e42e"}, "props_2d": {"master": "a45822b63519d7f9fb391ab6b1dced468c6f399d"}, "pandemonium_engine": {"master": "afa0e83f780ceb7255f2c4b5a72b7ed20931f3c2"}}
|
{"engine": {"3.2": "64a9e86c5c20bd4bd5833f0563457d0126617489", "3.x": "9b512dd510207d32911064a1bbe15b80c91b006b"}, "world_generator": {"master": "260c430f11b0b591eaf4714516419aa327d2842c"}, "entity_spell_system": {"master": "3536f01bacf5f54cefb32b768cd020a1f94d0ade"}, "ui_extensions": {"master": "80a3b96fc56991a0f88a1d441ed1e3cebaf3307a"}, "texture_packer": {"master": "ae4d222fbaade063ed6f0bc9f3aaa53df68a7fed"}, "fastnoise": {"master": "46bb1f610bfb7171613b5c708d312bcf94e89356"}, "thread_pool": {"master": "0917511d04bb1aa308385b63ec88d3c182990628"}, "mesh_data_resource": {"master": "a062d871d49d954c5466b9de54b4075cb61cbef4"}, "mesh_utils": {"master": "b52a261c31f04fad624e5cfbcdcc4a45d61136da"}, "props": {"master": "2afd6eff45f9a921bdf4090ff3029def86df5cb5"}, "terraman_2d": {"master": "60a7e84a5dc2fc252b0c582dd8f877685d28d74a"}, "broken_seals_module": {"master": "52c5a81350db1c29d375c63d95010260911ec034"}, "rtile_map": {"master": "389070cfef387b69902e23e6c4ac53997b69e42e"}, "props_2d": {"master": "a45822b63519d7f9fb391ab6b1dced468c6f399d"}, "pandemonium_engine": {"master": "25968b280341d89a9794cff2da00d1549ccbd14c"}}
|
@ -3,7 +3,21 @@ extends PaintCanvas
|
|||||||
|
|
||||||
var _mouse_down : bool = false
|
var _mouse_down : bool = false
|
||||||
|
|
||||||
func draw(local_position : Vector2) -> void:
|
var _actions_history : Array
|
||||||
|
var _redo_history : Array
|
||||||
|
var _current_action : PaintAction
|
||||||
|
|
||||||
|
var mouse_position : Vector2
|
||||||
|
#var canvas_position : Vector2
|
||||||
|
var canvas_mouse_position : Vector2
|
||||||
|
var cell_mouse_position : Vector2
|
||||||
|
|
||||||
|
var last_mouse_position : Vector2
|
||||||
|
#var last_canvas_position : Vector2
|
||||||
|
var last_canvas_mouse_position : Vector2
|
||||||
|
var last_cell_mouse_position : Vector2
|
||||||
|
|
||||||
|
func handle_draw(local_position : Vector2, event: InputEvent) -> void:
|
||||||
var proj : PaintProject = get_paint_project()
|
var proj : PaintProject = get_paint_project()
|
||||||
|
|
||||||
if !proj:
|
if !proj:
|
||||||
@ -11,13 +25,106 @@ func draw(local_position : Vector2) -> void:
|
|||||||
|
|
||||||
set_pixel(local_position.x, local_position.y, proj.current_color)
|
set_pixel(local_position.x, local_position.y, proj.current_color)
|
||||||
|
|
||||||
func is_local(var pos : Vector2) -> bool:
|
func get_current_color() -> Color:
|
||||||
|
var proj : PaintProject = get_paint_project()
|
||||||
|
|
||||||
|
if !proj:
|
||||||
|
print("!proj!")
|
||||||
|
return Color(1, 1, 1, 1)
|
||||||
|
|
||||||
|
return proj.current_color
|
||||||
|
|
||||||
|
func handle_mouse_button_down(local_position : Vector2, event: InputEvent) -> void:
|
||||||
|
if event.device == -1:
|
||||||
|
mouse_position = get_global_mouse_position()
|
||||||
|
cell_mouse_position = local_position
|
||||||
|
|
||||||
|
last_mouse_position = mouse_position
|
||||||
|
last_cell_mouse_position = local_position
|
||||||
|
|
||||||
|
if current_tool == CUT:
|
||||||
|
if !event.is_pressed():
|
||||||
|
commit_action()
|
||||||
|
elif current_tool == BUCKET:
|
||||||
|
if !_current_action:
|
||||||
|
_current_action = get_action()
|
||||||
|
|
||||||
|
var arr : Array = Array()
|
||||||
|
arr.push_back(cell_mouse_position)
|
||||||
|
arr.push_back(last_cell_mouse_position)
|
||||||
|
arr.push_back(get_current_color())
|
||||||
|
elif current_tool == COLORPICKER:
|
||||||
|
print("TODO")
|
||||||
|
elif current_tool == PASTECUT:
|
||||||
|
print("TODO")
|
||||||
|
elif current_tool == PAINT:
|
||||||
|
tool_process(local_position, event)
|
||||||
|
|
||||||
|
|
||||||
|
func do_action(arr : Array) -> void:
|
||||||
|
if !_current_action:
|
||||||
|
return
|
||||||
|
|
||||||
|
_current_action.do_action(arr)
|
||||||
|
update_textures()
|
||||||
|
|
||||||
|
func commit_action() -> void:
|
||||||
|
if !_current_action:
|
||||||
|
return
|
||||||
|
|
||||||
|
_current_action.commit_action()
|
||||||
|
|
||||||
|
_actions_history.push_back(_current_action)
|
||||||
|
_redo_history.clear()
|
||||||
|
|
||||||
|
if current_tool == CUT:
|
||||||
|
print("TODO")
|
||||||
|
return
|
||||||
|
|
||||||
|
_current_action = null
|
||||||
|
|
||||||
|
func has_point(var pos : Vector2) -> bool:
|
||||||
if pos.x < 0 || pos.y < 0 || pos.x > size.x || pos.y > size.y:
|
if pos.x < 0 || pos.y < 0 || pos.x > size.x || pos.y > size.y:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func forward_canvas_gui_input(event: InputEvent) -> bool:
|
func get_action() -> PaintAction:
|
||||||
|
var action : PaintAction = null
|
||||||
|
|
||||||
|
if current_tool == PAINT:
|
||||||
|
action = PencilAction.new()
|
||||||
|
|
||||||
|
if action:
|
||||||
|
action.paint_canvas = self
|
||||||
|
|
||||||
|
return action
|
||||||
|
|
||||||
|
func _on_tool_changed() -> void:
|
||||||
|
if current_tool == COLORPICKER:
|
||||||
|
if _current_action:
|
||||||
|
_current_action = null
|
||||||
|
return
|
||||||
|
|
||||||
|
_current_action = get_action()
|
||||||
|
|
||||||
|
func tool_process(local_position : Vector2, event: InputEvent) -> void:
|
||||||
|
if current_tool == COLORPICKER:
|
||||||
|
return
|
||||||
|
|
||||||
|
if !_current_action:
|
||||||
|
_current_action = get_action()
|
||||||
|
|
||||||
|
if current_tool == PAINT:
|
||||||
|
var arr : Array = Array()
|
||||||
|
arr.push_back(cell_mouse_position)
|
||||||
|
arr.push_back(last_cell_mouse_position)
|
||||||
|
arr.push_back(get_current_color())
|
||||||
|
|
||||||
|
do_action(arr)
|
||||||
|
|
||||||
|
|
||||||
|
func _forward_canvas_gui_input(event: InputEvent) -> bool:
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
if event.button_index != BUTTON_LEFT:
|
if event.button_index != BUTTON_LEFT:
|
||||||
return false
|
return false
|
||||||
@ -25,23 +132,39 @@ func forward_canvas_gui_input(event: InputEvent) -> bool:
|
|||||||
if _mouse_down:
|
if _mouse_down:
|
||||||
if !event.pressed:
|
if !event.pressed:
|
||||||
_mouse_down = false
|
_mouse_down = false
|
||||||
|
commit_action()
|
||||||
else:
|
else:
|
||||||
# This seems to be the easiest way to get local mouse position,
|
# This seems to be the easiest way to get local mouse position,
|
||||||
# even though the event is available
|
# even though the event is available
|
||||||
var local_position : Vector2 = get_local_mouse_position()
|
var local_position : Vector2 = get_local_mouse_position()
|
||||||
|
|
||||||
if is_local(local_position):
|
if has_point(local_position):
|
||||||
_mouse_down = true
|
_mouse_down = true
|
||||||
|
handle_mouse_button_down(local_position, event)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
if _mouse_down && event is InputEventMouseMotion:
|
if event is InputEventMouseMotion:
|
||||||
var local_position : Vector2 = get_local_mouse_position()
|
var local_position : Vector2 = get_local_mouse_position()
|
||||||
|
|
||||||
if is_local(local_position):
|
mouse_position = get_global_mouse_position()
|
||||||
draw(local_position)
|
cell_mouse_position = local_position
|
||||||
update_textures()
|
|
||||||
update()
|
if _mouse_down:
|
||||||
return true
|
if has_point(local_position):
|
||||||
|
#handle_draw(local_position, event)
|
||||||
|
cell_mouse_position = local_position
|
||||||
|
|
||||||
|
tool_process(local_position, event)
|
||||||
|
update_textures()
|
||||||
|
update()
|
||||||
|
|
||||||
|
last_mouse_position = mouse_position
|
||||||
|
last_cell_mouse_position = local_position
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
last_mouse_position = mouse_position
|
||||||
|
last_cell_mouse_position = local_position
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
@ -50,6 +173,11 @@ func _ready() -> void:
|
|||||||
resize(1, 1)
|
resize(1, 1)
|
||||||
resize(128, 128)
|
resize(128, 128)
|
||||||
|
|
||||||
|
if !is_connected("current_tool_changed", self, "_on_tool_changed"):
|
||||||
|
connect("current_tool_changed", self, "_on_tool_changed")
|
||||||
|
|
||||||
|
_on_tool_changed()
|
||||||
|
|
||||||
func _draw() -> void:
|
func _draw() -> void:
|
||||||
draw_texture(get_image_texture(), Vector2())
|
draw_texture(get_image_texture(), Vector2())
|
||||||
draw_texture(get_preview_image_texture(), Vector2())
|
draw_texture(get_preview_image_texture(), Vector2())
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
[node name="PaintProject" type="PaintProject"]
|
[node name="PaintProject" type="PaintProject"]
|
||||||
size = Vector2i( 128, 128 )
|
size = Vector2i( 128, 128 )
|
||||||
current_color = Color( 0.511169, 0.141401, 0.0907945, 1 )
|
current_color = Color( 0.254063, 0.387148, 0.290244, 1 )
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="PaintCanvas" type="PaintCanvas" parent="."]
|
[node name="PaintCanvas" type="PaintCanvas" parent="."]
|
||||||
|
@ -9,22 +9,8 @@ func handles(object: Object) -> bool:
|
|||||||
func edit(object: Object) -> void:
|
func edit(object: Object) -> void:
|
||||||
active_canvas = object
|
active_canvas = object
|
||||||
|
|
||||||
func forward_canvas_gui_input(event: InputEvent) -> bool:
|
|
||||||
if !active_canvas:
|
|
||||||
return false
|
|
||||||
|
|
||||||
#Temp!
|
|
||||||
if active_canvas.get_script() == null:
|
|
||||||
return false
|
|
||||||
|
|
||||||
return active_canvas.forward_canvas_gui_input(event)
|
|
||||||
|
|
||||||
func on_node_removed(node: Node) -> void:
|
|
||||||
if node == active_canvas:
|
|
||||||
active_canvas = null
|
|
||||||
|
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
get_tree().connect("node_removed", self, "on_node_removed")
|
#get_tree().connect("node_removed", self, "on_node_removed")
|
||||||
|
|
||||||
var paint_editor_plugin : EditorPlugin = Engine.get_global("PaintEditorPlugin")
|
var paint_editor_plugin : EditorPlugin = Engine.get_global("PaintEditorPlugin")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user