-
-
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
8 changed files
with
395 additions
and
5 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
99 changes: 99 additions & 0 deletions
99
addons/zylann.hterrain/tools/brush/brush_editor_overlay.gd
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,99 @@ | ||
@tool | ||
extends Control | ||
|
||
const MIN_UI_CIRCLE_SIZE = 40 | ||
const MAX_UI_CIRCLE_SIZE = 500 | ||
|
||
@onready var _brush_size_background: TextureRect = %BrushSizeBackground | ||
@onready var _brush_size_preview: TextureRect = %BrushSizePreview | ||
@onready var _value_label: Label = %ValueLabel | ||
@onready var _overlay_name_label: Label = %OverlayNameLabel | ||
@onready var _exponential_slider: HSlider = %ExponentialSlider | ||
|
||
@export var brush_size_factor: float = 2.5 | ||
@export var min_value: float = -1 | ||
@export var max_value: float = -1 | ||
var _brush_preview_color: Color = Color.LIGHT_GREEN | ||
var _dpi_scale: float = 1.0 | ||
var _value: float = 0.0 | ||
|
||
signal on_value_selected(new_value: int) | ||
signal on_cancel | ||
|
||
var background_margin: int = 10 | ||
|
||
|
||
func _physics_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 and event.pressed: | ||
on_value_selected.emit(_value) | ||
else: | ||
on_cancel.emit() | ||
if event is InputEventKey: | ||
if event.keycode == KEY_ESCAPE and event.pressed: | ||
on_cancel.emit() | ||
|
||
|
||
func set_brush_preview_color(brush_color): | ||
_brush_preview_color = brush_color | ||
_update_brush_preview_color() | ||
|
||
|
||
func _update_brush_preview_color(): | ||
_brush_size_preview.modulate = _brush_preview_color | ||
|
||
|
||
func set_overlay_name(overlay_label_name: String) -> void: | ||
_overlay_name_label.text = overlay_label_name | ||
|
||
|
||
func _update_size(value: float) -> void: | ||
var dist = clampi(value * brush_size_factor, MIN_UI_CIRCLE_SIZE*_dpi_scale, MAX_UI_CIRCLE_SIZE*_dpi_scale ) | ||
var ui_size := clampi(dist, MIN_UI_CIRCLE_SIZE*_dpi_scale, MAX_UI_CIRCLE_SIZE*_dpi_scale) | ||
_brush_size_background.size = Vector2(ui_size + background_margin, ui_size + background_margin) | ||
_brush_size_background.position = Vector2(-( (ui_size/2) + (background_margin/2)) , -( (ui_size/2) + (background_margin/2))) | ||
_brush_size_preview.size = Vector2(ui_size, ui_size) | ||
_brush_size_preview.position = Vector2(-(ui_size/2) , -(ui_size/2)) | ||
|
||
_exponential_slider.min_value = MIN_UI_CIRCLE_SIZE*_dpi_scale | ||
_exponential_slider.max_value = MAX_UI_CIRCLE_SIZE*_dpi_scale | ||
_exponential_slider.value = (_exponential_slider.min_value+_exponential_slider.max_value)-ui_size | ||
|
||
var re_value: float = absf(1.0-_exponential_slider.get_as_ratio()) * (max_value-min_value) | ||
re_value += min_value | ||
|
||
_value = roundi(re_value) | ||
_value_label.text = str(_value) | ||
|
||
|
||
func apply_dpi_scale(dpi_scale: float): | ||
_dpi_scale = dpi_scale | ||
|
||
|
||
func setup_start_position(start_pos, initial_value): | ||
position = start_pos | ||
|
||
_exponential_slider.min_value = MIN_UI_CIRCLE_SIZE*_dpi_scale | ||
_exponential_slider.max_value = MAX_UI_CIRCLE_SIZE*_dpi_scale | ||
|
||
var reverse = (initial_value - min_value) / (max_value-min_value) | ||
reverse = abs(1-reverse) | ||
_exponential_slider.set_as_ratio(reverse) | ||
|
||
var ui_size = (_exponential_slider.min_value+_exponential_slider.max_value) - _exponential_slider.value | ||
|
||
position.x -= (ui_size/brush_size_factor) | ||
|
||
|
||
func _get_mouse_distance() -> float: | ||
var global_mouse_pos = get_global_mouse_position() | ||
|
||
var distance: float = position.distance_to(global_mouse_pos) | ||
if position.x > global_mouse_pos.x: | ||
distance = 0 | ||
|
||
return distance; |
91 changes: 91 additions & 0 deletions
91
addons/zylann.hterrain/tools/brush/brush_editor_overlay.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,91 @@ | ||
[gd_scene load_steps=5 format=3 uid="uid://d324kwgdf7e6l"] | ||
|
||
[ext_resource type="Script" path="res://addons/zylann.hterrain/tools/brush/brush_editor_overlay.gd" id="1_grgos"] | ||
[ext_resource type="Texture2D" uid="uid://fk2rcx7lsbam" path="res://addons/zylann.hterrain/tools/icons/brush_circle_background.svg" id="2_jeqe2"] | ||
[ext_resource type="Texture2D" uid="uid://c4ma6f4217y48" path="res://addons/zylann.hterrain/tools/icons/brush_circle.svg" id="3_sw64o"] | ||
|
||
[sub_resource type="LabelSettings" id="LabelSettings_0d2ij"] | ||
font_size = 32 | ||
|
||
[node name="BrushEditorOverlay" 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_grgos") | ||
min_value = 2.0 | ||
max_value = 500.0 | ||
|
||
[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 = -209.0 | ||
offset_top = -209.0 | ||
offset_right = 210.0 | ||
offset_bottom = 210.0 | ||
texture = ExtResource("2_jeqe2") | ||
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 = -204.0 | ||
offset_top = -204.0 | ||
offset_right = 205.0 | ||
offset_bottom = 205.0 | ||
texture = ExtResource("3_sw64o") | ||
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 = -35.0 | ||
offset_top = -22.648 | ||
offset_right = 38.0 | ||
offset_bottom = 22.352 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
scale = Vector2(0.7, 0.7) | ||
pivot_offset = Vector2(33, 22) | ||
text = "266" | ||
label_settings = SubResource("LabelSettings_0d2ij") | ||
horizontal_alignment = 1 | ||
vertical_alignment = 1 | ||
|
||
[node name="OverlayNameLabel" type="Label" parent="."] | ||
unique_name_in_owner = true | ||
layout_mode = 1 | ||
anchors_preset = -1 | ||
offset_left = -211.0 | ||
offset_top = -62.0 | ||
offset_right = 400.0 | ||
offset_bottom = 19.0 | ||
scale = Vector2(0.7, 0.7) | ||
text = "Brush size" | ||
label_settings = SubResource("LabelSettings_0d2ij") | ||
horizontal_alignment = 1 | ||
vertical_alignment = 1 | ||
|
||
[node name="ExponentialSlider" type="HSlider" parent="."] | ||
unique_name_in_owner = true | ||
visible = false | ||
layout_mode = 0 | ||
offset_left = -132.0 | ||
offset_top = 50.0 | ||
offset_right = 140.0 | ||
offset_bottom = 66.0 | ||
focus_mode = 0 | ||
mouse_filter = 2 | ||
min_value = 40.0 | ||
max_value = 500.0 | ||
value = 131.0 | ||
exp_edit = true |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions
42
addons/zylann.hterrain/tools/icons/brush_circle_background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.