-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp_mainwindow.cpp
More file actions
3328 lines (2834 loc) · 267 KB
/
Copy pathtemp_mainwindow.cpp
File metadata and controls
3328 lines (2834 loc) · 267 KB
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mainwindow.h"
#include "glassbutton.h"
#include "gamecard.h"
#include "loadingspinner.h"
#include "gamedetailspage.h"
#include "socialpage.h"
#include "profilecard.h"
#include "customtitlebar.h"
#include "materialicons.h"
#include "notificationdialog.h"
#include "chatpage.h"
#include "friendpopover.h"
#include "userprofiledialog.h"
#include "workers/indexdownloadworker.h"
#include "workers/luadownloadworker.h"
#include "workers/generatorworker.h"
#include "workers/restartworker.h"
#include "workers/steampatchworker.h"
#include "utils/colors.h"
#include "utils/gameinfo.h"
#include "terminaldialog.h"
#include "addfrienddialog.h"
#include "utils/paths.h"
#include "config.h"
#include <QBuffer>
#include <QProcess>
#include <QApplication>
#include <QImageWriter>
#ifdef Q_OS_WIN
#include <windows.h>
#include <dwmapi.h>
#include <windowsx.h>
// windows.h defines ERROR as a macro which conflicts with Colors::ERROR
#undef ERROR
#endif
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPointer>
#include <QFileDialog>
#include <QStackedLayout>
#include <QPropertyAnimation>
#include <QPainter>
#include <QLinearGradient>
#include <QGraphicsDropShadowEffect>
#include <QMessageBox>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QUrlQuery>
#include <QFile>
#include <QDir>
#include <QPixmap>
#include <QPainterPath>
#include <QFileDialog>
#include <QScrollBar>
#include <QRandomGenerator>
#include <algorithm>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
#include <QSettings>
#include <QStandardPaths>
#include <QMouseEvent>
#include <QScreen>
#include <QGuiApplication>
#include <QNetworkDiskCache>
// ==========================================
// HeroBannerWidget Implementation
// ==========================================
HeroBannerWidget::HeroBannerWidget(QWidget* parent) : QWidget(parent), m_imageScale(1.05) {
m_scaleAnim = new QPropertyAnimation(this, "imageScale", this);
m_scaleAnim->setDuration(1000);
m_scaleAnim->setEasingCurve(QEasingCurve::OutSine);
setStyleSheet("border-radius: 12px; border: none; background: transparent;");
}
void HeroBannerWidget::setPixmap(const QPixmap& p) {
m_pixmap = p;
update();
}
void HeroBannerWidget::paintEvent(QPaintEvent* event) {
Q_UNUSED(event);
if (m_pixmap.isNull()) return;
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setRenderHint(QPainter::SmoothPixmapTransform);
QPainterPath path;
path.addRoundedRect(rect(), 12, 12);
p.setClipPath(path);
p.translate(rect().center());
p.scale(m_imageScale, m_imageScale);
p.translate(-rect().center());
QSize targetSize = rect().size();
QPixmap scaled = m_pixmap.scaled(targetSize, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
int sx = qMax(0, (scaled.width() - targetSize.width()) / 2);
int sy = qMax(0, (scaled.height() - targetSize.height()) / 2);
int sw = qMin(targetSize.width(), scaled.width() - sx);
int sh = qMin(targetSize.height(), scaled.height() - sy);
p.drawPixmap(rect(), scaled, QRect(sx, sy, sw, sh));
}
void HeroBannerWidget::enterEvent(QEnterEvent* event) {
m_scaleAnim->stop();
m_scaleAnim->setStartValue(m_imageScale);
m_scaleAnim->setEndValue(1.0);
m_scaleAnim->start();
QWidget::enterEvent(event);
}
void HeroBannerWidget::leaveEvent(QEvent* event) {
m_scaleAnim->stop();
m_scaleAnim->setStartValue(m_imageScale);
m_scaleAnim->setEndValue(1.05);
m_scaleAnim->start();
QWidget::leaveEvent(event);
}
// ==========================================
// MainWindow Implementation
// ==========================================
// ΓöÇΓöÇ Inline helper: a QWidget that paints a single Material icon ΓöÇΓöÇ
class MaterialIconWidget : public QWidget {
public:
MaterialIconWidget(MaterialIcons::Icon icon, const QColor& color, int size = 24, QWidget* parent = nullptr)
: QWidget(parent), m_icon(icon), m_color(color) {
setFixedSize(size, size);
setAttribute(Qt::WA_TranslucentBackground);
}
protected:
void paintEvent(QPaintEvent*) override {
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
QRectF r(4, 4, width() - 8, height() - 8);
MaterialIcons::draw(p, r, m_color, m_icon);
}
private:
MaterialIcons::Icon m_icon;
QColor m_color;
};
// ΓöÇΓöÇ Inline helper: a QPushButton that paints a Material icon ΓöÇΓöÇ
class MaterialIconButton : public QPushButton {
public:
MaterialIconButton(MaterialIcons::Icon icon, const QColor& color, int size = 40, QWidget* parent = nullptr)
: QPushButton(parent), m_icon(icon), m_color(color) {
setFixedSize(size, size);
setCursor(Qt::PointingHandCursor);
}
protected:
void paintEvent(QPaintEvent*) override {
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
// Background
QColor bg = Colors::toQColor(Colors::SURFACE_CONTAINER_HIGH);
if (underMouse()) bg = Colors::toQColor(Colors::SURFACE_CONTAINER_HIGHEST);
QPainterPath path;
path.addRoundedRect(QRectF(rect()), width() / 2.0, height() / 2.0);
p.fillPath(path, bg);
// Icon
int pad = 10;
QRectF iconRect(pad, pad, width() - 2 * pad, height() - 2 * pad);
MaterialIcons::draw(p, iconRect, m_color, m_icon);
}
private:
MaterialIcons::Icon m_icon;
QColor m_color;
};
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
, m_currentMode(AppMode::LuaPatcher)
, m_networkManager(nullptr)
, m_activeReply(nullptr)
, m_currentSearchId(0)
, m_syncWorker(nullptr)
, m_dlWorker(nullptr)
, m_genWorker(nullptr)
, m_restartWorker(nullptr)
, m_fetchingNames(false)
, m_nameFetchSearchId(0)
, m_hasCachedData(false)
, m_sidebarAvatarLabel(nullptr)
, m_sidebarUsernameLabel(nullptr)
, m_sidebarProfileWidget(nullptr)
{
// Retrieve username first so UI reflects it correctly (Avatar initial)
// Use AppData folder for settings
QString appDataPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
QDir().mkpath(appDataPath);
QString settingsPath = appDataPath + "/settings.ini";
QSettings settings(settingsPath, QSettings::IniFormat);
m_username = settings.value("username", "").toString();
m_isGuest = settings.value("isGuest", true).toBool();
QString dataStr = settings.value("userData", "").toString();
if (!dataStr.isEmpty()) {
m_userData = QJsonDocument::fromJson(dataStr.toUtf8()).object();
}
setWindowTitle("Lua Patcher");
setMinimumSize(900, 600);
resize(1280, 820);
// Center window on primary screen
if (auto screen = QGuiApplication::primaryScreen()) {
QRect screenGeometry = screen->availableGeometry();
move(screenGeometry.center() - rect().center());
}
setAcceptDrops(true);
// ΓöÇΓöÇ Native Frameless Window Approach ΓöÇΓöÇ
// We do NOT use Qt::FramelessWindowHint here.
// Instead, we let the window have its native frame but hide it using WM_NCCALCSIZE.
// This preserves native window behaviors like taskbar animations, snapping, and system menus.
// ΓöÇΓöÇ Enable Transparency for Desktop Blur ΓöÇΓöÇ
setAttribute(Qt::WA_TranslucentBackground);
QString iconPath = Paths::getResourcePath("icon.png");
if (QFile::exists(iconPath)) {
setWindowIcon(QIcon(iconPath));
}
// Initialize network manager BEFORE UI is built
m_networkManager = new QNetworkAccessManager(this);
// Enable persistent disk cache for images (50 MB)
QNetworkDiskCache* diskCache = new QNetworkDiskCache(this);
QString cachePath = QDir(Paths::getLocalCacheDir()).filePath("image_cache");
QDir().mkpath(cachePath);
diskCache->setCacheDirectory(cachePath);
diskCache->setMaximumCacheSize(50 * 1024 * 1024); // 50 MB
m_networkManager->setCache(diskCache);
connect(m_networkManager, &QNetworkAccessManager::finished,
this, &MainWindow::onSearchFinished);
initUI();
// Apply Desktop Acrylic/Mica Blur
enableAcrylicBlur();
m_debounceTimer = new QTimer(this);
m_debounceTimer->setSingleShot(true);
connect(m_debounceTimer, &QTimer::timeout, this, &MainWindow::doSearch);
m_currentGlowColor = Colors::toQColor(Colors::PRIMARY);
m_targetGlowColor = m_currentGlowColor;
m_glowTimer = new QTimer(this);
connect(m_glowTimer, &QTimer::timeout, this, &MainWindow::updateAmbientGlow);
QTimer::singleShot(10, this, [this]() {
startSync();
fetchTrendingGames();
checkAppUpdate();
});
}
MainWindow::~MainWindow() {
if (m_activeReply) {
m_activeReply->abort();
m_activeReply->deleteLater();
}
// Terminate any running network downloader threads cleanly before destruction
if (m_syncWorker && m_syncWorker->isRunning()) {
m_syncWorker->requestInterruption();
m_syncWorker->quit();
m_syncWorker->wait(100);
}
}
// ΓöÇΓöÇ Win32 Acrylic/Mica Blur ΓöÇΓöÇ
void MainWindow::enableAcrylicBlur() {
#ifdef Q_OS_WIN
HWND hwnd = reinterpret_cast<HWND>(winId());
// Step 1: Extend DWM frame into entire client area (required for blur visibility)
MARGINS margins = {-1, -1, -1, -1};
DwmExtendFrameIntoClientArea(hwnd, &margins);
// Step 2: Try Windows 11 system backdrop (DWMWA_SYSTEMBACKDROP_TYPE = 38)
// Value 3 = DWMSBT_TRANSIENTWINDOW (Acrylic ΓÇö see-through blur)
int backdropType = 3;
HRESULT hr = DwmSetWindowAttribute(hwnd, 38, &backdropType, sizeof(backdropType));
// Step 3: If Win11 backdrop failed, use SetWindowCompositionAttribute (Win10 1803+)
if (FAILED(hr)) {
struct ACCENT_POLICY {
int AccentState;
int AccentFlags;
int GradientColor;
int AnimationId;
};
struct WINDOWCOMPOSITIONATTRIBDATA {
int Attrib;
PVOID pvData;
SIZE_T cbData;
};
typedef BOOL(WINAPI* pSetWindowCompositionAttribute)(HWND, WINDOWCOMPOSITIONATTRIBDATA*);
HMODULE hUser = GetModuleHandleA("user32.dll");
if (hUser) {
auto SetWCA = (pSetWindowCompositionAttribute)GetProcAddress(hUser, "SetWindowCompositionAttribute");
if (SetWCA) {
ACCENT_POLICY policy = {};
policy.AccentState = 4; // ACCENT_ENABLE_ACRYLICBLURBEHIND
policy.AccentFlags = 2; // ACCENT_FLAG_DRAW_ALL
policy.GradientColor = 0x33191B21; // AABBGGRR ΓÇö very light tint, mostly see-through
WINDOWCOMPOSITIONATTRIBDATA data = {};
data.Attrib = 19; // WCA_ACCENT_POLICY
data.pvData = &policy;
data.cbData = sizeof(policy);
SetWCA(hwnd, &data);
}
}
}
#endif
}
// ΓöÇΓöÇ Native event passthrough & Frameless Window Logic ΓöÇΓöÇ
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, qintptr *result) {
#ifdef Q_OS_WIN
MSG* msg = static_cast<MSG*>(message);
switch (msg->message) {
case WM_NCCALCSIZE: {
if (msg->wParam) {
// By returning 0 here, we tell Windows that the client area is the entire window,
// effectively removing the standard title bar while keeping the window "native".
*result = 0;
return true;
}
break;
}
case WM_NCHITTEST: {
const long border_width = 8;
RECT winrect;
GetWindowRect(msg->hwnd, &winrect);
long x = GET_X_LPARAM(msg->lParam);
long y = GET_Y_LPARAM(msg->lParam);
// 1. Resizing zones (highest priority)
bool left = x >= winrect.left && x < winrect.left + border_width;
bool right = x < winrect.right && x >= winrect.right - border_width;
bool top = y >= winrect.top && y < winrect.top + border_width;
bool bottom = y < winrect.bottom && y >= winrect.bottom - border_width;
if (left && top) { *result = HTTOPLEFT; return true; }
if (left && bottom) { *result = HTBOTTOMLEFT; return true; }
if (right && top) { *result = HTTOPRIGHT; return true; }
if (right && bottom) { *result = HTBOTTOMRIGHT; return true; }
if (left) { *result = HTLEFT; return true; }
if (right) { *result = HTRIGHT; return true; }
if (top) { *result = HTTOP; return true; }
if (bottom) { *result = HTBOTTOM; return true; }
// 2. Title Bar / Dragging zone
if (m_titleBar) {
// Use Qt's DPI-aware coordinate mapping instead of manual ScreenToClient.
// This correctly converts physical screen pixels (x, y) to logical widget pixels.
QPoint localPos = m_titleBar->mapFromGlobal(QPoint(x, y));
if (m_titleBar->rect().contains(localPos)) {
// Check if it's over a button inside the title bar
QWidget* w = m_titleBar->childAt(localPos);
if (w) {
// If it's a known system button, return the appropriate hit-test result
// to support native hover effects and menus (like Windows 11 Snap Layouts).
if (w->objectName() == "minBtn") { *result = HTMINBUTTON; return true; }
if (w->objectName() == "maxBtn") { *result = HTMAXBUTTON; return true; }
if (w->objectName() == "closeBtn") { *result = HTCLOSE; return true; }
// If it's another interactive widget (like a search input), let Qt handle it
if (qobject_cast<QPushButton*>(w) || qobject_cast<QLineEdit*>(w)) {
return false;
}
}
*result = HTCAPTION;
return true;
}
}
break;
}
}
#endif
return QMainWindow::nativeEvent(eventType, message, result);
}
void MainWindow::onTitleBarMinimize() {
showMinimized();
}
void MainWindow::onTitleBarMaximize() {
if (isMaximized()) {
showNormal();
} else {
showMaximized();
}
}
void MainWindow::onTitleBarClose() {
close();
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
if (event->type() == QEvent::MouseButtonPress) {
if (obj->property("isHeroSlide").toBool()) {
QString appId = obj->property("gameAppId").toString();
for (const auto& g : m_supportedGames) {
if (g.id == appId) {
// Build game data without creating a temporary GameCard
// (a stack-allocated card would be destroyed when this scope exits,
// leaving m_selectedCard as a dangling pointer → crash on Back)
QMap<QString, QString> cd;
cd["name"] = m_nameCache.value(g.id, g.id);
cd["appid"] = g.id;
cd["supported"] = "true";
cd["hasFix"] = g.hasFix ? "true" : "false";
// Deselect any previously selected card safely
if (m_selectedCard) m_selectedCard->setSelected(false);
m_selectedCard = nullptr; // No real card for hero slides
m_selectedGame = cd;
bool isSupported = true;
bool hasFix = g.hasFix;
m_gameDetailsPage->loadGame(cd["appid"], cd["name"], isSupported, hasFix);
m_stack->setCurrentIndex(3);
m_targetGlowColor = Colors::toQColor(Colors::PRIMARY);
m_glowTimer->start(16);
return true;
}
}
} else if (obj == m_topProfileWidget) {
// Open user profile dialog
QTimer::singleShot(50, this, [this]() {
showBlurOverlay();
UserProfileDialog* dlg = new UserProfileDialog(m_username, m_username, m_networkManager, this);
dlg->move(geometry().center() - dlg->rect().center());
connect(dlg, &UserProfileDialog::avatarUpdated, this, [this](const QString& b64) {
m_userData["avatar_url"] = b64;
QString appDataPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
QString settingsPath = appDataPath + "/settings.ini";
QSettings settings(settingsPath, QSettings::IniFormat);
settings.setValue("userData", QJsonDocument(m_userData).toJson());
updateSidebarAvatar();
});
QPointer<MainWindow> guard(this);
dlg->exec();
if (guard) guard->hideBlurOverlay();
dlg->deleteLater();
});
return true;
}
} else if (obj == m_sidebarWidget) {
// Sidebar is always expanded ΓÇö no animation
}
return QMainWindow::eventFilter(obj, event);
}
void MainWindow::expandSidebar() {
// Sidebar always expanded ΓÇö no-op
}
void MainWindow::collapseSidebarDelayed() {
// Sidebar always expanded ΓÇö no-op
}
void MainWindow::scrollCarousel() {
if (m_heroStack->count() <= 1 || !m_heroStack->isVisible()) return;
int oldIndex = m_currentHeroIndex;
if (oldIndex >= m_heroStack->count() || oldIndex < 0) {
oldIndex = 0;
}
m_currentHeroIndex = oldIndex + 1;
if (m_currentHeroIndex >= m_heroStack->count()) {
m_currentHeroIndex = 0;
}
QWidget* oldSlide = m_heroStack->widget(oldIndex);
QWidget* newSlide = m_heroStack->widget(m_currentHeroIndex);
if (!oldSlide || !newSlide || oldSlide == newSlide) return;
// Set up opacity effects for crossfade reusing existing if present to avoid animation conflict races
auto* fadeOutEffect = qobject_cast<QGraphicsOpacityEffect*>(oldSlide->graphicsEffect());
if (!fadeOutEffect) {
fadeOutEffect = new QGraphicsOpacityEffect(oldSlide);
oldSlide->setGraphicsEffect(fadeOutEffect);
}
fadeOutEffect->setOpacity(1.0);
auto* fadeInEffect = qobject_cast<QGraphicsOpacityEffect*>(newSlide->graphicsEffect());
if (!fadeInEffect) {
fadeInEffect = new QGraphicsOpacityEffect(newSlide);
newSlide->setGraphicsEffect(fadeInEffect);
}
fadeInEffect->setOpacity(0.0);
// Switch to new slide (it's invisible at opacity 0)
m_heroStack->setCurrentIndex(m_currentHeroIndex);
// Animate fade-out of old slide
auto* fadeOut = new QPropertyAnimation(fadeOutEffect, "opacity", this);
fadeOut->setDuration(400);
fadeOut->setStartValue(1.0);
fadeOut->setEndValue(0.0);
fadeOut->setEasingCurve(QEasingCurve::InOutQuad);
// Animate fade-in of new slide
auto* fadeIn = new QPropertyAnimation(fadeInEffect, "opacity", this);
fadeIn->setDuration(400);
fadeIn->setStartValue(0.0);
fadeIn->setEndValue(1.0);
fadeIn->setEasingCurve(QEasingCurve::InOutQuad);
fadeOut->start(QAbstractAnimation::DeleteWhenStopped);
fadeIn->start(QAbstractAnimation::DeleteWhenStopped);
updateHeroIndicators();
}
void MainWindow::jumpToHeroSlide(int index) {
if (!m_heroStack || index < 0 || index >= m_heroStack->count() || index == m_currentHeroIndex) return;
int oldIndex = m_currentHeroIndex;
if (oldIndex >= m_heroStack->count() || oldIndex < 0) {
oldIndex = 0;
}
m_currentHeroIndex = index;
QWidget* oldSlide = m_heroStack->widget(oldIndex);
QWidget* newSlide = m_heroStack->widget(m_currentHeroIndex);
if (!oldSlide || !newSlide || oldSlide == newSlide) return;
auto* fadeOutEffect = qobject_cast<QGraphicsOpacityEffect*>(oldSlide->graphicsEffect());
if (!fadeOutEffect) {
fadeOutEffect = new QGraphicsOpacityEffect(oldSlide);
oldSlide->setGraphicsEffect(fadeOutEffect);
}
fadeOutEffect->setOpacity(1.0);
auto* fadeInEffect = qobject_cast<QGraphicsOpacityEffect*>(newSlide->graphicsEffect());
if (!fadeInEffect) {
fadeInEffect = new QGraphicsOpacityEffect(newSlide);
newSlide->setGraphicsEffect(fadeInEffect);
}
fadeInEffect->setOpacity(0.0);
m_heroStack->setCurrentIndex(m_currentHeroIndex);
auto* fadeOut = new QPropertyAnimation(fadeOutEffect, "opacity", this);
fadeOut->setDuration(300);
fadeOut->setStartValue(1.0);
fadeOut->setEndValue(0.0);
fadeOut->setEasingCurve(QEasingCurve::InOutQuad);
auto* fadeIn = new QPropertyAnimation(fadeInEffect, "opacity", this);
fadeIn->setDuration(300);
fadeIn->setStartValue(0.0);
fadeIn->setEndValue(1.0);
fadeIn->setEasingCurve(QEasingCurve::InOutQuad);
fadeOut->start(QAbstractAnimation::DeleteWhenStopped);
fadeIn->start(QAbstractAnimation::DeleteWhenStopped);
updateHeroIndicators();
// Reset the auto-scroll timer
if (m_heroCarouselTimer->isActive()) {
m_heroCarouselTimer->start(5000);
}
}
void MainWindow::updateHeroIndicators() {
if (!m_heroIndicatorLayout) return;
int count = m_heroStack ? m_heroStack->count() : 0;
// Clear existing indicators
QLayoutItem* child;
while ((child = m_heroIndicatorLayout->takeAt(0)) != nullptr) {
if (child->widget()) child->widget()->deleteLater();
delete child;
}
if (count <= 1) return; // No indicators needed for 0 or 1 slides
for (int i = 0; i < count; ++i) {
QPushButton* bar = new QPushButton();
bar->setFixedSize(i == m_currentHeroIndex ? 36 : 24, 4);
bar->setCursor(Qt::PointingHandCursor);
bar->setFlat(true);
if (i == m_currentHeroIndex) {
bar->setStyleSheet(
"QPushButton { background: qlineargradient(x1:0, y1:0, x2:1, y2:0, "
"stop:0 #bb86fc, stop:1 #6200ee); border: none; border-radius: 2px; }"
);
} else {
bar->setStyleSheet(
"QPushButton { background: rgba(255,255,255,60); border: none; border-radius: 2px; }"
"QPushButton:hover { background: rgba(255,255,255,120); }"
);
}
connect(bar, &QPushButton::clicked, this, [this, i]() {
jumpToHeroSlide(i);
});
m_heroIndicatorLayout->addWidget(bar);
}
}
void MainWindow::updateAmbientGlow() {
int dr = m_targetGlowColor.red() - m_currentGlowColor.red();
int dg = m_targetGlowColor.green() - m_currentGlowColor.green();
int db = m_targetGlowColor.blue() - m_currentGlowColor.blue();
if (qAbs(dr) < 2 && qAbs(dg) < 2 && qAbs(db) < 2) {
m_currentGlowColor = m_targetGlowColor;
m_glowTimer->stop();
} else {
m_currentGlowColor.setRed(m_currentGlowColor.red() + dr * 0.1);
m_currentGlowColor.setGreen(m_currentGlowColor.green() + dg * 0.1);
m_currentGlowColor.setBlue(m_currentGlowColor.blue() + db * 0.1);
}
update();
}
void MainWindow::paintEvent(QPaintEvent* event) {
Q_UNUSED(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
// ΓöÇΓöÇ Pitch black background ΓöÇΓöÇ
painter.fillRect(rect(), QColor(0, 0, 0));
// ΓöÇΓöÇ Subtle dark blue secondary glow (top right) ΓöÇΓöÇ
QRadialGradient glow1(rect().width() * 0.75, rect().height() * 0.25, rect().width() * 0.4);
QColor darkBlue = Colors::toQColor(Colors::SECONDARY);
darkBlue.setAlpha(12); // Extremely subtle light blue
glow1.setColorAt(0, darkBlue);
glow1.setColorAt(1, QColor(0, 0, 0, 0));
painter.fillRect(rect(), glow1);
// ΓöÇΓöÇ Subtle dark blue secondary glow (bottom left) ΓöÇΓöÇ
QRadialGradient glow2(rect().width() * 0.2, rect().height() * 0.9, rect().width() * 0.5);
QColor veryDarkBlue = Colors::toQColor(Colors::TERTIARY);
veryDarkBlue.setAlpha(8);
glow2.setColorAt(0, veryDarkBlue);
glow2.setColorAt(1, QColor(0, 0, 0, 0));
painter.fillRect(rect(), glow2);
}
void MainWindow::dragEnterEvent(QDragEnterEvent* event) {
if (event->mimeData()->hasUrls()) {
QList<QUrl> urls = event->mimeData()->urls();
for (const QUrl& url : urls) {
if (url.isLocalFile() && url.toLocalFile().endsWith(".lua", Qt::CaseInsensitive)) {
event->acceptProposedAction();
return;
}
}
}
}
void MainWindow::dropEvent(QDropEvent* event) {
QList<QUrl> urls = event->mimeData()->urls();
if (urls.isEmpty()) return;
QString pluginDir = Config::getSteamPluginDir();
QDir dir(pluginDir);
if (!dir.exists()) dir.mkpath(".");
int count = 0;
QString lastFile;
for (const QUrl& url : urls) {
if (url.isLocalFile()) {
QString srcPath = url.toLocalFile();
if (srcPath.endsWith(".lua", Qt::CaseInsensitive)) {
QString fileName = QFileInfo(srcPath).fileName();
QString destPath = dir.filePath(fileName);
QFile::remove(destPath); // Overwrite
if (QFile::copy(srcPath, destPath)) {
count++;
lastFile = fileName;
}
}
}
}
if (count > 0) {
m_statusLabel->setText(QString("Installed %1 patch%2").arg(count).arg(count > 1 ? "es" : ""));
if (m_currentMode == AppMode::Library) {
displayLibrary();
} else {
// Switch to library to show the new patch
m_tabLibrary->animateClick();
}
event->acceptProposedAction();
}
}
void MainWindow::initUI() {
QWidget* central = new QWidget(this);
setCentralWidget(central);
QVBoxLayout* wrapperLayout = new QVBoxLayout(central);
wrapperLayout->setContentsMargins(0, 0, 0, 0);
wrapperLayout->setSpacing(0);
// ΓöÇΓöÇ Custom Title Bar ΓöÇΓöÇ
m_titleBar = new CustomTitleBar(this);
connect(m_titleBar, &CustomTitleBar::minimizeRequested, this, &MainWindow::onTitleBarMinimize);
connect(m_titleBar, &CustomTitleBar::maximizeRequested, this, &MainWindow::onTitleBarMaximize);
connect(m_titleBar, &CustomTitleBar::closeRequested, this, &MainWindow::onTitleBarClose);
wrapperLayout->addWidget(m_titleBar);
QHBoxLayout* rootLayout = new QHBoxLayout();
wrapperLayout->addLayout(rootLayout);
rootLayout->setContentsMargins(0, 0, 0, 0);
rootLayout->setSpacing(0);
// ΓöÇΓöÇΓöÇΓöÇ Material Navigation Rail (Sidebar) ΓöÇΓöÇΓöÇΓöÇ
m_sidebarWidget = new QWidget(this);
m_sidebarWidget->setObjectName("sidebar");
m_sidebarWidget->setFixedWidth(240);
m_sidebarWidget->setAttribute(Qt::WA_StyledBackground);
m_sidebarWidget->setAutoFillBackground(false);
m_sidebarWidget->setStyleSheet(QString(
"background-color: #000000; border-right: 1px solid rgba(255, 255, 255, 13);"
));
m_sidebarWidget->installEventFilter(this);
// Animation setup
m_sidebarCollapseTimer = new QTimer(this);
m_sidebarCollapseTimer->setSingleShot(true);
connect(m_sidebarCollapseTimer, &QTimer::timeout, this, &MainWindow::collapseSidebarDelayed);
// Inner container, now allows shrinking so buttons get narrow!
QWidget* sidebarInner = new QWidget();
sidebarInner->setMinimumWidth(60);
sidebarInner->setStyleSheet("background: transparent; border: none;");
QVBoxLayout* sidebarInnerLayout = new QVBoxLayout(sidebarInner);
sidebarInnerLayout->setContentsMargins(16, 24, 16, 16);
sidebarInnerLayout->setSpacing(12);
QVBoxLayout* sidebarOuterLayout = new QVBoxLayout(m_sidebarWidget);
sidebarOuterLayout->setContentsMargins(0, 0, 0, 0);
sidebarOuterLayout->setAlignment(Qt::AlignLeft);
sidebarOuterLayout->addWidget(sidebarInner);
// ΓöÇΓöÇ App header with actual logo ΓöÇΓöÇ
QHBoxLayout* headerLayout = new QHBoxLayout();
headerLayout->setSpacing(12);
QLabel* appIconLabel = new QLabel();
appIconLabel->setFixedSize(36, 36);
QString iconPath = Paths::getResourcePath("icon.png");
if (QFile::exists(iconPath)) {
QPixmap logoPixmap(iconPath);
appIconLabel->setPixmap(logoPixmap.scaled(36, 36, Qt::KeepAspectRatio, Qt::SmoothTransformation));
} else {
// Fallback: draw a Material Flash icon
appIconLabel->setStyleSheet(QString(
"background: %1; border-radius: 10px; border: none;"
).arg(Colors::PRIMARY_CONTAINER));
}
appIconLabel->setStyleSheet(appIconLabel->styleSheet() + " border: none; background: transparent;");
headerLayout->addWidget(appIconLabel);
m_appTitleLabel = new QLabel("Lua Patcher");
m_appTitleLabel->setStyleSheet(QString(
"font-size: 20px; font-weight: 700; letter-spacing: -1px; color: %1; background: transparent; border: none; font-family: 'Oswald', sans-serif;"
).arg(Colors::ON_SURFACE));
headerLayout->addWidget(m_appTitleLabel);
headerLayout->addStretch();
sidebarInnerLayout->addLayout(headerLayout);
sidebarInnerLayout->addSpacing(30);
// ΓöÇΓöÇ Section label ΓöÇΓöÇ
m_navTitleLabel = new QLabel("NAVIGATION");
m_navTitleLabel->setStyleSheet(QString(
"font-size: 10px; font-weight: 600; color: %1; letter-spacing: 1px;"
" background: transparent; border: none; padding-left: 4px; font-family: 'Oswald', sans-serif;"
).arg(Colors::OUTLINE));
m_navTitleLabel->hide();
sidebarInnerLayout->addWidget(m_navTitleLabel);
sidebarInnerLayout->addSpacing(4);
// m_appTitleLabel->hide();
// m_navTitleLabel->hide();
// Navigation tabs
m_tabLua = new GlassButton(MaterialIcons::Home, " App Store", "", Colors::PRIMARY);
m_tabLua->setFixedHeight(45);
connect(m_tabLua, &QPushButton::clicked, this, [this](){ switchMode(AppMode::LuaPatcher); });
sidebarInnerLayout->addWidget(m_tabLua);
m_tabLibrary = new GlassButton(MaterialIcons::Library, " Library", "", Colors::PRIMARY);
m_tabLibrary->setFixedHeight(45);
connect(m_tabLibrary, &QPushButton::clicked, this, [this](){ switchMode(AppMode::Library); });
sidebarInnerLayout->addWidget(m_tabLibrary);
// ΓöÇΓöÇ Animated sidebar indicator bar ΓöÇΓöÇ
m_sidebarIndicator = new QWidget(m_sidebarWidget);
m_sidebarIndicator->setFixedSize(6, 28);
m_sidebarIndicator->setStyleSheet("background: #EFECE3; border-radius: 2px;");
m_sidebarIndicator->raise();
m_indicatorAnimation = new QPropertyAnimation(m_sidebarIndicator, "pos", this);
m_indicatorAnimation->setDuration(250);
m_indicatorAnimation->setEasingCurve(QEasingCurve::OutCubic);
sidebarInnerLayout->addStretch();
m_btnRestart = new GlassButton(MaterialIcons::Steam, " Restart Steam", "", Colors::OUTLINE);
m_btnRestart->setFixedHeight(45);
connect(m_btnRestart, &QPushButton::clicked, this, &MainWindow::doRestart);
sidebarInnerLayout->addWidget(m_btnRestart);
sidebarInnerLayout->addSpacing(8);
m_tabSettings = new GlassButton(MaterialIcons::Settings, " Settings", "", Colors::OUTLINE);
m_tabSettings->setFixedHeight(45);
connect(m_tabSettings, &QPushButton::clicked, this, [this](){ switchMode(AppMode::Settings); });
sidebarInnerLayout->addWidget(m_tabSettings);
sidebarInnerLayout->addSpacing(8);
// Pro Pass Promo Card
m_statusLabel = new QLabel("Initializing...");
m_statusLabel->hide();
sidebarInnerLayout->addSpacing(16);
// Divider before version info
QFrame* line2 = new QFrame();
line2->setFrameShape(QFrame::HLine);
line2->setFixedHeight(1);
line2->setStyleSheet(QString("background: %1; border: none;").arg(Colors::OUTLINE_VARIANT));
sidebarInnerLayout->addWidget(line2);
sidebarInnerLayout->addSpacing(8);
m_infoTitleLabel = new QLabel(QString("v%1<br>by <a href=\"https://github.com/sayedalimollah2602-prog\" style=\"color: %2; text-decoration: none;\">leVI</a> & <a href=\"https://github.com/raxnmint\" style=\"color: %2; text-decoration: none;\">raxnmint</a>").arg(Config::APP_VERSION).arg(Colors::ON_SURFACE_VARIANT));
m_infoTitleLabel->setStyleSheet(QString("color: %1; font-size: 10px; font-weight: bold; font-family: 'Oswald', sans-serif; background: transparent; border: none;").arg(Colors::ON_SURFACE_VARIANT));
m_infoTitleLabel->setAlignment(Qt::AlignCenter);
m_infoTitleLabel->setTextFormat(Qt::RichText);
m_infoTitleLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
m_infoTitleLabel->setOpenExternalLinks(true);
sidebarInnerLayout->addWidget(m_infoTitleLabel);
m_infoTitleLabel->hide(); // Start collapsed
m_infoTitleLabel->hide(); // Start collapsed
rootLayout->addWidget(m_sidebarWidget);
// ΓöÇΓöÇΓöÇΓöÇ Content Area ΓöÇΓöÇΓöÇΓöÇ
QWidget* contentWidget = new QWidget();
contentWidget->setStyleSheet("background: transparent;");
QVBoxLayout* mainLayout = new QVBoxLayout(contentWidget);
mainLayout->setContentsMargins(0, 40, 30, 20);
mainLayout->setSpacing(20);
// ΓöÇΓöÇ Top Bar (Search + Profile) ΓöÇΓöÇ
QWidget* topBarWidget = new QWidget();
QHBoxLayout* topBarLayout = new QHBoxLayout(topBarWidget);
topBarLayout->setContentsMargins(0, 0, 0, 0);
topBarLayout->setSpacing(16);
// Search Container
QWidget* searchContainer = new QWidget();
searchContainer->setStyleSheet(QString(
"background: rgba(255, 255, 255, 12); border-radius: 16px; border: 1px solid rgba(255, 255, 255, 25);"
));
searchContainer->setFixedHeight(56);
QHBoxLayout* searchLayout = new QHBoxLayout(searchContainer);
searchLayout->setContentsMargins(12, 4, 12, 4);
MaterialIconWidget* searchIconWidget = new MaterialIconWidget(
MaterialIcons::Search, Colors::toQColor(Colors::ON_SURFACE_VARIANT), 32);
searchLayout->addWidget(searchIconWidget);
m_searchInput = new QLineEdit();
m_searchInput->setPlaceholderText("Search thousands of games...");
m_searchInput->setStyleSheet(QString(
"QLineEdit { background: transparent; border: none; font-size: 15px; color: %1; padding: 0 8px; }"
"QLineEdit:focus { border: none; background: transparent; }"
).arg(Colors::ON_SURFACE));
connect(m_searchInput, &QLineEdit::textChanged, this, &MainWindow::onSearchChanged);
searchLayout->addWidget(m_searchInput);
MaterialIconButton* refreshBtn = new MaterialIconButton(
MaterialIcons::Refresh, Colors::toQColor(Colors::ON_SURFACE_VARIANT), 36);
connect(refreshBtn, &QPushButton::clicked, this, [this]() {
if (m_searchInput->text().trimmed().isEmpty()) startSync(); else doSearch();
});
searchLayout->addWidget(refreshBtn);
topBarLayout->addWidget(searchContainer, 1);
// Top Bar Right Side (Notifications)
QWidget* topActions = new QWidget();
QHBoxLayout* topActionsLayout = new QHBoxLayout(topActions);
topActionsLayout->setContentsMargins(0, 0, 0, 0);
m_mainNotifBtn = new MaterialIconButton(MaterialIcons::Notifications, Colors::toQColor(Colors::ON_SURFACE_VARIANT), 40, topActions);
connect(m_mainNotifBtn, &QPushButton::clicked, this, &MainWindow::onNotificationClicked);
// Add badge
m_mainNotifBadge = new QLabel(m_mainNotifBtn);
m_mainNotifBadge->setFixedSize(16, 16);
m_mainNotifBadge->setAlignment(Qt::AlignCenter);
m_mainNotifBadge->move(20, 6);
m_mainNotifBadge->setStyleSheet(
"background: #E74C3C;"
"color: white;"
"font-size: 9px;"
"font-weight: bold;"
"font-family: 'Oswald', sans-serif;"
"border-radius: 8px;"
"border: none;"
);
m_mainNotifBadge->hide();
topActionsLayout->addWidget(m_mainNotifBtn);
topBarLayout->addWidget(topActions);
mainLayout->addWidget(topBarWidget);
// Stacked widget: page 0 = loading, page 1 = main content
m_stack = new QStackedWidget();
QWidget* pageLoading = new QWidget();
QVBoxLayout* layLoading = new QVBoxLayout(pageLoading);
layLoading->setAlignment(Qt::AlignCenter);
m_spinner = new LoadingSpinner();
layLoading->addWidget(m_spinner);
m_stack->addWidget(pageLoading); // index 0
// ΓöÇΓöÇ Main Content Page (Scrollable) ΓöÇΓöÇ
m_mainScrollArea = new QScrollArea();
m_mainScrollArea->setWidgetResizable(true);
m_mainScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_mainScrollArea->setFrameShape(QFrame::NoFrame);
m_mainScrollArea->setStyleSheet(QString(
"QScrollArea { background: transparent; border: none; }"
"QScrollBar:vertical { background: %1; width: 8px; border-radius: 4px; }"
"QScrollBar::handle:vertical { background: %2; border-radius: 4px; min-height: 30px; }"
"QScrollBar::handle:vertical:hover { background: %3; }"
).arg("rgba(0,0,0,0)").arg(Colors::OUTLINE_VARIANT).arg(Colors::OUTLINE));
m_mainScrollContainer = new QWidget();
m_mainScrollContainer->setStyleSheet("background: transparent;");
m_mainScrollLayout = new QVBoxLayout(m_mainScrollContainer);
// Increased horizontal padding (15px) and spacing (10px) to perfectly fit the 175px game cards
m_mainScrollLayout->setContentsMargins(15, 0, 15, 20);
m_mainScrollLayout->setSpacing(10);
// 1. Hero Stack ΓÇö holds up to 4 trending games, shows exactly one at a time
QWidget* trendingHeader = new QWidget();
QHBoxLayout* trendLay = new QHBoxLayout(trendingHeader);
trendLay->setContentsMargins(0, 0, 0, 8);
trendLay->setSpacing(8);
QLabel* trendIcon = new QLabel();
trendIcon->setPixmap(MaterialIcons::getPixmap(MaterialIcons::Flash, 28, QColor(255, 255, 255)));
m_leadingTitlesLabel = new QLabel("<span style='color: #ffffff;'>TRENDING TITLES</span>");
m_leadingTitlesLabel->setStyleSheet("font-size: 24px; font-weight: 800; padding-left: 0px; font-family: 'Oswald', sans-serif;");
trendLay->addWidget(trendIcon);
trendLay->addWidget(m_leadingTitlesLabel);
trendLay->addStretch();
m_heroStack = new QStackedWidget();
m_heroStack->setFixedHeight(320);
m_heroStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_heroStack->setStyleSheet("background: transparent; border: none; border-radius: 25px;");
m_mainScrollLayout->addWidget(trendingHeader, 0, Qt::AlignLeft);
m_mainScrollLayout->addWidget(m_heroStack);
// Pagination indicators (Steam-style bars)
m_heroIndicators = new QWidget();
m_heroIndicators->setFixedHeight(20);
m_heroIndicators->setMaximumWidth(1200);
m_heroIndicators->setStyleSheet("background: transparent;");