Commit f1562ea5 authored by Georgiy Yankovskiy's avatar Georgiy Yankovskiy

Basic RunningScene.qml, GameInfoScene.qml

parent 53dc9a1a
...@@ -2,13 +2,10 @@ import QtQuick ...@@ -2,13 +2,10 @@ import QtQuick
import QtQuick.Controls as C import QtQuick.Controls as C
C.Button { C.Button {
// control.down // control.down
// control.activeFocus // control.activeFocus
id: control id: control
width: 150
height: 50
text: qsTr("Button") text: qsTr("Button")
contentItem: Text { contentItem: Text {
......
import QtQuick
import QtQuick.Controls as C
import "."
Button {
property string imageUrl: "../images/generic.svg"
id: button
contentItem: Image {
source: button.imageUrl
fillMode: Image.PreserveAspectFit // ensure it fits
}
}
...@@ -84,8 +84,8 @@ Rectangle { ...@@ -84,8 +84,8 @@ Rectangle {
exec: model.exec exec: model.exec
icon: model.icon icon: model.icon
// width: gamesGrid.elementWidth width: 256
// height: gamesGrid.elementHeight height: 256
// icon: core_app.games.icon // icon: core_app.games.icon
// exec: core_app.games.exec // exec: core_app.games.exec
} }
...@@ -120,6 +120,8 @@ Rectangle { ...@@ -120,6 +120,8 @@ Rectangle {
Button { Button {
id: buttonSystemManagement id: buttonSystemManagement
text: "System management" text: "System management"
width: 150
height: 50
onClicked: function(){ onClicked: function(){
tabs.currentTab = TabConstants.systemManagementTab; tabs.currentTab = TabConstants.systemManagementTab;
// tabs.changeTab(); // tabs.changeTab();
...@@ -130,6 +132,8 @@ Rectangle { ...@@ -130,6 +132,8 @@ Rectangle {
Button { Button {
id: buttonGames id: buttonGames
text: "Games" text: "Games"
width: 150
height: 50
onClicked: function(){ onClicked: function(){
tabs.currentTab = TabConstants.gamesTab; tabs.currentTab = TabConstants.gamesTab;
//if(core_app === undefined) return; //if(core_app === undefined) return;
...@@ -146,8 +150,4 @@ Rectangle { ...@@ -146,8 +150,4 @@ Rectangle {
} }
/*##^##
Designer {
D{i:0}D{i:1;invisible:true}
}
##^##*/
var homeScene = "home";
var gameInfoScene = "gameInfo";
var runningScene = "running";
\ No newline at end of file
import QtQuick import QtQuick
import "../constants/scene.js" as SceneConstants
Rectangle { Rectangle {
property string title: "Generic title" property string title: "Generic title"
...@@ -12,6 +13,19 @@ Rectangle { ...@@ -12,6 +13,19 @@ Rectangle {
radius: 5 radius: 5
border.width: 1 border.width: 1
MouseArea {
anchors.fill: parent
onClicked: function(){
// console.log(game.title);
gameInfoScene.title = game.title;
gameInfoScene.icon = game.icon;
gameInfoScene.exec = game.exec;
window.scene = SceneConstants.gameInfoScene;
}
}
Image { Image {
id: image id: image
anchors.left: parent.left anchors.left: parent.left
......
<?xml version="1.0" encoding="UTF-8"?>
<svg width="128" height="128" version="1.1" viewBox="0 0 33.867 33.867" xmlns="http://www.w3.org/2000/svg">
<path d="m32.211 22.315h-18.796v6.0794l-11.461-11.461 11.461-11.461v6.0794h18.796z" fill="#f9f9f9" stroke="#1a1a1a" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.438" style="paint-order:normal"/>
</svg>
<?xml version="1.0" encoding="UTF-8"?>
<svg width="128" height="128" version="1.1" viewBox="0 0 33.867 33.867" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(-1.1156 2.8582)" stroke="#1a1a1a" stroke-linecap="round" stroke-linejoin="round">
<path d="m13.952 5.5733c0.1189-0.93676 0.77503-1.6426 1.43-2.2733 0.38912-0.37471 0.62422-0.62811 1.1-0.88 1.5766-0.83466 2.771-0.42136 4.0333 0.69667 0.50459 0.44693 0.70636 0.62165 1.0633 1.1733 0.96765 1.4955 0.55549 2.3404-0.14667 3.85-0.32616 0.70125-0.69834 1.3791-1.1367 2.0167-0.47007 0.68375-1.0553 1.271-1.54 1.9433-0.20617 0.28598-0.39111 0.58667-0.58667 0.88-0.42478 0.63717-0.89741 1.2767-1.21 1.98-0.36563 0.82266-0.54629 1.6465-0.69667 2.53-0.18045 1.0601-0.32624 2.1115-0.25667 3.19 0.04662 0.72258 0.36404 1.3488 0.58667 2.0167" fill="none" stroke-width="1.438" style="paint-order:normal"/>
<path d="m17.942 25.729a0.63785 0.63785 0 0 1-0.63785 0.63785 0.63785 0.63785 0 0 1-0.63785-0.63785 0.63785 0.63785 0 0 1 0.63785-0.63785 0.63785 0.63785 0 0 1 0.63785 0.63785z" stroke-width="1.0423"/>
</g>
</svg>
...@@ -3,8 +3,23 @@ import QtQuick ...@@ -3,8 +3,23 @@ import QtQuick
// Import all components from folder // Import all components from folder
import "scenes" import "scenes"
import "constants/scene.js" as SceneConstants
Window { Window {
property string scene: SceneConstants.homeScene
Connections {
target: core_app
function onGameStarted(done) {
console.log("gameStarted!!");
window.scene = SceneConstants.runningScene;
}
function onGameEnded(done) {
console.log("gameEnded!!");
window.scene = SceneConstants.gameInfoScene;
}
}
id: window id: window
width: 640 width: 640
height: 480 height: 480
...@@ -12,10 +27,25 @@ Window { ...@@ -12,10 +27,25 @@ Window {
title: qsTr("Launcher") title: qsTr("Launcher")
HomeScene { HomeScene {
id: grid visible: scene == SceneConstants.homeScene
id: homeScene
anchors.fill: parent anchors.fill: parent
} }
GameInfoScene {
visible: scene == SceneConstants.gameInfoScene
id: gameInfoScene
anchors.fill: parent
}
RunningScene {
visible: scene == SceneConstants.runningScene
id: runningScene
anchors.fill: parent
}
/* InputPanelHomeScene { /* InputPanelHomeScene {
id: inputPanel id: inputPanel
z: 99 z: 99
......
import QtQuick
import QtQuick.Controls
import "../components"
import "../constants/scene.js" as S
Rectangle {
property string title: "Generic title"
property string icon: ""
property string exec: ""
id: container
x: 0
y: 0
width: 640
height: 480
Rectangle {
id: rectangle
height: 64
color: "#2b2b2b"
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.rightMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
}
ButtonImage {
id: back
x: 0
y: 0
width: 64
height: 64
imageUrl: "../images/back.svg"
onClicked: function(){
window.scene = S.homeScene;
}
}
Image {
id: gameImage
width: 128
height: 128
anchors.left: parent.left
anchors.top: parent.top
source: container.icon
anchors.leftMargin: 8
anchors.topMargin: 70
fillMode: Image.PreserveAspectFit
}
Text {
id: title
height: 49
text: container.title
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
font.pixelSize: 32
anchors.leftMargin: 142
anchors.topMargin: 70
anchors.rightMargin: 8
}
Button {
anchors.left: parent.left
anchors.top: parent.top
anchors.leftMargin: 142
anchors.topMargin: 125
text: "Run game"
onClicked: function(){
if(core_app === undefined) return;
core_app.start_game(container.exec);
}
}
}
...@@ -12,7 +12,7 @@ Rectangle { ...@@ -12,7 +12,7 @@ Rectangle {
Rectangle { Rectangle {
id: rectangle id: rectangle
height: 50 height: 64
color: "#2b2b2b" color: "#2b2b2b"
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
...@@ -28,7 +28,7 @@ Rectangle { ...@@ -28,7 +28,7 @@ Rectangle {
anchors.right: parent.right anchors.right: parent.right
anchors.top: parent.top anchors.top: parent.top
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.topMargin: 48 anchors.topMargin: 64
anchors.bottomMargin: 0 anchors.bottomMargin: 0
anchors.leftMargin: 0 anchors.leftMargin: 0
anchors.rightMargin: 0 anchors.rightMargin: 0
......
import QtQuick
import QtQuick.Controls
import "../components"
Rectangle {
id: container
x: 0
y: 0
width: 640
height: 480
Rectangle {
id: rectangle
color: "#2b2b2b"
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.rightMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
Text {
id: text1
color: "#ffffff"
text: qsTr("Game is now running...")
anchors.fill: parent
font.pixelSize: 24
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
}
}
}
...@@ -4,8 +4,8 @@ from pathlib import Path ...@@ -4,8 +4,8 @@ from pathlib import Path
from PySide6.QtGui import QGuiApplication from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine from PySide6.QtQml import QQmlApplicationEngine
from src.models.App import App from models.App import App
from src.models.GamesModel import GamesModel from models.GamesModel import GamesModel
# TODO: add VirtualKeyboard # TODO: add VirtualKeyboard
......
import threading
from time import sleep
from PySide6 import QtCore from PySide6 import QtCore
from os.path import expanduser from os.path import expanduser
import glob import glob
from desktop_parser import DesktopFile from desktop_parser import DesktopFile
import os.path import os.path
from pathlib import Path from pathlib import Path
from PySide6.QtCore import Property, Signal, Slot, QObject from PySide6.QtCore import Property, Signal, Slot, QObject, Qt
from src.models.GamesModel import Game, GamesModel from models.GamesModel import Game, GamesModel
import subprocess
class GameShortcut: class GameShortcut:
...@@ -16,12 +20,16 @@ class GameShortcut: ...@@ -16,12 +20,16 @@ class GameShortcut:
class App(QtCore.QObject): class App(QtCore.QObject):
game_started = Signal(bool, name="gameStarted")
game_ended = Signal(bool, name="gameEnded")
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.games_model = GamesModel() self.games_model = GamesModel()
self.home = expanduser('~') self.home = expanduser('~')
self.config_location = '/.config/PortProton.conf' self.config_location = '/.config/PortProton.conf'
self.portproton_location = '' self.portproton_location = ''
self.running_game_process = None
self.setup() self.setup()
def setup(self): def setup(self):
...@@ -29,8 +37,10 @@ class App(QtCore.QObject): ...@@ -29,8 +37,10 @@ class App(QtCore.QObject):
with open(self.home + self.config_location, 'r') as file: with open(self.home + self.config_location, 'r') as file:
self.portproton_location = file.read().strip() self.portproton_location = file.read().strip()
print(f'Current PortProton location: {self.portproton_location}') print(f'Current PortProton location: {self.portproton_location}')
self.games_model.clear() self.games_model.clear()
files = glob.glob(f"{self.portproton_location}/*.desktop") files = glob.glob(f"{self.portproton_location}/*.desktop")
for val in files: for val in files:
desktop_file = DesktopFile.from_file(val) desktop_file = DesktopFile.from_file(val)
data = desktop_file.data data = desktop_file.data
...@@ -66,6 +76,33 @@ class App(QtCore.QObject): ...@@ -66,6 +76,33 @@ class App(QtCore.QObject):
### SLOTS ### ### SLOTS ###
@Slot(str)
def start_game(self, exec):
self.game_started.emit(True)
def run_in_thread(t, _exec):
t.running_game_process = subprocess.Popen(
_exec,
shell=True,
bufsize=0,
stdout=subprocess.PIPE,
universal_newlines=True
)
t.running_game_process.wait()
t.game_ended.emit(True)
# output = self.running_game_process.stdout.read()
# self.running_game_process.stdout.close()
return
thread = threading.Thread(target=run_in_thread, args=(self, exec))
thread.start()
pass
### PROPERTIES ###
@Property(QObject, constant=True) @Property(QObject, constant=True)
def games(self): def games(self):
return self.games_model return self.games_model
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment