fix(achievements): show position before score submit, closes #223
This commit is contained in:
@@ -72,10 +72,6 @@ func generate_achievement_literal(achievement_id: String, variant: String = "_ti
|
||||
return literal
|
||||
|
||||
|
||||
func format_time(time) -> String:
|
||||
return str(time)
|
||||
|
||||
|
||||
func start_tracking_time() -> void:
|
||||
if not time_tracker == null:
|
||||
time_tracker.restart()
|
||||
|
||||
@@ -118,6 +118,16 @@ func submit_score(collection: String, name: String, time: int) -> bool:
|
||||
return response_data != null
|
||||
|
||||
|
||||
## Calculates a certain time which position would have in scoreboard. First position is 0.
|
||||
func calculate_score_position(collection: String, time: int) -> int:
|
||||
var scores: Array[RTMIScoreRow] = await get_scores(collection)
|
||||
var pos = scores.find_custom(func(score): return time < score.time)
|
||||
if pos < 0:
|
||||
return scores.size()
|
||||
|
||||
return pos
|
||||
|
||||
|
||||
func _score_http_request(
|
||||
http_request: HTTPRequest, url: String, method: int = HTTPClient.METHOD_GET, request_data: String = "", additional_headers: Array = []
|
||||
) -> Variant:
|
||||
|
||||
@@ -4,9 +4,12 @@ const CHARACTER_LIMIT: int = 32
|
||||
const ALLOWED_CHARACTERS = "[à-ÿÀ-ŸA-Za-z0-9 _-]"
|
||||
|
||||
var perfect = false
|
||||
var collection: String
|
||||
|
||||
@onready var input_name: LineEdit = %InputName
|
||||
@onready var total_time: Label = %TotalTime
|
||||
@onready var pos: Label = %Position
|
||||
@onready var achievement_count: Label = %AchievementCount
|
||||
@onready var unlocked_achievements_container: VBoxContainer = %UnlockedAchievementsContainer
|
||||
@onready var submit_button: RTMIMenuButton = %SubmitButton
|
||||
@onready var spinner: Spinner = %Spinner
|
||||
@@ -27,13 +30,9 @@ func _input(event: InputEvent) -> void:
|
||||
_on_submit_button_up()
|
||||
|
||||
|
||||
func refresh() -> void:
|
||||
_fill()
|
||||
|
||||
|
||||
func _fill():
|
||||
_clear()
|
||||
total_time.text = gymkhana.achievement_manager.format_time(gymkhana.achievement_manager.played_time)
|
||||
total_time.text = gymkhana.score_manager.format_time(gymkhana.achievement_manager.played_time)
|
||||
var achievements = gymkhana.achievement_manager.get_achievements()
|
||||
var unlocked = 0
|
||||
for achievement_key in achievements:
|
||||
@@ -45,9 +44,13 @@ func _fill():
|
||||
unlocked += 1
|
||||
unlocked_achievements_container.add_child(label)
|
||||
|
||||
achievement_count.text = "%s / %s" % [unlocked, achievements.size()]
|
||||
|
||||
if unlocked == achievements.size():
|
||||
submit_button.text = tr("SUBMIT_PERFECT_SCORE")
|
||||
perfect = true
|
||||
|
||||
collection = gymkhana.score_manager.PERFECT if perfect else gymkhana.score_manager.FASTEST
|
||||
check_score()
|
||||
|
||||
|
||||
@@ -55,6 +58,9 @@ func check_score():
|
||||
if perfect:
|
||||
escoria.game_scene.launch_confetti()
|
||||
escoria.game_scene.launch_confetti()
|
||||
var played_time = floor(randf() * 1000)
|
||||
var pos_int = await gymkhana.score_manager.calculate_score_position(collection, gymkhana.achievement_manager.played_time)
|
||||
pos.text = "#" + str(pos_int + 1)
|
||||
|
||||
|
||||
func _clear() -> void:
|
||||
@@ -88,7 +94,6 @@ func _on_submit_button_up() -> void:
|
||||
return
|
||||
|
||||
spinner.show()
|
||||
var collection: String = gymkhana.score_manager.PERFECT if perfect else gymkhana.score_manager.FASTEST
|
||||
var success: bool = await gymkhana.score_manager.submit_score(collection, input_name.text, gymkhana.achievement_manager.played_time)
|
||||
if success:
|
||||
_set_submit_ok()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://ch5d4emoxq6t4"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://ch5d4emoxq6t4"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://wor3bvk7tdh0" path="res://addons/escoria-ui-return-monkey-island/achievements/summary/rtmi_achievement_summary.gd" id="1_vcqj7"]
|
||||
[ext_resource type="Script" uid="uid://elqkwjm0r5c7" path="res://addons/escoria-ui-return-monkey-island/menus/rtmi_menu_button.gd" id="2_3d1qx"]
|
||||
[ext_resource type="Script" uid="uid://doqt8bqgwakt" path="res://addons/tattomoosa.spinner/spinner.gd" id="3_co5jd"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_co5jd"]
|
||||
|
||||
[node name="AchievementSummary" type="PanelContainer"]
|
||||
custom_minimum_size = Vector2(300, 0)
|
||||
offset_right = 40.0
|
||||
@@ -20,32 +22,71 @@ theme_override_constants/margin_bottom = 10
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Title" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 23
|
||||
text = "ACHIEVEMENT_SUMMARY"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="TotalTimeLabel" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="TotalTimeLabel" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 20
|
||||
text = "TOTAL_TIME"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="TotalTime" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
[node name="TotalTime" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 41
|
||||
text = "00:00:00s"
|
||||
theme_override_font_sizes/font_size = 24
|
||||
text = "0h 00m 00s"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 2
|
||||
|
||||
[node name="VBoxContainer2" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="PositionLabel" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 20
|
||||
text = "POSITION"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Position" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 24
|
||||
text = "#3"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 2
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_styles/separator = SubResource("StyleBoxEmpty_co5jd")
|
||||
|
||||
[node name="MarginContainer2" type="MarginContainer" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="AchievementTitle" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "ACHIEVEMENT_SUMMARY"
|
||||
|
||||
[node name="AchievementCount" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "1 / 7"
|
||||
horizontal_alignment = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 5
|
||||
theme_override_constants/margin_top = 10
|
||||
theme_override_constants/margin_right = 5
|
||||
theme_override_constants/margin_bottom = 10
|
||||
|
||||
[node name="UnlockedAchievementsContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/MarginContainer"]
|
||||
@@ -77,6 +118,10 @@ text = "ACHIEVEMENT TEXT PLACEHOLDER"
|
||||
layout_mode = 2
|
||||
text = "ACHIEVEMENT TEXT PLACEHOLDER"
|
||||
|
||||
[node name="HSeparator3" type="HSeparator" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_styles/separator = SubResource("StyleBoxEmpty_co5jd")
|
||||
|
||||
[node name="InputName" type="LineEdit" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(0, 60)
|
||||
@@ -85,6 +130,10 @@ placeholder_text = "NAME_PLACEHOLDER"
|
||||
clear_button_enabled = true
|
||||
caret_blink = true
|
||||
|
||||
[node name="HSeparator2" type="HSeparator" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_styles/separator = SubResource("StyleBoxEmpty_co5jd")
|
||||
|
||||
[node name="SubmitButton" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(0, 60)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[gd_resource type="Resource" script_class="ESCAnimationResource" load_steps=36 format=3 uid="uid://cyjo7aq0e4hbe"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationresource.gd" id="1"]
|
||||
[ext_resource type="Script" path="res://addons/escoria-core/game/core-scripts/resources/esc_directionangle.gd" id="2"]
|
||||
[ext_resource type="Script" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationname.gd" id="3"]
|
||||
[ext_resource type="Script" uid="uid://sksvt0n8gle2" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationresource.gd" id="1"]
|
||||
[ext_resource type="Script" uid="uid://bxc3dll30x8tl" path="res://addons/escoria-core/game/core-scripts/resources/esc_directionangle.gd" id="2"]
|
||||
[ext_resource type="Script" uid="uid://clixil1u5exq7" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationname.gd" id="3"]
|
||||
|
||||
[sub_resource type="Resource" id="1"]
|
||||
script = ExtResource("2")
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[gd_resource type="Resource" script_class="ESCAnimationResource" load_steps=7 format=3 uid="uid://cr02ebtkhjlw7"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationresource.gd" id="1"]
|
||||
[ext_resource type="Script" path="res://addons/escoria-core/game/core-scripts/resources/esc_directionangle.gd" id="2"]
|
||||
[ext_resource type="Script" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationname.gd" id="3"]
|
||||
[ext_resource type="Script" uid="uid://sksvt0n8gle2" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationresource.gd" id="1"]
|
||||
[ext_resource type="Script" uid="uid://bxc3dll30x8tl" path="res://addons/escoria-core/game/core-scripts/resources/esc_directionangle.gd" id="2"]
|
||||
[ext_resource type="Script" uid="uid://clixil1u5exq7" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationname.gd" id="3"]
|
||||
|
||||
[sub_resource type="Resource" id="1"]
|
||||
script = ExtResource("2")
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[gd_resource type="Resource" script_class="ESCAnimationResource" load_steps=7 format=3 uid="uid://bl5rc1krhwcbu"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationresource.gd" id="1"]
|
||||
[ext_resource type="Script" path="res://addons/escoria-core/game/core-scripts/resources/esc_directionangle.gd" id="2"]
|
||||
[ext_resource type="Script" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationname.gd" id="3"]
|
||||
[ext_resource type="Script" uid="uid://sksvt0n8gle2" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationresource.gd" id="1"]
|
||||
[ext_resource type="Script" uid="uid://bxc3dll30x8tl" path="res://addons/escoria-core/game/core-scripts/resources/esc_directionangle.gd" id="2"]
|
||||
[ext_resource type="Script" uid="uid://clixil1u5exq7" path="res://addons/escoria-core/game/core-scripts/resources/esc_animationname.gd" id="3"]
|
||||
|
||||
[sub_resource type="Resource" id="1"]
|
||||
script = ExtResource("2")
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
[gd_scene load_steps=11 format=3 uid="uid://csb7hwb1v016e"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/escoria-core/game/core-scripts/esc_room.gd" id="1"]
|
||||
[ext_resource type="Script" uid="uid://c7fcpp72w3dnj" path="res://addons/escoria-core/game/core-scripts/esc_room.gd" id="1"]
|
||||
[ext_resource type="PackedScene" uid="uid://cjmsexhyhi4vs" path="res://gymkhana/characters/oier/oier.tscn" id="2"]
|
||||
[ext_resource type="Texture2D" uid="uid://dvofjrubnnone" path="res://gymkhana/rooms/turno_cocina/creditos/assets/background.png" id="3"]
|
||||
[ext_resource type="Texture2D" uid="uid://dc7j1xq3x7gwp" path="res://gymkhana/rooms/turno_cocina/creditos/assets/background.png" id="3"]
|
||||
[ext_resource type="PackedScene" uid="uid://fgwob47tewuf" path="res://gymkhana/rooms/turno_cocina/creditos/ScrollingText.tscn" id="4"]
|
||||
[ext_resource type="PackedScene" uid="uid://bgiskd55j17fc" path="res://gymkhana/rooms/turno_cocina/creditos/EnekoDancing.tscn" id="5"]
|
||||
[ext_resource type="Texture2D" uid="uid://bgfi7t6khinjw" path="res://gymkhana/logo-small.png" id="6"]
|
||||
[ext_resource type="Texture2D" uid="uid://budal8dqwrifr" path="res://gymkhana/logo-small.png" id="6"]
|
||||
[ext_resource type="Script" uid="uid://ib2j5oleakyb" path="res://gymkhana/rooms/turno_cocina/creditos/SceneHandler.gd" id="7"]
|
||||
[ext_resource type="PackedScene" uid="uid://dg3q322t7b34f" path="res://gymkhana/rooms/turno_cocina/creditos/OierDancing.tscn" id="9"]
|
||||
[ext_resource type="PackedScene" uid="uid://ch5d4emoxq6t4" path="res://addons/escoria-ui-return-monkey-island/achievements/summary/rtmi_achievement_summary.tscn" id="9_oudlg"]
|
||||
@@ -77,6 +77,7 @@ alignment = 1
|
||||
[node name="Credits" type="Button" parent="Summary/CenterContainer/VBoxContainer/HBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 40)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "SHOW_CREDITS"
|
||||
script = ExtResource("10_f1tcv")
|
||||
metadata/_custom_type_script = "uid://elqkwjm0r5c7"
|
||||
@@ -84,6 +85,7 @@ metadata/_custom_type_script = "uid://elqkwjm0r5c7"
|
||||
[node name="Back" type="Button" parent="Summary/CenterContainer/VBoxContainer/HBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 40)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "BACK_MAIN_MENU"
|
||||
script = ExtResource("10_f1tcv")
|
||||
metadata/_custom_type_script = "uid://elqkwjm0r5c7"
|
||||
|
||||
@@ -28,15 +28,16 @@
|
||||
"SKIP_VIDEO"," Skip video",,,"Saltar video","Bideoa pasa"
|
||||
"ACHIEVEMENT_UNLOCKED_NOTIFICATION_LABEL","Unlocked achievement:",,,"Logro desbloqueado:","Lorpen desblokeatua:"
|
||||
"ACHIEVEMENT_SUMMARY","Achivement summary","","","Resumen de logros","Lorpenen laburpena"
|
||||
"TOTAL_TIME","Total time:","","","Tiempo total:","Denbora totala:"
|
||||
"TOTAL_TIME","Total time","","","Tiempo total","Denbora guztira"
|
||||
"POSITION","Position","","","Posición","Postua"
|
||||
"SCOREBOARD_PERFECT_TITLE","Perfect TOP 10","","","Perfect TOP 10","Perfect TOP 10"
|
||||
"SCOREBOARD_FASTEST_TITLE","Fastest TOP 10","","","Fastest TOP 10","Fastest TOP 10"
|
||||
"SHOW_CREDITS"," See credits",,,"Ver créditos","Kredituak ikusi"
|
||||
"SHOW_CREDITS","Credits",,,"Créditos","Kredituak"
|
||||
"SKIP_CREDITS"," Skip credits",,,"Saltar créditos","Kredituak pasa"
|
||||
"NAME_PLACEHOLDER","Your name",,,"Tu nombre","Zure izena"
|
||||
"SUBMIT_SCORE","Submit score",,,"Enviar puntuación","Puntuazioa bidali"
|
||||
"SUBMIT_PEREFCT_SCORE","Submit PERFECT score",,,"Enviar puntuación perfecta","Puntuazioa perfektua bidali"
|
||||
"BACK_MAIN_MENU","Return to the main menu",,,"Volver al menú principal","Menu nagusira bueltatu"
|
||||
"BACK_MAIN_MENU","Main menu",,,"Menú principal","Menu nagusia"
|
||||
"SCOREBOARD_REFRESH","Refresh","","","Refrescar",""
|
||||
"SCOREBOARD_BACK","Back","Retour","Zurück","Volver","Itzuli"
|
||||
"CURRENT_PLAYING_TIME","Current playing time:",,,"Tiempo de la partida:","Jolastutako denbora:"
|
||||
|
||||
|
Reference in New Issue
Block a user