first commit
This commit is contained in:
174
addons/zylann.hterrain/tools/resize_dialog/resize_dialog.gd
Executable file
174
addons/zylann.hterrain/tools/resize_dialog/resize_dialog.gd
Executable file
@@ -0,0 +1,174 @@
|
||||
@tool
|
||||
extends AcceptDialog
|
||||
|
||||
const HT_Util = preload("../../util/util.gd")
|
||||
const HT_Logger = preload("../../util/logger.gd")
|
||||
const HTerrain = preload("../../hterrain.gd")
|
||||
const HTerrainData = preload("../../hterrain_data.gd")
|
||||
|
||||
const ANCHOR_TOP_LEFT = 0
|
||||
const ANCHOR_TOP = 1
|
||||
const ANCHOR_TOP_RIGHT = 2
|
||||
const ANCHOR_LEFT = 3
|
||||
const ANCHOR_CENTER = 4
|
||||
const ANCHOR_RIGHT = 5
|
||||
const ANCHOR_BOTTOM_LEFT = 6
|
||||
const ANCHOR_BOTTOM = 7
|
||||
const ANCHOR_BOTTOM_RIGHT = 8
|
||||
const ANCHOR_COUNT = 9
|
||||
|
||||
const _anchor_dirs = [
|
||||
[-1, -1],
|
||||
[0, -1],
|
||||
[1, -1],
|
||||
[-1, 0],
|
||||
[0, 0],
|
||||
[1, 0],
|
||||
[-1, 1],
|
||||
[0, 1],
|
||||
[1, 1]
|
||||
]
|
||||
|
||||
const _anchor_icon_names = [
|
||||
"anchor_top_left",
|
||||
"anchor_top",
|
||||
"anchor_top_right",
|
||||
"anchor_left",
|
||||
"anchor_center",
|
||||
"anchor_right",
|
||||
"anchor_bottom_left",
|
||||
"anchor_bottom",
|
||||
"anchor_bottom_right"
|
||||
]
|
||||
|
||||
signal permanent_change_performed(message)
|
||||
|
||||
@onready var _resolution_dropdown : OptionButton = $VBoxContainer/GridContainer/ResolutionDropdown
|
||||
@onready var _stretch_checkbox : CheckBox = $VBoxContainer/GridContainer/StretchCheckBox
|
||||
@onready var _anchor_control : Control = $VBoxContainer/GridContainer/HBoxContainer/AnchorControl
|
||||
|
||||
const _resolutions = HTerrainData.SUPPORTED_RESOLUTIONS
|
||||
|
||||
var _anchor_buttons := []
|
||||
var _anchor_buttons_grid := {}
|
||||
var _anchor_button_group : ButtonGroup = null
|
||||
var _selected_anchor = ANCHOR_TOP_LEFT
|
||||
var _logger = HT_Logger.get_for(self)
|
||||
|
||||
var _terrain : HTerrain = null
|
||||
|
||||
|
||||
func set_terrain(terrain: HTerrain):
|
||||
_terrain = terrain
|
||||
|
||||
|
||||
static func _get_icon(name) -> Texture2D:
|
||||
return load("res://addons/zylann.hterrain/tools/icons/icon_" + name + ".svg")
|
||||
|
||||
|
||||
func _init():
|
||||
get_ok_button().hide()
|
||||
|
||||
|
||||
func _ready():
|
||||
if HT_Util.is_in_edited_scene(self):
|
||||
return
|
||||
# TEST
|
||||
#show()
|
||||
|
||||
for i in len(_resolutions):
|
||||
_resolution_dropdown.add_item(str(_resolutions[i]), i)
|
||||
|
||||
_anchor_button_group = ButtonGroup.new()
|
||||
_anchor_buttons.resize(ANCHOR_COUNT)
|
||||
var x := 0
|
||||
var y := 0
|
||||
for i in _anchor_control.get_child_count():
|
||||
var child_node = _anchor_control.get_child(i)
|
||||
assert(child_node is Button)
|
||||
var child := child_node as Button
|
||||
child.toggle_mode = true
|
||||
child.custom_minimum_size = child.size
|
||||
child.icon = null
|
||||
child.pressed.connect(_on_AnchorButton_pressed.bind(i, x, y))
|
||||
child.button_group = _anchor_button_group
|
||||
_anchor_buttons[i] = child
|
||||
_anchor_buttons_grid[Vector2(x, y)] = child
|
||||
x += 1
|
||||
if x >= 3:
|
||||
x = 0
|
||||
y += 1
|
||||
|
||||
_anchor_buttons[_selected_anchor].button_pressed = true
|
||||
# The signal apparently doesn't trigger in this case
|
||||
_on_AnchorButton_pressed(_selected_anchor, 0, 0)
|
||||
|
||||
|
||||
func _notification(what: int):
|
||||
if what == NOTIFICATION_VISIBILITY_CHANGED:
|
||||
if visible:
|
||||
# Select current resolution
|
||||
if _terrain != null and _terrain.get_data() != null:
|
||||
var res := _terrain.get_data().get_resolution()
|
||||
for i in len(_resolutions):
|
||||
if res == _resolutions[i]:
|
||||
_resolution_dropdown.select(i)
|
||||
break
|
||||
|
||||
|
||||
func _on_AnchorButton_pressed(anchor0: int, x0: int, y0: int):
|
||||
_selected_anchor = anchor0
|
||||
|
||||
for button in _anchor_buttons:
|
||||
button.icon = null
|
||||
|
||||
for anchor in ANCHOR_COUNT:
|
||||
var d = _anchor_dirs[anchor]
|
||||
var nx = x0 + d[0]
|
||||
var ny = y0 + d[1]
|
||||
var k = Vector2(nx, ny)
|
||||
if not _anchor_buttons_grid.has(k):
|
||||
continue
|
||||
var button : Button = _anchor_buttons_grid[k]
|
||||
var icon := _get_icon(_anchor_icon_names[anchor])
|
||||
button.icon = icon
|
||||
|
||||
|
||||
func _set_anchor_control_active(active: bool):
|
||||
for button in _anchor_buttons:
|
||||
button.disabled = not active
|
||||
|
||||
|
||||
func _on_ResolutionDropdown_item_selected(id):
|
||||
pass
|
||||
|
||||
|
||||
func _on_StretchCheckBox_toggled(button_pressed: bool):
|
||||
_set_anchor_control_active(not button_pressed)
|
||||
|
||||
|
||||
func _on_ApplyButton_pressed():
|
||||
var stretch = _stretch_checkbox.button_pressed
|
||||
var res = _resolutions[_resolution_dropdown.get_selected_id()]
|
||||
var dir = _anchor_dirs[_selected_anchor]
|
||||
_apply(res, stretch, Vector2(dir[0], dir[1]))
|
||||
hide()
|
||||
|
||||
|
||||
func _on_CancelButton_pressed():
|
||||
hide()
|
||||
|
||||
|
||||
func _apply(p_resolution: int, p_stretch: bool, p_anchor: Vector2):
|
||||
if _terrain == null:
|
||||
_logger.error("Cannot apply resize, terrain is not set")
|
||||
return
|
||||
|
||||
var data = _terrain.get_data()
|
||||
if data == null:
|
||||
_logger.error("Cannot apply resize, terrain has no data")
|
||||
return
|
||||
|
||||
data.resize(p_resolution, p_stretch, p_anchor)
|
||||
data.notify_full_change()
|
||||
permanent_change_performed.emit("Resize terrain")
|
||||
@@ -0,0 +1 @@
|
||||
uid://c8ifc22pssc0x
|
||||
159
addons/zylann.hterrain/tools/resize_dialog/resize_dialog.tscn
Normal file
159
addons/zylann.hterrain/tools/resize_dialog/resize_dialog.tscn
Normal file
@@ -0,0 +1,159 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://gt402qqhab7j"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c8ifc22pssc0x" path="res://addons/zylann.hterrain/tools/resize_dialog/resize_dialog.gd" id="1"]
|
||||
[ext_resource type="Texture2D" uid="uid://b4ya0po3a4nqa" path="res://addons/zylann.hterrain/tools/icons/icon_heightmap_unmask.svg" id="2"]
|
||||
[ext_resource type="Texture2D" uid="uid://d3vie0tj3ry6k" path="res://addons/zylann.hterrain/tools/icons/icon_long_arrow_right.svg" id="3"]
|
||||
[ext_resource type="Texture2D" uid="uid://b6l5dys0awbwd" path="res://addons/zylann.hterrain/tools/icons/icon_long_arrow_down.svg" id="4"]
|
||||
[ext_resource type="Texture2D" uid="uid://bdkcgtv1r5j31" path="res://addons/zylann.hterrain/tools/icons/icon_small_circle.svg" id="5"]
|
||||
[ext_resource type="PackedScene" path="res://addons/zylann.hterrain/tools/util/dialog_fitter.tscn" id="6"]
|
||||
|
||||
[node name="ResizeDialog" type="AcceptDialog"]
|
||||
title = "Resize terrain"
|
||||
size = Vector2i(300, 201)
|
||||
min_size = Vector2i(300, 200)
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 8.0
|
||||
offset_top = 8.0
|
||||
offset_right = -8.0
|
||||
offset_bottom = -18.0
|
||||
|
||||
[node name="GridContainer" type="GridContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
columns = 2
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
text = "Resolution"
|
||||
|
||||
[node name="ResolutionDropdown" type="OptionButton" parent="VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
toggle_mode = false
|
||||
|
||||
[node name="Label3" type="Label" parent="VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
text = "Stretch"
|
||||
|
||||
[node name="StretchCheckBox" type="CheckBox" parent="VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label2" type="Label" parent="VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
text = "Direction"
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/GridContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="AnchorControl" type="GridContainer" parent="VBoxContainer/GridContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
columns = 3
|
||||
|
||||
[node name="TopLeftButton" type="Button" parent="VBoxContainer/GridContainer/HBoxContainer/AnchorControl"]
|
||||
layout_mode = 2
|
||||
icon = ExtResource("2")
|
||||
|
||||
[node name="TopButton" type="Button" parent="VBoxContainer/GridContainer/HBoxContainer/AnchorControl"]
|
||||
layout_mode = 2
|
||||
icon = ExtResource("2")
|
||||
|
||||
[node name="TopRightButton" type="Button" parent="VBoxContainer/GridContainer/HBoxContainer/AnchorControl"]
|
||||
layout_mode = 2
|
||||
icon = ExtResource("2")
|
||||
|
||||
[node name="LeftButton" type="Button" parent="VBoxContainer/GridContainer/HBoxContainer/AnchorControl"]
|
||||
layout_mode = 2
|
||||
icon = ExtResource("2")
|
||||
|
||||
[node name="CenterButton" type="Button" parent="VBoxContainer/GridContainer/HBoxContainer/AnchorControl"]
|
||||
layout_mode = 2
|
||||
icon = ExtResource("2")
|
||||
|
||||
[node name="RightButton" type="Button" parent="VBoxContainer/GridContainer/HBoxContainer/AnchorControl"]
|
||||
layout_mode = 2
|
||||
icon = ExtResource("2")
|
||||
|
||||
[node name="ButtomLeftButton" type="Button" parent="VBoxContainer/GridContainer/HBoxContainer/AnchorControl"]
|
||||
layout_mode = 2
|
||||
icon = ExtResource("2")
|
||||
|
||||
[node name="ButtomButton" type="Button" parent="VBoxContainer/GridContainer/HBoxContainer/AnchorControl"]
|
||||
layout_mode = 2
|
||||
icon = ExtResource("2")
|
||||
|
||||
[node name="BottomRightButton" type="Button" parent="VBoxContainer/GridContainer/HBoxContainer/AnchorControl"]
|
||||
layout_mode = 2
|
||||
icon = ExtResource("2")
|
||||
|
||||
[node name="Reference" type="Control" parent="VBoxContainer/GridContainer/HBoxContainer"]
|
||||
custom_minimum_size = Vector2(100, 0)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="XArrow" type="TextureRect" parent="VBoxContainer/GridContainer/HBoxContainer/Reference"]
|
||||
modulate = Color(1, 0.292969, 0.292969, 1)
|
||||
layout_mode = 0
|
||||
anchor_right = 1.0
|
||||
offset_left = 9.0
|
||||
offset_bottom = 16.0
|
||||
texture = ExtResource("3")
|
||||
|
||||
[node name="ZArrow" type="TextureRect" parent="VBoxContainer/GridContainer/HBoxContainer/Reference"]
|
||||
modulate = Color(0.292969, 0.602295, 1, 1)
|
||||
layout_mode = 0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = 10.0
|
||||
offset_right = 16.0
|
||||
texture = ExtResource("4")
|
||||
|
||||
[node name="ZLabel" type="Label" parent="VBoxContainer/GridContainer/HBoxContainer/Reference"]
|
||||
layout_mode = 0
|
||||
offset_left = 14.0
|
||||
offset_top = 54.0
|
||||
offset_right = 22.0
|
||||
offset_bottom = 68.0
|
||||
text = "Z"
|
||||
|
||||
[node name="XLabel" type="Label" parent="VBoxContainer/GridContainer/HBoxContainer/Reference"]
|
||||
layout_mode = 0
|
||||
offset_left = 52.0
|
||||
offset_top = 14.0
|
||||
offset_right = 60.0
|
||||
offset_bottom = 28.0
|
||||
text = "X"
|
||||
|
||||
[node name="Origin" type="TextureRect" parent="VBoxContainer/GridContainer/HBoxContainer/Reference"]
|
||||
layout_mode = 0
|
||||
offset_left = 3.0
|
||||
offset_top = 4.0
|
||||
offset_right = 11.0
|
||||
offset_bottom = 12.0
|
||||
texture = ExtResource("5")
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="ApplyButton" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Apply (no undo)"
|
||||
|
||||
[node name="CancelButton" type="Button" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Cancel"
|
||||
|
||||
[node name="DialogFitter" parent="." instance=ExtResource("6")]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_left = 8.0
|
||||
offset_top = 8.0
|
||||
offset_right = 292.0
|
||||
offset_bottom = 183.0
|
||||
|
||||
[connection signal="item_selected" from="VBoxContainer/GridContainer/ResolutionDropdown" to="." method="_on_ResolutionDropdown_item_selected"]
|
||||
[connection signal="toggled" from="VBoxContainer/GridContainer/StretchCheckBox" to="." method="_on_StretchCheckBox_toggled"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/ApplyButton" to="." method="_on_ApplyButton_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer/CancelButton" to="." method="_on_CancelButton_pressed"]
|
||||
Reference in New Issue
Block a user