-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from amalija-ramljak/dajana-question_card
Dajana question card
- Loading branch information
Showing
15 changed files
with
408 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ export_presets.cfg | |
# Mono-specific ignores | ||
.mono/ | ||
data_*/ | ||
.DS_Store |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"0": { | ||
"text": "Ovo je tekst prvog pitanja?", | ||
"correctAnswer": "0", | ||
"answers": ["odg a", "odg b", "odg c", "odg d"] | ||
}, | ||
"1": { | ||
"text": "Ovo je tekst drugog pitanja?", | ||
"correctAnswer": "1", | ||
"answers": ["odg a", "odg b", "odg c", "odg d"] | ||
}, | ||
"2": { | ||
"text": "Ovo je tekst treceg pitanja?", | ||
"correctAnswer": "2", | ||
"answers": ["odg a", "odg b", "odg c", "odg d"] | ||
}, | ||
"3": { | ||
"text": "Ovo je tekst cetvrtog pitanja?", | ||
"correctAnswer": "3", | ||
"answers": ["odg a", "odg b", "odg c", "odg d"] | ||
}, | ||
"4": { | ||
"text": "Ovo je tekst petog pitanja?", | ||
"correctAnswer": "0", | ||
"answers": ["odg a", "odg b", "odg c", "odg d"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"0": { | ||
"text": "Ovo je tekst prve situacije", | ||
"consequence": 1 | ||
}, | ||
"1": { | ||
"text": "Ovo je tekst druge situacije", | ||
"consequence": 0 | ||
}, | ||
"2": { | ||
"text": "Ovo je tekst trece situacije", | ||
"consequence": 0 | ||
}, | ||
"3": { | ||
"text": "Ovo je tekst cetvrte situacije", | ||
"consequence": 1 | ||
}, | ||
"4": { | ||
"text": "Ovo je tekst pete situacije", | ||
"consequence": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
extends Node | ||
export (PackedScene) var QuestionFeedbackCard | ||
|
||
var AnswersButtonGroup | ||
var question | ||
var questions | ||
var unansweredKeys | ||
var answeredKeys = Array() | ||
var randomIndex | ||
var randomQuestionKey | ||
var answerIndex = [0, 1, 2, 3] | ||
|
||
func _ready(): | ||
#group buttons so they act as radio buttons | ||
AnswersButtonGroup = ButtonGroup.new() | ||
$Answers/optionA.set_button_group(AnswersButtonGroup) | ||
$Answers/optionB.set_button_group(AnswersButtonGroup) | ||
$Answers/optionC.set_button_group(AnswersButtonGroup) | ||
$Answers/optionD.set_button_group(AnswersButtonGroup) | ||
|
||
#load json file with questions and parse it to the questions dictionary | ||
questions = self.load("res://leveldata/level1_questions_list.json") | ||
questions = JSON.parse(questions).result | ||
#fill unansweredKeys array with questions dictionary keys | ||
unansweredKeys = questions.keys() | ||
|
||
#ensure that a new seed will be used each time (if you want non-reproducible shuffling) | ||
randomize() | ||
#generate random key for the questions dictionary | ||
randomIndex = randi()%unansweredKeys.size() | ||
|
||
#select randomly chosen question from the questions dictionary | ||
randomQuestionKey = unansweredKeys[randomIndex] | ||
question = questions[str(randomQuestionKey)] | ||
|
||
#shuffle answers order | ||
answerIndex.shuffle() | ||
|
||
set_question_txt(question.text) | ||
set_answers_txt() | ||
|
||
func load(var path): | ||
var file = File.new() | ||
file.open(path, File.READ) | ||
var content = file.get_as_text() | ||
file.close() | ||
return content | ||
|
||
func set_question_txt(var txt): | ||
$QuestionText.text = " %s" % txt | ||
|
||
func set_answers_txt(): | ||
$Answers/optionA.text = " %s" % question.answers[answerIndex[0]] | ||
$Answers/optionB.text = " %s" % question.answers[answerIndex[1]] | ||
$Answers/optionC.text = " %s" % question.answers[answerIndex[2]] | ||
$Answers/optionD.text = " %s" % question.answers[answerIndex[3]] | ||
|
||
func _on_Button_pressed(): | ||
queue_free() | ||
var question_feedback = preload("res://scenes/components/QuestionFeedbackCard.tscn").instance() | ||
self.get_parent().add_child(question_feedback) | ||
#selected correct answer | ||
if ((AnswersButtonGroup.get_pressed_button()==$Answers/optionA && str(answerIndex[0])==question.correctAnswer) | ||
|| (AnswersButtonGroup.get_pressed_button()==$Answers/optionB && str(answerIndex[1])==question.correctAnswer) | ||
|| (AnswersButtonGroup.get_pressed_button()==$Answers/optionC && str(answerIndex[2])==question.correctAnswer) | ||
|| (AnswersButtonGroup.get_pressed_button()==$Answers/optionD && str(answerIndex[3])==question.correctAnswer)): | ||
question_feedback.positive_feedback() | ||
|
||
#if answer is correct, remove question key from the unansweredKeys array | ||
unansweredKeys.remove(randomIndex) | ||
#...and add it to the answeredKeys array | ||
answeredKeys.append(randomQuestionKey) | ||
|
||
#if unansweredKeys array is empty, refill it | ||
if(unansweredKeys.empty()): | ||
unansweredKeys=answeredKeys | ||
answeredKeys.clear() | ||
#selected wrong answer or no answer selected | ||
else: | ||
question_feedback.negative_feedback() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
[gd_scene load_steps=6 format=2] | ||
|
||
[ext_resource path="res://scenes/components/QuestionCard.gd" type="Script" id=2] | ||
|
||
[sub_resource type="ButtonGroup" id=1] | ||
resource_local_to_scene = false | ||
|
||
[sub_resource type="ButtonGroup" id=2] | ||
resource_local_to_scene = false | ||
|
||
[sub_resource type="ButtonGroup" id=3] | ||
|
||
[sub_resource type="ButtonGroup" id=4] | ||
resource_local_to_scene = false | ||
|
||
[node name="QuestionCard" type="Panel"] | ||
anchor_left = 0.5 | ||
anchor_top = 0.5 | ||
anchor_right = 0.5 | ||
anchor_bottom = 0.5 | ||
margin_left = -189.0 | ||
margin_top = -168.0 | ||
margin_right = 186.0 | ||
margin_bottom = -10.0 | ||
script = ExtResource( 2 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="QuestionText" type="Label" parent="."] | ||
margin_right = 375.0 | ||
margin_bottom = 14.0 | ||
text = "Pitanje" | ||
align = 1 | ||
|
||
[node name="Answers" type="GridContainer" parent="."] | ||
margin_top = 18.0 | ||
margin_right = 375.0 | ||
margin_bottom = 126.0 | ||
|
||
[node name="optionA" type="CheckBox" parent="Answers"] | ||
margin_right = 24.0 | ||
margin_bottom = 24.0 | ||
action_mode = 0 | ||
group = SubResource( 1 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="optionB" type="CheckBox" parent="Answers"] | ||
margin_top = 28.0 | ||
margin_right = 24.0 | ||
margin_bottom = 52.0 | ||
action_mode = 0 | ||
group = SubResource( 2 ) | ||
|
||
[node name="optionC" type="CheckBox" parent="Answers"] | ||
margin_top = 56.0 | ||
margin_right = 24.0 | ||
margin_bottom = 80.0 | ||
action_mode = 0 | ||
group = SubResource( 3 ) | ||
|
||
[node name="optionD" type="CheckBox" parent="Answers"] | ||
margin_top = 84.0 | ||
margin_right = 24.0 | ||
margin_bottom = 108.0 | ||
action_mode = 0 | ||
group = SubResource( 4 ) | ||
|
||
[node name="Button" type="Button" parent="."] | ||
margin_top = 130.0 | ||
margin_right = 375.0 | ||
margin_bottom = 150.0 | ||
text = "Potvrdi odgovor" | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extends Panel | ||
|
||
func _on_Button_pressed(): | ||
queue_free() | ||
|
||
func positive_feedback(): | ||
$QuestionFeedback.text = "Tocan odgovor!" | ||
$QuestionConsequence.text = "+1 bod" | ||
|
||
func negative_feedback(): | ||
$QuestionFeedback.text = "Pogresan odgovor!" | ||
$QuestionConsequence.text = "-1 bod" | ||
|
||
func set_total_points(): | ||
$TotalPointsLabel.text = "10 bodova" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://scenes/components/QuestionFeedbackCard.gd" type="Script" id=1] | ||
|
||
[node name="QuestionFeedbackCard" type="Panel"] | ||
anchor_left = 0.5 | ||
anchor_top = 0.5 | ||
anchor_right = 0.5 | ||
anchor_bottom = 0.5 | ||
margin_left = -189.0 | ||
margin_top = -168.544 | ||
margin_right = 186.0 | ||
margin_bottom = -10.5438 | ||
rect_pivot_offset = Vector2( 260.512, 313.021 ) | ||
script = ExtResource( 1 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="QuestionFeedback" type="Label" parent="."] | ||
margin_left = -0.328552 | ||
margin_top = 0.328552 | ||
margin_right = 373.671 | ||
margin_bottom = 35.3286 | ||
text = "Tocan odgovor! / Pogresan odgovor!" | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="QuestionConsequence" type="Label" parent="."] | ||
anchor_top = 0.5 | ||
anchor_right = 1.0 | ||
anchor_bottom = 0.5 | ||
margin_top = -23.0 | ||
margin_bottom = 2.0 | ||
text = "+1 / -1 bod" | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="TotalPointsLabel" type="Label" parent="."] | ||
anchor_top = 0.5 | ||
anchor_right = 1.0 | ||
anchor_bottom = 0.5 | ||
margin_left = 0.328552 | ||
margin_top = 18.9557 | ||
margin_right = 0.328552 | ||
margin_bottom = 38.9557 | ||
text = "Ukupan broj bodova: 10" | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="Button" type="Button" parent="."] | ||
anchor_top = 1.0 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
margin_top = -28.5424 | ||
margin_bottom = -8.54236 | ||
text = "U redu" | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"] |
Oops, something went wrong.