Skip to content

Commit

Permalink
Add new quick menu, controller applet...
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Nov 16, 2019
1 parent 71b7d03 commit 3a90499
Show file tree
Hide file tree
Showing 16 changed files with 377 additions and 17 deletions.
29 changes: 29 additions & 0 deletions CurrentChangelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Changelog

- Settings menu

- New settings were added:

- Console information upload (enable/disable)

- Automatic titles' download (e/d)

- Console auto-update (e/d)

- Bluetooth (e/d)

- 3.0 USB (e/d)

- NFC (e/d)

- Wireless LAN (e/d)

- MAC address

- Serial number

- General

- Custom icons in entry JSONs can now be used with normal titles too, not just homebrew.

- Certain parts of the code/functionality were slightly improved (speed might be slightly faster in certain laggy moments)
4 changes: 4 additions & 0 deletions LibraryAppletQMenu/Include/ui/ui_MenuLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <ui/ui_SideMenu.hpp>
#include <ui/ui_RawData.hpp>
#include <ui/ui_ClickableImage.hpp>
#include <ui/ui_QuickMenu.hpp>
#include <cfg/cfg_Config.hpp>

namespace ui
Expand Down Expand Up @@ -33,6 +34,8 @@ namespace ui
void HandleWebPageOpen();
void HandleSettingsMenu();
void HandleThemesMenu();
void HandleControllerAppletOpen();
void HandleShowHelp();
void HandleMultiselectMoveToFolder(std::string folder);
void StopMultiselect();
private:
Expand All @@ -58,6 +61,7 @@ namespace ui
pu::ui::elm::TextBlock::Ref itemVersion;
pu::ui::elm::Image::Ref bannerImage;
ClickableImage::Ref menuToggle;
QuickMenu::Ref quickMenu;
std::string curfolder;
std::chrono::steady_clock::time_point tp;
bool warnshown;
Expand Down
65 changes: 65 additions & 0 deletions LibraryAppletQMenu/Include/ui/ui_QuickMenu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

#pragma once
#include <q_Include.hpp>
#include <pu/Plutonium>

namespace ui
{
enum class QuickMenuDirection
{
Up,
Down,
Left,
Right,
UpLeft,
UpRight,
DownLeft,
DownRight,
None
};

struct QuickMenuSubItem
{
std::function<void()> on_select;
pu::ui::render::NativeTexture nicon;
};

class QuickMenu : public pu::ui::elm::Element
{
static constexpr s32 MainItemSize = 300;
static constexpr s32 SubItemsSize = 150;
static constexpr s32 CommonAreaSize = 50;

static constexpr s32 MainItemX = (1280 - MainItemSize) / 2;
static constexpr s32 MainItemY = (720 - MainItemSize) / 2;

public:
QuickMenu(std::string main_icon);
PU_SMART_CTOR(QuickMenu)
~QuickMenu();

void SetEntry(QuickMenuDirection direction, std::string icon, std::function<void()> on_selected);
void RemoveEntry(QuickMenuDirection direction);

s32 GetX();
s32 GetY();
s32 GetWidth();
s32 GetHeight();

bool IsOn();

void OnRender(pu::ui::render::Renderer::Ref &Drawer, s32 X, s32 Y);
void OnInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);

private:
QuickMenuDirection GetCurrentDirection();
std::tuple<s32, s32> ComputePositionForDirection(QuickMenuDirection direction);
bool on;
s64 off_wait;
pu::ui::render::NativeTexture nmain;
u64 lastheld;
s32 bgalpha;
s32 fgalpha;
std::map<QuickMenuDirection, QuickMenuSubItem> item_map;
};
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions LibraryAppletQMenu/Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int main()
if(R_SUCCEEDED(rc))
{
am::QDaemonStatus status = {};

// Information block sent as an extra storage to QMenu.
am::QLibraryAppletReadStorage(&status, sizeof(status));

Expand Down
57 changes: 51 additions & 6 deletions LibraryAppletQMenu/Source/ui/ui_MenuLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ namespace ui
this->itemsMenu->SetOnSelectionChanged(std::bind(&MenuLayout::menu_OnSelected, this, std::placeholders::_1));
qapp->ApplyConfigForElement("main_menu", "items_menu", this->itemsMenu, false); // Main menu must be visible, and only Y is customizable here
this->Add(this->itemsMenu);

this->quickMenu = QuickMenu::New(cfg::ProcessedThemeResource(theme, "ui/QuickMenuMain.png"));

this->quickMenu->SetEntry(QuickMenuDirection::Down, cfg::ProcessedThemeResource(theme, "ui/QuickMenuSettingsItem.png"), std::bind(&MenuLayout::settings_Click, this));
this->quickMenu->SetEntry(QuickMenuDirection::Left, cfg::ProcessedThemeResource(theme, "ui/QuickMenuWebItem.png"), std::bind(&MenuLayout::web_Click, this));
this->quickMenu->SetEntry(QuickMenuDirection::Right, cfg::ProcessedThemeResource(theme, "ui/QuickMenuThemesItem.png"), std::bind(&MenuLayout::themes_Click, this));
this->quickMenu->SetEntry(QuickMenuDirection::UpLeft, cfg::ProcessedThemeResource(theme, "ui/QuickMenuControllerItem.png"), std::bind(&MenuLayout::HandleControllerAppletOpen, this));
this->quickMenu->SetEntry(QuickMenuDirection::DownRight, cfg::ProcessedThemeResource(theme, "ui/QuickMenuHelpItem.png"), std::bind(&MenuLayout::HandleShowHelp, this));

this->Add(this->quickMenu);

this->tp = std::chrono::steady_clock::now();

this->sfxTitleLaunch = pu::audio::Load(cfg::ProcessedThemeResource(theme, "sound/TitleLaunch.wav"));
Expand Down Expand Up @@ -711,15 +722,13 @@ namespace ui
}
else if(down & KEY_PLUS) this->logo_Click();
else if(down & KEY_MINUS) this->menuToggle_Click();
else if(down & KEY_ZL) this->HandleUserMenu();
else if(down & KEY_L) this->HandleWebPageOpen();
else if(down & KEY_R) this->HandleSettingsMenu();
else if(down & KEY_ZR) this->HandleThemesMenu();
}

void MenuLayout::SetUser(u128 user)
{
this->users->SetImage(os::GetIconCacheImagePath(user));
auto path = os::GetIconCacheImagePath(user);
this->users->SetImage(path);
this->quickMenu->SetEntry(QuickMenuDirection::Up, path, std::bind(&MenuLayout::users_Click, this));
this->users->SetWidth(50);
this->users->SetHeight(50);
}
Expand All @@ -739,7 +748,7 @@ namespace ui
void MenuLayout::logo_Click()
{
qapp->CreateShowDialog(cfg::GetLanguageString(config.main_lang, config.default_lang, "ulaunch_about"), "uLaunch v" + std::string(Q_VERSION) + "\n\n" + cfg::GetLanguageString(config.main_lang, config.default_lang, "ulaunch_desc") + "\n\n" + cfg::GetLanguageString(config.main_lang, config.default_lang, "ulaunch_contribute") + ":\nhttps://github.com/XorTroll/uLaunch", { cfg::GetLanguageString(config.main_lang, config.default_lang, "ok") }, true, "romfs:/LogoLarge.png");
qapp->ShowNotification("(-) -> " + cfg::GetLanguageString(config.main_lang, config.default_lang, "control_minus") + " | (X) -> " + cfg::GetLanguageString(config.main_lang, config.default_lang, "control_x") + " | (Y) -> " + cfg::GetLanguageString(config.main_lang, config.default_lang, "control_y") + " | (L), (R), (ZL), (ZR) -> " + cfg::GetLanguageString(config.main_lang, config.default_lang, "control_zlr"), 3500);
// qapp->ShowNotification("(-) -> " + cfg::GetLanguageString(config.main_lang, config.default_lang, "control_minus") + " | (X) -> " + cfg::GetLanguageString(config.main_lang, config.default_lang, "control_x") + " | (Y) -> " + cfg::GetLanguageString(config.main_lang, config.default_lang, "control_y") + " | (L), (R), (ZL), (ZR) -> " + cfg::GetLanguageString(config.main_lang, config.default_lang, "control_zlr"), 3500);
}

void MenuLayout::settings_Click()
Expand Down Expand Up @@ -1036,6 +1045,42 @@ namespace ui
qapp->FadeIn();
}

void MenuLayout::HandleControllerAppletOpen()
{
am::controller::InitialArg arg1 = {};
HidControllerType type;
hidGetSupportedNpadStyleSet(&type);
arg1.controller_type = (u64)type;
arg1.this_size = sizeof(arg1);
arg1.unk2 = true;
arg1.unk3 = true;

am::controller::MainArg arg2 = {};
arg2.min_player_count = 0;
arg2.max_player_count = 4;
arg2.take_over_connection = true;
arg2.left_justify = true;

am::LibraryAppletQMenuLaunchWith(AppletId_controller, 0,
[&](AppletHolder *h)
{
libappletPushInData(h, &arg1, sizeof(arg1));
libappletPushInData(h, &arg2, sizeof(arg2));
},
[&](AppletHolder *h)
{
},
[&]() -> bool
{
return !am::QMenuIsHomePressed();
});
}

void MenuLayout::HandleShowHelp()
{

}

void MenuLayout::HandleMultiselectMoveToFolder(std::string folder)
{
if(this->select_on)
Expand Down
15 changes: 5 additions & 10 deletions LibraryAppletQMenu/Source/ui/ui_QMenuApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,12 @@ namespace ui

switch(this->stmode)
{
case am::QMenuStartMode::Menu:
case am::QMenuStartMode::MenuApplicationSuspended:
case am::QMenuStartMode::MenuLaunchFailure:
{
// Returned from applet/title
this->StartPlayBGM();
this->LoadMenu();
case am::QMenuStartMode::StartupScreen:
this->LoadStartupMenu();
break;
}
default:
this->LoadStartupMenu();
this->StartPlayBGM();
this->LoadMenu();
break;
}
}
Expand Down Expand Up @@ -159,7 +154,7 @@ namespace ui
writer.Write<u128>(user_id);
writer.FinishWrite();

this->status.selected_user = user_id;
memcpy(&this->status.selected_user, &user_id, sizeof(user_id));
}

u128 QMenuApplication::GetSelectedUser()
Expand Down
Loading

0 comments on commit 3a90499

Please sign in to comment.