scoreboards screen implemented!
This commit is contained in:
parent
4fa7f1ff56
commit
377b7b2211
5 changed files with 181 additions and 26 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue