Skip to content

Commit

Permalink
Add map background plane to hide transparent window
Browse files Browse the repository at this point in the history
  • Loading branch information
Hop311 committed Mar 13, 2024
1 parent 8ccddb7 commit 1d64ee9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
20 changes: 17 additions & 3 deletions game/src/Game/GameSession/MapView.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ var _map_shader_material : ShaderMaterial
var _map_mesh_corner : Vector2
var _map_mesh_dims : Vector2

@export var _map_background_instance : MeshInstance3D

var _mouse_pos_viewport : Vector2 = Vector2(0.5, 0.5)
var _mouse_pos_map : Vector2 = Vector2(0.5, 0.5)
var _viewport_dims : Vector2 = Vector2(1, 1)
Expand All @@ -56,12 +58,12 @@ var _viewport_dims : Vector2 = Vector2(1, 1)
# editor, GDExtension, my own extension, or a combination of them.
# This was an absolute pain to track down. --- hop311
func _ready() -> void:
if _camera == null:
if not _camera:
push_error("MapView's _camera variable hasn't been set!")
return
_zoom_target = _camera.position.y
if _map_mesh_instance == null:
push_error("MapView's _map_mesh variable hasn't been set!")
if not _map_mesh_instance:
push_error("MapView's _map_mesh_instance variable hasn't been set!")
return

# Shader Material
Expand Down Expand Up @@ -91,6 +93,18 @@ func _ready() -> void:

GameSingleton.province_selected.connect(_on_province_selected)

if not _map_background_instance:
push_error("MapView's _map_background_instance variable hasn't been set!")
return

if not _map_background_instance.mesh is PlaneMesh:
push_error("Invalid map background mesh class: ", _map_background_instance.mesh.get_class(), "(expected PlaneMesh)")
return
var scaled_dims : Vector3 = _map_background_instance.transform.affine_inverse() * Vector3(_map_mesh_dims.x, 0.0, _map_mesh_dims.y)
scaled_dims.x *= 1.0 + 2.0 * _map_mesh.get_repeat_proportion()
scaled_dims.z *= 2.0
(_map_background_instance.mesh as PlaneMesh).set_size(Vector2(scaled_dims.x, scaled_dims.z))

func _notification(what : int) -> void:
match what:
NOTIFICATION_WM_MOUSE_ENTER: # Mouse inside window
Expand Down
16 changes: 14 additions & 2 deletions game/src/Game/GameSession/MapView.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=5 format=3 uid="uid://dkehmdnuxih2r"]
[gd_scene load_steps=7 format=3 uid="uid://dkehmdnuxih2r"]

[ext_resource type="Script" path="res://src/Game/GameSession/MapView.gd" id="1_exccw"]
[ext_resource type="Shader" path="res://src/Game/GameSession/TerrainMap.gdshader" id="1_upocn"]
Expand All @@ -16,11 +16,19 @@ shader_parameter/overlay_tile_factor = null

[sub_resource type="MapMesh" id="MapMesh_3gtsd"]

[node name="MapView" type="Node3D" node_paths=PackedStringArray("_camera", "_map_mesh_instance")]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_irk50"]
albedo_color = Color(0, 0, 0, 1)

[sub_resource type="PlaneMesh" id="PlaneMesh_fnhgl"]
material = SubResource("StandardMaterial3D_irk50")
size = Vector2(6, 2)

[node name="MapView" type="Node3D" node_paths=PackedStringArray("_camera", "_map_mesh_instance", "_map_background_instance")]
editor_description = "SS-73"
script = ExtResource("1_exccw")
_camera = NodePath("MapCamera")
_map_mesh_instance = NodePath("MapMeshInstance")
_map_background_instance = NodePath("MapBackgroundInstance")

[node name="MapCamera" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0.25, 1.5, -2.75)
Expand All @@ -31,3 +39,7 @@ editor_description = "FS-343"
transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0)
material_override = SubResource("ShaderMaterial_tayeg")
mesh = SubResource("MapMesh_3gtsd")

[node name="MapBackgroundInstance" type="MeshInstance3D" parent="."]
transform = Transform3D(10, 0, 0, 0, 10, 0, 0, 0, 10, 0, -1, 0)
mesh = SubResource("PlaneMesh_fnhgl")

0 comments on commit 1d64ee9

Please sign in to comment.