Debian Codegraph @

Source/Core/DolphinQt/SkylanderPortal/SkylanderPortalWindow.h

raw symbols SCIP
1 // Copyright 2022 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <array>
7 #include <optional>
8
9 #include <QBrush>
10 #include <QFrame>
11 #include <QString>
12 #include <QTimer>
13 #include <QVBoxLayout>
14 #include <QWidget>
15
16 #include "Core/Core.h"
17 #include "Core/IOS/USB/Emulated/Skylanders/Skylander.h"
18 #include "Core/IOS/USB/Emulated/Skylanders/SkylanderFigure.h"
19
20 class QCheckBox;
21 class QGroupBox;
22 class QLineEdit;
23 class QPushButton;
24 class QRadioButton;
25 class QListWidget;
26
27 using Element = IOS::HLE::USB::Element;
28 using Game = IOS::HLE::USB::Game;
29 using Type = IOS::HLE::USB::Type;
30
31 constexpr u8 NUM_SKYLANDER_ELEMENTS_RADIO = NUM_SKYLANDER_ELEMENTS + 1;
32
33 struct Skylander
34 {
35 u8 portal_slot;
36 u16 m_sky_id;
37 u16 m_sky_var;
38 };
39
40 class SkylanderPortalWindow : public QWidget
41 {
42 Q_OBJECT
43 public:
44 explicit SkylanderPortalWindow(QWidget* parent = nullptr);
45 ~SkylanderPortalWindow() override;
46
47 void RefreshList();
48
49 protected:
50 std::array<QLineEdit*, MAX_SKYLANDERS> m_edit_skylanders;
51 std::array<std::optional<Skylander>, MAX_SKYLANDERS> m_sky_slots;
52
53 private:
54 // Window
55 void CreateMainWindow();
56 QVBoxLayout* CreateSlotLayout();
57 QVBoxLayout* CreateFinderLayout();
58 void closeEvent(QCloseEvent* bar) override;
59 bool eventFilter(QObject* object, QEvent* event) final;
60
61 // UI
62 void EmulatePortal(bool emulate);
63 void SelectCollectionPath();
64 void LoadSelected();
65 void LoadFromFile();
66 void ClearSlot(u8 slot);
67 void CreateSkylanderAdvanced();
68 void ModifySkylander();
69
70 // Behind the scenes
71 void OnEmulationStateChanged(Core::State state);
72 void OnCollectionPathChanged();
73 void UpdateCurrentIDs();
74 void CreateSkyfile(const QString& path, bool load_after);
75 void LoadSkyfilePath(u8 slot, const QString& path);
76 void UpdateSlotNames();
77
78 // Helpers
79 bool PassesFilter(const QString& name, u16 id, u16 var) const;
80 QString GetFilePath(u16 id, u16 var) const;
81 u8 GetCurrentSlot() const;
82 int GetElementRadio() const;
83 int GetTypeRadio() const;
84 static QBrush GetBaseColor(std::pair<const u16, const u16> ids, bool dark_theme);
85 static int GetGameID(Game game);
86 static int GetElementID(Element elem);
87 static int GetTypeID(Type type);
88
89 bool m_emulating;
90 QCheckBox* m_enabled_checkbox;
91 QFrame* m_group_skylanders;
92 QFrame* m_command_buttons;
93 std::array<QRadioButton*, MAX_SKYLANDERS> m_slot_radios;
94
95 // Qt is not guaranteed to keep track of file paths using native file pickers, so we use this
96 // variable to ensure we open at the most recent Skylander file location
97 QString m_last_skylander_path;
98
99 QString m_collection_path;
100 QLineEdit* m_path_edit;
101 QPushButton* m_path_select;
102
103 std::array<QCheckBox*, NUM_SKYLANDER_GAMES> m_game_filters;
104 std::array<QRadioButton*, NUM_SKYLANDER_ELEMENTS_RADIO> m_element_filter;
105 std::array<QRadioButton*, NUM_SKYLANDER_TYPES> m_type_filter;
106 QCheckBox* m_only_show_collection;
107 QLineEdit* m_sky_search;
108 QListWidget* m_skylander_list;
109 u16 m_sky_id = 0;
110 u16 m_sky_var = 0;
111 };