1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-21 07:14:20 +00:00
This commit is contained in:
Steffo 2023-10-02 15:12:08 +02:00
parent 82b2b981c9
commit 362f6d45b1
Signed by: steffo
GPG key ID: 2A24051445686895
13 changed files with 190 additions and 70 deletions

View file

@ -75,4 +75,3 @@ func update_counter_icon():
store_collector_texturerect.texture = upgrade_gold_texture
else:
store_collector_texturerect.texture = null

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=21 format=3 uid="uid://c3rxmcwa5nqng"]
[gd_scene load_steps=22 format=3 uid="uid://c3rxmcwa5nqng"]
[ext_resource type="Script" path="res://game/game.gd" id="1_i3ly0"]
[ext_resource type="PackedScene" uid="uid://bllsprv8orpn4" path="res://bottle/bottle.tscn" id="1_y7o2l"]
@ -8,6 +8,7 @@
[ext_resource type="PackedScene" uid="uid://c3kitncwpi42j" path="res://entity/coin_copper/coin_copper.tscn" id="4_5oayc"]
[ext_resource type="Texture2D" uid="uid://taojrwr7xrp4" path="res://interface/upgrade_gold.png" id="4_i557v"]
[ext_resource type="PackedScene" uid="uid://beg758fa6o0cs" path="res://value/evaluator.tscn" id="6_my6nv"]
[ext_resource type="PackedScene" path="res://entity/gem/gemstone.tscn" id="7_13ofu"]
[ext_resource type="PackedScene" uid="uid://ratkps4plkhl" path="res://converters/copper_to_silver/copper_converter.tscn" id="7_ipeok"]
[ext_resource type="PackedScene" uid="uid://but1bdslxp5jl" path="res://converters/silver_to_gold/silver_converter.tscn" id="8_0bbpi"]
[ext_resource type="PackedScene" uid="uid://c2rlx7egl7xiv" path="res://collector/universal_collector.tscn" id="9_7op48"]
@ -38,6 +39,11 @@ upgrade_copper_texture = ExtResource("11_lt33g")
upgrade_silver_texture = ExtResource("3_8wvr1")
upgrade_gold_texture = ExtResource("4_i557v")
[node name="Ghost" parent="." instance=ExtResource("16_8vhx6")]
position = Vector2(90, 306)
collision_layer = 8
collision_mask = 6
[node name="Bottle" parent="." instance=ExtResource("1_y7o2l")]
[node name="TimeSpawner" parent="." node_paths=PackedStringArray("target") instance=ExtResource("3_qwsty")]

20
game_camera.gd Normal file
View file

@ -0,0 +1,20 @@
extends Camera2D
class_name GameCamera
func set_camera_position(scaling_factor: float):
var cutouts: Array[Rect2] = DisplayServer.get_display_cutouts()
var bottom
if len(cutouts) == 0:
bottom = 8
else:
var screen: Vector2i = DisplayServer.screen_get_size()
var rect: Rect2i = DisplayServer.get_display_safe_area()
bottom = max(8, screen.y - rect.end.y)
print("[GameCamera] Bottom margin is: ", bottom)
var size = get_window().size.y / scaling_factor
position.y = 480 - (size / 2)

View file

@ -5,6 +5,10 @@ class_name CustomUI
@onready var window: Window = get_window()
@onready var viewport: Viewport = window.get_viewport()
@onready var game_safe_ui: MarginContainer = $GameSafeUI
@onready var shop_safe_ui: MarginContainer = $ShopSafeUI
@onready var game_camera: GameCamera = $GameViewport/Viewport/GameCamera
func _ready():
viewport.size_changed.connect(_on_viewport_size_changed)
@ -21,4 +25,6 @@ func _on_viewport_size_changed():
scaling_factor = window_size.y / 480
print("[View] Scaling factor is: ", scaling_factor)
get_window().set_content_scale_factor(scaling_factor)
$SafeUI.set_safe_margins(scaling_factor)
game_safe_ui.set_safe_margins(scaling_factor)
shop_safe_ui.set_safe_margins(scaling_factor)
game_camera.set_camera_position(scaling_factor)

View file

@ -5,12 +5,11 @@
[ext_resource type="PackedScene" uid="uid://bey5lilvteg32" path="res://interface/score_button.tscn" id="3_vobar"]
[node name="GameUI" type="Control" node_paths=PackedStringArray("score_button")]
custom_minimum_size = Vector2(0, 54)
layout_mode = 3
anchors_preset = 15
anchors_preset = 10
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_ppf8y")
script = ExtResource("2_33nqa")
score_button = NodePath("ScoreButton")
@ -18,7 +17,6 @@ score_button = NodePath("ScoreButton")
[node name="ScoreButton" parent="." instance=ExtResource("3_vobar")]
custom_minimum_size = Vector2(88, 0)
layout_mode = 0
text = "$0.00"
[node name="SpawnButton" type="Button" parent="."]
custom_minimum_size = Vector2(88, 0)

25
interface/ghost.gd Normal file
View file

@ -0,0 +1,25 @@
extends Area2D
class_name Ghost
var is_dragging: bool
var previous_position: Vector2
func _input(event: InputEvent):
if event is InputEventMouseButton:
is_dragging = event.pressed
previous_position = event.position
elif event is InputEventScreenTouch:
is_dragging = event.pressed
previous_position = event.position
if is_dragging:
if event is InputEventMouseMotion:
var delta = event.position - previous_position
print(delta)
position += delta
previous_position = event.position
elif event is InputEventScreenDrag:
var delta = event.position - previous_position
print(delta)
position += delta
previous_position = event.position

20
interface/ghost.tscn Normal file
View file

@ -0,0 +1,20 @@
[gd_scene load_steps=4 format=3 uid="uid://qtk4tm6l367w"]
[ext_resource type="Script" path="res://interface/ghost.gd" id="1_gvls7"]
[ext_resource type="Texture2D" uid="uid://pj3ip6vlatms" path="res://converters/copper_to_silver/copper_converter.png" id="1_lo8gj"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hmopu"]
size = Vector2(34, 34)
[node name="Ghost" type="Area2D"]
scale = Vector2(3, 3)
input_pickable = false
script = ExtResource("1_gvls7")
[node name="Sprite" type="Sprite2D" parent="."]
modulate = Color(1, 1, 1, 0.470588)
z_index = 10
texture = ExtResource("1_lo8gj")
[node name="Shape" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_hmopu")

View file

@ -2,6 +2,12 @@ extends MarginContainer
class_name SafeUI
@export var apply_margin_left: bool
@export var apply_margin_right: bool
@export var apply_margin_top: bool
@export var apply_margin_bottom: bool
func set_safe_margins(scaling_factor: float):
var cutouts: Array[Rect2] = DisplayServer.get_display_cutouts()
@ -18,16 +24,21 @@ func set_safe_margins(scaling_factor: float):
else:
var screen: Vector2i = DisplayServer.screen_get_size()
var rect: Rect2i = DisplayServer.get_display_safe_area()
left = rect.position.x
right = screen.x - rect.end.x
top = rect.position.y
bottom = screen.y - rect.end.y
left = max(8, rect.position.x)
right = max(8, screen.x - rect.end.x)
top = max(8, rect.position.y)
bottom = max(8, screen.y - rect.end.y)
print("[SafeUI] Left margin is: ", left)
print("[SafeUI] Right margin is: ", right)
print("[SafeUI] Top margin is: ", top)
print("[SafeUI] Bottom margin is: ", bottom)
add_theme_constant_override("margin_left", left / scaling_factor)
add_theme_constant_override("margin_right", right / scaling_factor)
add_theme_constant_override("margin_top", top / scaling_factor)
add_theme_constant_override("margin_bottom", bottom / scaling_factor)
if apply_margin_left:
add_theme_constant_override("margin_left", left / scaling_factor)
if apply_margin_right:
add_theme_constant_override("margin_right", right / scaling_factor)
if apply_margin_top:
add_theme_constant_override("margin_top", top / scaling_factor)
if apply_margin_bottom:
add_theme_constant_override("margin_bottom", bottom / scaling_factor)

11
interface/safe_ui.tscn Normal file
View file

@ -0,0 +1,11 @@
[gd_scene load_steps=2 format=3 uid="uid://e4be5wkya7g0"]
[ext_resource type="Script" path="res://interface/safe_ui.gd" id="1_ceq6m"]
[node name="SafeUI" type="MarginContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_ceq6m")

16
main.gd
View file

@ -3,8 +3,10 @@ class_name Main
@onready var tree: SceneTree = get_tree()
@onready var game_ui: GameUI = $CustomUI/SafeUI/GameUI
@onready var shop_ui: ShopUI = $CustomUI/SafeUI/ShopUI
@onready var game_safe_ui: MarginContainer = $CustomUI/GameSafeUI
@onready var game_ui: GameUI = $CustomUI/GameSafeUI/GameUI
@onready var shop_safe_ui: MarginContainer = $CustomUI/ShopSafeUI
@onready var shop_ui: ShopUI = $CustomUI/ShopSafeUI/ShopUI
enum UIState {
@ -20,12 +22,14 @@ enum UIState {
match value:
UIState.GAME:
tree.paused = false
game_ui.show()
shop_ui.hide()
game_safe_ui.show()
shop_safe_ui.hide()
shop_safe_ui.process_mode = Node.PROCESS_MODE_DISABLED
UIState.SHOP:
tree.paused = true
game_ui.hide()
shop_ui.show()
game_safe_ui.hide()
shop_safe_ui.show()
shop_safe_ui.process_mode = Node.PROCESS_MODE_ALWAYS
UIState.SCORE:
pass

106
main.tscn
View file

@ -1,12 +1,17 @@
[gd_scene load_steps=8 format=3 uid="uid://dqm0h5h0baqcg"]
[gd_scene load_steps=10 format=3 uid="uid://dqm0h5h0baqcg"]
[ext_resource type="Script" path="res://main.gd" id="1_fqt34"]
[ext_resource type="Theme" uid="uid://ba5utvfhnxa5i" path="res://interface/interface_theme.tres" id="1_je7w1"]
[ext_resource type="PackedScene" uid="uid://c3rxmcwa5nqng" path="res://game/game.tscn" id="2_32lou"]
[ext_resource type="PackedScene" uid="uid://cklkdygv61bny" path="res://interface/shop_ui.tscn" id="2_qj86l"]
[ext_resource type="Script" path="res://interface/custom_ui.gd" id="3_xav0n"]
[ext_resource type="Script" path="res://interface/safe_ui.gd" id="4_nel0n"]
[ext_resource type="PackedScene" uid="uid://bo5unrhqpoyim" path="res://interface/game_ui.tscn" id="4_siim3"]
[ext_resource type="PackedScene" uid="uid://bpvx3nkkbluip" path="res://safe_ui.tscn" id="5_2uxda"]
[ext_resource type="Script" path="res://game_camera.gd" id="5_xxjtg"]
[sub_resource type="GDScript" id="GDScript_kyj65"]
script/source = "extends SubViewport
"
[node name="Main" type="Node"]
script = ExtResource("1_fqt34")
@ -20,65 +25,68 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_vertical = 8
mouse_filter = 1
theme = ExtResource("1_je7w1")
script = ExtResource("3_xav0n")
[node name="GameWorld" type="CenterContainer" parent="CustomUI"]
custom_minimum_size = Vector2(270, 480)
layout_mode = 1
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -135.0
offset_top = -480.0
offset_right = 135.0
grow_horizontal = 2
grow_vertical = 0
[node name="GameViewport" type="SubViewportContainer" parent="CustomUI/GameWorld"]
layout_mode = 2
[node name="Viewport" type="SubViewport" parent="CustomUI/GameWorld/GameViewport"]
disable_3d = true
handle_input_locally = false
size = Vector2i(270, 480)
render_target_update_mode = 4
[node name="Game" parent="CustomUI/GameWorld/GameViewport/Viewport" instance=ExtResource("2_32lou")]
[node name="Camera" type="Camera2D" parent="CustomUI/GameWorld/GameViewport/Viewport"]
anchor_mode = 0
[node name="SafeUI" type="MarginContainer" parent="CustomUI"]
[node name="GameViewport" type="SubViewportContainer" parent="CustomUI"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("4_nel0n")
mouse_default_cursor_shape = 5
stretch = true
[node name="GameUI" parent="CustomUI/SafeUI" instance=ExtResource("4_siim3")]
[node name="Viewport" type="SubViewport" parent="CustomUI/GameViewport"]
disable_3d = true
handle_input_locally = false
physics_object_picking = true
size = Vector2i(270, 480)
render_target_update_mode = 4
script = SubResource("GDScript_kyj65")
[node name="Game" parent="CustomUI/GameViewport/Viewport" instance=ExtResource("2_32lou")]
[node name="GameCamera" type="Camera2D" parent="CustomUI/GameViewport/Viewport"]
position = Vector2(135, 480)
script = ExtResource("5_xxjtg")
[node name="GameSafeUI" parent="CustomUI" instance=ExtResource("5_2uxda")]
layout_mode = 1
anchors_preset = 10
anchor_bottom = 0.0
grow_vertical = 1
apply_margin_left = true
apply_margin_right = true
apply_margin_top = true
[node name="GameUI" parent="CustomUI/GameSafeUI" instance=ExtResource("4_siim3")]
layout_mode = 2
[node name="ShopUI" parent="CustomUI/SafeUI" instance=ExtResource("2_qj86l")]
process_mode = 3
[node name="ShopSafeUI" parent="CustomUI" instance=ExtResource("5_2uxda")]
process_mode = 4
visible = false
layout_mode = 1
apply_margin_left = true
apply_margin_right = true
apply_margin_top = true
apply_margin_bottom = true
[node name="ShopUI" parent="CustomUI/ShopSafeUI" instance=ExtResource("2_qj86l")]
layout_mode = 2
[connection signal="score_changed" from="CustomUI/GameWorld/GameViewport/Viewport/Game" to="CustomUI/SafeUI/GameUI" method="_on_game_score_changed"]
[connection signal="score_changed" from="CustomUI/GameWorld/GameViewport/Viewport/Game" to="CustomUI/SafeUI/ShopUI" method="_on_game_score_changed"]
[connection signal="score_button_pressed" from="CustomUI/SafeUI/GameUI" to="." method="_on_game_ui_score_button_pressed"]
[connection signal="shop_button_pressed" from="CustomUI/SafeUI/GameUI" to="." method="_on_game_ui_shop_button_pressed"]
[connection signal="spawn_button_pressed" from="CustomUI/SafeUI/GameUI" to="CustomUI/GameWorld/GameViewport/Viewport/Game" method="trigger_spawn"]
[connection signal="back_button_pressed" from="CustomUI/SafeUI/ShopUI" to="." method="_on_shop_ui_back_button_pressed"]
[connection signal="delete_button_pressed" from="CustomUI/SafeUI/ShopUI" to="." method="_on_shop_ui_delete_button_pressed"]
[connection signal="purchase_begin" from="CustomUI/SafeUI/ShopUI" to="." method="_on_shop_ui_purchase_begin"]
[connection signal="purchase_begin" from="CustomUI/SafeUI/ShopUI" to="CustomUI/GameWorld/GameViewport/Viewport/Game" method="_on_purchase_begin"]
[connection signal="purchase_cancel" from="CustomUI/SafeUI/ShopUI" to="CustomUI/GameWorld/GameViewport/Viewport/Game" method="_on_purchase_cancel"]
[connection signal="purchase_success" from="CustomUI/SafeUI/ShopUI" to="CustomUI/GameWorld/GameViewport/Viewport/Game" method="_on_purchase_success"]
[connection signal="score_button_pressed" from="CustomUI/SafeUI/ShopUI" to="." method="_on_shop_ui_score_button_pressed"]
[connection signal="upgraded_auto_spawn" from="CustomUI/SafeUI/ShopUI" to="CustomUI/GameWorld/GameViewport/Viewport/Game" method="_on_upgraded_auto_spawn"]
[connection signal="upgraded_manual_spawn" from="CustomUI/SafeUI/ShopUI" to="CustomUI/GameWorld/GameViewport/Viewport/Game" method="_on_upgraded_manual_spawn"]
[connection signal="score_changed" from="CustomUI/GameViewport/Viewport/Game" to="CustomUI/GameSafeUI/GameUI" method="_on_game_score_changed"]
[connection signal="score_button_pressed" from="CustomUI/GameSafeUI/GameUI" to="." method="_on_game_ui_score_button_pressed"]
[connection signal="shop_button_pressed" from="CustomUI/GameSafeUI/GameUI" to="." method="_on_game_ui_shop_button_pressed"]
[connection signal="spawn_button_pressed" from="CustomUI/GameSafeUI/GameUI" to="CustomUI/GameViewport/Viewport/Game" method="trigger_spawn"]
[connection signal="back_button_pressed" from="CustomUI/ShopSafeUI/ShopUI" to="." method="_on_shop_ui_back_button_pressed"]
[connection signal="delete_button_pressed" from="CustomUI/ShopSafeUI/ShopUI" to="." method="_on_shop_ui_delete_button_pressed"]
[connection signal="purchase_begin" from="CustomUI/ShopSafeUI/ShopUI" to="." method="_on_shop_ui_purchase_begin"]
[connection signal="purchase_begin" from="CustomUI/ShopSafeUI/ShopUI" to="CustomUI/GameViewport/Viewport/Game" method="_on_purchase_begin"]
[connection signal="purchase_cancel" from="CustomUI/ShopSafeUI/ShopUI" to="CustomUI/GameViewport/Viewport/Game" method="_on_purchase_cancel"]
[connection signal="purchase_success" from="CustomUI/ShopSafeUI/ShopUI" to="CustomUI/GameViewport/Viewport/Game" method="_on_purchase_success"]
[connection signal="score_button_pressed" from="CustomUI/ShopSafeUI/ShopUI" to="." method="_on_shop_ui_score_button_pressed"]
[connection signal="upgraded_auto_spawn" from="CustomUI/ShopSafeUI/ShopUI" to="CustomUI/GameViewport/Viewport/Game" method="_on_upgraded_auto_spawn"]
[connection signal="upgraded_manual_spawn" from="CustomUI/ShopSafeUI/ShopUI" to="CustomUI/GameViewport/Viewport/Game" method="_on_upgraded_manual_spawn"]

View file

@ -30,6 +30,7 @@ window/handheld/orientation=1
2d_physics/layer_1="Default"
2d_physics/layer_2="Bottle"
2d_physics/layer_3="Entities"
2d_physics/layer_4="Ghost"
[physics]

11
safe_ui.tscn Normal file
View file

@ -0,0 +1,11 @@
[gd_scene load_steps=2 format=3 uid="uid://bpvx3nkkbluip"]
[ext_resource type="Script" path="res://interface/safe_ui.gd" id="1_y2ofp"]
[node name="SafeUI" type="MarginContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_y2ofp")