-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy paththeme.qml
346 lines (268 loc) · 8.35 KB
/
theme.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
import QtQuick 2.15
import QtGraphicalEffects 1.12
import QtMultimedia 5.9
import SortFilterProxyModel 0.2
import 'components' as Components
FocusScope {
id: root
//
//
//Variables, functions
//
//
Component.onCompleted: homeSound.play()
//System index from memory so we can remember the last system we were in
property var currentCollectionIndexMemory : api.memory.get('currentCollectionIndex');
property var currentCollectionIndex: {
if(currentCollectionIndexMemory)
return currentCollectionIndexMemory;
if(!currentCollectionIndexMemory)
return 0
}
property var currentCollection: allCollections[currentCollectionIndex]
//Games index
property var currentGameIndex: 0
property var currentGame: {
if (currentCollection.shortName === "all-favorites")
return api.allGames.get(allFavorites.mapToSource(currentGameIndex))
if (currentCollection.shortName === "all-lastplayed")
return api.allGames.get(allLastPlayed.mapToSource(currentGameIndex))
if (searchValue !== '')
return currentCollection.games.get(searchGames.mapToSource(currentGameIndex))
return currentCollection.games.get(currentGameIndex)
}
//We remove the favorite, lastplayed, etc collections so we can put them in another place
property var allCollections: {
let collections = api.collections.toVarArray()
collections.unshift({"name": "All Games", "shortName": "all-allgames", "games": api.allGames})
collections.unshift({"name": "Last Played", "shortName": "all-lastplayed", "games": filterLastPlayed})
collections.unshift({"name": "Favorites", "shortName": "all-favorites", "games": allFavorites})
return collections
}
FontLoader { id: titleFont; source: "assets/fonts/Nintendo_Switch_UI_Font.ttf" }
// We show the game list if we have stored the collection ID
property var currentPage : currentCollectionIndexMemory ? 'ListPage' : 'HomePage';
property var themeLight : {
"background": "#ebebeb",
"accent": "#10adc5",
"buttons": "white",
"text":"#666666",
"footer_icon":"rp2.png",
"system_icon":"allsoft_icon.svg",
"title":"#444"
}
property var themeDark : {
"background": "#222222",
"accent": "#10adc5",
"buttons": "#4a4a4a",
"text":"#6f6f6f",
"footer_icon":"rp2_dark.png",
"system_icon":"allsoft_icon_dark.svg",
"title":"white"
}
property var theme : api.memory.get('theme') === 'themeLight' ? themeLight : themeDark ;
property var searchValue: '';
property var screenRatio: root.height < 481 ? 1.98 : 1.88;
property var screenProportion: root.width / root.height;
function calculateAspectRatio(screenProportion){
if (screenProportion < 1.34){
return 43;
}
// if (screenProportion < 1.666666666666668){
// return 53;
// }
return 169;
}
property var aspectRatio : calculateAspectRatio(screenProportion)
property var itemsNumber : aspectRatio === 43 ? 3 : 4
//used by Zoom in game lists
property var itemsRow : api.memory.get('itemsRow') ? api.memory.get('itemsRow') : itemsNumber ;
//Used to hide or show the header
property var headerHeightCorrection: api.memory.get('headerHeightCorrection') === headerCSS.height ? headerCSS.height : 0;
property var wrapperCSS : {
"width": parent.width,
"height": parent.height,
"background": theme.background,
}
property var headerCSS : {
"width": wrapperCSS.width,
"height": aspectRatio == 43 ? 90 : vpx(90),
"background": "transparent",
}
property var mainCSS : {
"width": wrapperCSS.width,
"height": wrapperCSS.height - headerCSS.height - footerCSS.height,
"background": "transparent",
}
property var footerCSS : {
"width": wrapperCSS.width,
"height": aspectRatio == 43 ? 74 : 90,
"background": "transparent",
}
//Percentage calculator
function vw(pixel){
//in 100
//out 1280
switch (aspectRatio) {
case 43:
return vpx(pixel*12.8)
break;
case 169:
return vpx(pixel*12.8)
break;
default:
return vpx(pixel*12.8)
break;
}
}
function toggleDarkMode(){
if(theme === themeLight){
api.memory.set('theme', 'themeDark');
}else{
api.memory.set('theme', 'themeLight');
}
}
function toggleZoom(){
if(headerHeightCorrection === headerCSS.height){
api.memory.set('headerHeightCorrection', 0);
headerHeightCorrection = 0
toggleSound.play()
}else{
api.memory.set('headerHeightCorrection', headerCSS.height);
headerHeightCorrection = headerCSS.height
toggleSound.play()
}
}
function toggleItemsRow(){
if(aspectRatio === 43){
if ( api.memory.get('itemsRow') >= 5 ){
api.memory.set('itemsRow', 3);
}else{
api.memory.set('itemsRow', itemsRow+1);
}
}else{
if ( api.memory.get('itemsRow') >= 7 ){
api.memory.set('itemsRow', 5);
}else{
api.memory.set('itemsRow', itemsRow+1);
}
}
}
function navigate(page){
currentPage = page
goBackSound.play()
/*pageNames
'HomePage'
'ListPage'
*/
}
//Sounds
SoundEffect {
id: homeSound
source: "assets/sound/Home.wav"
volume: 1.0
}
SoundEffect {
id: navSound
source: "assets/sound/Interface Click 1.wav"
volume: 1.0
}
SoundEffect {
id: toggleSound
source: "assets/sound/Interface Click 1.wav"
volume: 1.0
}
SoundEffect {
id: goBackSound
source: "assets/sound/EnterBack.wav"
volume: 1.0
}
SoundEffect {
id: launchSound
source: "assets/sound/PopupRunTitle.wav"
volume: 1.0
}
SoundEffect {
id: settingsSound
source: "assets/sound/Settings.wav"
volume: 1.0
}
SoundEffect {
id: favSound
source: "assets/sound/Border.wav"
volume: 0.1
}
property int maximumPlayedGames: {
if (allLastPlayed.count >= 17) {
return 17
}
return allLastPlayed.count
}
SortFilterProxyModel {
id: allFavorites
sourceModel: api.allGames
filters: ValueFilter { roleName: "favorite"; value: true; }
}
SortFilterProxyModel {
id: allLastPlayed
sourceModel: api.allGames
filters: ValueFilter { roleName: "lastPlayed"; value: ""; inverted: true; }
sorters: RoleSorter { roleName: "lastPlayed"; sortOrder: Qt.DescendingOrder }
}
SortFilterProxyModel {
id: filterLastPlayed
sourceModel: allLastPlayed
filters: IndexFilter { maximumIndex: maximumPlayedGames }
}
SortFilterProxyModel {
id: currentFavorites
sourceModel: currentCollection.games
filters: ValueFilter { roleName: "favorite"; value: true; }
}
SortFilterProxyModel {
id: searchGames
sourceModel: currentCollection.games
filters: [
RegExpFilter { roleName: "title"; pattern: searchValue; caseSensitivity: Qt.CaseInsensitive; enabled: searchValue != "" }
]
// sorters: [
// RoleSorter { roleName: sortByFilter[sortByIndex]; sortOrder: orderBy }
// ]
}
//
//
//Actual UI
//
//
//RP2 screen Boundaries, use it to trace a design
Rectangle {
id: wrapper
color: wrapperCSS.background
width: wrapperCSS.width
height: wrapperCSS.height
anchors.top: parent.top
// Image {
// id: collectionLogo
// height: wrapperCSS.height
// fillMode: Image.PreserveAspectFit
// source: "assets/bg.jpg"
// asynchronous: true
// anchors.top: parent.top
//
// }
// Rectangle{
// id: cropzone
// width: 640
// height: 480
// color: "transparent"
// border.color: "red"
// border.width: 1
// }
Components.HomePage {
visible: currentPage === 'HomePage' ? 1 : 0 ;
}
Components.ListPage {
visible: currentPage === 'ListPage' ? 1 : 0 ;
}
}
}