-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shortcut widget to change size and opacity, fix bottom panel not …
…updating size/opacity
- Loading branch information
Showing
7 changed files
with
227 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
@tool | ||
extends Control | ||
|
||
@export var brush_size_factor: int = 3 | ||
@export var min_value: int = -1 | ||
@export var max_value: int = -1 | ||
@export var brush_preview_color: Color = Color.LIGHT_GREEN : | ||
set(value): | ||
brush_preview_color = value | ||
if is_inside_tree(): | ||
%BrushSizePreview.modulate = brush_preview_color | ||
|
||
signal on_value_selected(new_value: int) | ||
signal on_cancel | ||
|
||
var background_margin: int = 10 | ||
|
||
|
||
func _ready() -> void: | ||
%BrushSizePreview.modulate = brush_preview_color | ||
|
||
|
||
func _process(delta: float) -> void: | ||
_update_size(_get_mouse_distance()) | ||
|
||
|
||
func _input(event: InputEvent) -> void: | ||
if event is InputEventMouseButton: | ||
if event.button_index == MOUSE_BUTTON_LEFT: | ||
var distance := _get_mouse_distance() | ||
on_value_selected.emit(distance) | ||
else: | ||
on_cancel.emit() | ||
|
||
|
||
func _update_size(value: int) -> void: | ||
var size := value * brush_size_factor | ||
var ui_size := clamp(size, 40, 1000) | ||
%BrushSizeBackground.size = Vector2(ui_size + background_margin, ui_size + background_margin) | ||
%BrushSizeBackground.position = Vector2(-( (ui_size/2) + (background_margin/2)) , -( (ui_size/2) + (background_margin/2))) | ||
%BrushSizePreview.size = Vector2(ui_size, ui_size) | ||
%BrushSizePreview.position = Vector2(-(ui_size/2) , -(ui_size/2)) | ||
|
||
%ValueLabel.text = str(value) | ||
|
||
|
||
func _get_mouse_distance() -> int: | ||
var global_mouse_pos = get_global_mouse_position() | ||
|
||
var distance: int = position.distance_to(global_mouse_pos) | ||
if position.x > global_mouse_pos.x: | ||
distance = 0 | ||
|
||
if (min_value >= 0): | ||
distance = maxi(distance, min_value) | ||
|
||
if (max_value >= 0): | ||
distance = mini(distance, max_value) | ||
|
||
return distance; | ||
|
||
|
||
func set_initial_value(value: float) -> void: | ||
position -= Vector2(value, 0) | ||
_update_size(value) |
61 changes: 61 additions & 0 deletions
61
addons/zylann.hterrain/tools/brush/brush_size_selector.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
[gd_scene load_steps=5 format=3 uid="uid://d324kwgdf7e6l"] | ||
|
||
[ext_resource type="Script" path="res://addons/zylann.hterrain/tools/brush/brush_size_selector.gd" id="1_r2t4n"] | ||
[ext_resource type="Texture2D" uid="uid://dthlbsmf51jk3" path="res://addons/zylann.hterrain/tools/brush/ui_images/brush_circle.png" id="2_hu4m7"] | ||
[ext_resource type="Texture2D" uid="uid://b8nf7x6l56anw" path="res://addons/zylann.hterrain/tools/brush/ui_images/brush_circle_background.png" id="2_mj44p"] | ||
|
||
[sub_resource type="LabelSettings" id="LabelSettings_0d2ij"] | ||
font_size = 32 | ||
|
||
[node name="BrushSizeSelector" type="Control"] | ||
layout_mode = 3 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
script = ExtResource("1_r2t4n") | ||
brush_preview_color = Color(1, 0, 0, 1) | ||
|
||
[node name="BrushSizeBackground" type="TextureRect" parent="."] | ||
unique_name_in_owner = true | ||
modulate = Color(0.478431, 0.478431, 0.478431, 0.423529) | ||
layout_mode = 0 | ||
offset_left = -162.0 | ||
offset_top = -162.0 | ||
offset_right = 163.0 | ||
offset_bottom = 163.0 | ||
texture = ExtResource("2_mj44p") | ||
expand_mode = 1 | ||
metadata/_edit_use_anchors_ = true | ||
|
||
[node name="BrushSizePreview" type="TextureRect" parent="."] | ||
unique_name_in_owner = true | ||
modulate = Color(1, 0, 0, 1) | ||
layout_mode = 1 | ||
offset_left = -157.0 | ||
offset_top = -157.0 | ||
offset_right = 158.0 | ||
offset_bottom = 158.0 | ||
texture = ExtResource("2_hu4m7") | ||
expand_mode = 1 | ||
metadata/_edit_use_anchors_ = true | ||
|
||
[node name="ValueLabel" type="Label" parent="."] | ||
unique_name_in_owner = true | ||
layout_mode = 1 | ||
anchors_preset = -1 | ||
anchor_top = 0.001 | ||
anchor_bottom = 0.001 | ||
offset_left = -36.0 | ||
offset_top = -22.648 | ||
offset_right = 37.0 | ||
offset_bottom = 22.352 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
scale = Vector2(0.7, 0.7) | ||
pivot_offset = Vector2(36, 22) | ||
text = "105" | ||
label_settings = SubResource("LabelSettings_0d2ij") | ||
horizontal_alignment = 1 | ||
vertical_alignment = 1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.21 KB
addons/zylann.hterrain/tools/brush/ui_images/brush_circle_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters