KanaVoicing mechanics Finished

This commit is contained in:
Hannes
2026-03-07 01:41:43 +01:00
parent 47a0e11088
commit f202619644
4 changed files with 208 additions and 48 deletions
+10
View File
@@ -71,6 +71,12 @@ PanelWindow {
kanaVoicing.visible = false kanaVoicing.visible = false
} }
function switchResult(result) {
console.log("Result: " + result)
languageChooser.visible = true
kanaVoicing.visible = false
}
ModeChooser { ModeChooser {
id: languageChooser id: languageChooser
} }
@@ -79,6 +85,10 @@ PanelWindow {
id: kanaVoicing id: kanaVoicing
} }
// KanaVoicing {
// id: kanaVoicing
// }
} }
} }
} }
+75 -47
View File
@@ -20,13 +20,20 @@ Item { // Kana_Try
property var currentKana: [] property var currentKana: []
property int roundNum: 0 property int roundNum: 0
property int maxRoundNum: 9 property int correct: 0
property int maxRoundNum: 10
function endRounds() {
console.log("Switching back")
roundNum = 0
parent.switchResult(correct/maxRoundNum)
kanaVoicingAnswer.placeholderText = "Type Voicing..."
kanaVoicingAnswerBackground.color = kanaVoicingAnswer.activeFocus ? Colors.tertiary_fg : Colors.primary_fg
}
function randomKana() { function randomKana() {
if (roundNum >= maxRoundNum) { if (roundNum >= maxRoundNum) {
console.log("Switching back") endRounds()
roundNum = 0
parent.switchModeChooser()
} }
var list = kanaData.kana var list = kanaData.kana
currentKana = list[Math.floor(Math.random() * list.length)] currentKana = list[Math.floor(Math.random() * list.length)]
@@ -36,9 +43,7 @@ Item { // Kana_Try
function randomKnownKana() { function randomKnownKana() {
if (roundNum >= maxRoundNum) { if (roundNum >= maxRoundNum) {
console.log("Switching back") endRounds()
roundNum = 0
parent.switchModeChooser()
} }
var knownList = kanaData.kana.filter(k => k.known) var knownList = kanaData.kana.filter(k => k.known)
currentKana = knownList[Math.floor(Math.random() * knownList.length)] currentKana = knownList[Math.floor(Math.random() * knownList.length)]
@@ -58,7 +63,7 @@ Item { // Kana_Try
Text { Text {
id: kanaVoicingText id: kanaVoicingText
text: "Im Spiel" text: "Im Spiel - Runde: " + kanaVoicing.roundNum
width: parent.width width: parent.width
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
font.pixelSize: 28 font.pixelSize: 28
@@ -68,54 +73,77 @@ Item { // Kana_Try
Row { Row {
width: parent.width width: parent.width
height: parent.height - kanaVoicingTextRectangale.height - parent.spacing height: (parent.height - kanaVoicingTextRectangale.height)*0.8 - parent.spacing*2
spacing: 15 spacing: 0
MouseArea { Rectangle {
hoverEnabled: true color: "transparent"
cursorShape: Qt.PointingHandCursor width: (parent.width - kanaVoicingKanaRectangle.width)/2
width: (parent.width - parent.spacing) / 2 height: parent.height
}
Rectangle {
id: kanaVoicingKanaRectangle
color: "#000000"
width: parent.height
height: parent.height height: parent.height
onClicked: { Text {
kanaVoicing.randomKnownKana() id: kanaVoicingKana
text: kanaVoicing.currentKana ? kanaVoicing.currentKana.hira : ""
anchors.centerIn: parent
font.pixelSize: Math.min(parent.width / text.length * 1.2, parent.height * 0.8)
color: "white"
} }
}
}
Rectangle { TextField {
anchors.fill: parent id: kanaVoicingAnswer
color: "#FFFFFF"
Text { placeholderText: "Type Voicing..."
id: kanaVoicingKana1
text: kanaVoicing.currentKana ? kanaVoicing.currentKana.hira : "" anchors.horizontalCenter: parent.horizontalCenter
anchors.centerIn: parent
font.pixelSize: Math.min(parent.width / text.length * 1.2, parent.height * 0.8) width: parent.width / 3
color: "black" height: (parent.height - kanaVoicingTextRectangale.height) * 0.2 - parent.spacing*2
}
font.pixelSize: height * 0.8
color: "white"
placeholderTextColor: "#888"
background: Rectangle {
id: kanaVoicingAnswerBackground
radius: 12
color: kanaVoicingAnswer.activeFocus ? Colors.tertiary_fg : Colors.primary_fg
border.color: kanaVoicingAnswer.activeFocus ? Colors.tertiary : Colors.primary
border.width: 1
}
Keys.onReleased: {
if (event.key === Qt.Key_Escape) {
console.log("Escape pressed inside TextField")
console.log("Pressed Escape, closing JLearner")
jLearnerLoader.active = false
} }
} }
MouseArea { onAccepted: function(event) {
hoverEnabled: true console.log("Enter pressed inside TextField")
cursorShape: Qt.PointingHandCursor if (kanaVoicing.currentKana.voice.includes(kanaVoicingAnswer.text.toLowerCase())){
width: (parent.width - parent.spacing) / 2 console.log("Correct")
height: parent.height kanaVoicingAnswer.text = ""
kanaVoicingAnswer.placeholderText = "[" + kanaVoicing.currentKana.voice + "]"
onClicked: { kanaVoicingAnswerBackground.color = "green"
kanaVoicing.randomKnownKana() kanaVoicing.correct = kanaVoicing.correct + 1
} randomKnownKana()
} else {
Rectangle { console.log("Wrong: [" + currentKana.voice + "]")
anchors.fill: parent kanaVoicingAnswer.text = ""
color: "#000000" kanaVoicingAnswerBackground.color = "red"
kanaVoicingAnswer.placeholderText = "[" + kanaVoicing.currentKana.voice + "]"
Text { randomKnownKana()
id: kanaVoicingKana2
text: kanaVoicing.currentKana ? kanaVoicing.currentKana.hira : ""
anchors.centerIn: parent
font.pixelSize: Math.min(parent.width / text.length * 1.2, parent.height * 0.8)
color: "white"
}
} }
} }
} }
+123
View File
@@ -0,0 +1,123 @@
import QtQuick
import QtQuick.Controls
import "../../../colors"
Item { // Kana_Try
id: voicingKana
width: window.width
height: window.height - head.height
anchors.margins: 15
visible: false
Component.onCompleted: {
randomKnownKana()
}
KanaData {
id: kanaData
}
property var currentKana: []
property int roundNum: 0
property int maxRoundNum: 10
function randomKana() {
if (roundNum >= maxRoundNum) {
console.log("Switching back")
roundNum = 0
parent.switchModeChooser()
}
var list = kanaData.kana
currentKana = list[Math.floor(Math.random() * list.length)]
console.log("Round Num: " + roundNum + " - Choosing Kana: " + currentKana.hira)
roundNum = roundNum + 1
}
function randomKnownKana() {
if (roundNum >= maxRoundNum) {
console.log("Switching back")
roundNum = 0
parent.switchModeChooser()
}
var knownList = kanaData.kana.filter(k => k.known)
currentKana = knownList[Math.floor(Math.random() * knownList.length)]
console.log("Round Num: " + roundNum + " - Choosing Kana: " + currentKana.hira)
roundNum = roundNum + 1
}
Column {
anchors.fill: parent
spacing: 10
Rectangle {
id: voicingKanaTextRectangale
color: "#FFFFFF"
width: parent.width
height: voicingKanaText.height + parent.spacing/2
Text {
id: voicingKanaText
text: "Im Spiel - Runde: " + voicingKana.roundNum
width: parent.width
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 28
color: "black"
}
}
Row {
width: parent.width
height: parent.height - voicingKanaTextRectangale.height - parent.spacing
spacing: 15
MouseArea {
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
width: (parent.width - parent.spacing) / 2
height: parent.height
onClicked: {
voicingKana.randomKnownKana()
}
Rectangle {
anchors.fill: parent
color: "#FFFFFF"
Text {
id: voicingKanaKana1
text: voicingKana.currentKana ? voicingKana.currentKana.hira : ""
anchors.centerIn: parent
font.pixelSize: Math.min(parent.width / text.length * 1.2, parent.height * 0.8)
color: "black"
}
}
}
MouseArea {
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
width: (parent.width - parent.spacing) / 2
height: parent.height
onClicked: {
voicingKana.randomKnownKana()
}
Rectangle {
anchors.fill: parent
color: "#000000"
Text {
id: voicingKanaKana2
text: voicingKana.currentKana ? voicingKana.currentKana.hira : ""
anchors.centerIn: parent
font.pixelSize: Math.min(parent.width / text.length * 1.2, parent.height * 0.8)
color: "white"
}
}
}
}
}
}
-1
View File
@@ -75,7 +75,6 @@ PanelWindow {
pickerScope.focus = true pickerScope.focus = true
} }
} }
} }