Skip to content

Commit a677c64

Browse files
Enable landscape orientation and sensor-based orientation changes
1 parent 966ab61 commit a677c64

11 files changed

Lines changed: 139 additions & 92 deletions

File tree

project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ HandlerGUI="*res://src/autoload/HandlerGUI.gd"
3737
window/size/viewport_width=720
3838
window/size/viewport_height=1280
3939
window/energy_saving/keep_screen_on=false
40-
window/handheld/orientation=1
40+
window/handheld/orientation=6
4141
mouse_cursor/tooltip_position_offset=Vector2(0, 10)
4242

4343
[editor_plugins]

src/autoload/Configs.gd

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,32 @@ signal tab_removed
3535
signal tab_selected(index: int)
3636
@warning_ignore("unused_signal")
3737
signal layout_changed
38+
@warning_ignore("unused_signal")
39+
signal orientation_changed
3840

3941
var current_sdk: int = -1
4042

43+
enum orientation {PORTRAIT, LANDSCAPE}
44+
var current_orientation := orientation.PORTRAIT
45+
46+
func _ready() -> void:
47+
get_tree().root.size_changed.connect(check_orientation)
48+
49+
func check_orientation():
50+
var width = DisplayServer.window_get_size().x
51+
var height = DisplayServer.window_get_size().y
52+
53+
var new_orientation: orientation
54+
if width > height:
55+
new_orientation = orientation.LANDSCAPE
56+
else:
57+
new_orientation = orientation.PORTRAIT
58+
59+
if new_orientation != current_orientation:
60+
current_orientation = new_orientation
61+
orientation_changed.emit()
62+
63+
4164
const savedata_path = "user://savedata.tres"
4265
var savedata: SaveData:
4366
set(new_value):

src/autoload/HandlerGUI.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ const DonateMenuScene = preload("res://src/ui_parts/donate_menu.tscn")
88
const UpdateMenuScene = preload("res://src/ui_parts/update_menu.tscn")
99
const ExportMenuScene = preload("res://src/ui_parts/export_menu.tscn")
1010
const ShortcutPanelScene = preload("res://src/ui_parts/shortcut_panel.tscn")
11+
const TabsPanel = preload("res://src/ui_parts/tabs_panel.tscn")
1112

1213
# Menus should be added with add_menu() and removed by being freed.
1314
# To add them as modals that don't hide the previous one, use add_dialog().
1415
var menu_stack: Array[ColorRect]
1516
var popup_stack: Array[Control]
1617

1718
var shortcut_panel: PanelContainer
19+
var tabs_panel: PanelContainer
1820

1921
func _enter_tree() -> void:
2022
var window := get_window()
@@ -33,6 +35,14 @@ func _ready() -> void:
3335

3436
shortcut_panel = ShortcutPanelScene.instantiate()
3537
get_tree().root.add_child(shortcut_panel)
38+
39+
tabs_panel = TabsPanel.instantiate()
40+
var overlay_ref := ColorRect.new()
41+
overlay_ref.color = Color(0, 0, 0, 0.4)
42+
overlay_ref.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
43+
overlay_ref.hide()
44+
get_tree().root.add_child.call_deferred(overlay_ref)
45+
overlay_ref.add_child(tabs_panel)
3646

3747
func _notification(what: int) -> void:
3848
if what == NOTIFICATION_WM_ABOUT:

src/config_classes/SaveData.gd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ func validate() -> void:
5959
_active_tab_index = _active_tab_index # Run the setter.
6060

6161
# End of the method, would need to be rewritten if more things need validation.
62-
for location in [LayoutLocation.TOP_LEFT, LayoutLocation.BOTTOM_LEFT]:
62+
for location in [LayoutLocation.SIDE_PANEL_TOP, LayoutLocation.SIDE_PANEL_BOTTOM]:
6363
if _layout.has(location) and not _layout[location].is_empty():
6464
return
6565
_layout = {
66-
LayoutLocation.TOP_LEFT: [Utils.LayoutPart.INSPECTOR, Utils.LayoutPart.CODE_EDITOR]
66+
LayoutLocation.SIDE_PANEL_TOP: [Utils.LayoutPart.INSPECTOR, Utils.LayoutPart.CODE_EDITOR]
6767
}
6868

6969

@@ -755,7 +755,7 @@ func move_tab(old_idx: int, new_idx: int) -> void:
755755
Configs.tabs_changed.emit()
756756

757757

758-
enum LayoutLocation {NONE, EXCLUDED, TOP_LEFT, BOTTOM_LEFT}
758+
enum LayoutLocation { NONE, EXCLUDED, SIDE_PANEL_TOP, SIDE_PANEL_BOTTOM }
759759

760760
@export var _layout: Dictionary[LayoutLocation, Array]: # Array[Utils.LayoutPart]
761761
set(new_value):
@@ -840,14 +840,14 @@ func get_layout_part_index(part: Utils.LayoutPart) -> int:
840840
main_splitter_offset = new_value
841841
emit_changed()
842842

843-
@export var top_vertical_splitter_offset := -240:
843+
@export var side_panel_splitter_offset := -240:
844844
set(new_value):
845845
# Validation
846846
if is_nan(new_value):
847847
new_value = 0
848848
# Main part
849-
if top_vertical_splitter_offset != new_value:
850-
top_vertical_splitter_offset = new_value
849+
if side_panel_splitter_offset != new_value:
850+
side_panel_splitter_offset = new_value
851851
emit_changed()
852852

853853

src/ui_parts/display.gd

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
extends VBoxContainer
22

33
const NumberEdit = preload("res://src/ui_widgets/number_edit.gd")
4-
const TabsPanel = preload("res://src/ui_parts/tabs_panel.tscn")
54

65
@onready var viewport: SubViewport = %Viewport
76
@onready var reference_texture: TextureRect = %Viewport/ReferenceTexture
@@ -38,14 +37,6 @@ func _ready() -> void:
3837
update_theme()
3938
update_snap_config()
4039
get_window().window_input.connect(_update_input_debug)
41-
42-
tabs_panel = TabsPanel.instantiate()
43-
var overlay_ref := ColorRect.new()
44-
overlay_ref.color = Color(0, 0, 0, 0.4)
45-
overlay_ref.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
46-
overlay_ref.hide()
47-
get_tree().root.add_child.call_deferred(overlay_ref)
48-
overlay_ref.add_child(tabs_panel)
4940

5041
func update_translations() -> void:
5142
%LeftMenu/Visuals.tooltip_text = Translator.translate("Visuals")
@@ -59,10 +50,12 @@ func update_theme() -> void:
5950

6051
var frame := StyleBoxFlat.new()
6152
frame.draw_center = false
62-
frame.border_width_top = 2
53+
if Configs.current_orientation == Configs.orientation.PORTRAIT:
54+
frame.border_width_top = 2
55+
else:
56+
frame.border_width_left = 2
6357
frame.border_color = ThemeUtils.connected_button_border_color_pressed
64-
frame.content_margin_left = 2.0
65-
frame.content_margin_top = 2.0
58+
frame.set_content_margin_all(2.0)
6659
viewport_panel.add_theme_stylebox_override("panel", frame)
6760

6861
func update_snap_config() -> void:
@@ -174,7 +167,7 @@ func _update_input_debug(event: InputEvent) -> void:
174167

175168
func show_tabs_panel() -> void:
176169
if should_refresh_tabs:
177-
tabs_panel.refresh_tabs()
170+
HandlerGUI.tabs_panel.refresh_tabs()
178171
should_refresh_tabs = false
179-
tabs_panel.get_parent().show()
180-
tabs_panel.animate_in()
172+
HandlerGUI.tabs_panel.get_parent().show()
173+
HandlerGUI.tabs_panel.animate_in()

src/ui_parts/display.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ unique_name_in_owner = true
5151
disable_3d = true
5252
handle_input_locally = false
5353
gui_snap_controls_to_pixels = false
54-
size = Vector2i(716, 1248)
54+
size = Vector2i(720, 1249)
5555
size_2d_override_stretch = true
5656
render_target_update_mode = 4
5757
script = ExtResource("9_4xrk7")

src/ui_parts/editor_scene.gd

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,24 @@ const ViewportScene = preload("res://src/ui_parts/display.tscn")
77

88
@onready var panel_container: PanelContainer = $PanelContainer
99

10+
var main_splitter: SplitContainer
11+
12+
1013
func _ready() -> void:
1114
Configs.theme_changed.connect(update_theme)
1215
Configs.layout_changed.connect(update_layout)
16+
Configs.orientation_changed.connect(update_orientation)
1317
update_layout()
1418
update_theme()
1519
var version = JavaClassWrapper.wrap("android.os.Build$VERSION")
1620
if version: Configs.current_sdk = version.SDK_INT
1721

22+
func update_orientation():
23+
if Configs.current_orientation == Configs.orientation.PORTRAIT:
24+
main_splitter.vertical = true
25+
else:
26+
main_splitter.vertical = false
27+
1828
func update_theme() -> void:
1929
var stylebox := StyleBoxFlat.new()
2030
stylebox.bg_color = ThemeUtils.overlay_panel_inner_color
@@ -26,54 +36,53 @@ func update_layout() -> void:
2636
for child in panel_container.get_children():
2737
child.queue_free()
2838

29-
var top_left := Configs.savedata.get_layout_parts(SaveData.LayoutLocation.TOP_LEFT)
30-
var bottom_left := Configs.savedata.get_layout_parts(SaveData.LayoutLocation.BOTTOM_LEFT)
39+
var side_panel_top := Configs.savedata.get_layout_parts(SaveData.LayoutLocation.SIDE_PANEL_TOP)
40+
var side_panel_bottom := Configs.savedata.get_layout_parts(SaveData.LayoutLocation.SIDE_PANEL_BOTTOM)
3141

32-
# Set up the horizontal splitter.
33-
var main_splitter := VSplitContainer.new()
34-
main_splitter.size_flags_horizontal = Control.SIZE_FILL
42+
# Set up the main splitter.
43+
main_splitter = SplitContainer.new()
44+
main_splitter.vertical = true
3545
main_splitter.dragger_visibility = SplitContainer.DRAGGER_HIDDEN_COLLAPSED
3646
main_splitter.touch_dragger_enabled = true
3747
main_splitter.split_offset = Configs.savedata.main_splitter_offset
3848
main_splitter.dragged.connect(_on_main_splitter_dragged)
3949
panel_container.add_child(main_splitter)
4050

41-
var top_margin_container := MarginContainer.new()
42-
top_margin_container.custom_minimum_size.x = 350
43-
top_margin_container.begin_bulk_theme_override()
44-
top_margin_container.add_theme_constant_override("margin_top", 6)
45-
top_margin_container.add_theme_constant_override("margin_bottom", 3)
46-
top_margin_container.add_theme_constant_override("margin_left", 6)
47-
top_margin_container.add_theme_constant_override("margin_right", 6)
48-
top_margin_container.end_bulk_theme_override()
49-
main_splitter.add_child(top_margin_container)
51+
var side_panel_margin_container := MarginContainer.new()
52+
side_panel_margin_container.begin_bulk_theme_override()
53+
side_panel_margin_container.add_theme_constant_override("margin_top", 6)
54+
side_panel_margin_container.add_theme_constant_override("margin_bottom", 3)
55+
side_panel_margin_container.add_theme_constant_override("margin_left", 6)
56+
side_panel_margin_container.add_theme_constant_override("margin_right", 6)
57+
side_panel_margin_container.end_bulk_theme_override()
58+
main_splitter.add_child(side_panel_margin_container)
5059

51-
var bottom_margin_container := MarginContainer.new()
52-
bottom_margin_container.add_theme_constant_override("margin_top", 3)
53-
bottom_margin_container.add_child(create_layout_node(Utils.LayoutPart.VIEWPORT))
54-
main_splitter.add_child(bottom_margin_container)
60+
var main_view_margin_container := MarginContainer.new()
61+
main_view_margin_container.add_theme_constant_override("margin_top", 3)
62+
main_view_margin_container.add_child(create_layout_node(Utils.LayoutPart.VIEWPORT))
63+
main_splitter.add_child(main_view_margin_container)
5564

56-
var left_vbox := VBoxContainer.new()
57-
left_vbox.add_theme_constant_override("separation", 6)
58-
top_margin_container.add_child(left_vbox)
65+
var side_panel_vbox := VBoxContainer.new()
66+
side_panel_vbox.add_theme_constant_override("separation", 6)
67+
side_panel_margin_container.add_child(side_panel_vbox)
5968

6069
var global_actions := GlobalActionsScene.instantiate()
61-
left_vbox.add_child(global_actions)
70+
side_panel_vbox.add_child(global_actions)
6271

63-
if not top_left.is_empty() and not bottom_left.is_empty():
72+
if not side_panel_top.is_empty() and not side_panel_bottom.is_empty():
6473
# Layout parts both on top and on the bottom.
65-
var top_vertical_split_container := VSplitContainer.new()
66-
top_vertical_split_container.size_flags_vertical = Control.SIZE_EXPAND_FILL
67-
top_vertical_split_container.dragger_visibility = SplitContainer.DRAGGER_HIDDEN_COLLAPSED
68-
top_vertical_split_container.touch_dragger_enabled = true
69-
top_vertical_split_container.split_offset = Configs.savedata.top_vertical_splitter_offset
70-
top_vertical_split_container.dragged.connect(_on_top_vertical_splitter_dragged)
71-
top_vertical_split_container.add_child(create_layout_node(top_left[0]))
72-
top_vertical_split_container.add_child(create_layout_node(bottom_left[0]))
73-
left_vbox.add_child(top_vertical_split_container)
74-
elif top_left.size() == 2 or bottom_left.size() == 2:
74+
var side_panel_split_container := VSplitContainer.new()
75+
side_panel_split_container.size_flags_vertical = Control.SIZE_EXPAND_FILL
76+
side_panel_split_container.dragger_visibility = SplitContainer.DRAGGER_HIDDEN_COLLAPSED
77+
side_panel_split_container.touch_dragger_enabled = true
78+
side_panel_split_container.split_offset = Configs.savedata.side_panel_splitter_offset
79+
side_panel_split_container.dragged.connect(_on_side_panel_splitter_dragged)
80+
side_panel_split_container.add_child(create_layout_node(side_panel_top[0]))
81+
side_panel_split_container.add_child(create_layout_node(side_panel_bottom[0]))
82+
side_panel_vbox.add_child(side_panel_split_container)
83+
elif side_panel_top.size() == 2 or side_panel_bottom.size() == 2:
7584
# Tabs for the different layout parts.
76-
var layout_parts := top_left if bottom_left.is_empty() else bottom_left
85+
var layout_parts := side_panel_top if side_panel_bottom.is_empty() else side_panel_bottom
7786
var vbox := VBoxContainer.new()
7887
vbox.size_flags_vertical = Control.SIZE_EXPAND_FILL
7988
var buttons_hbox := HBoxContainer.new()
@@ -114,19 +123,19 @@ func update_layout() -> void:
114123
if i == 0:
115124
btn.button_pressed = true
116125
layout_nodes[part].show()
117-
left_vbox.add_child(vbox)
126+
side_panel_vbox.add_child(vbox)
118127
else:
119128
# Layout parts disabled.
120-
if not top_left.is_empty():
121-
left_vbox.add_child(create_layout_node(top_left[0]))
122-
elif not bottom_left.is_empty():
123-
left_vbox.add_child(create_layout_node(bottom_left[0]))
129+
if not side_panel_top.is_empty():
130+
side_panel_vbox.add_child(create_layout_node(side_panel_top[0]))
131+
elif not side_panel_bottom.is_empty():
132+
side_panel_vbox.add_child(create_layout_node(side_panel_bottom[0]))
124133

125134
func _on_main_splitter_dragged(offset: int) -> void:
126135
Configs.savedata.main_splitter_offset = offset
127136

128-
func _on_top_vertical_splitter_dragged(offset: int) -> void:
129-
Configs.savedata.top_vertical_splitter_offset = offset
137+
func _on_side_panel_splitter_dragged(offset: int) -> void:
138+
Configs.savedata.side_panel_splitter_offset = offset
130139

131140

132141
func create_layout_node(layout_part: Utils.LayoutPart) -> Node:

src/ui_parts/inspector.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ theme_override_constants/h_separation = 4
3333
icon = ExtResource("3_vo6hf")
3434

3535
[node name="ElementContainer" type="Control" parent="."]
36-
custom_minimum_size = Vector2(0, 150)
36+
custom_minimum_size = Vector2(340, 150)
3737
layout_mode = 2
3838
size_flags_vertical = 3
3939
script = ExtResource("3_qeptj")

0 commit comments

Comments
 (0)