mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-14 07:56:32 +00:00
✨ flag refactoring
This commit is contained in:
parent
69c8b65093
commit
6ba368c76e
21 changed files with 389 additions and 198 deletions
1
interfaces/waypoint/assets/waypoint.svg
Normal file
1
interfaces/waypoint/assets/waypoint.svg
Normal file
|
|
@ -0,0 +1 @@
|
|||
<svg height="128" viewBox="0 0 33.866666 33.866666" width="128" xmlns="http://www.w3.org/2000/svg"><path d="m2.5 3.6166886h28.8667346l-14.433367 27.0625224z" fill="#fff" stroke="#000" stroke-width="3"/></svg>
|
||||
|
After Width: | Height: | Size: 209 B |
38
interfaces/waypoint/assets/waypoint.svg.import
Normal file
38
interfaces/waypoint/assets/waypoint.svg.import
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cpb6vpa0c74rl"
|
||||
path.s3tc="res://.godot/imported/waypoint.svg-e7e029f470e2f863636e9426f3893ced.s3tc.ctex"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://interfaces/waypoint/assets/waypoint.svg"
|
||||
dest_files=["res://.godot/imported/waypoint.svg-e7e029f470e2f863636e9426f3893ced.s3tc.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=0
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
129
interfaces/waypoint/waypoint.gd
Normal file
129
interfaces/waypoint/waypoint.gd
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
# This file is part of open-fpsz.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
extends Control
|
||||
|
||||
# Some margin to keep the marker away from the screen's corners.
|
||||
const MARGIN : float = 8.
|
||||
|
||||
# If `true`, the waypoint sticks to the viewport's edges when moving off-screen.
|
||||
@export var sticky : bool = true
|
||||
|
||||
# If `true`, the waypoint fades as the camera get closer.
|
||||
@export var fade : bool = true
|
||||
|
||||
# The waypoint's text.
|
||||
@export var text : String = "Waypoint":
|
||||
set(value):
|
||||
text = value
|
||||
# The label's text can only be set once the node is ready.
|
||||
if is_inside_tree():
|
||||
label.text = value
|
||||
|
||||
@onready var camera : Camera3D = get_viewport().get_camera_3d()
|
||||
@onready var label : Label = $Label
|
||||
@onready var parent : Node = get_parent()
|
||||
|
||||
func _ready() -> void:
|
||||
self.text = text
|
||||
if not parent is Node3D:
|
||||
push_error("The waypoint's parent node must inherit from Node3D.")
|
||||
if DisplayServer.get_name() == "headless":
|
||||
parent.queue_free()
|
||||
|
||||
func _process(_delta : float) -> void:
|
||||
if not camera.current:
|
||||
# If the camera we have isn't the current one, get the current camera.
|
||||
camera = get_viewport().get_camera_3d()
|
||||
|
||||
var parent_position : Vector3 = parent.global_transform.origin
|
||||
var camera_transform : Transform3D = camera.global_transform
|
||||
var camera_position : Vector3 = camera_transform.origin
|
||||
|
||||
# We would use "camera.is_position_behind(parent_position)", except
|
||||
# that it also accounts for the near clip plane, which we don't want.
|
||||
var is_behind : bool = camera_transform.basis.z.dot(parent_position - camera_position) > 0
|
||||
|
||||
# Fade the waypoint when the camera gets close.
|
||||
if fade:
|
||||
var distance : float = camera_position.distance_to(parent_position)
|
||||
modulate.a = remap(distance, 0., 256., 0., 1.)
|
||||
|
||||
var unprojected_position : Vector2 = camera.unproject_position(parent_position)
|
||||
var viewport_size : Vector2 = get_viewport_rect().size
|
||||
|
||||
if not sticky:
|
||||
# For non-sticky waypoints, we don't need to clamp and calculate
|
||||
# the position if the waypoint goes off screen.
|
||||
position = unprojected_position
|
||||
visible = not is_behind
|
||||
return
|
||||
|
||||
# We need to handle the axes differently.
|
||||
# For the screen's X axis, the projected position is useful to us,
|
||||
# but we need to force it to the side if it's also behind.
|
||||
if is_behind:
|
||||
if unprojected_position.x < viewport_size.x / 2.:
|
||||
unprojected_position.x = viewport_size.x - MARGIN
|
||||
else:
|
||||
unprojected_position.x = MARGIN
|
||||
|
||||
# For the screen's Y axis, the projected position is NOT useful to us
|
||||
# because we don't want to indicate to the user that they need to look
|
||||
# up or down to see something behind them. Instead, here we approximate
|
||||
# the correct position using difference of the X axis Euler angles
|
||||
# (up/down rotation) and the ratio of that with the camera's FOV.
|
||||
# This will be slightly off from the theoretical "ideal" position.
|
||||
if is_behind or unprojected_position.x < MARGIN or \
|
||||
unprojected_position.x > viewport_size.x - MARGIN:
|
||||
var look : Transform3D = camera_transform.looking_at(parent_position, Vector3.UP)
|
||||
var diff : float = angle_diff(
|
||||
look.basis.get_euler().x, camera_transform.basis.get_euler().x)
|
||||
unprojected_position.y = viewport_size.y * (0.5 + (diff / deg_to_rad(camera.fov)))
|
||||
|
||||
position = Vector2(
|
||||
clamp(unprojected_position.x, MARGIN, viewport_size.x - MARGIN),
|
||||
clamp(unprojected_position.y, MARGIN, viewport_size.y - MARGIN)
|
||||
)
|
||||
|
||||
label.visible = true
|
||||
rotation = 0
|
||||
# Used to display a diagonal arrow when the waypoint is displayed in
|
||||
# one of the screen corners.
|
||||
var overflow : float = .0
|
||||
|
||||
if position.x <= MARGIN:
|
||||
# Left overflow.
|
||||
overflow = -TAU / 8.0
|
||||
label.visible = false
|
||||
rotation = TAU / 4.0
|
||||
elif position.x >= viewport_size.x - MARGIN:
|
||||
# Right overflow.
|
||||
overflow = TAU / 8.0
|
||||
label.visible = false
|
||||
rotation = TAU * 3.0 / 4.0
|
||||
|
||||
if position.y <= MARGIN:
|
||||
# Top overflow.
|
||||
label.visible = false
|
||||
rotation = TAU / 2.0 + overflow
|
||||
elif position.y >= viewport_size.y - MARGIN:
|
||||
# Bottom overflow.
|
||||
label.visible = false
|
||||
rotation = -overflow
|
||||
|
||||
|
||||
static func angle_diff(from : float, to : float) -> float:
|
||||
var diff : float = fmod(to - from, TAU)
|
||||
return fmod(2.0 * diff, TAU) - diff
|
||||
30
interfaces/waypoint/waypoint.tscn
Normal file
30
interfaces/waypoint/waypoint.tscn
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://bcgkc5fhhyauv"]
|
||||
|
||||
[ext_resource type="Script" path="res://interfaces/waypoint/waypoint.gd" id="1_gmnl6"]
|
||||
[ext_resource type="Texture2D" uid="uid://cpb6vpa0c74rl" path="res://interfaces/waypoint/assets/waypoint.svg" id="2_xby6k"]
|
||||
|
||||
[node name="Waypoint" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
size_flags_horizontal = 3
|
||||
script = ExtResource("1_gmnl6")
|
||||
fade = false
|
||||
|
||||
[node name="Marker" type="TextureRect" parent="."]
|
||||
visible = false
|
||||
layout_mode = 0
|
||||
offset_left = -8.0
|
||||
offset_top = -16.0
|
||||
offset_right = 8.0
|
||||
texture = ExtResource("2_xby6k")
|
||||
expand_mode = 1
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = -128.0
|
||||
offset_top = -42.0
|
||||
offset_right = 128.0
|
||||
offset_bottom = -19.0
|
||||
theme_override_font_sizes/font_size = 14
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 2
|
||||
45
interfaces/waypoint/waypoint3d.gd
Normal file
45
interfaces/waypoint/waypoint3d.gd
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# This file is part of open-fpsz.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
@tool
|
||||
class_name Waypoint3D extends Node3D
|
||||
|
||||
# If `true`, the waypoint sticks to the viewport's edges when moving off-screen.
|
||||
@export var sticky : bool = true
|
||||
|
||||
# If `true`, the waypoint fades as the camera get closer.
|
||||
@export var fade : bool = true
|
||||
|
||||
# The waypoint's text.
|
||||
@export var text : String:
|
||||
set(value):
|
||||
text = value
|
||||
# The label's text can only be set once the node is ready.
|
||||
if is_inside_tree():
|
||||
label.text = value
|
||||
|
||||
## The foreground color to modulate the waypoint color
|
||||
@export var foreground_color : Color = Color.WHITE
|
||||
|
||||
@onready var label : Label3D = $Label3D
|
||||
@onready var sprite : Sprite3D = $Sprite3D
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
func _process(_delta : float) -> void:
|
||||
sprite.modulate = foreground_color
|
||||
label.modulate = foreground_color
|
||||
label.outline_modulate.a = foreground_color.a
|
||||
23
interfaces/waypoint/waypoint3d.tscn
Normal file
23
interfaces/waypoint/waypoint3d.tscn
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://2350a3ce4xs8"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cpb6vpa0c74rl" path="res://interfaces/waypoint/assets/waypoint.svg" id="1_502g6"]
|
||||
[ext_resource type="Script" path="res://interfaces/waypoint/waypoint3d.gd" id="1_kq7bj"]
|
||||
|
||||
[node name="Waypoint" type="Node3D"]
|
||||
script = ExtResource("1_kq7bj")
|
||||
|
||||
[node name="Label3D" type="Label3D" parent="."]
|
||||
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0)
|
||||
offset = Vector2(0, 48)
|
||||
billboard = 2
|
||||
no_depth_test = true
|
||||
fixed_size = true
|
||||
line_spacing = 32.025
|
||||
|
||||
[node name="Sprite3D" type="Sprite3D" parent="."]
|
||||
transform = Transform3D(0.05, 0, 0, 0, 0.05, 0, 0, 0, 0.05, 0, 0, 0)
|
||||
offset = Vector2(0, 64)
|
||||
billboard = 2
|
||||
no_depth_test = true
|
||||
fixed_size = true
|
||||
texture = ExtResource("1_502g6")
|
||||
Loading…
Add table
Add a link
Reference in a new issue