Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert project to Godot 4 #9

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ scn/
override.cfg

# Godot-specific ignores
.import/
.godot/
export.cfg
export_presets.cfg

Expand Down
16 changes: 8 additions & 8 deletions BootScreen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func _ready():
Core.game_dir = config.sections["paths"]["sc4_files"]
else:
$dialog.popup_centered(get_viewport_rect().size / 2)
yield($dialog, "popup_hide")
await $dialog.popup_hide
config.sections["paths"] = {}
config.sections["paths"]["sc4_files"] = Core.game_dir
config.save_file()
Expand All @@ -36,7 +36,7 @@ func _ready():
var dir_complete = true
while not dir_complete:
if dir.open(Core.game_dir) == OK:
dir.list_dir_begin()
dir.list_dir_begin() # TODOGODOT4 fill missing arguments https://github.com/godotengine/godot/pull/40547
var files = []
var file_name = dir.get_next()
while file_name != "":
Expand All @@ -52,7 +52,7 @@ func _ready():
var subdir = Directory.new()
print(Core.game_dir+folder_dir)
if subdir.open(Core.game_dir+folder_dir) == OK:
subdir.list_dir_begin()
subdir.list_dir_begin() # TODOGODOT4 fill missing arguments https://github.com/godotengine/godot/pull/40547
var subfile_name = subdir.get_next()
var found = false
while subfile_name != "":
Expand All @@ -75,18 +75,18 @@ func _ready():
if not dir_complete:
$dialog.window_title = "dir was incomplete, select the SC4 installation folder"
$dialog.popup_centered(get_viewport_rect().size / 2)
yield($dialog, "popup_hide")
await $dialog.popup_hide
print("todo: store path in cfg.ini")
config.sections["paths"] = {}
config.sections["paths"]["sc4_files"] = Core.game_dir
config.save_file()
$dialog.deselect_items()
$dialog.deselect_all()
$LoadProgress.value = 0
loading_thread = Thread.new()
Logger.info("Loading OpenSC4...")
Logger.info("Using %s as game data folder" % Core.game_dir)
# Would be nice to start multiple threads here not only one
var err = loading_thread.start(self, 'load_DATs')
var err = loading_thread.start(Callable(self,'load_DATs'))
if err != OK:
Logger.error("Error starting thread: " % err)
return
Expand Down Expand Up @@ -117,12 +117,12 @@ func _on_dialog_confirmed():

func _on_DATExplorerButton_pressed():
print("here")
var err = get_tree().change_scene("res://DATExplorer/DATExplorer.tscn")
var err = get_tree().change_scene_to_file("res://DATExplorer/DATExplorer.tscn")
if err != OK:
Logger.error("Error: %s" % err)

func _on_GameButton_pressed():
var err = get_tree().change_scene("res://Region.tscn")
var err = get_tree().change_scene_to_file("res://Region.tscn")
if err != OK:
Logger.error("Error: %s" % err)

Expand Down
87 changes: 40 additions & 47 deletions BootScreen.tscn
Original file line number Diff line number Diff line change
@@ -1,96 +1,89 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=3 format=3 uid="uid://d0ediey6qa77f"]

[ext_resource path="res://BootScreen.gd" type="Script" id=1]
[ext_resource path="res://splash.png" type="Texture" id=2]
[ext_resource type="Script" path="res://BootScreen.gd" id="1"]
[ext_resource type="Texture2D" uid="uid://swmrfycjhv5j" path="res://splash.png" id="2"]

[node name="BootScreen" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
script = ExtResource("1")

[node name="dialog" type="FileDialog" parent="."]
margin_left = 228.0
margin_top = 87.0
margin_right = 1045.0
margin_bottom = 649.0
rect_min_size = Vector2( 150, 52.5 )
popup_exclusive = true
window_title = "set the SimCity 4 directory"
mode_overrides_title = false
mode = 2
mode_overrides_title = false
access = 2
show_hidden_files = true

[node name="LoadProgress" type="ProgressBar" parent="."]
layout_mode = 0
anchor_left = 0.25
anchor_top = 0.514
anchor_right = 0.75
anchor_bottom = 0.55
margin_left = -10.0
margin_top = 219.92
margin_right = -10.0
margin_bottom = 219.92
offset_left = -10.0
offset_top = 219.92
offset_right = -10.0
offset_bottom = 219.92

[node name="Label" type="Label" parent="."]
margin_left = 310.0
margin_top = 568.0
margin_right = 433.0
margin_bottom = 582.0
layout_mode = 0
offset_left = 310.0
offset_top = 568.0
offset_right = 433.0
offset_bottom = 582.0
text = "Loading OpenSC4..."

[node name="CurrentFileLabel" type="Label" parent="."]
margin_left = 310.0
margin_top = 631.0
margin_right = 350.0
margin_bottom = 645.0
layout_mode = 0
offset_left = 310.0
offset_top = 631.0
offset_right = 350.0
offset_bottom = 645.0

[node name="background" type="Sprite" parent="."]
position = Vector2( 636, 366 )
scale = Vector2( 0.6625, 0.675 )
[node name="background" type="Sprite2D" parent="."]
z_index = -1
texture = ExtResource( 2 )
position = Vector2(636, 366)
scale = Vector2(0.6625, 0.675)
texture = ExtResource("2")

[node name="NextScene" type="Panel" parent="."]
visible = false
layout_mode = 0
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -381.0
margin_top = -139.0
margin_right = 381.0
margin_bottom = 139.0
offset_left = -381.0
offset_top = -139.0
offset_right = 381.0
offset_bottom = 139.0

[node name="VBoxContainer" type="VBoxContainer" parent="NextScene"]
layout_mode = 0
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -122.0
margin_top = -19.0
margin_right = -122.0
margin_bottom = -19.0
offset_left = -122.0
offset_top = -19.0
offset_right = -122.0
offset_bottom = -19.0

[node name="Label" type="Label" parent="NextScene/VBoxContainer"]
margin_right = 244.0
margin_bottom = 14.0
layout_mode = 2
text = "Game files loaded"
align = 1

[node name="HBoxContainer" type="HBoxContainer" parent="NextScene/VBoxContainer"]
margin_top = 18.0
margin_right = 244.0
margin_bottom = 38.0
layout_mode = 2

[node name="GameButton" type="Button" parent="NextScene/VBoxContainer/HBoxContainer"]
margin_right = 96.0
margin_bottom = 20.0
layout_mode = 2
text = "Launch game"

[node name="DATExplorerButton" type="Button" parent="NextScene/VBoxContainer/HBoxContainer"]
margin_left = 100.0
margin_right = 244.0
margin_bottom = 20.0
layout_mode = 2
text = "Launch DAT explorer"

[connection signal="confirmed" from="dialog" to="." method="_on_dialog_confirmed"]
Expand Down
6 changes: 4 additions & 2 deletions CameraAnchor.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends KinematicBody2D
extends CharacterBody2D

var velocity = Vector2(0, 0)
var viewport = 0
Expand Down Expand Up @@ -63,4 +63,6 @@ func right_click_movement():

func _process(delta):
right_click_movement()
self.move_and_slide(self.velocity * delta)
self.set_velocity(self.velocity * delta)
self.move_and_slide()
self.velocity
70 changes: 36 additions & 34 deletions CityView/CityScene/CameraAnchor3D.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extends KinematicBody
extends CharacterBody3D

var zoom = 1
var zoom_list = [292, 146, 73, 32, 16, 8]
var elevations = [60, 55, 50, 45, 45, 45]
var AZIMUTH = deg2rad(67.5)
var AZIMUTH = deg_to_rad(67.5)
var rotated = 2
var boot = true
var velocity = Vector3(0, 0, 0)
Expand All @@ -12,7 +12,7 @@ var hold_r = []
func _ready():
self.transform.origin = Vector3(self.transform.origin.x, get_parent().WATER_HEIGHT, self.transform.origin.z)
_set_view()
$Camera.set_znear(-200.0)
$Camera3D.set_near(-200.0)
pass

func _input(event):
Expand All @@ -24,7 +24,7 @@ func _input(event):
var camera_left = Vector3(self.transform.basis.x.x, 0, self.transform.basis.x.z)

# Should move one screen width every 5 seconds
var move_vel = $Camera.size
var move_vel = $Camera3D.size
if event is InputEventMouseMotion:
if event.position.x < margin_w:
move -= camera_left
Expand All @@ -37,48 +37,50 @@ func _input(event):
move += camera_forward

self.velocity = move.normalized() * move_vel
#print($Camera.project_position(Vector2(0.5, 0.5), 0.5))
#print($Camera3D.project_position(Vector2(0.5, 0.5), 0.5))
elif event is InputEventMouseButton:
if event.is_pressed():
if event.button_index == BUTTON_WHEEL_UP:
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
self.zoom += 1
if self.zoom > 6:
self.zoom = 6
$Camera.size = zoom_list[self.zoom-1]
$Camera3D.size = zoom_list[self.zoom-1]
_set_view()
elif event.button_index == BUTTON_RIGHT:
elif event.button_index == MOUSE_BUTTON_RIGHT:
if len(hold_r) == 0:
hold_r = [event.position.x, event.position.y]
elif event.button_index == BUTTON_WHEEL_DOWN:
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
self.zoom -= 1
if self.zoom < 1:
self.zoom = 1
$Camera.size = zoom_list[self.zoom-1]
$Camera3D.size = zoom_list[self.zoom-1]
_set_view()
if not event.is_pressed():
if event.button_index == BUTTON_RIGHT:
if event.button_index == MOUSE_BUTTON_RIGHT:
hold_r = []
elif event is InputEventKey:
if event.pressed and event.scancode == KEY_PAGEUP:
if event.pressed and event.keycode == KEY_PAGEUP:
rotated = (rotated + 1)%4
var rot = round(((rotated*(PI/2)) + get_node("../Spatial").rotation.y) / (PI/2))*(PI/2)
var rot_trans = get_node("../Spatial").transform.rotated(Vector3(0,1,0), rot)
get_node("../Spatial").set_transform(rot_trans)
var rot = round(((rotated*(PI/2)) + get_node("../Node3D").rotation.y) / (PI/2))*(PI/2)
var rot_trans = get_node("../Node3D").transform.rotated(Vector3(0,1,0), rot)
get_node("../Node3D").set_transform(rot_trans)
var old = self.transform.origin
self.transform.origin = Vector3(-old.z, old.y, old.x)
elif event.pressed and event.scancode == KEY_PAGEDOWN:
elif event.pressed and event.keycode == KEY_PAGEDOWN:
rotated = ((rotated-1)+4)%4
var rot = round(((rotated*(PI/2)) + get_node("../Spatial").rotation.y) / (PI/2))*(PI/2)
var rot_trans = get_node("../Spatial").transform.rotated(Vector3(0,1,0), rot)
get_node("../Spatial").set_transform(rot_trans)
var rot = round(((rotated*(PI/2)) + get_node("../Node3D").rotation.y) / (PI/2))*(PI/2)
var rot_trans = get_node("../Node3D").transform.rotated(Vector3(0,1,0), rot)
get_node("../Node3D").set_transform(rot_trans)
var old = self.transform.origin
self.transform.origin = Vector3(old.z, old.y, -old.x)
func _physics_process(_delta):
self.move_and_slide(self.velocity)
self.set_velocity(self.velocity)
self.move_and_slide()
self.velocity

func _set_view():
# Elevation angle, Azimuth is a class var since it doesn't change
var El = deg2rad(elevations[zoom-1])
var El = deg_to_rad(elevations[zoom-1])

# exposure angles D and E
var D = atan( (cos(El)) / (tan(AZIMUTH)) )
Expand All @@ -97,23 +99,23 @@ func _set_view():
v_trans = v_trans.inverse()
v_trans.origin = self.transform.origin
self.transform = v_trans
#print("in", v_trans, "\ncm", self.get_node("Camera").transform)
#print("in", v_trans, "\ncm", self.get_node("Camera3D").transform)

# set sun location
self.get_node("../Sun").transform.origin = Vector3(-50, 30, 20)
self.get_node("../Sun").look_at(Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0))

# set zoom related uniforms for shaders
var mat = self.get_parent().get_node("Spatial/Terrain").get_material_override()
mat.set_shader_param("zoom", zoom)
mat.set_shader_param("tiling_factor", zoom)
self.get_parent().get_node("Spatial/Terrain").set_material_override(mat)
var mat_e = self.get_parent().get_node("Spatial/Border").get_material_override()
mat_e.set_shader_param("zoom", zoom)
mat_e.set_shader_param("tiling_factor", zoom)
self.get_parent().get_node("Spatial/Border").set_material_override(mat_e)
var mat_w = self.get_parent().get_node("Spatial/WaterPlane").get_material_override()
mat_w.set_shader_param("zoom", zoom)
mat_w.set_shader_param("tiling_factor", zoom)
self.get_parent().get_node("Spatial/WaterPlane").set_material_override(mat_w)
var mat = self.get_parent().get_node("Node3D/Terrain").get_material_override()
mat.set_shader_parameter("zoom", zoom)
mat.set_shader_parameter("tiling_factor", zoom)
self.get_parent().get_node("Node3D/Terrain").set_material_override(mat)
var mat_e = self.get_parent().get_node("Node3D/Border").get_material_override()
mat_e.set_shader_parameter("zoom", zoom)
mat_e.set_shader_parameter("tiling_factor", zoom)
self.get_parent().get_node("Node3D/Border").set_material_override(mat_e)
var mat_w = self.get_parent().get_node("Node3D/WaterPlane").get_material_override()
mat_w.set_shader_parameter("zoom", zoom)
mat_w.set_shader_parameter("tiling_factor", zoom)
self.get_parent().get_node("Node3D/WaterPlane").set_material_override(mat_w)

Loading