1
Fork 0
mirror of https://github.com/Steffo99/pineapple-surf.git synced 2024-11-25 01:04:18 +00:00

better scoreboard

This commit is contained in:
Steffo 2023-01-14 21:28:28 +01:00
parent 56c60c6072
commit d6e086567d
Signed by: steffo
GPG key ID: 2A24051445686895
10 changed files with 77 additions and 37 deletions

View file

@ -23,6 +23,7 @@ var current_scene: Node = null:
current_scene.queue_free()
current_scene = new_scene
add_child(current_scene)
move_child(current_scene, 0)
## Change the current scene to the Island.

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://cj86x6gplsbrb"]
[ext_resource type="Script" path="res://base/BaseScene.gd" id="1_n2o7j"]
[ext_resource type="PackedScene" uid="uid://tmxndy6x0u3l" path="res://menu/ScoreboardContainer.tscn" id="2_tjx6n"]
[ext_resource type="PackedScene" path="res://menu/ScoreboardContainer.tscn" id="2_tjx6n"]
[node name="BaseScene" type="Node"]
script = ExtResource("1_n2o7j")

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=18 format=3 uid="uid://bg88gc1w1gw5m"]
[ext_resource type="PackedScene" path="res://island/sinking/Sea.tscn" id="1_e0hpm"]
[ext_resource type="PackedScene" uid="uid://dh5blytk6vmdu" path="res://island/sinking/Sea.tscn" id="1_e0hpm"]
[ext_resource type="PackedScene" uid="uid://bbp47va0yygpw" path="res://player/Player.tscn" id="3_5378m"]
[ext_resource type="PackedScene" uid="uid://cyuqnp5bfan4y" path="res://island/IslandMesh.tscn" id="3_g5ug0"]
[ext_resource type="PackedScene" uid="uid://tahdk48hqxis" path="res://island/HillMesh.tscn" id="4_5ll24"]

View file

@ -19,4 +19,6 @@ func _on_fetched_scores():
func _ready():
print("Connecting fetched_scores to the Scores button")
$"/root/BaseScene/ScoreboardContainer".connect("fetched_scores", _on_fetched_scores)
$"/root/BaseScene/ScoreboardContainer".fetch_scores(false)

28
menu/ScoreBox.gd Normal file
View file

@ -0,0 +1,28 @@
extends MarginContainer
class_name ScoreBox
@onready var name_label: Label = $HBoxContainer/Name
@onready var score_label: Label = $HBoxContainer/Score
var username: String:
get:
return username
set(value):
username = value
name_label.text = value
if value == Singletons.username:
name_label.add_theme_color_override("font_color", Color.YELLOW)
score_label.add_theme_color_override("font_color", Color.YELLOW)
else:
name_label.remove_theme_color_override("font_color")
score_label.remove_theme_color_override("font_color")
var score: float:
get:
return score
set(value):
score = value
score_label.text = "%0.3f s" % value

View file

@ -1,8 +1,11 @@
[gd_scene format=3 uid="uid://b7h36f4ai0qmq"]
[gd_scene load_steps=2 format=3 uid="uid://b7h36f4ai0qmq"]
[node name="MarginContainer" type="MarginContainer"]
[ext_resource type="Script" path="res://menu/ScoreBox.gd" id="1_exul7"]
[node name="ScoreBox" type="MarginContainer"]
theme_override_constants/margin_left = 5
theme_override_constants/margin_right = 5
script = ExtResource("1_exul7")
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 2

View file

@ -5,31 +5,28 @@ extends Control
var scores_downloaded := false
var scores := [] as Array[Array]
var score_scene := preload("res://menu/score.tscn")
var score_scene := preload("res://menu/ScoreBox.tscn")
var is_uploading := false
var prev_mouse_mode := Input.MOUSE_MODE_VISIBLE
var prev_mouse_mode: Input.MouseMode = Input.MOUSE_MODE_VISIBLE
signal fetched_scores()
func _ready() -> void:
_fetch_scores()
func upload_score(score: float):
var url = "https://arcade.steffo.eu/score/?board=test&player=%s" % Singletons.username
var httpreq = HTTPRequest.new()
add_child(httpreq)
httpreq.connect("request_completed", func(result, response_code, headers, body):
httpreq.connect("request_completed", func(_result, _response_code, _headers, body):
var json = JSON.parse_string(body.get_string_from_utf8())
# { score, rank }
print(json)
self.is_uploading = false
_fetch_scores(true)
httpreq.queue_free()
await get_tree().create_timer(1.75).timeout
fetch_scores(true)
)
self.is_uploading = true
httpreq.request(url, [
@ -38,14 +35,12 @@ func upload_score(score: float):
"Authorization: Bearer hahaha-ronaldinho-soccer"
], true, HTTPClient.METHOD_PUT, str(score))
_fetch_scores(true)
func _fetch_scores(open_after: bool = false):
func fetch_scores(open_after: bool = false):
const url = "https://arcade.steffo.eu/board/?board=test&offset=0&size=10"
var httpreq = HTTPRequest.new()
add_child(httpreq)
httpreq.connect("request_completed", func(result, response_code, headers, body):
httpreq.connect("request_completed", func(_result, _response_code, _headers, body):
var json = JSON.parse_string(body.get_string_from_utf8())
self.scores = (json as Array).map(func(element): return [element.name, element.score])
@ -53,13 +48,12 @@ func _fetch_scores(open_after: bool = false):
child.queue_free()
for score in self.scores:
var score_sc = score_scene.instantiate()
score_sc.get_node("HBoxContainer/Name").text = score[0]
score_sc.get_node("HBoxContainer/Score").text = "%0.3f s" % score[1]
var score_sc: ScoreBox = score_scene.instantiate()
$Panel/VBoxContainer/ScrollContainer/ScoresVBox.add_child(score_sc)
score_sc.username = score[0]
score_sc.score = score[1]
self.scores_downloaded = true
print(self.scores)
emit_signal("fetched_scores")
if open_after:
show_scores()
@ -70,11 +64,14 @@ func _fetch_scores(open_after: bool = false):
func show_scores():
prev_mouse_mode = Input.mouse_mode
print("Displaying scores...")
prev_mouse_mode = Input.mouse_mode as Input.MouseMode
print("Previous mouse mode was: ", prev_mouse_mode)
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
visible = true
func hide_scores():
print("Hiding scores...")
Input.set_mouse_mode(prev_mouse_mode)
visible = false

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=6 format=3 uid="uid://tmxndy6x0u3l"]
[gd_scene load_steps=6 format=3]
[ext_resource type="PackedScene" uid="uid://b7h36f4ai0qmq" path="res://menu/score.tscn" id="1_a00v5"]
[ext_resource type="PackedScene" uid="uid://b7h36f4ai0qmq" path="res://menu/ScoreBox.tscn" id="1_a00v5"]
[ext_resource type="Theme" uid="uid://c5a1nyqumj46j" path="res://menu/menu_theme.tres" id="1_pm2j4"]
[ext_resource type="Script" path="res://menu/ScoreboardContainer.gd" id="1_rc765"]
@ -13,19 +13,21 @@ shadow_color = Color(0, 0, 0, 0.431373)
[node name="ScoreboardContainer" type="Control"]
visible = false
z_index = 4096
z_as_relative = false
texture_filter = 1
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme = ExtResource("1_pm2j4")
script = ExtResource("1_rc765")
[node name="ColorRect" type="ColorRect" parent="."]
anchors_preset = 15
layout_mode = 0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
@ -33,7 +35,7 @@ grow_vertical = 2
color = Color(0, 0, 0, 0.635294)
[node name="Panel" type="Panel" parent="."]
anchors_preset = 8
layout_mode = 0
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
@ -47,36 +49,37 @@ grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_uie3v")
[node name="VBoxContainer" type="VBoxContainer" parent="Panel"]
anchors_preset = 15
layout_mode = 0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Authors" type="Label" parent="Panel/VBoxContainer"]
layout_mode = 2
text = "Scores"
label_settings = SubResource("LabelSettings_xmwgs")
horizontal_alignment = 1
[node name="ScrollContainer" type="ScrollContainer" parent="Panel/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
[node name="ScoresVBox" type="VBoxContainer" parent="Panel/VBoxContainer/ScrollContainer"]
offset_right = 100.0
offset_bottom = 18.0
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 0
[node name="score" parent="Panel/VBoxContainer/ScrollContainer/ScoresVBox" instance=ExtResource("1_a00v5")]
layout_mode = 2
[node name="MarginContainer" type="MarginContainer" parent="Panel/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_bottom = 2
[node name="closebtn" type="Button" parent="Panel/VBoxContainer/MarginContainer"]
custom_minimum_size = Vector2(52, 2.08165e-12)
offset_top = 6.0
offset_right = 52.0
offset_bottom = 24.0
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
theme_override_font_sizes/font_size = 0

View file

@ -79,7 +79,7 @@ grow_horizontal = 2
grow_vertical = 2
[node name="CameraViewportContainer" type="SubViewportContainer" parent="Head/Viewport"]
anchors_preset = 15
layout_mode = 0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
@ -118,7 +118,7 @@ theme = SubResource("Theme_smyke")
[node name="SubViewportContainer" type="SubViewportContainer" parent="HUD"]
show_behind_parent = true
anchors_preset = 15
layout_mode = 0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
@ -147,7 +147,7 @@ scale = Vector2(1.65, 1)
metadata/_edit_lock_ = true
[node name="PineappleLabel" type="Label" parent="HUD"]
anchors_preset = 2
layout_mode = 0
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 8.0
@ -161,7 +161,7 @@ text = "0 harvested"
vertical_alignment = 2
[node name="AmmoLabel" type="Label" parent="HUD"]
anchors_preset = 3
layout_mode = 0
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
@ -180,7 +180,7 @@ vertical_alignment = 2
[node name="Crosshair" type="ColorRect" parent="HUD"]
material = SubResource("ShaderMaterial_2p6rt")
anchors_preset = 15
layout_mode = 0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2

View file

@ -44,6 +44,11 @@ _global_script_classes=[{
"language": &"GDScript",
"path": "res://player/PlayerInputData.gd"
}, {
"base": "MarginContainer",
"class": &"ScoreBox",
"language": &"GDScript",
"path": "res://menu/ScoreBox.gd"
}, {
"base": "Area3D",
"class": &"SinkArea",
"language": &"GDScript",
@ -57,6 +62,7 @@ _global_script_class_icons={
"PeaShooter": "",
"Player": "",
"PlayerInputData": "",
"ScoreBox": "",
"SinkArea": ""
}