Skip to content

Commit

Permalink
Found and implemented viewport resize script
Browse files Browse the repository at this point in the history
  • Loading branch information
HoratioWildebeest committed Nov 14, 2018
1 parent c2924a8 commit b3906e0
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Client/Scenes/build.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions Client/Scripts/Singletons/viewport.gd
Original file line number Diff line number Diff line change
@@ -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))
25 changes: 25 additions & 0 deletions Client/Scripts/Singletons/viewport2.gd
Original file line number Diff line number Diff line change
@@ -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))
1 change: 0 additions & 1 deletion Client/Scripts/battle_camera.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export(float) var min_distance = 600
export(float) var max_distance = 2000

func _ready():
print(_player)
pass

func _process(delta):
Expand Down
2 changes: 2 additions & 0 deletions Client/Scripts/build.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 7 additions & 3 deletions Client/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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]
Expand Down

0 comments on commit b3906e0

Please sign in to comment.