summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-11-22 21:02:36 -0500
committerGravatar Zach Hilman2018-12-03 17:26:27 -0500
commit4fb59fdfe1e5fe2d0b9313c395e0d7c880e00c6f (patch)
treef8ccb5bf5e31a915a0572e1789f8b08dd9796f27 /src/core
parentqt: Register to use Qt ProfileSelector instead of default (diff)
downloadyuzu-4fb59fdfe1e5fe2d0b9313c395e0d7c880e00c6f.tar.gz
yuzu-4fb59fdfe1e5fe2d0b9313c395e0d7c880e00c6f.tar.xz
yuzu-4fb59fdfe1e5fe2d0b9313c395e0d7c880e00c6f.zip
applets: Implement ProfileSelect applet
Allows the player to select an emulated profile.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/service/am/applets/profile_select.cpp76
-rw-r--r--src/core/hle/service/am/applets/profile_select.h54
2 files changed, 130 insertions, 0 deletions
diff --git a/src/core/hle/service/am/applets/profile_select.cpp b/src/core/hle/service/am/applets/profile_select.cpp
new file mode 100644
index 000000000..750f0fdeb
--- /dev/null
+++ b/src/core/hle/service/am/applets/profile_select.cpp
@@ -0,0 +1,76 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <cstring>
6#include "common/assert.h"
7#include "common/string_util.h"
8#include "core/core.h"
9#include "core/frontend/applets/software_keyboard.h"
10#include "core/hle/service/am/am.h"
11#include "core/hle/service/am/applets/profile_select.h"
12
13namespace Service::AM::Applets {
14
15constexpr ResultCode ERR_USER_CANCELLED_SELECTION{ErrorModule::Account, 1};
16
17ProfileSelect::ProfileSelect() = default;
18ProfileSelect::~ProfileSelect() = default;
19
20void ProfileSelect::Initialize() {
21 complete = false;
22 status = RESULT_SUCCESS;
23 final_data.clear();
24
25 Applet::Initialize();
26
27 const auto user_config_storage = broker.PopNormalDataToApplet();
28 ASSERT(user_config_storage != nullptr);
29 const auto& user_config = user_config_storage->GetData();
30
31 ASSERT(user_config.size() >= sizeof(UserSelectionConfig));
32 std::memcpy(&config, user_config.data(), sizeof(UserSelectionConfig));
33}
34
35bool ProfileSelect::TransactionComplete() const {
36 return complete;
37}
38
39ResultCode ProfileSelect::GetStatus() const {
40 return status;
41}
42
43void ProfileSelect::ExecuteInteractive() {
44 UNREACHABLE_MSG("Attempted to call interactive execution on non-interactive applet.");
45}
46
47void ProfileSelect::Execute() {
48 if (complete) {
49 broker.PushNormalDataFromApplet(IStorage{final_data});
50 return;
51 }
52
53 const auto& frontend{Core::System::GetInstance().GetProfileSelector()};
54
55 frontend.SelectProfile([this](std::optional<Account::UUID> uuid) { SelectionComplete(uuid); });
56}
57
58void ProfileSelect::SelectionComplete(std::optional<Account::UUID> uuid) {
59 UserSelectionOutput output{};
60
61 if (uuid.has_value() && uuid->uuid != Account::INVALID_UUID) {
62 output.result = 0;
63 output.uuid_selected = uuid->uuid;
64 } else {
65 status = ERR_USER_CANCELLED_SELECTION;
66 output.result = ERR_USER_CANCELLED_SELECTION.raw;
67 output.uuid_selected = Account::INVALID_UUID;
68 }
69
70 final_data = std::vector<u8>(sizeof(UserSelectionOutput));
71 std::memcpy(final_data.data(), &output, final_data.size());
72 broker.PushNormalDataFromApplet(IStorage{final_data});
73 broker.SignalStateChanged();
74}
75
76} // namespace Service::AM::Applets
diff --git a/src/core/hle/service/am/applets/profile_select.h b/src/core/hle/service/am/applets/profile_select.h
new file mode 100644
index 000000000..c383527f4
--- /dev/null
+++ b/src/core/hle/service/am/applets/profile_select.h
@@ -0,0 +1,54 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <string>
9#include <vector>
10
11#include "common/common_funcs.h"
12#include "common/swap.h"
13#include "core/hle/service/acc/profile_manager.h"
14#include "core/hle/service/am/am.h"
15#include "core/hle/service/am/applets/applets.h"
16
17namespace Service::AM::Applets {
18
19struct UserSelectionConfig {
20 // TODO(DarkLordZach): RE this structure
21 // It seems to be flags and the like that determine the UI of the applet on the switch... from
22 // my research this is safe to ignore for now.
23 INSERT_PADDING_BYTES(0xA0);
24};
25static_assert(sizeof(UserSelectionConfig) == 0xA0, "UserSelectionConfig has incorrect size.");
26
27struct UserSelectionOutput {
28 u64 result;
29 u128 uuid_selected;
30};
31static_assert(sizeof(UserSelectionOutput) == 0x18, "UserSelectionOutput has incorrect size.");
32
33class ProfileSelect final : public Applet {
34public:
35 ProfileSelect();
36 ~ProfileSelect() override;
37
38 void Initialize() override;
39
40 bool TransactionComplete() const override;
41 ResultCode GetStatus() const override;
42 void ExecuteInteractive() override;
43 void Execute() override;
44
45 void SelectionComplete(std::optional<Account::UUID> uuid);
46
47private:
48 UserSelectionConfig config;
49 bool complete = false;
50 ResultCode status = RESULT_SUCCESS;
51 std::vector<u8> final_data;
52};
53
54} // namespace Service::AM::Applets