From ca74fb82ea53d00ff5abb5a3a2b908681f74bd21 Mon Sep 17 00:00:00 2001 From: Bojidar Marinov <bojidar.marinov.bg@gmail.com> Date: Thu, 5 May 2016 21:59:10 +0300 Subject: [PATCH 1/2] Fix the way screen resizing works, closes #79, maybe #80 too --- engine.cfg | 2 +- main/gui.gd | 2 ++ main/level_holder.gd | 2 ++ main/main.tscn | 3 +- menu/menu.gd | 40 +++++++++++++++++++------- menu/menu.tscn | 74 +++++++++++++++++++++++++----------------------- shared/screen_manager.gd | 34 +++++++++++++++------- 7 files changed, 98 insertions(+), 59 deletions(-) diff --git a/engine.cfg b/engine.cfg index ff67194..a91eb1d 100644 --- a/engine.cfg +++ b/engine.cfg @@ -20,7 +20,7 @@ version_build="" config="res://shared/config.gd" SaveManager="*res://shared/save_manager.gd" -ScreenManager="res://shared/screen_manager.gd" +ScreenManager="*res://shared/screen_manager.gd" ScenesManager="*res://shared/scenes_manager.gd" SettingsManager="*res://shared/settings_manager.gd" FileManager="*res://shared/file_manager.gd" diff --git a/main/gui.gd b/main/gui.gd index e060af9..44d5d4b 100644 --- a/main/gui.gd +++ b/main/gui.gd @@ -12,6 +12,8 @@ onready var level_holder = get_node("../level_holder") onready var player = get_node("../player_holder/player") func _ready(): + ScreenManager.set_minimum_size(Vector2(0, 0)) + var nodes_left = get_node("popup/popup_node/body/container").get_children() # Removes the focus from the buttons diff --git a/main/level_holder.gd b/main/level_holder.gd index 849ee86..36a9bd1 100644 --- a/main/level_holder.gd +++ b/main/level_holder.gd @@ -88,6 +88,8 @@ func load_level(pack, level): # Load level from pack func window_resize(): var new_size = get_node("/root").get_size_override() + if !level_node: + return var tilemap = level_node.get_node("tilemap") for i in range(ceil(new_size.x/2/64)): tilemap.set_cell(tile_map_acid_x_start - i, tile_map_acid_y, 2) diff --git a/main/main.tscn b/main/main.tscn index ef101a1..69001b5 100644 --- a/main/main.tscn +++ b/main/main.tscn @@ -47,7 +47,7 @@ size_flags/vertical = 2 margin/left = 8.0 margin/top = 8.0 margin/right = 8.0 -margin/bottom = 68.0 +margin/bottom = 76.0 alignment = 0 __meta__ = { "_editor_collapsed":true } @@ -799,6 +799,7 @@ transform/pos = Vector2( 32, 32 ) [node name="player" parent="player_holder" instance=ExtResource( 16 )] transform/pos = Vector2( 228.814, 197.081 ) +collision/margin = 0.08 [node name="sample_player" type="SamplePlayer" parent="."] diff --git a/menu/menu.gd b/menu/menu.gd index 08ccc8c..efb2239 100644 --- a/menu/menu.gd +++ b/menu/menu.gd @@ -25,9 +25,18 @@ func _ready(): if node.has_node("back"): node.get_node("back").connect("pressed", self, "go_to_target", ["start"]) + # Screen size + var minimum_size = get_minimum_size() + for child in get_children(): + if child extends Control: + var child_minimum_size = child.get_minimum_size() + minimum_size.x = max(minimum_size.x, child_minimum_size.x) + minimum_size.y = max(minimum_size.y, child_minimum_size.y) + ScreenManager.set_minimum_size(minimum_size) + # Splash fadeout if ScenesManager.is_first_load: - get_node("initial_splash/animation_player").play("SplashFade") + get_node("animation_player").play("SplashFade") # Prepare to move thing when the aspect ratio changes connect("resized", self, "reposition_screens") @@ -38,7 +47,6 @@ func reposition_screens(): if size == old_size: return - old_size = size levels.set_margin(MARGIN_LEFT, size.x) @@ -50,15 +58,21 @@ func reposition_screens(): credits.set_margin(MARGIN_TOP, size.y) credits.set_margin(MARGIN_BOTTOM, -size.y) - var scale = size.x/1024 - if scale > 1: + var initial_size = ScreenManager.get_original_size() + var scale_vector = size / initial_size + var scale = max(scale_vector.x, scale_vector.y) + + if scale > 1: get_node("background_layer").set_scale(Vector2(scale,scale)) - get_node("background_layer").set_offset(Vector2(0,-(scale*768-768))) - get_node("initial_splash").set_scale(Vector2(scale,scale)) - get_node("initial_splash").set_offset(Vector2(0,-(scale*768-768)/2)) - go_to_target(current_screen) + get_node("initial_splash").set_offset((size - initial_size) * Vector2(0.5, 0)) + if scale_vector.y / scale_vector.x < 1: + get_node("background_layer").set_offset(Vector2(0, (1 - scale_vector.x / scale_vector.y) * initial_size.y)) + else: + get_node("background_layer").set_offset(Vector2(0, 0)) + tween.remove_all() + go_to_target(current_screen, false) -func go_to_target(var screen = "start"): +func go_to_target(screen = "start", animate = true): current_screen = screen var target_coordinates = Vector2(0, 0) # By default, use the 0, 0 coordinates @@ -70,8 +84,12 @@ func go_to_target(var screen = "start"): var time = distance/screen_move_speed if time > 0: - tween.interpolate_property(self, "rect/pos", current_coordinates, -target_coordinates, time, Tween.TRANS_EXPO, Tween.EASE_OUT, 0) - tween.start() + tween.remove_all() + if animate: + tween.interpolate_property(self, "rect/pos", current_coordinates, -target_coordinates, time, Tween.TRANS_EXPO, Tween.EASE_OUT, 0) + tween.start() + else: + set("rect/pos", -target_coordinates) func quit(): get_tree().quit() # Exit the game diff --git a/menu/menu.tscn b/menu/menu.tscn index f60b68d..878223e 100644 --- a/menu/menu.tscn +++ b/menu/menu.tscn @@ -28,17 +28,6 @@ tracks/0/keys = { "cont":true, "times":FloatArray( 0, 8 ), "transitions":FloatAr [sub_resource type="Animation" id=2] -resource/name = "SplashFade" -length = 2.0 -loop = false -step = 0.1 -tracks/0/type = "value" -tracks/0/path = NodePath("image:visibility/opacity") -tracks/0/interp = 1 -tracks/0/keys = { "cont":true, "times":FloatArray( 0, 1, 2 ), "transitions":FloatArray( 1, 1, 1 ), "values":[ 1.0, 1.0, 0.0 ] } - -[sub_resource type="Animation" id=3] - length = 1.0 loop = true step = 0.1 @@ -51,6 +40,20 @@ tracks/1/path = NodePath(".:transform/scale") tracks/1/interp = 1 tracks/1/keys = { "cont":true, "times":FloatArray( 0, 0.5 ), "transitions":FloatArray( 1, 1 ), "values":[ Vector2( 1, 1 ), Vector2( 1.2, 1.2 ) ] } +[sub_resource type="Animation" id=3] + +length = 2.0 +loop = false +step = 0.1 +tracks/0/type = "value" +tracks/0/path = NodePath("initial_splash/image:visibility/opacity") +tracks/0/interp = 1 +tracks/0/keys = { "cont":true, "times":FloatArray( 0, 1, 2 ), "transitions":FloatArray( 1, 1, 1 ), "values":[ 1.0, 1.0, 0.0 ] } +tracks/1/type = "value" +tracks/1/path = NodePath("background_layer/background:visibility/opacity") +tracks/1/interp = 1 +tracks/1/keys = { "cont":true, "times":FloatArray( 0, 2 ), "transitions":FloatArray( 1, 1 ), "values":[ 0.0, 1.0 ] } + [node name="menu" type="Control"] anchor/right = 1 @@ -117,17 +120,6 @@ margin/bottom = 768.0 texture = ExtResource( 4 ) expand = true -[node name="animation_player" type="AnimationPlayer" parent="initial_splash"] - -playback/process_mode = 1 -playback/default_blend_time = 0.0 -root/root = NodePath("..") -anims/SplashFade = SubResource( 2 ) -playback/active = true -playback/speed = 3.0 -blend_times = [ ] -autoplay = "" - [node name="main" type="VBoxContainer" parent="."] anchor/right = 1 @@ -139,7 +131,7 @@ size_flags/horizontal = 3 size_flags/vertical = 3 margin/left = 0.0 margin/top = 16.0 -margin/right = 0.0 +margin/right = -4.0 margin/bottom = 0.0 custom_constants/separation = 20 alignment = 0 @@ -151,17 +143,18 @@ focus/stop_mouse = true size_flags/horizontal = 1 size_flags/vertical = 1 size_flags/stretch_ratio = 3.0 -margin/left = 198.0 +margin/left = 200.0 margin/top = 26.0 -margin/right = 825.0 +margin/right = 827.0 margin/bottom = 179.0 texture = ExtResource( 5 ) __meta__ = { "_editor_collapsed":true } [node name="splash" type="Node2D" parent="main/logo"] -transform/pos = Vector2( 618.213, 157.035 ) +transform/pos = Vector2( 602.573, 151.655 ) transform/rot = 15.0502 +transform/scale = Vector2( 1, 1 ) z/z = 4 script/script = ExtResource( 6 ) __meta__ = { "_editor_collapsed":true } @@ -194,7 +187,7 @@ max_lines_visible = -1 playback/process_mode = 1 playback/default_blend_time = 0.0 root/root = NodePath("..") -anims/loop = SubResource( 3 ) +anims/loop = SubResource( 2 ) playback/active = true playback/speed = 0.2 blend_times = [ ] @@ -220,9 +213,9 @@ focus/stop_mouse = false size_flags/horizontal = 1 size_flags/vertical = 1 size_flags/stretch_ratio = 3.0 -margin/left = 312.0 +margin/left = 314.0 margin/top = 226.0 -margin/right = 712.0 +margin/right = 714.0 margin/bottom = 526.0 custom_constants/vseparation = 10 custom_constants/hseparation = 10 @@ -294,7 +287,7 @@ size_flags/vertical = 1 size_flags/stretch_ratio = 2.0 margin/left = 0.0 margin/top = 564.0 -margin/right = 1024.0 +margin/right = 1028.0 margin/bottom = 664.0 custom_constants/separation = 40 alignment = 1 @@ -307,9 +300,9 @@ focus/ignore_mouse = true focus/stop_mouse = true size_flags/horizontal = 2 size_flags/vertical = 1 -margin/left = 237.0 +margin/left = 239.0 margin/top = 0.0 -margin/right = 514.0 +margin/right = 516.0 margin/bottom = 100.0 texture = ExtResource( 7 ) expand = true @@ -321,9 +314,9 @@ focus/ignore_mouse = true focus/stop_mouse = true size_flags/horizontal = 2 size_flags/vertical = 2 -margin/left = 554.0 +margin/left = 556.0 margin/top = 0.0 -margin/right = 787.0 +margin/right = 789.0 margin/bottom = 100.0 texture = ExtResource( 8 ) expand = true @@ -336,7 +329,7 @@ focus/stop_mouse = true size_flags/horizontal = 2 margin/left = 0.0 margin/top = 703.0 -margin/right = 1024.0 +margin/right = 1028.0 margin/bottom = 751.0 custom_colors/font_color = Color( 0, 0, 0, 1 ) text = "© 2015-2016 KOBUGE Games - kobuge-games.github.io/minilens" @@ -711,4 +704,15 @@ playback/active = false playback/repeat = false playback/speed = 1.0 +[node name="animation_player" type="AnimationPlayer" parent="."] + +playback/process_mode = 1 +playback/default_blend_time = 0.0 +root/root = NodePath("..") +anims/SplashFade = SubResource( 3 ) +playback/active = true +playback/speed = 3.0 +blend_times = [ ] +autoplay = "" + diff --git a/shared/screen_manager.gd b/shared/screen_manager.gd index ca7ee4f..c5f4298 100644 --- a/shared/screen_manager.gd +++ b/shared/screen_manager.gd @@ -4,24 +4,36 @@ extends Node onready var viewport = get_viewport() onready var initial_size = viewport.get_rect().size +var minimum_size = Vector2(0, 0) + func _ready(): + if Globals.has("display/width"): + initial_size.x = Globals.get("display/width") + if Globals.has("display/height"): + initial_size.y = Globals.get("display/height") + viewport.connect("size_changed", self, "window_resize") window_resize() +func set_minimum_size(s): + if minimum_size != s: + minimum_size = s + window_resize() + +func get_original_size(): + return initial_size + func window_resize(): var current_size = OS.get_window_size() - var changed = false - if current_size.x < 100: - current_size.x = 100 - changed = true - if current_size.y < 100: - current_size.y = 100 - changed = true - - if changed: - OS.set_window_size(current_size) - var scale_factor = initial_size.y/current_size.y var new_size = Vector2(current_size.x*scale_factor, initial_size.y) + + if new_size.y < minimum_size.y: + scale_factor = minimum_size.y/new_size.y + new_size = Vector2(new_size.x*scale_factor, minimum_size.y) + if new_size.x < minimum_size.x: + scale_factor = minimum_size.x/new_size.x + new_size = Vector2(minimum_size.x, new_size.y*scale_factor) + viewport.set_size_override(true, new_size) -- 2.8.2