Skip to content

Commit

Permalink
improvement: show an indicator when practice was completed before/sol…
Browse files Browse the repository at this point in the history
…ution was used
  • Loading branch information
YuriSizov committed Jan 26, 2022
1 parent 5ca7512 commit c0be654
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ui/UINavigator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ func _on_practice_next_requested(practice: Practice) -> void:

# This is the last practice in the set, move to the next lesson.
if index >= practices.size() - 1:
# Checking that it's the last practice is not enough.
# TODO: Check if all practices are completed before moving to the next lesson.
# TODO: Show a popup with information, but allow to move forward regardless.

yield(get_tree(), "idle_frame") # Allow the rest of practice handlers to sync up.
_on_lesson_completed(lesson_data)
else:
Expand Down
8 changes: 7 additions & 1 deletion ui/UIPractice.gd
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func setup(practice: Practice, lesson: Lesson, course: Course) -> void:
_game_view.use_scene(_current_scene, _script_slice.get_scene_properties().viewport_size)

# In case we directly test a practice from the editor, we don't have access to the lesson.
if lesson:
if lesson and course:
var practice_index := lesson.practices.find(_practice)
var practice_max := lesson.practices.size() - 1
_practice_progress.set_previous_enabled(practice_index > 0)
Expand All @@ -147,6 +147,11 @@ func setup(practice: Practice, lesson: Lesson, course: Course) -> void:
_practice_list.clear_items()
for practice_data in lesson.practices:
_practice_list.add_item(practice_data, lesson, course, practice_data == practice)

var user_profile := UserProfiles.get_profile()
var completed_before = user_profile.is_lesson_practice_completed(course.resource_path, lesson.resource_path, practice.resource_path)
if completed_before:
_info_panel.set_status_icon(_info_panel.Status.COMPLETED_BEFORE)


func get_screen_resource() -> Practice:
Expand Down Expand Up @@ -363,6 +368,7 @@ func _on_code_editor_button(which: String) -> void:
_reset_practice()
_code_editor.ACTIONS.SOLUTION:
_practice_solution_used = true
_info_panel.set_status_icon(_info_panel.Status.SOLUTION_USED)
_code_editor.ACTIONS.CONTINUE:
_on_next_requested()

Expand Down
1 change: 1 addition & 0 deletions ui/UIPractice.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ anchor_bottom = 0.0
margin_left = 644.0
margin_right = 1276.0
margin_bottom = 1080.0
text = ""

[node name="Output" type="VBoxContainer" parent="Margin/Layout"]
margin_left = 1288.0
Expand Down
7 changes: 6 additions & 1 deletion ui/components/CodeEditor.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ script = ExtResource( 6 )
__meta__ = {
"_edit_use_anchors_": false
}
text = null

[node name="Column" type="VBoxContainer" parent="."]
margin_right = 1920.0
Expand Down Expand Up @@ -109,6 +108,7 @@ margin_top = 820.0
margin_right = 1912.0
margin_bottom = 867.0
hint_tooltip = "Toggle the code editor expanded.
Shortcut:
Shortcut:"
size_flags_horizontal = 8
size_flags_vertical = 8
Expand Down Expand Up @@ -179,6 +179,7 @@ margin_right = 844.0
margin_bottom = 71.0
rect_min_size = Vector2( 160, 40 )
hint_tooltip = "Run your code.
Shortcut:
Shortcut:"
custom_styles/hover = ExtResource( 13 )
custom_styles/pressed = ExtResource( 11 )
Expand All @@ -195,6 +196,7 @@ margin_right = 1020.0
margin_bottom = 71.0
rect_min_size = Vector2( 160, 40 )
hint_tooltip = "Toggle the game viewport paused.
Shortcut:
Shortcut:"
custom_styles/hover = ExtResource( 13 )
custom_styles/pressed = ExtResource( 11 )
Expand All @@ -211,6 +213,7 @@ margin_right = 1196.0
margin_bottom = 71.0
rect_min_size = Vector2( 160, 40 )
hint_tooltip = "Reset your code to the starting point.
Shortcut:
Shortcut:"
size_flags_horizontal = 0
custom_styles/hover = ExtResource( 13 )
Expand All @@ -236,6 +239,7 @@ margin_right = 834.0
margin_bottom = 70.0
rect_min_size = Vector2( 160, 40 )
hint_tooltip = "Show this practice's solution code.
Shortcut:
Shortcut:"
size_flags_horizontal = 0
custom_styles/hover = ExtResource( 13 )
Expand All @@ -252,6 +256,7 @@ margin_left = 850.0
margin_right = 1017.0
margin_bottom = 70.0
hint_tooltip = "Toggle the output console's visibility.
Shortcut:
Shortcut:"
custom_styles/hover = ExtResource( 13 )
custom_styles/pressed = ExtResource( 11 )
Expand Down
30 changes: 30 additions & 0 deletions ui/screens/practice/PracticeInfoPanel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ extends PanelContainer

signal tests_updated

enum Status { NONE, COMPLETED_BEFORE, SOLUTION_USED }

const STATUS_ICON_COMPLETED_BEFORE := preload("res://ui/icons/checkmark_valid.svg")
const STATUS_ICON_SOLUTION_USED := preload("res://ui/icons/checkmark_invalid.svg")

const QueryResult := Documentation.QueryResult
const TestDisplayScene = preload("PracticeTestDisplay.tscn")

export var title := "Title" setget set_title

var _current_status: int = Status.NONE

onready var title_label := find_node("Title") as Label
onready var _status_icon := find_node("StatusIcon") as TextureRect
onready var goal_rich_text_label := find_node("Goal").find_node("TextBox") as RichTextLabel
onready var hints_container := find_node("Hints") as Revealer
onready var docs_container := find_node("Documentation") as Revealer
Expand Down Expand Up @@ -134,3 +142,25 @@ func set_documentation(documentation: QueryResult) -> void:

func clear_documentation() -> void:
docs_container.hide()


func set_status_icon(status: int) -> void:
if not _current_status == Status.NONE:
return
_current_status = status

match status:
Status.NONE:
_status_icon.texture = null
_status_icon.hint_tooltip = ""
_status_icon.hide()

Status.COMPLETED_BEFORE:
_status_icon.texture = STATUS_ICON_COMPLETED_BEFORE
_status_icon.hint_tooltip = "You've completed this practice before."
_status_icon.show()

Status.SOLUTION_USED:
_status_icon.texture = STATUS_ICON_SOLUTION_USED
_status_icon.hint_tooltip = "You've used the provided solution.\nThis practice will not count towards your course progress."
_status_icon.show()
22 changes: 18 additions & 4 deletions ui/screens/practice/PracticeInfoPanel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,34 @@ margin_right = 1900.0
margin_bottom = 1001.0
size_flags_vertical = 3

[node name="Title" type="Label" parent="LessonRequirements/Margin/Column"]
[node name="TitleBox" type="HBoxContainer" parent="LessonRequirements/Margin/Column"]
margin_right = 1880.0
margin_bottom = 32.0

[node name="Title" type="Label" parent="LessonRequirements/Margin/Column/TitleBox"]
margin_right = 1832.0
margin_bottom = 31.0
size_flags_horizontal = 3
custom_fonts/font = ExtResource( 3 )
text = "Summary - Lesson Name"

[node name="StatusIcon" type="TextureRect" parent="LessonRequirements/Margin/Column/TitleBox"]
modulate = Color( 0.572549, 0.560784, 0.721569, 1 )
margin_left = 1848.0
margin_right = 1880.0
margin_bottom = 32.0
rect_min_size = Vector2( 32, 32 )
expand = true
stretch_mode = 6

[node name="HSeparator" type="HSeparator" parent="LessonRequirements/Margin/Column"]
margin_top = 47.0
margin_top = 48.0
margin_right = 1880.0
margin_bottom = 63.0
margin_bottom = 64.0
custom_constants/separation = 16

[node name="Scroll" type="ScrollContainer" parent="LessonRequirements/Margin/Column"]
margin_top = 79.0
margin_top = 80.0
margin_right = 1880.0
margin_bottom = 981.0
size_flags_vertical = 3
Expand Down

0 comments on commit c0be654

Please sign in to comment.