Skip to content

Commit 546c4f2

Browse files
authored
Merge pull request #33 from IcterusGames/v-2.0.6-dev-2
support for undo/redo
2 parents 4753a8d + fc90f43 commit 546c4f2

File tree

6 files changed

+80
-37
lines changed

6 files changed

+80
-37
lines changed

addons/simplegrasstextured/plugin.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="SimpleGrassTextured"
44
description="Create simple grass textured"
55
author="IcterusGames"
6-
version="2.0.6d1"
6+
version="2.0.6d2"
77
script="plugin.gd"

addons/simplegrasstextured/plugin.gd

+13
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,23 @@ func _forward_3d_gui_input(viewport_camera: Camera3D, event: InputEvent) -> int:
358358
if not (_edit_draw or _edit_fill or _edit_erase):
359359
return EditorPlugin.AFTER_GUI_INPUT_PASS
360360
if event.pressed:
361+
if _edit_draw:
362+
get_undo_redo().create_action(_grass_selected.name + " Draw")
363+
elif _edit_fill:
364+
get_undo_redo().create_action(_grass_selected.name + " Fill")
365+
elif _edit_erase:
366+
get_undo_redo().create_action(_grass_selected.name + " Erase")
367+
else:
368+
get_undo_redo().create_action(_grass_selected.name)
369+
get_undo_redo().add_undo_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
370+
get_undo_redo().add_undo_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
361371
_project_ray_origin = viewport_camera.project_ray_origin(event.position)
362372
_project_ray_normal = viewport_camera.project_ray_normal(event.position)
363373
_mouse_event = EVENT_MOUSE.EVENT_CLICK
364374
else:
375+
get_undo_redo().add_do_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
376+
get_undo_redo().add_do_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
377+
get_undo_redo().commit_action()
365378
_time_draw = 0
366379
_object_draw = null
367380
_mouse_event = EVENT_MOUSE.EVENT_NONE

addons/simplegrasstextured/shaders/grass.gdshader

+19-19
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ This file is part of: SimpleGrassTextured
33
Copyright (c) 2023 IcterusGames
44

55
Permission is hereby granted, free of charge, to any person obtaining
6-
a copy of this software and associated documentation files (the
7-
"Software"), to deal in the Software without restriction, including
8-
without limitation the rights to use, copy, modify, merge, publish,
9-
distribute, sublicense, and/or sell copies of the Software, and to
10-
permit persons to whom the Software is furnished to do so, subject to
11-
the following conditions:
12-
13-
The above copyright notice and this permission notice shall be
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
1414
included in all copies or substantial portions of the Software.
1515

16-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2222
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
2323

2424
shader_type spatial;
@@ -92,11 +92,11 @@ void vertex() {
9292
float rand = wrap(dot(NODE_POSITION_WORLD, NODE_POSITION_WORLD * 10.0), 0.0, 256.0);
9393
float randf = fract(rand);
9494
int randi = int(randf * 10.0);
95-
95+
9696
uv_align = vec2(float(randi % int(texture_frames.x)), float(int(randf * 100.0) % int(texture_frames.y)));
9797
uv_align /= texture_frames;
9898
uv_scale = vec2(1.0 / texture_frames.x, 1.0 / texture_frames.y);
99-
99+
100100
float text_wind = texture(sgt_wind_pattern, (vec2(NODE_POSITION_WORLD.x, NODE_POSITION_WORLD.z) * 0.005) - sgt_wind_movement.xz).r;
101101
VERTEX.x += text_wind * lev * sgt_wind_strength * sgt_wind_direction.x * (1.0 - grass_strength);
102102
VERTEX.z += text_wind * lev * sgt_wind_strength * sgt_wind_direction.z * (1.0 - grass_strength);
@@ -106,7 +106,7 @@ void vertex() {
106106
VERTEX.y += sgt_wind_direction.y * lev * (sgt_wind_strength + (sin(TIME + rand) * 0.2 * (1.0 - grass_strength) * min(1.0, sgt_wind_turbulence))) * (1.0 - grass_strength);
107107
VERTEX.z += cos(rand + sgt_wind_movement.y) * lev * ((1.0 - grass_strength) / 10.0);
108108
VERTEX.z += sgt_wind_direction.z * lev * (sgt_wind_strength + (sin(TIME + rand) * 0.2 * (1.0 - grass_strength) * min(1.0, sgt_wind_turbulence))) * (1.0 - grass_strength);
109-
109+
110110
vec3 align = VERTEX - NODE_POSITION_WORLD;
111111
float scale_rand = ((float(randi % 5) / 5.0) * scale_var);
112112
float dist = 1.0;
@@ -115,10 +115,10 @@ void vertex() {
115115
dist = 1.0 - clamp(0.0, 1.0, float(randi % int(max(1.0, node_dist / optimization_level))));
116116
dist *= smoothstep(optimization_dist_max, optimization_dist_min, node_dist);
117117
}
118-
118+
119119
vec3 scale = vec3(scale_w, scale_h, scale_w) * (1.0 + scale_rand);
120120
VERTEX = NODE_POSITION_WORLD + (align * dist * scale);
121-
121+
122122
if(dist > 0.0 && interactive_mode) {
123123
float node_x = NODE_POSITION_WORLD.x / 50.0;
124124
float node_z = NODE_POSITION_WORLD.z / 50.0;

addons/simplegrasstextured/shaders/motion1.gdshader

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ This file is part of: SimpleGrassTextured
33
Copyright (c) 2023 IcterusGames
44

55
Permission is hereby granted, free of charge, to any person obtaining
6-
a copy of this software and associated documentation files (the
7-
"Software"), to deal in the Software without restriction, including
8-
without limitation the rights to use, copy, modify, merge, publish,
9-
distribute, sublicense, and/or sell copies of the Software, and to
10-
permit persons to whom the Software is furnished to do so, subject to
11-
the following conditions:
12-
13-
The above copyright notice and this permission notice shall be
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
1414
included in all copies or substantial portions of the Software.
1515

16-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2222
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
2323

2424
shader_type canvas_item;

addons/simplegrasstextured/singleton.tscn

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ shader_parameter/normal_texture = ExtResource("5_3dhao")
4646

4747
[sub_resource type="ShaderMaterial" id="ShaderMaterial_bi14c"]
4848
shader = ExtResource("3_amjfl")
49+
shader_parameter/delta = 1.0
4950

5051
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5hmhs"]
5152
shader = ExtResource("4_5b1gv")

addons/simplegrasstextured/toolbar_menu.gd

+32-3
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ enum MENU_ID {
3535
RECALCULATE_AABB,
3636
}
3737

38+
var _plugin: EditorPlugin = null
3839
var _grass_selected = null
3940
var _tools_menu :PopupMenu = null
4041

4142

42-
func set_plugin(_plugin :EditorPlugin) -> void:
43+
func set_plugin(plugin :EditorPlugin) -> void:
4344
var popup := get_popup()
45+
_plugin = plugin
4446
_tools_menu = PopupMenu.new()
4547
_tools_menu.name = &"ToolsMenu"
4648
_tools_menu.add_check_item("Follow terrain's normal", MENU_ID.TOOL_FOLLOW_NORMAL)
@@ -50,7 +52,7 @@ func set_plugin(_plugin :EditorPlugin) -> void:
5052
popup.add_separator()
5153
popup.add_item("Auto center position", MENU_ID.AUTO_CENTER_POSITION)
5254
popup.add_item("Recalculate custom AABB", MENU_ID.RECALCULATE_AABB)
53-
popup.add_check_item("Bake height map", MENU_ID.BAKE_HEIGHT_MAP)
55+
popup.add_item("Bake height map", MENU_ID.BAKE_HEIGHT_MAP)
5456
popup.add_check_item("Cast shadow", MENU_ID.CAST_SHADOW)
5557
popup.add_item("Global parameters", MENU_ID.GLOBAL_PARAMETERS)
5658
popup.add_separator()
@@ -71,7 +73,12 @@ func set_current_grass(grass_selected) -> void:
7173
popup.set_item_checked(popup.get_item_index(MENU_ID.CAST_SHADOW), false)
7274
else:
7375
popup.set_item_checked(popup.get_item_index(MENU_ID.CAST_SHADOW), true)
74-
popup.set_item_checked(popup.get_item_index(MENU_ID.BAKE_HEIGHT_MAP), _grass_selected.baked_height_map != null)
76+
if _grass_selected.baked_height_map != null:
77+
popup.set_item_text(popup.get_item_index(MENU_ID.BAKE_HEIGHT_MAP), "Bake height map (already baked)")
78+
popup.set_item_disabled(popup.get_item_index(MENU_ID.BAKE_HEIGHT_MAP), true)
79+
else:
80+
popup.set_item_text(popup.get_item_index(MENU_ID.BAKE_HEIGHT_MAP), "Bake height map")
81+
popup.set_item_disabled(popup.get_item_index(MENU_ID.BAKE_HEIGHT_MAP), false)
7582
_tools_menu.set_item_checked(_tools_menu.get_item_index(MENU_ID.TOOL_FOLLOW_NORMAL), _grass_selected.sgt_follow_normal)
7683

7784

@@ -80,14 +87,30 @@ func _on_sgt_menu_button(id :int) -> void:
8087
return
8188
match id:
8289
MENU_ID.AUTO_CENTER_POSITION:
90+
_plugin.get_undo_redo().create_action(_grass_selected.name + " Auto Center Position")
91+
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
92+
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
93+
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"global_position", _grass_selected.global_position)
8394
_grass_selected.auto_center_position()
95+
_plugin.get_undo_redo().add_do_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
96+
_plugin.get_undo_redo().add_do_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
97+
_plugin.get_undo_redo().add_do_property(_grass_selected, &"global_position", _grass_selected.global_position)
98+
_plugin.get_undo_redo().commit_action()
8499
MENU_ID.RECALCULATE_AABB:
100+
_plugin.get_undo_redo().create_action(_grass_selected.name + " Recalculate Custom AABB")
101+
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"custom_aabb", _grass_selected.custom_aabb)
85102
_grass_selected.recalculate_custom_aabb()
103+
_plugin.get_undo_redo().add_do_property(_grass_selected, &"custom_aabb", _grass_selected.custom_aabb)
104+
_plugin.get_undo_redo().commit_action()
86105
MENU_ID.CAST_SHADOW:
106+
_plugin.get_undo_redo().create_action(_grass_selected.name + " Toogle Cast Shadow")
107+
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"cast_shadow", _grass_selected.cast_shadow)
87108
if _grass_selected.cast_shadow == GeometryInstance3D.SHADOW_CASTING_SETTING_OFF:
88109
_grass_selected.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_ON
89110
else:
90111
_grass_selected.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
112+
_plugin.get_undo_redo().add_do_property(_grass_selected, &"cast_shadow", _grass_selected.cast_shadow)
113+
_plugin.get_undo_redo().commit_action()
91114
MENU_ID.BAKE_HEIGHT_MAP:
92115
_grass_selected.bake_height_map()
93116
MENU_ID.GLOBAL_PARAMETERS:
@@ -121,4 +144,10 @@ func _on_about_to_popup() -> void:
121144
func _on_clear_all_confirmation_dialog_confirmed() -> void:
122145
if _grass_selected == null:
123146
return
147+
_plugin.get_undo_redo().create_action(_grass_selected.name + " Clear All Grass")
148+
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
149+
_plugin.get_undo_redo().add_undo_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
124150
_grass_selected.clear_all()
151+
_plugin.get_undo_redo().add_do_property(_grass_selected, &"baked_height_map", _grass_selected.baked_height_map)
152+
_plugin.get_undo_redo().add_do_property(_grass_selected, &"multimesh", _grass_selected.multimesh)
153+
_plugin.get_undo_redo().commit_action()

0 commit comments

Comments
 (0)