Skip to content

Commit

Permalink
Rework decal visibility updating
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Aug 12, 2024
1 parent 8a45d61 commit 529c7e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
12 changes: 4 additions & 8 deletions project/addons/terrain_3d/editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,7 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->

## Update decal
ui.decal.global_position = mouse_global_position
ui.decal.albedo_mix = 1.0
if ui.decal_timer.is_stopped():
ui.update_decal()
else:
ui.decal_timer.start()
ui.update_decal()

## Update region highlight
var region_size = terrain.get_storage().get_region_size()
Expand All @@ -189,6 +185,8 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
return AFTER_GUI_INPUT_STOP

elif p_event is InputEventMouseButton:
if p_event.get_button_index() == MOUSE_BUTTON_RIGHT and p_event.is_released():
ui.last_rmb_time = Time.get_ticks_msec()
ui.update_decal()

if p_event.get_button_index() == MOUSE_BUTTON_LEFT:
Expand Down Expand Up @@ -225,10 +223,8 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
# Mouse released, save undo data
editor.stop_operation()
return AFTER_GUI_INPUT_STOP

return AFTER_GUI_INPUT_PASS


return AFTER_GUI_INPUT_PASS


func update_region_grid() -> void:
Expand Down
12 changes: 7 additions & 5 deletions project/addons/terrain_3d/src/ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var modifier_alt: bool
var modifier_shift: bool
var last_tool: Terrain3DEditor.Tool
var last_operation: Terrain3DEditor.Operation
var last_rmb_time: int = 0


func _enter_tree() -> void:
Expand Down Expand Up @@ -248,8 +249,13 @@ func _on_setting_changed() -> void:

func update_decal() -> void:
var mouse_buttons: int = Input.get_mouse_button_mask()

# If not a state that should show the decal, hide everything and return
if not visible or \
not plugin.terrain or \
# Wait for cursor to recenter after right-click before revealing
# See https://github.com/godotengine/godot/issues/70098
Time.get_ticks_msec() - last_rmb_time <= 10 or \
brush_data.is_empty() or \
mouse_buttons & MOUSE_BUTTON_RIGHT or \
(mouse_buttons & MOUSE_BUTTON_LEFT and not brush_data["show_cursor_while_painting"]) or \
Expand All @@ -258,12 +264,8 @@ func update_decal() -> void:
for gradient_decal in gradient_decals:
gradient_decal.visible = false
return
else:
# Wait for cursor to recenter after right-click before revealing
# See https://github.com/godotengine/godot/issues/70098
await get_tree().create_timer(.05).timeout
decal.visible = true

decal.visible = true
decal.size = Vector3.ONE * brush_data["size"]
if brush_data["align_to_view"]:
var cam: Camera3D = plugin.terrain.get_camera();
Expand Down

0 comments on commit 529c7e9

Please sign in to comment.