RhythmGame 1.4.3
Loading...
Searching...
No Matches
1. Make a main menu

Tutorial | Next: QML basics

Goal: Install a main menu with an image and four working navigation buttons, then edit its title or color.

Download 01-main or open the source folder.

Install the folder

Close the game. Extract the download or copy docs/examples/theme-tutorial/01-main/ into your user theme directory. The game creates this directory on first launch.

Platform User theme directory
Windows APPDATA%/RhythmGame/themes/
Linux ~/.local/share/RhythmGame/themes/
macOS ~/Library/Application Support/RhythmGame/themes/

On Linux, use $XDG_DATA_HOME instead of ~/.local/share if it is set. The game also reads themes from its installation's data directory, where the Default theme is stored.

Portable mode is enabled by portable.ini in the installation prefix, one directory above bin. In portable mode the game uses the installation's data directory and doesn't scan a separate user theme directory.

Keep the folder structure intact after extracting the download.

themes/
01-main/
theme.json
main.qml
images/
notes.svg

Register the screen

The game reads theme.json to find the screens a theme provides. The scripts object maps each screen to a QML file, using paths relative to the theme's folder. The first example provides only main.

{
"$schema": "https://raw.githubusercontent.com/Bobini1/RhythmGame/master/schemas/theme.json",
"scripts": {
"main": "main.qml"
}
}

The $schema URL helps a text editor check the file. It's not required. The theme's name comes from its folder name, so the example will appear as 01-main in the game.

The default theme config lists all screen names.

Draw the menu

Open 01-main/main.qml. QtQuick supplies the basic visual objects, QtQuick.Controls.FluentWinUI3 supplies the buttons and label, and QtQuick.Layouts arranges them. RhythmGameQml supplies the game's types.

The examples import the FluentWinUI3 style explicitly to give the controls a consistent style. You can use another Qt Quick Controls style or draw your own controls.

StandardMainController handles menu actions, the bound START button and background music. It draws nothing, so the theme creates buttons whose onClicked handlers call openSelect(), openArena(), openSettings() and quit() for the four menu actions. The component is optional. You can call globalRoot.openSelect(), globalRoot.openArenaBrowser(), globalRoot.openSettings() and globalRoot.quitApplication() directly. If you replace it, keep a way for controller users to open song select. The standard component binds START to openSelect().

StandardMainController {
id: actions
}
Button {
Layout.fillWidth: true
text: "Song select"
focus: true
onClicked: actions.openSelect()
}
Button {
Layout.fillWidth: true
text: "Multiplayer"
onClicked: actions.openArena()
}
Button {
Layout.fillWidth: true
text: "Settings"
onClicked: actions.openSettings()
}
Button {
Layout.fillWidth: true
text: "Quit"
onClicked: actions.quit()
}

The image is a file in the theme's images folder, and its path is relative to main.qml. Qt's Image documentation explains image sizing, fitting and cropping.

Image {
Layout.fillWidth: true
Layout.preferredHeight: 120
source: "images/notes.svg"
sourceSize: Qt.size(320, 120)
fillMode: Image.PreserveAspectFit
Accessible.ignored: true
}

Keep theme assets in the theme

Keep the images, fonts and sounds used by your interface in the theme folder, then copy them with the QML files when you install or publish the theme. images, fonts and sounds are useful folder names, but the game does not require a particular layout.

Use a relative URL from the QML file that uses the asset, such as images/notes.svg. To use a custom font, load its file with FontLoader.

Here is the complete screen:

1import QtQuick
2import QtQuick.Controls.FluentWinUI3
3import QtQuick.Layouts
4import RhythmGameQml
5
6Rectangle {
7 id: screen
8 color: "#18232e"
9
10 // [main-actions]
11 StandardMainController {
12 id: actions
13 }
14 // [main-actions]
15
16 // [canvas]
17 Item {
18 id: canvas
19 width: 960
20 height: 540
21 anchors.centerIn: parent
22 scale: Math.min(screen.width / canvas.width, screen.height / canvas.height)
23 // [canvas]
24
25 ColumnLayout {
26 anchors.centerIn: parent
27 width: 320
28 spacing: 20
29
30 // [image]
31 Image {
32 Layout.fillWidth: true
33 Layout.preferredHeight: 120
34 source: "images/notes.svg"
35 sourceSize: Qt.size(320, 120)
36 fillMode: Image.PreserveAspectFit
37 Accessible.ignored: true
38 }
39 // [image]
40
41 Label {
42 Layout.fillWidth: true
43 text: "My first theme"
44 color: "white"
45 font.pixelSize: 32
46 horizontalAlignment: Text.AlignHCenter
47 }
48
49 // [buttons]
50 Button {
51 Layout.fillWidth: true
52 text: "Song select"
53 focus: true
54 onClicked: actions.openSelect()
55 }
56 Button {
57 Layout.fillWidth: true
58 text: "Multiplayer"
59 onClicked: actions.openArena()
60 }
61 Button {
62 Layout.fillWidth: true
63 text: "Settings"
64 onClicked: actions.openSettings()
65 }
66 Button {
67 Layout.fillWidth: true
68 text: "Quit"
69 onClicked: actions.quit()
70 }
71 // [buttons]
72 }
73 }
74}
The example menu with FluentWinUI3 controls in dark mode

Choose the theme and try a change

Launch the game and open Settings. Under Themes, select Main Menu and choose 01-main as its theme. Leave the other screens on Default or your existing themes, then go back to see the newly selected main menu.

Click Song select or press your bound START button. The chosen selection screen should open. Multiplayer opens the configured Multiplayer screen, where you can join an Arena room. Settings opens settings, and Quit closes the game.

Edit the title or background color in main.qml, save the file, and restart the game.

Press F10 to inspect the log if the screen fails to load. log.txt is in the game's data directory, next to themes.

Resize the window to a square, a 4:3 rectangle and a wide rectangle. The menu should stay centered with all four buttons visible. The next lesson explains the sizing and adds controls you can reuse.