From b3906e0e977786e38b6737c68f2782302f9a551a Mon Sep 17 00:00:00 2001 From: Alex Zacharias <43507078+Zinjanjie@users.noreply.github.com> Date: Tue, 13 Nov 2018 22:06:31 -0600 Subject: [PATCH] Found and implemented viewport resize script https://github.com/godotengine/godot/issues/6506 --- Client/Scenes/build.tscn | 2 +- Client/Scripts/{ => Singletons}/head.gd | 0 Client/Scripts/Singletons/viewport.gd | 28 +++++++++++++++++++++++++ Client/Scripts/Singletons/viewport2.gd | 25 ++++++++++++++++++++++ Client/Scripts/battle_camera.gd | 1 - Client/Scripts/build.gd | 2 ++ Client/project.godot | 10 ++++++--- 7 files changed, 63 insertions(+), 5 deletions(-) rename Client/Scripts/{ => Singletons}/head.gd (100%) create mode 100644 Client/Scripts/Singletons/viewport.gd create mode 100644 Client/Scripts/Singletons/viewport2.gd diff --git a/Client/Scenes/build.tscn b/Client/Scenes/build.tscn index 5e6a124a..aaeb1586 100644 --- a/Client/Scenes/build.tscn +++ b/Client/Scenes/build.tscn @@ -11,7 +11,7 @@ [ext_resource path="res://assets/sword.png" type="Texture" id=9] [ext_resource path="res://themes/bot_stats.theme" type="Theme" id=10] -[node name="build" type="Node" index="0"] +[node name="build" type="Node"] script = ExtResource( 1 ) diff --git a/Client/Scripts/head.gd b/Client/Scripts/Singletons/head.gd similarity index 100% rename from Client/Scripts/head.gd rename to Client/Scripts/Singletons/head.gd diff --git a/Client/Scripts/Singletons/viewport.gd b/Client/Scripts/Singletons/viewport.gd new file mode 100644 index 00000000..482a49c4 --- /dev/null +++ b/Client/Scripts/Singletons/viewport.gd @@ -0,0 +1,28 @@ +# Script from chanon and sysharm +# https://github.com/godotengine/godot/issues/6506 + +extends Node + +# don't forget to use stretch mode 'viewport' and aspect 'ignore' +onready var viewport = get_viewport() + +func _ready(): + get_tree().connect("screen_resized", self, "_screen_resized") + +func _screen_resized(): + var window_size = OS.get_window_size() + + # see how big the window is compared to the viewport size + # floor it so we only get round numbers (0, 1, 2, 3 ...) + var scale_x = floor(window_size.x / viewport.size.x) + var scale_y = floor(window_size.y / viewport.size.y) + + # use the smaller scale with 1x minimum scale + var scale = max(1, min(scale_x, scale_y)) + + # find the coordinate we will use to center the viewport inside the window + var diff = window_size - (viewport.size * scale) + var diffhalf = (diff * 0.5).floor() + + # attach the viewport to the rect we calculated + viewport.set_attach_to_screen_rect(Rect2(diffhalf, viewport.size * scale)) \ No newline at end of file diff --git a/Client/Scripts/Singletons/viewport2.gd b/Client/Scripts/Singletons/viewport2.gd new file mode 100644 index 00000000..6115b2ce --- /dev/null +++ b/Client/Scripts/Singletons/viewport2.gd @@ -0,0 +1,25 @@ +# Script from chanon and sysharm +# https://github.com/godotengine/godot/issues/6506 + +extends Node + +# don't forget to use stretch mode 'viewport' and aspect 'ignore' +onready var viewport = get_viewport() + +func _ready(): + get_tree().connect("screen_resized", self, "_screen_resized") + +func _screen_resized(): + var window_size = OS.get_window_size() + + var scale_x = window_size.x / viewport.size.x + var scale_y = window_size.y / viewport.size.y + + var scale = min(scale_x, scale_y) + + # find the coordinate we will use to center the viewport inside the window + var diff = window_size - (viewport.size * scale) + var diffhalf = (diff * 0.5) + + # attach the viewport to the rect we calculated + viewport.set_attach_to_screen_rect(Rect2(diffhalf, viewport.size * scale)) \ No newline at end of file diff --git a/Client/Scripts/battle_camera.gd b/Client/Scripts/battle_camera.gd index 6af52b0a..79bbbc02 100644 --- a/Client/Scripts/battle_camera.gd +++ b/Client/Scripts/battle_camera.gd @@ -10,7 +10,6 @@ export(float) var min_distance = 600 export(float) var max_distance = 2000 func _ready(): - print(_player) pass func _process(delta): diff --git a/Client/Scripts/build.gd b/Client/Scripts/build.gd index c5479e11..342e0354 100644 --- a/Client/Scripts/build.gd +++ b/Client/Scripts/build.gd @@ -47,6 +47,8 @@ func _ready(): var size = OS.get_window_size() _background.scale = Vector2(size.x / head.NORMAL_WIDTH, size.y / head.NORMAL_HEIGHT) + _confirm_save.get_cancel().text = "No" + for stat in stats: _stats.add_item(stat, null, false) diff --git a/Client/project.godot b/Client/project.godot index f7b714c0..e06ece17 100644 --- a/Client/project.godot +++ b/Client/project.godot @@ -16,7 +16,13 @@ config/icon="res://icon.png" [autoload] -head="*res://Scripts/head.gd" +head="*res://Scripts/Singletons/head.gd" +viewport="res://Scripts/Singletons/viewport.gd" +viewport2="*res://Scripts/Singletons/viewport2.gd" + +[display] + +window/stretch/mode="viewport" [input] @@ -43,8 +49,6 @@ secondary_attack=[ Object(InputEventMouseButton,"resource_local_to_scene":false, shutdown=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"unicode":0,"echo":false,"script":null) ] toggle_fullscreen=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777254,"unicode":0,"echo":false,"script":null) -] -ability=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) ] [rendering]