fix: Last-State, Keks-Größe, Musik-Button
- Last-State speichert in .cache/fortunecookie.darklithium/music_enabled - Geöffneter Keks: 36x28 gu (geschlossen: 32x24 gu) - Musik-Button: 10x10 gu, x-large Icon, erst nach Init sichtbar - Python ohne PySide2-Abhängigkeiten - Properties vor Functions in QML Fixes: PermissionError auf .config/, Icon-Flickern Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
+80
-52
@@ -1,5 +1,6 @@
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Layouts 1.3
|
||||
import QtMultimedia 5.0
|
||||
import Lomiri.Components 1.3
|
||||
import Lomiri.Components.Popups 1.3
|
||||
import io.thp.pyotherside 1.4
|
||||
@@ -11,97 +12,114 @@ MainView {
|
||||
height: units.gu(75)
|
||||
theme.name: "Lomiri.Components.Themes.SuruDark"
|
||||
|
||||
// ====================================================================
|
||||
// 1. PYTHON-MODUL (STANDARD 1.7)
|
||||
// ====================================================================
|
||||
property bool fortuneOpened: false
|
||||
property string currentFortune: ""
|
||||
property bool musicPlaying: false
|
||||
property bool musicButtonVisible: false
|
||||
|
||||
Python {
|
||||
id: py
|
||||
Component.onCompleted: {
|
||||
addImportPath(Qt.resolvedUrl("../src"));
|
||||
importModule("fortunecookie", function() {
|
||||
console.log("Python-Modul fortunecookie geladen");
|
||||
// Initialisierung
|
||||
currentFortuneLabel.text = py.call_sync("fortunecookie.get_initial_fortune", []);
|
||||
cookieImage.source = "assets/cookie_closed.png";
|
||||
fortuneOpened = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
// 2. APP-ZUSTAND (STANDARD 1.7)
|
||||
// ====================================================================
|
||||
property bool fortuneOpened: false
|
||||
property string currentFortune: ""
|
||||
property bool musicPlaying: false
|
||||
MediaPlayer {
|
||||
id: mediaPlayer
|
||||
source: Qt.resolvedUrl("../assets/chinese_music.mp3")
|
||||
loops: MediaPlayer.Infinite
|
||||
volume: 0.5
|
||||
}
|
||||
|
||||
MediaPlayer {
|
||||
id: crackMediaPlayer
|
||||
source: Qt.resolvedUrl("../assets/cookie_crack.mp3")
|
||||
volume: 1.0
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
// 3. HAUPTSEITE
|
||||
// ====================================================================
|
||||
Page {
|
||||
id: mainPage
|
||||
anchors.fill: parent
|
||||
|
||||
// Header
|
||||
header: PageHeader {
|
||||
title: "Fortune Cookie"
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// COOKIE & SPRUCH
|
||||
// ================================================================
|
||||
Timer {
|
||||
id: initTimer
|
||||
interval: 1000 // Warte 1 Sekunde auf Python-Ladung
|
||||
running: true
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
try {
|
||||
currentFortuneLabel.text = py.call_sync("fortunecookie.get_initial_fortune", []);
|
||||
cookieImage.source = Qt.resolvedUrl("../assets/cookie_closed2.png");
|
||||
musicPlaying = py.call_sync("fortunecookie.get_music_enabled", []);
|
||||
console.log("DEBUG QML: musicPlaying loaded from Python: " + musicPlaying);
|
||||
if (musicPlaying) {
|
||||
mediaPlayer.play();
|
||||
}
|
||||
musicButtonVisible = true;
|
||||
} catch (e) {
|
||||
console.log("ERROR QML: Failed to initialize: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cookie-Image (zentral)
|
||||
Image {
|
||||
id: cookieImage
|
||||
anchors.centerIn: parent
|
||||
width: units.gu(30)
|
||||
height: units.gu(30)
|
||||
source: fortuneOpened ? "assets/cookie_open.png" : "assets/cookie_closed.png"
|
||||
width: fortuneOpened ? units.gu(36) : units.gu(32)
|
||||
height: fortuneOpened ? units.gu(28) : units.gu(24)
|
||||
source: fortuneOpened ? Qt.resolvedUrl("../assets/cookie_open2.png") : Qt.resolvedUrl("../assets/cookie_closed2.png")
|
||||
fillMode: Image.PreserveAspectFit
|
||||
|
||||
// Wisch-Geste nach oben
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
property real startY: 0
|
||||
|
||||
onPressed: {
|
||||
startY = mouseY
|
||||
}
|
||||
onPressed: startY = mouseY
|
||||
|
||||
onReleased: {
|
||||
// Ende der Geste - pruufen ob nach oben gewischt
|
||||
if (mouseY < startY - units.gu(2)) {
|
||||
// Wisch nach oben -> Cookie oeffnen
|
||||
py.call("fortunecookie.open_fortune", [], function() {
|
||||
crackMediaPlayer.play();
|
||||
fortuneOpened = true;
|
||||
currentFortune = py.call_sync("fortunecookie.get_current_fortune", []);
|
||||
currentFortuneLabel.text = currentFortune;
|
||||
cookieImage.source = "assets/cookie_open.png";
|
||||
cookieImage.source = Qt.resolvedUrl("../assets/cookie_open2.png");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tap auf Cookie (wenn geschlossen)
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
|
||||
onClicked: {
|
||||
if (!fortuneOpened) {
|
||||
// Cookie oeffnen (gleiche Funktion wie Wisch nach oben)
|
||||
py.call("fortunecookie.open_fortune", [], function() {
|
||||
crackMediaPlayer.play();
|
||||
fortuneOpened = true;
|
||||
currentFortune = py.call_sync("fortunecookie.get_current_fortune", []);
|
||||
currentFortuneLabel.text = currentFortune;
|
||||
cookieImage.source = "assets/cookie_open.png";
|
||||
currentFortuneLabel.visible = true;
|
||||
cookieImage.source = Qt.resolvedUrl("../assets/cookie_open2.png");
|
||||
});
|
||||
} else {
|
||||
fortuneOpened = false;
|
||||
currentFortuneLabel.text = "";
|
||||
currentFortuneLabel.visible = false;
|
||||
cookieImage.source = Qt.resolvedUrl("../assets/cookie_closed2.png");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fortune-Text (erscheint nach dem Oeffnen)
|
||||
Label {
|
||||
id: currentFortuneLabel
|
||||
anchors {
|
||||
@@ -118,7 +136,6 @@ MainView {
|
||||
visible: fortuneOpened
|
||||
wrapMode: Text.WordWrap
|
||||
|
||||
// Tap auf Spruch -> neuer Cookie
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
|
||||
@@ -127,34 +144,45 @@ MainView {
|
||||
fortuneOpened = false;
|
||||
currentFortune = py.call_sync("fortunecookie.get_current_fortune", []);
|
||||
currentFortuneLabel.text = currentFortune;
|
||||
cookieImage.source = "assets/cookie_closed.png";
|
||||
cookieImage.source = Qt.resolvedUrl("../assets/cookie_closed2.png");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// MUSIK BUTTON (rechts unten)
|
||||
// ================================================================
|
||||
Button {
|
||||
id: musicButton
|
||||
Item {
|
||||
id: musicButtonContainer
|
||||
anchors {
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
margins: units.gu(2)
|
||||
}
|
||||
width: units.gu(8)
|
||||
height: units.gu(8)
|
||||
text: musicPlaying ? "\uD83D\uDD07" : "\uD83D\uDD0A"
|
||||
fontSize: "x-large"
|
||||
width: units.gu(10)
|
||||
height: units.gu(10)
|
||||
visible: musicButtonVisible
|
||||
|
||||
onClicked: {
|
||||
if (musicPlaying) {
|
||||
py.call("fortunecookie.stop_music", []);
|
||||
} else {
|
||||
py.call("fortunecookie.start_music", []);
|
||||
Label {
|
||||
id: musicButton
|
||||
text: musicPlaying ? "\uD83D\uDD0A" : "\uD83D\uDD07"
|
||||
fontSize: "x-large"
|
||||
anchors.centerIn: parent
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
|
||||
onClicked: {
|
||||
console.log("DEBUG QML: Music button clicked, current musicPlaying: " + musicPlaying);
|
||||
if (musicPlaying) {
|
||||
mediaPlayer.stop();
|
||||
} else {
|
||||
mediaPlayer.play();
|
||||
}
|
||||
musicPlaying = !musicPlaying;
|
||||
console.log("DEBUG QML: Setting music enabled to: " + musicPlaying);
|
||||
py.call("fortunecookie.set_music_enabled", [musicPlaying]);
|
||||
}
|
||||
}
|
||||
musicPlaying = !musicPlaying;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user