Skip to content

Commit

Permalink
Replace some sliders with Pixelorama's custom ValueSlider, allow the …
Browse files Browse the repository at this point in the history
…file dialog to be affected by Pixelorama's native file dialog setting
  • Loading branch information
OverloadedOrama committed Jul 1, 2024
1 parent 115df8b commit d255fa0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 79 deletions.
25 changes: 21 additions & 4 deletions export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,39 @@
name="Linux/X11"
platform="Linux/X11"
runnable=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter="*json"
exclude_filter="res://src/Extensions/KeyDisplay/ExtensionsApi.gd"
exclude_filter="res://src/Extensions/Voxelorama/ExtensionsApi.gd"
export_path=""
script_export_mode=1
script_encryption_key=""
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false

[preset.0.options]

custom_template/debug=""
custom_template/release=""
binary_format/64_bits=true
debug/export_console_wrapper=1
binary_format/embed_pck=false
texture_format/bptc=false
texture_format/s3tc=true
texture_format/etc=false
texture_format/etc2=false
binary_format/architecture="x86_64"
ssh_remote_deploy/enabled=false
ssh_remote_deploy/host="user@host_ip"
ssh_remote_deploy/port="22"
ssh_remote_deploy/extra_args_ssh=""
ssh_remote_deploy/extra_args_scp=""
ssh_remote_deploy/run_script="#!/usr/bin/env bash
export DISPLAY=:0
unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"
\"{temp_dir}/{exe_name}\" {cmd_args}"
ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash
kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")
rm -rf \"{temp_dir}\""
binary_format/64_bits=true
texture_format/no_bptc_fallbacks=true
21 changes: 17 additions & 4 deletions src/Extensions/Voxelorama/Tools/Depth.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,31 @@ var kname: String
var tool_slot = null # Tools.Slot
var cursor_text := ""

var _depth_slider: TextureProgressBar
var _cursor := Vector2.INF
var _depth_array: Array[PackedFloat32Array] = []
var _depth := 1.0
var _canvas_depth := preload("res://src/Extensions/Voxelorama/Tools/CanvasDepth.tscn")
var _canvas_depth_node: Node2D

var _canvas: Node2D


func _ready() -> void:
_depth_slider = ExtensionsApi.general.create_value_slider()
_depth_slider.custom_minimum_size.y = 24
_depth_slider.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
_depth_slider.value_changed.connect(_on_depth_slider_value_changed)
_depth_slider.min_value = 1
_depth_slider.max_value = 25
_depth_slider.step = 0.5
_depth_slider.value = 1
_depth_slider.allow_greater = true
add_child(_depth_slider)
kname = name.replace(" ", "_").to_lower()
if tool_slot.name == "Left tool":
$ColorRect.color = ExtensionsApi.general.get_global().left_tool_color
else:
$ColorRect.color = ExtensionsApi.general.get_global().right_tool_color
load_config()

_canvas = ExtensionsApi.general.get_canvas()
Expand Down Expand Up @@ -49,8 +63,7 @@ func set_config(config: Dictionary) -> void:


func update_config() -> void:
$HBoxContainer/DepthHSlider.value = _depth
$HBoxContainer/DepthSpinBox.value = _depth
_depth_slider.value = _depth


func draw_start(position: Vector2) -> void:
Expand Down Expand Up @@ -119,7 +132,7 @@ func _update_array(cel: RefCounted, position: Vector2) -> void:
_canvas_depth_node.queue_redraw()


func _on_DepthHSlider_value_changed(value: float) -> void:
func _on_depth_slider_value_changed(value: float) -> void:
_depth = value
update_config()
save_config()
Expand Down
47 changes: 11 additions & 36 deletions src/Extensions/Voxelorama/Tools/Depth.tscn
Original file line number Diff line number Diff line change
@@ -1,44 +1,19 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=2 format=3 uid="uid://xfhcfrlwm1o5"]

[ext_resource path="res://src/Extensions/Voxelorama/Tools/Depth.gd" type="Script" id=1]
[ext_resource type="Script" path="res://src/Extensions/Voxelorama/Tools/Depth.gd" id="1"]

[node name="DepthTool" type="VBoxContainer"]
offset_right = 40.0
offset_bottom = 40.0
script = ExtResource( 1 )

[node name="Label" type="Label" parent="."]
offset_right = 94.0
offset_bottom = 14.0
text = "Depth"

[node name="HBoxContainer" type="HBoxContainer" parent="."]
offset_top = 18.0
offset_right = 94.0
offset_bottom = 42.0

[node name="DepthHSlider" type="HSlider" parent="HBoxContainer"]
offset_right = 16.0
offset_bottom = 16.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
min_value = 1.0
max_value = 25.0
step = 0.5
value = 1.0
allow_greater = true
script = ExtResource("1")

[node name="DepthSpinBox" type="SpinBox" parent="HBoxContainer"]
offset_left = 20.0
offset_right = 94.0
offset_bottom = 24.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
min_value = 1.0
max_value = 25.0
step = 0.5
value = 1.0
allow_greater = true
[node name="ColorRect" type="ColorRect" parent="."]
custom_minimum_size = Vector2(0, 4)
layout_mode = 2

[connection signal="value_changed" from="HBoxContainer/DepthHSlider" to="." method="_on_DepthHSlider_value_changed"]
[connection signal="value_changed" from="HBoxContainer/DepthSpinBox" to="." method="_on_DepthHSlider_value_changed"]
[node name="Label" type="Label" parent="."]
layout_mode = 2
theme_type_variation = &"HeaderSmall"
text = "Depth"
horizontal_alignment = 1
30 changes: 22 additions & 8 deletions src/Extensions/Voxelorama/Voxelorama.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ var depth_tool_scene := "res://src/Extensions/Voxelorama/Tools/Depth.tscn"
var unshaded_env := preload("res://assets/environments/unshaded.tres")
var shaded_env := preload("res://assets/environments/shaded.tres")
var voxel_art_gen_script := preload("res://src/Extensions/Voxelorama/VoxelArtGen.gd")
var scale_slider: TextureProgressBar

## Only when used as a Pixelorama extension
var menu_item_index: int

@onready var voxel_art_gen: MeshInstance3D = find_child("VoxelArtGen")
@onready var camera: Camera3D = find_child("Camera3D")
@onready var camera: Camera3D = voxel_art_gen.camera
@onready var file_dialog: FileDialog = find_child("FileDialog")


Expand All @@ -25,6 +26,21 @@ func _enter_tree() -> void:
ExtensionsApi.tools.add_tool("Depth", "Depth", depth_tool_scene)


func _ready() -> void:
$FileDialog.use_native_dialog = ExtensionsApi.general.get_global().use_native_file_dialogs
scale_slider = ExtensionsApi.general.create_value_slider()
scale_slider.size_flags_horizontal = Control.SIZE_EXPAND_FILL
scale_slider.custom_minimum_size.y = 24
scale_slider.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
scale_slider.value_changed.connect(_on_scale_value_changed)
scale_slider.min_value = 0.1
scale_slider.max_value = 10
scale_slider.step = 0.1
scale_slider.allow_greater = true
scale_slider.value = 1
%ScaleHBox.add_child(scale_slider)


func _input(event: InputEvent) -> void:
if !viewport_has_focus:
rotate = false
Expand Down Expand Up @@ -69,15 +85,15 @@ func _on_Voxelorama_about_to_show():
initiate_generation()


func initiate_generation():
func initiate_generation() -> void:
generate()
if voxel_art_gen.layer_images.size() == 0:
return
var first_layer: Image = voxel_art_gen.layer_images[0].image
if first_layer:
camera.position.y = first_layer.get_size().y / 8
camera.position.x = first_layer.get_size().x / 8
camera.position.z = max(first_layer.get_size().x, first_layer.get_size().y)
camera.position.y = first_layer.get_size().y / 8.0
camera.position.x = first_layer.get_size().x / 8.0
camera.position.z = maxf(first_layer.get_size().x, first_layer.get_size().y)

var project = ExtensionsApi.project.current_project
var global = ExtensionsApi.general.get_global()
Expand Down Expand Up @@ -134,10 +150,8 @@ func _on_ViewportContainer_mouse_exited() -> void:
viewport_has_focus = false


func _on_Scale_value_changed(value: float) -> void:
func _on_scale_value_changed(value: float) -> void:
voxel_art_gen.mesh_scale = value
$"%ScaleSlider".value = value
$"%ScaleSpinBox".value = value


func _on_FileDialog_file_selected(path: String) -> void:
Expand Down
32 changes: 5 additions & 27 deletions src/Extensions/Voxelorama/Voxelorama.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ stretch = true
[node name="SubViewport" type="SubViewport" parent="VBoxContainer/ViewportAndStatus/Panel/SubViewportContainer"]
transparent_bg = true
handle_input_locally = false
size = Vector2i(572, 450)
size = Vector2i(2, 2)
render_target_update_mode = 0

[node name="VoxeloramaPreview" parent="VBoxContainer/ViewportAndStatus/Panel/SubViewportContainer/SubViewport" instance=ExtResource("2")]
Expand Down Expand Up @@ -107,34 +107,13 @@ layout_mode = 2
size_flags_horizontal = 3

[node name="ScaleHBox" type="HBoxContainer" parent="VBoxContainer/Options"]
unique_name_in_owner = true
layout_mode = 2

[node name="Label" type="Label" parent="VBoxContainer/Options/ScaleHBox"]
layout_mode = 2
text = "Scale:"

[node name="ScaleSlider" type="HSlider" parent="VBoxContainer/Options/ScaleHBox"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 4
mouse_default_cursor_shape = 2
min_value = 0.1
max_value = 10.0
step = 0.1
value = 1.0
allow_greater = true

[node name="ScaleSpinBox" type="SpinBox" parent="VBoxContainer/Options/ScaleHBox"]
unique_name_in_owner = true
layout_mode = 2
mouse_default_cursor_shape = 2
min_value = 0.1
max_value = 10.0
step = 0.1
value = 1.0
allow_greater = true

[node name="FlagsHeader" type="HBoxContainer" parent="VBoxContainer/Options"]
layout_mode = 2

Expand Down Expand Up @@ -191,18 +170,17 @@ layout_mode = 2
mouse_default_cursor_shape = 2
text = "Export"

[node name="FileDialog" type="FileDialog" parent="."]
[node name="FileDialog" type="FileDialog" parent="." groups=["FileDialogs"]]
size = Vector2i(677, 300)
access = 2
filters = PackedStringArray("*.obj", "*.svg")
filters = PackedStringArray("*.obj")
show_hidden_files = true

[connection signal="about_to_popup" from="." to="." method="_on_Voxelorama_about_to_show"]
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
[connection signal="mouse_entered" from="VBoxContainer/ViewportAndStatus/Panel/SubViewportContainer" to="." method="_on_ViewportContainer_mouse_entered"]
[connection signal="mouse_exited" from="VBoxContainer/ViewportAndStatus/Panel/SubViewportContainer" to="." method="_on_ViewportContainer_mouse_exited"]
[connection signal="toggled" from="VBoxContainer/ViewportAndStatus/ShadedPreview" to="." method="_on_ShadedPreview_toggled"]
[connection signal="value_changed" from="VBoxContainer/Options/ScaleHBox/ScaleSlider" to="." method="_on_Scale_value_changed"]
[connection signal="value_changed" from="VBoxContainer/Options/ScaleHBox/ScaleSpinBox" to="." method="_on_Scale_value_changed"]
[connection signal="toggled" from="VBoxContainer/Options/Flags/VBoxContainer/Centered" to="." method="_on_Centered_toggled"]
[connection signal="toggled" from="VBoxContainer/Options/Flags/VBoxContainer/Symmetrical" to="." method="_on_Symmetrical_toggled"]
[connection signal="toggled" from="VBoxContainer/Options/Flags/VBoxContainer/MergeFrames" to="." method="_on_MergeFrames_toggled"]
Expand Down

0 comments on commit d255fa0

Please sign in to comment.