From a4429fbe32261aaf13dd9aa6986bbe1d22ae44f6 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Thu, 2 Jan 2025 14:54:31 +0700 Subject: [PATCH] [Tile Drawer] Now supports undo. --- PixelComposer.resource_order | 17 ++++++++--------- scripts/__tiler_tool/__tiler_tool.gml | 6 +++--- scripts/node_tiler/node_tiler.gml | 10 ++++++++++ scripts/tiler_tool_brush/tiler_tool_brush.gml | 3 ++- .../tiler_tool_brush_shape.gml | 3 ++- scripts/tiler_tool_fill/tiler_tool_fill.gml | 6 ++++-- .../tiler_tool_selection.gml | 2 +- 7 files changed, 30 insertions(+), 17 deletions(-) diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index 9bea53099..ea926ff3a 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -451,10 +451,9 @@ {"name":"__shapes","order":3,"path":"scripts/__shapes/__shapes.yy",}, {"name":"__strandSim","order":2,"path":"scripts/__strandSim/__strandSim.yy",}, {"name":"__surface","order":7,"path":"scripts/__surface/__surface.yy",}, - {"name":"__tiler_animated","order":1,"path":"scripts/__tiler_animated/__tiler_animated.yy",}, - {"name":"__tiler_autoterrain","order":6,"path":"scripts/__tiler_autoterrain/__tiler_autoterrain.yy",}, - {"name":"__tiler_brush","order":2,"path":"scripts/__tiler_brush/__tiler_brush.yy",}, - {"name":"__tiler_rule","order":7,"path":"scripts/__tiler_rule/__tiler_rule.yy",}, + {"name":"__tiler_autoterrain","order":1,"path":"scripts/__tiler_autoterrain/__tiler_autoterrain.yy",}, + {"name":"__tiler_brush","order":3,"path":"scripts/__tiler_brush/__tiler_brush.yy",}, + {"name":"__tiler_rule","order":4,"path":"scripts/__tiler_rule/__tiler_rule.yy",}, {"name":"__tiler_tool","order":2,"path":"scripts/__tiler_tool/__tiler_tool.yy",}, {"name":"__vec2","order":7,"path":"scripts/__vec2/__vec2.yy",}, {"name":"__vec3","order":8,"path":"scripts/__vec3/__vec3.yy",}, @@ -1406,11 +1405,11 @@ {"name":"textBox","order":2,"path":"scripts/textBox/textBox.yy",}, {"name":"textInput","order":3,"path":"scripts/textInput/textInput.yy",}, {"name":"theme_definition","order":14,"path":"scripts/theme_definition/theme_definition.yy",}, - {"name":"tiler_tool_brush_shape","order":4,"path":"scripts/tiler_tool_brush_shape/tiler_tool_brush_shape.yy",}, - {"name":"tiler_tool_brush","order":2,"path":"scripts/tiler_tool_brush/tiler_tool_brush.yy",}, - {"name":"tiler_tool_fill","order":3,"path":"scripts/tiler_tool_fill/tiler_tool_fill.yy",}, - {"name":"tiler_tool_selection_shape","order":6,"path":"scripts/tiler_tool_selection_shape/tiler_tool_selection_shape.yy",}, - {"name":"tiler_tool_selection","order":5,"path":"scripts/tiler_tool_selection/tiler_tool_selection.yy",}, + {"name":"tiler_tool_brush_shape","order":7,"path":"scripts/tiler_tool_brush_shape/tiler_tool_brush_shape.yy",}, + {"name":"tiler_tool_brush","order":5,"path":"scripts/tiler_tool_brush/tiler_tool_brush.yy",}, + {"name":"tiler_tool_fill","order":6,"path":"scripts/tiler_tool_fill/tiler_tool_fill.yy",}, + {"name":"tiler_tool_selection_shape","order":9,"path":"scripts/tiler_tool_selection_shape/tiler_tool_selection_shape.yy",}, + {"name":"tiler_tool_selection","order":8,"path":"scripts/tiler_tool_selection/tiler_tool_selection.yy",}, {"name":"tilesetBox","order":1,"path":"scripts/tilesetBox/tilesetBox.yy",}, {"name":"time_source","order":43,"path":"scripts/time_source/time_source.yy",}, {"name":"timeline_data","order":18,"path":"scripts/timeline_data/timeline_data.yy",}, diff --git a/scripts/__tiler_tool/__tiler_tool.gml b/scripts/__tiler_tool/__tiler_tool.gml index 0954cf624..a3e41544a 100644 --- a/scripts/__tiler_tool/__tiler_tool.gml +++ b/scripts/__tiler_tool/__tiler_tool.gml @@ -1,6 +1,6 @@ -function tiler_tool(node) constructor { - self.node = node; - subtool = 0; +function tiler_tool(_node) constructor { + node = _node; + subtool = 0; brush_resizable = true; apply_draw_surface = noone; diff --git a/scripts/node_tiler/node_tiler.gml b/scripts/node_tiler/node_tiler.gml index 97faac271..32e19a509 100644 --- a/scripts/node_tiler/node_tiler.gml +++ b/scripts/node_tiler/node_tiler.gml @@ -118,6 +118,16 @@ function Node_Tile_Drawer(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou triggerRender(); } + static storeAction = function() { + var action = recordAction(ACTION_TYPE.custom, function(data) { + var _canvas = surface_clone(canvas_surface); + canvas_surface = data.surface; + data.surface = _canvas; + triggerRender(); + + }, { surface: surface_clone(canvas_surface), tooltip: "Modify tilemap" }); + } + function reset_surface(surface) { surface_set_shader(surface, noone, true, BLEND.over); draw_surface(canvas_surface, 0, 0); diff --git a/scripts/tiler_tool_brush/tiler_tool_brush.gml b/scripts/tiler_tool_brush/tiler_tool_brush.gml index a1412800e..27c76425f 100644 --- a/scripts/tiler_tool_brush/tiler_tool_brush.gml +++ b/scripts/tiler_tool_brush/tiler_tool_brush.gml @@ -1,4 +1,4 @@ -function tiler_tool_brush(node, _brush, eraser = false) : tiler_tool(node) constructor { +function tiler_tool_brush(_node, _brush, eraser = false) : tiler_tool(_node) constructor { self.brush = _brush; isEraser = eraser; brush_resizable = true; @@ -51,6 +51,7 @@ function tiler_tool_brush(node, _brush, eraser = false) : tiler_tool(node) const } if(mouse_press(mb_left, active)) { + node.storeAction(); surface_set_target(drawing_surface); tiler_draw_point_brush(brush, mouse_cur_x, mouse_cur_y); diff --git a/scripts/tiler_tool_brush_shape/tiler_tool_brush_shape.gml b/scripts/tiler_tool_brush_shape/tiler_tool_brush_shape.gml index 3077f7e05..2637847b5 100644 --- a/scripts/tiler_tool_brush_shape/tiler_tool_brush_shape.gml +++ b/scripts/tiler_tool_brush_shape/tiler_tool_brush_shape.gml @@ -1,4 +1,4 @@ -function tiler_tool_shape(node, _brush, _shape) : tiler_tool(node) constructor { +function tiler_tool_shape(_node, _brush, _shape) : tiler_tool(_node) constructor { self.brush = _brush; self.shape = _shape; @@ -54,6 +54,7 @@ function tiler_tool_shape(node, _brush, _shape) : tiler_tool(node) constructor { mouse_pre_x = mouse_cur_x; mouse_pre_y = mouse_cur_y; + node.storeAction(); mouse_holding = true; } diff --git a/scripts/tiler_tool_fill/tiler_tool_fill.gml b/scripts/tiler_tool_fill/tiler_tool_fill.gml index b2c019ea9..cd0c51150 100644 --- a/scripts/tiler_tool_fill/tiler_tool_fill.gml +++ b/scripts/tiler_tool_fill/tiler_tool_fill.gml @@ -1,4 +1,4 @@ -function tiler_tool_fill(node, _brush, toolAttr) : tiler_tool(node) constructor { +function tiler_tool_fill(_node, _brush, toolAttr) : tiler_tool(_node) constructor { self.brush = _brush; self.tool_attribute = toolAttr; @@ -18,12 +18,14 @@ function tiler_tool_fill(node, _brush, toolAttr) : tiler_tool(node) constructor var _auto = brush.autoterrain; if(mouse_press(mb_left, active) && point_in_rectangle(mouse_cur_x, mouse_cur_y, 0, 0, surface_w - 1, surface_h - 1)) { + node.storeAction(); + surface_set_target(drawing_surface); tiler_flood_fill_scanline(drawing_surface, mouse_cur_x, mouse_cur_y, brush, tool_attribute.fillType); surface_reset_target(); if(_auto != noone) { - _auto.drawing_start(drawing_surface, isEraser); + _auto.drawing_start(drawing_surface); tiler_flood_fill_scanline(drawing_surface, mouse_cur_x, mouse_cur_y, brush, tool_attribute.fillType); _auto.drawing_end(); } diff --git a/scripts/tiler_tool_selection/tiler_tool_selection.gml b/scripts/tiler_tool_selection/tiler_tool_selection.gml index ee44c86ec..eae94a9e7 100644 --- a/scripts/tiler_tool_selection/tiler_tool_selection.gml +++ b/scripts/tiler_tool_selection/tiler_tool_selection.gml @@ -1,3 +1,3 @@ -function tiler_tool_selection(node) : tiler_tool(node) constructor { +function tiler_tool_selection(_node) : tiler_tool(_node) constructor { } \ No newline at end of file