forked from team-sg/hero-mark-2
scoreboards screen implemented!
This commit is contained in:
parent
4fa7f1ff56
commit
377b7b2211
5 changed files with 181 additions and 26 deletions
|
@ -5,14 +5,22 @@ export var place: int = 0 setget _set_place
|
|||
export var user: String = "Username" setget _set_user
|
||||
export var score: String = "00000" setget _set_score
|
||||
|
||||
func _ready() -> void:
|
||||
$Place.text = " %01d " % place
|
||||
$User.text = user
|
||||
$Score.text = score
|
||||
|
||||
func _set_place(value: int) -> void:
|
||||
place = value
|
||||
if is_inside_tree():
|
||||
$Place.text = " %01d " % place
|
||||
|
||||
func _set_user(value: String) -> void:
|
||||
user = value
|
||||
if is_inside_tree():
|
||||
$User.text = user
|
||||
|
||||
func _set_score(value: String) -> void:
|
||||
score = value
|
||||
if is_inside_tree():
|
||||
$Score.text = score
|
||||
|
|
|
@ -9,6 +9,8 @@ margin_bottom = 10.0
|
|||
theme = ExtResource( 1 )
|
||||
custom_constants/separation = 8
|
||||
script = ExtResource( 2 )
|
||||
user = "--------"
|
||||
score = "-----"
|
||||
|
||||
[node name="Place" type="Label" parent="."]
|
||||
margin_right = 21.0
|
||||
|
@ -20,11 +22,11 @@ margin_left = 29.0
|
|||
margin_right = 167.0
|
||||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Username"
|
||||
text = "--------"
|
||||
|
||||
[node name="Score" type="Label" parent="."]
|
||||
margin_left = 175.0
|
||||
margin_right = 210.0
|
||||
margin_bottom = 10.0
|
||||
text = "00000"
|
||||
text = "-----"
|
||||
align = 2
|
||||
|
|
|
@ -9,10 +9,14 @@ const COMPLETION_NAMES = ["Any%", "100%"]
|
|||
const SCORE_TYPE_NAMES = ["Scores", "Times"]
|
||||
|
||||
|
||||
var selected_level: int = 0
|
||||
var selected_difficulty: int = Game.Difficulty.SPICY
|
||||
var selected_completion: int = Completion.ANY
|
||||
var selected_type: int = ScoreType.SCORE
|
||||
|
||||
var _scoreboard_id: int = -1
|
||||
var _scoreboard_tag: String = "spicy-any%"
|
||||
|
||||
|
||||
onready var level_title: Button = $"%LevelTitle"
|
||||
onready var back_arrow: TextureRect = $"%BackArrow"
|
||||
|
@ -20,18 +24,75 @@ onready var next_arrow: TextureRect = $"%NextArrow"
|
|||
onready var difficulty: Button = $"%Difficulty"
|
||||
onready var completion: Button = $"%Completion"
|
||||
onready var type: Button = $"%Type"
|
||||
onready var scores: VBoxContainer = $"%Scores"
|
||||
onready var scoreboard_tabs: TabContainer = $"%ScoreboardTabs"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
yield(get_tree(), "idle_frame")
|
||||
level_title.text = LevelData.levels[selected_level].title
|
||||
level_title.grab_focus()
|
||||
match selected_type:
|
||||
ScoreType.SCORE:
|
||||
_scoreboard_id = LevelData.levels[selected_level].scores_id
|
||||
ScoreType.TIME:
|
||||
_scoreboard_id = LevelData.levels[selected_level].times_id
|
||||
reload_scores()
|
||||
|
||||
|
||||
# reload scores from newgrounds
|
||||
func reload_scores() -> void:
|
||||
pass
|
||||
scoreboard_tabs.current_tab = 1
|
||||
# attempt the thing
|
||||
if _scoreboard_id >= 0 and Ngio.keys_loaded:
|
||||
var response = yield(Ngio.request_execute("ScoreBoard.getScores", {
|
||||
id = _scoreboard_id,
|
||||
limit = scores.get_child_count(),
|
||||
skip = 0,
|
||||
tag = _scoreboard_tag,
|
||||
}), "completed")
|
||||
if "success" in response and response.success and response.result.data.success:
|
||||
var retrieved_scores = response.result.data.scores
|
||||
for i in scores.get_child_count():
|
||||
var score_entry = scores.get_child(i)
|
||||
if i < retrieved_scores.size():
|
||||
var score = retrieved_scores[i]
|
||||
score_entry.user = score.user.name
|
||||
if score_entry.user.length() > 16:
|
||||
score_entry.user = score_entry.substr(0, 16) + "..."
|
||||
match selected_type:
|
||||
ScoreType.SCORE:
|
||||
score_entry.score = "%05d" % score.value
|
||||
ScoreType.TIME:
|
||||
score_entry.score = Game.format_time(float(score.value * 1000))
|
||||
else:
|
||||
score_entry.user = "--------"
|
||||
match selected_type:
|
||||
ScoreType.SCORE:
|
||||
score_entry.score = "-----"
|
||||
ScoreType.TIME:
|
||||
score_entry.score = "--:--.--"
|
||||
scoreboard_tabs.current_tab = 0
|
||||
return
|
||||
scoreboard_tabs.current_tab = 2
|
||||
|
||||
# set tag from selected difficulty and completion
|
||||
func _set_tag() -> void:
|
||||
match selected_difficulty:
|
||||
Game.Difficulty.SWEET:
|
||||
_scoreboard_tag = "sweet"
|
||||
Game.Difficulty.SALTY:
|
||||
_scoreboard_tag = "salty"
|
||||
Game.Difficulty.SPICY:
|
||||
_scoreboard_tag = "spicy"
|
||||
Game.Difficulty.PUNGENT:
|
||||
_scoreboard_tag = "pungent"
|
||||
match selected_completion:
|
||||
Completion.ANY:
|
||||
_scoreboard_tag += "-any%"
|
||||
Completion.FULL:
|
||||
_scoreboard_tag += "-100%"
|
||||
|
||||
# show arrows when level is focused
|
||||
func _on_LevelTitle_focus_entered() -> void:
|
||||
|
@ -45,25 +106,58 @@ func _on_LevelTitle_focus_exited() -> void:
|
|||
|
||||
# detect left and right presses when level is focused
|
||||
func _on_LevelTitle_gui_input(event: InputEvent) -> void:
|
||||
if scoreboard_tabs.current_tab == 1: # do nothing if already loading
|
||||
return
|
||||
if event.is_action_pressed("ui_left"):
|
||||
print("PREV")
|
||||
selected_level = posmod(selected_level - 1, LevelData.levels.size())
|
||||
while LevelData.levels[selected_level].boss:
|
||||
selected_level = posmod(selected_level - 1, LevelData.levels.size())
|
||||
level_title.text = LevelData.levels[selected_level].title
|
||||
match selected_type:
|
||||
ScoreType.SCORE:
|
||||
_scoreboard_id = LevelData.levels[selected_level].scores_id
|
||||
ScoreType.TIME:
|
||||
_scoreboard_id = LevelData.levels[selected_level].times_id
|
||||
reload_scores()
|
||||
elif event.is_action_pressed("ui_right"):
|
||||
print("NEXT")
|
||||
selected_level = posmod(selected_level + 1, LevelData.levels.size())
|
||||
while LevelData.levels[selected_level].boss:
|
||||
selected_level = posmod(selected_level + 1, LevelData.levels.size())
|
||||
level_title.text = LevelData.levels[selected_level].title
|
||||
match selected_type:
|
||||
ScoreType.SCORE:
|
||||
_scoreboard_id = LevelData.levels[selected_level].scores_id
|
||||
ScoreType.TIME:
|
||||
_scoreboard_id = LevelData.levels[selected_level].times_id
|
||||
reload_scores()
|
||||
|
||||
# difficulty selector
|
||||
func _on_Difficulty_pressed() -> void:
|
||||
if scoreboard_tabs.current_tab == 1: # do nothing if already loading
|
||||
return
|
||||
selected_difficulty = posmod(selected_difficulty + 1, 4)
|
||||
difficulty.text = Game.DIFFICULTY_NAMES[selected_difficulty]
|
||||
_set_tag()
|
||||
reload_scores()
|
||||
|
||||
# completion amount selector
|
||||
func _on_Completion_pressed() -> void:
|
||||
if scoreboard_tabs.current_tab == 1: # do nothing if already loading
|
||||
return
|
||||
selected_completion = posmod(selected_completion + 1, 2)
|
||||
completion.text = COMPLETION_NAMES[selected_completion]
|
||||
_set_tag()
|
||||
reload_scores()
|
||||
|
||||
# score type selector
|
||||
func _on_Type_pressed() -> void:
|
||||
if scoreboard_tabs.current_tab == 1: # do nothing if already loading
|
||||
return
|
||||
selected_type = posmod(selected_type + 1, 2)
|
||||
match selected_type:
|
||||
ScoreType.SCORE:
|
||||
_scoreboard_id = LevelData.levels[selected_level].scores_id
|
||||
ScoreType.TIME:
|
||||
_scoreboard_id = LevelData.levels[selected_level].times_id
|
||||
type.text = SCORE_TYPE_NAMES[selected_type]
|
||||
reload_scores()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=11 format=2]
|
||||
[gd_scene load_steps=12 format=2]
|
||||
|
||||
[ext_resource path="res://shaders/ska_plane.gdshader" type="Shader" id=1]
|
||||
[ext_resource path="res://menus/scoreboards.gd" type="Script" id=2]
|
||||
|
@ -32,6 +32,13 @@ shader_param/ammount = Vector2( 2, 0 )
|
|||
shader_param/offset = Vector2( 0, 0 )
|
||||
shader_param/delay = Vector2( 4, 0 )
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=4]
|
||||
shader = ExtResource( 4 )
|
||||
shader_param/speed = Vector2( 8, 4 )
|
||||
shader_param/ammount = Vector2( 12, 24 )
|
||||
shader_param/offset = Vector2( 0, 0 )
|
||||
shader_param/delay = Vector2( 0, 0 )
|
||||
|
||||
[node name="Scoreboards" type="Node"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
|
@ -183,16 +190,16 @@ text = " # "
|
|||
|
||||
[node name="User" type="Label" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/Header"]
|
||||
margin_left = 29.0
|
||||
margin_right = 160.0
|
||||
margin_right = 167.0
|
||||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "User"
|
||||
|
||||
[node name="Score" type="Label" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/Header"]
|
||||
margin_left = 168.0
|
||||
margin_left = 175.0
|
||||
margin_right = 210.0
|
||||
margin_bottom = 10.0
|
||||
text = "Times "
|
||||
text = "score"
|
||||
align = 2
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
|
@ -200,41 +207,82 @@ margin_top = 14.0
|
|||
margin_right = 210.0
|
||||
margin_bottom = 18.0
|
||||
|
||||
[node name="Scores" type="VBoxContainer" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
[node name="ScoreboardTabs" type="TabContainer" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
margin_top = 22.0
|
||||
margin_right = 210.0
|
||||
margin_bottom = 130.0
|
||||
size_flags_vertical = 3
|
||||
tabs_visible = false
|
||||
|
||||
[node name="ScoreEntry1" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/Scores" instance=ExtResource( 7 )]
|
||||
score = "0:00.00"
|
||||
[node name="Scores" type="VBoxContainer" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs"]
|
||||
unique_name_in_owner = true
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
||||
[node name="ScoreEntry2" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/Scores" instance=ExtResource( 7 )]
|
||||
[node name="ScoreEntry1" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs/Scores" instance=ExtResource( 7 )]
|
||||
place = 1
|
||||
|
||||
[node name="ScoreEntry2" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs/Scores" instance=ExtResource( 7 )]
|
||||
margin_top = 14.0
|
||||
margin_bottom = 24.0
|
||||
place = 2
|
||||
|
||||
[node name="ScoreEntry3" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/Scores" instance=ExtResource( 7 )]
|
||||
[node name="ScoreEntry3" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs/Scores" instance=ExtResource( 7 )]
|
||||
margin_top = 28.0
|
||||
margin_bottom = 38.0
|
||||
place = 3
|
||||
|
||||
[node name="ScoreEntry4" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/Scores" instance=ExtResource( 7 )]
|
||||
[node name="ScoreEntry4" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs/Scores" instance=ExtResource( 7 )]
|
||||
margin_top = 42.0
|
||||
margin_bottom = 52.0
|
||||
place = 4
|
||||
|
||||
[node name="ScoreEntry5" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/Scores" instance=ExtResource( 7 )]
|
||||
[node name="ScoreEntry5" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs/Scores" instance=ExtResource( 7 )]
|
||||
margin_top = 56.0
|
||||
margin_bottom = 66.0
|
||||
place = 5
|
||||
|
||||
[node name="ScoreEntry6" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/Scores" instance=ExtResource( 7 )]
|
||||
[node name="ScoreEntry6" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs/Scores" instance=ExtResource( 7 )]
|
||||
margin_top = 70.0
|
||||
margin_bottom = 80.0
|
||||
place = 6
|
||||
|
||||
[node name="ScoreEntry7" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/Scores" instance=ExtResource( 7 )]
|
||||
[node name="ScoreEntry7" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs/Scores" instance=ExtResource( 7 )]
|
||||
margin_top = 84.0
|
||||
margin_bottom = 94.0
|
||||
place = 7
|
||||
|
||||
[node name="ScoreEntry8" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/Scores" instance=ExtResource( 7 )]
|
||||
[node name="ScoreEntry8" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs/Scores" instance=ExtResource( 7 )]
|
||||
margin_top = 98.0
|
||||
margin_bottom = 108.0
|
||||
place = 8
|
||||
|
||||
[node name="LoadingIndicator" type="CenterContainer" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs"]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="TextureRect" type="Label" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs/LoadingIndicator"]
|
||||
material = SubResource( 4 )
|
||||
margin_left = 101.0
|
||||
margin_top = 49.0
|
||||
margin_right = 108.0
|
||||
margin_bottom = 59.0
|
||||
text = "§"
|
||||
|
||||
[node name="FailedIndicator" type="CenterContainer" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs"]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
||||
[node name="Label" type="Label" parent="BoardsScreen/Scoreboard/PanelContainer/MarginContainer/VBoxContainer/ScoreboardTabs/FailedIndicator"]
|
||||
margin_left = 56.0
|
||||
margin_top = 49.0
|
||||
margin_right = 154.0
|
||||
margin_bottom = 59.0
|
||||
text = "Failed to load"
|
||||
|
||||
[connection signal="focus_entered" from="BoardsScreen/SelectLevel/LevelTitle" to="." method="_on_LevelTitle_focus_entered"]
|
||||
[connection signal="focus_exited" from="BoardsScreen/SelectLevel/LevelTitle" to="." method="_on_LevelTitle_focus_exited"]
|
||||
|
|
|
@ -2,15 +2,18 @@ tool
|
|||
class_name LevelEntry
|
||||
extends Resource
|
||||
|
||||
export var title = "" setget set_title
|
||||
export var shard_titles = [
|
||||
export var title: String = "" setget set_title
|
||||
export var shard_titles: Array = [
|
||||
"", "", "", "",
|
||||
"5 Rainbow Stars",
|
||||
"Collection Bonus",
|
||||
"Time Bonus",
|
||||
"Life Bonus"]
|
||||
export var save_id = ""
|
||||
export (PackedScene) var scene
|
||||
export var save_id: String = ""
|
||||
export var boss: bool = false
|
||||
export var scores_id: int = -1
|
||||
export var times_id: int = -1
|
||||
export var scene: PackedScene
|
||||
|
||||
func set_title(value):
|
||||
title = value
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue