Skip to content

Commit cf0adbe

Browse files
committed
Rework remote ISO UI a bit (more to come)
1 parent e382075 commit cf0adbe

File tree

2 files changed

+93
-113
lines changed

2 files changed

+93
-113
lines changed

UI/RemoteISOScreen.cpp

+84-95
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "Core/System.h"
4545
#include "Core/WebServer.h"
4646
#include "UI/RemoteISOScreen.h"
47+
#include "UI/OnScreenDisplay.h"
4748

4849
using namespace UI;
4950

@@ -271,10 +272,22 @@ static bool LoadGameList(const Path &url, std::vector<Path> &games) {
271272
return !games.empty();
272273
}
273274

274-
RemoteISOScreen::RemoteISOScreen(const Path &filename) : UIDialogScreenWithGameBackground(filename) {}
275+
RemoteISOScreen::RemoteISOScreen(const Path &filename) : TabbedUIDialogScreenWithGameBackground(filename) {}
276+
277+
278+
void RemoteISOScreen::CreateTabs() {
279+
auto ri = GetI18NCategory(I18NCat::REMOTEISO);
280+
281+
UI::LinearLayout *connect = AddTab("Connect", ri->T("Connect"));
282+
connect->SetSpacing(5.0f);
283+
CreateConnectTab(connect);
284+
285+
UI::LinearLayout *settings = AddTab("Settings", ri->T("Settings"));
286+
CreateSettingsTab(settings);
287+
}
275288

276289
void RemoteISOScreen::update() {
277-
UIDialogScreenWithBackground::update();
290+
TabbedUIDialogScreenWithGameBackground::update();
278291

279292
if (!WebServerStopped(WebServerFlags::DISCS)) {
280293
auto result = IsServerAllowed(g_Config.iRemoteISOPort);
@@ -296,17 +309,24 @@ void RemoteISOScreen::update() {
296309
serverRunning_ = nowRunning;
297310
}
298311

299-
void RemoteISOScreen::CreateViews() {
312+
void RemoteISOScreen::CreateConnectTab(UI::ViewGroup *tab) {
300313
auto di = GetI18NCategory(I18NCat::DIALOG);
301314
auto ri = GetI18NCategory(I18NCat::REMOTEISO);
302315

303316
Margins actionMenuMargins(0, 20, 15, 0);
304317
Margins contentMargins(0, 20, 5, 5);
318+
305319
ViewGroup *leftColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 0.4f, contentMargins));
306320
LinearLayout *leftColumnItems = new LinearLayout(ORIENT_VERTICAL, new LayoutParams(WRAP_CONTENT, FILL_PARENT));
307321
ViewGroup *rightColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins));
308322
LinearLayout *rightColumnItems = new LinearLayout(ORIENT_VERTICAL);
309323

324+
if (serverRunning_) {
325+
leftColumnItems->Add(new NoticeView(NoticeLevel::SUCCESS, ri->T("Currently sharing"), "", new LinearLayoutParams(Margins(12, 5, 0, 5))));
326+
} else {
327+
leftColumnItems->Add(new NoticeView(NoticeLevel::INFO, ri->T("Not currently sharing"), "", new LinearLayoutParams(Margins(12, 5, 0, 5))));
328+
}
329+
310330
if ((RemoteISOShareType)g_Config.iRemoteISOShareType == RemoteISOShareType::RECENT) {
311331
leftColumnItems->Add(new TextView(ri->T("RemoteISODesc", "Games in your recent list will be shared"), new LinearLayoutParams(Margins(12, 5, 0, 5))));
312332
} else {
@@ -330,18 +350,73 @@ void RemoteISOScreen::CreateViews() {
330350
rightColumnItems->Add(new Choice(ri->T("Share Games (Server)")))->OnClick.Handle(this, &RemoteISOScreen::HandleStartServer);
331351
browseChoice->SetEnabled(true);
332352
}
333-
Choice *settingsChoice = new Choice(ri->T("Settings"));
334-
rightColumnItems->Add(settingsChoice)->OnClick.Handle(this, &RemoteISOScreen::HandleSettings);
335353

336-
LinearLayout *beforeBack = new LinearLayout(ORIENT_HORIZONTAL, new AnchorLayoutParams(FILL_PARENT, FILL_PARENT));
354+
LinearLayout *beforeBack = new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, FILL_PARENT));
337355
beforeBack->Add(leftColumn);
338356
beforeBack->Add(rightColumn);
339-
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
340-
root_->Add(beforeBack);
341-
root_->Add(new Choice(di->T("Back"), "", false, new AnchorLayoutParams(150, WRAP_CONTENT, 10, NONE, NONE, 10)))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
342357

343358
leftColumn->Add(leftColumnItems);
344359
rightColumn->Add(rightColumnItems);
360+
tab->Add(beforeBack);
361+
}
362+
363+
void RemoteISOScreen::CreateSettingsTab(UI::ViewGroup *remoteisoSettings) {
364+
serverRunning_ = !WebServerStopped(WebServerFlags::DISCS);
365+
366+
auto ri = GetI18NCategory(I18NCat::REMOTEISO);
367+
368+
remoteisoSettings->Add(new ItemHeader(ri->T("Remote disc streaming")));
369+
remoteisoSettings->Add(new CheckBox(&g_Config.bRemoteShareOnStartup, ri->T("Share on PPSSPP startup")));
370+
remoteisoSettings->Add(new CheckBox(&g_Config.bRemoteISOManual, ri->T("Manual Mode Client", "Manually configure client")));
371+
remoteisoSettings->Add(new CheckBox(&g_Config.bRemoteTab, ri->T("Show Remote tab on main screen")));
372+
373+
if (System_GetPropertyBool(SYSPROP_HAS_FOLDER_BROWSER)) {
374+
static const char *shareTypes[] = { "Recent files", "Choose directory" };
375+
remoteisoSettings->Add(new PopupMultiChoice(&g_Config.iRemoteISOShareType, ri->T("Files to share"), shareTypes, 0, ARRAY_SIZE(shareTypes), I18NCat::REMOTEISO, screenManager()));
376+
FolderChooserChoice *folderChooser = remoteisoSettings->Add(new FolderChooserChoice(GetRequesterToken(), &g_Config.sRemoteISOSharedDir, ri->T("Files to share")));
377+
folderChooser->SetEnabledFunc([=]() {
378+
return g_Config.iRemoteISOShareType == (int)RemoteISOShareType::LOCAL_FOLDER;
379+
});
380+
} else {
381+
// Can't pick a folder, only allow sharing recent stuff.
382+
g_Config.iRemoteISOShareType = (int)RemoteISOShareType::RECENT;
383+
}
384+
385+
UI::Choice *remoteServer = new PopupTextInputChoice(GetRequesterToken(), &g_Config.sLastRemoteISOServer, ri->T("Remote Server"), "", 255, screenManager());
386+
remoteisoSettings->Add(remoteServer);
387+
remoteServer->SetEnabledPtr(&g_Config.bRemoteISOManual);
388+
389+
PopupSliderChoice *remotePort = remoteisoSettings->Add(new PopupSliderChoice(&g_Config.iLastRemoteISOPort, 0, 65535, 0, ri->T("Remote Port"), 100, screenManager()));
390+
remotePort->SetEnabledPtr(&g_Config.bRemoteISOManual);
391+
392+
UI::Choice *remoteSubdir;
393+
{
394+
PopupTextInputChoice *remoteSubdirInput = new PopupTextInputChoice(GetRequesterToken(), &g_Config.sRemoteISOSubdir, ri->T("Remote Subdirectory"), "", 255, screenManager());
395+
remoteSubdirInput->OnChange.Handle(this, &RemoteISOScreen::OnChangeRemoteISOSubdir);
396+
remoteSubdir = remoteSubdirInput;
397+
}
398+
remoteisoSettings->Add(remoteSubdir);
399+
remoteSubdir->SetEnabledPtr(&g_Config.bRemoteISOManual);
400+
401+
PopupSliderChoice *portChoice = new PopupSliderChoice(&g_Config.iRemoteISOPort, 0, 65535, 0, ri->T("Local Server Port", "Local Server Port"), 100, screenManager());
402+
remoteisoSettings->Add(portChoice);
403+
portChoice->SetDisabledPtr(&serverRunning_);
404+
}
405+
406+
static void CleanupRemoteISOSubdir() {
407+
// Replace spaces and force forward slashes.
408+
// TODO: Maybe we should uri escape this after?
409+
ReplaceAll(g_Config.sRemoteISOSubdir, " ", "%20");
410+
ReplaceAll(g_Config.sRemoteISOSubdir, "\\", "/");
411+
// Make sure it begins with /.
412+
if (g_Config.sRemoteISOSubdir.empty() || g_Config.sRemoteISOSubdir[0] != '/')
413+
g_Config.sRemoteISOSubdir = "/" + g_Config.sRemoteISOSubdir;
414+
}
415+
416+
417+
UI::EventReturn RemoteISOScreen::OnChangeRemoteISOSubdir(UI::EventParams &e) {
418+
CleanupRemoteISOSubdir();
419+
return UI::EVENT_DONE;
345420
}
346421

347422
UI::EventReturn RemoteISOScreen::HandleStartServer(UI::EventParams &e) {
@@ -368,11 +443,6 @@ UI::EventReturn RemoteISOScreen::HandleBrowse(UI::EventParams &e) {
368443
return EVENT_DONE;
369444
}
370445

371-
UI::EventReturn RemoteISOScreen::HandleSettings(UI::EventParams &e) {
372-
screenManager()->push(new RemoteISOSettingsScreen());
373-
return EVENT_DONE;
374-
}
375-
376446
RemoteISOConnectScreen::RemoteISOConnectScreen() {
377447
scanCancelled = false;
378448
scanAborted = false;
@@ -570,84 +640,3 @@ void RemoteISOBrowseScreen::CreateViews() {
570640

571641
upgradeBar_ = 0;
572642
}
573-
574-
RemoteISOSettingsScreen::RemoteISOSettingsScreen() {
575-
serverRunning_ = !WebServerStopped(WebServerFlags::DISCS);
576-
}
577-
578-
void RemoteISOSettingsScreen::update() {
579-
UIDialogScreenWithBackground::update();
580-
581-
bool nowRunning = !WebServerStopped(WebServerFlags::DISCS);
582-
if (serverRunning_ != nowRunning) {
583-
RecreateViews();
584-
}
585-
serverRunning_ = nowRunning;
586-
}
587-
588-
void RemoteISOSettingsScreen::CreateViews() {
589-
auto ri = GetI18NCategory(I18NCat::REMOTEISO);
590-
591-
ViewGroup *remoteisoSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LayoutParams(FILL_PARENT, FILL_PARENT));
592-
remoteisoSettingsScroll->SetTag("RemoteISOSettings");
593-
LinearLayout *remoteisoSettings = new LinearLayoutList(ORIENT_VERTICAL);
594-
remoteisoSettings->SetSpacing(0);
595-
remoteisoSettingsScroll->Add(remoteisoSettings);
596-
597-
remoteisoSettings->Add(new ItemHeader(ri->T("Remote disc streaming")));
598-
remoteisoSettings->Add(new CheckBox(&g_Config.bRemoteShareOnStartup, ri->T("Share on PPSSPP startup")));
599-
remoteisoSettings->Add(new CheckBox(&g_Config.bRemoteISOManual, ri->T("Manual Mode Client", "Manually configure client")));
600-
remoteisoSettings->Add(new CheckBox(&g_Config.bRemoteTab, ri->T("Show Remote tab on main screen")));
601-
602-
if (System_GetPropertyBool(SYSPROP_HAS_FOLDER_BROWSER)) {
603-
static const char *shareTypes[] = { "Recent files", "Choose directory" };
604-
remoteisoSettings->Add(new PopupMultiChoice(&g_Config.iRemoteISOShareType, ri->T("Files to share"), shareTypes, 0, ARRAY_SIZE(shareTypes), I18NCat::REMOTEISO, screenManager()));
605-
FolderChooserChoice *folderChooser = remoteisoSettings->Add(new FolderChooserChoice(GetRequesterToken(), &g_Config.sRemoteISOSharedDir, ri->T("Files to share")));
606-
folderChooser->SetEnabledFunc([=]() {
607-
return g_Config.iRemoteISOShareType == (int)RemoteISOShareType::LOCAL_FOLDER;
608-
});
609-
} else {
610-
// Can't pick a folder, only allow sharing recent stuff.
611-
g_Config.iRemoteISOShareType = (int)RemoteISOShareType::RECENT;
612-
}
613-
614-
UI::Choice *remoteServer = new PopupTextInputChoice(GetRequesterToken(), &g_Config.sLastRemoteISOServer, ri->T("Remote Server"), "", 255, screenManager());
615-
remoteisoSettings->Add(remoteServer);
616-
remoteServer->SetEnabledPtr(&g_Config.bRemoteISOManual);
617-
618-
PopupSliderChoice *remotePort = remoteisoSettings->Add(new PopupSliderChoice(&g_Config.iLastRemoteISOPort, 0, 65535, 0, ri->T("Remote Port"), 100, screenManager()));
619-
remotePort->SetEnabledPtr(&g_Config.bRemoteISOManual);
620-
621-
UI::Choice *remoteSubdir;
622-
{
623-
PopupTextInputChoice *remoteSubdirInput = new PopupTextInputChoice(GetRequesterToken(), &g_Config.sRemoteISOSubdir, ri->T("Remote Subdirectory"), "", 255, screenManager());
624-
remoteSubdirInput->OnChange.Handle(this, &RemoteISOSettingsScreen::OnChangeRemoteISOSubdir);
625-
remoteSubdir = remoteSubdirInput;
626-
}
627-
remoteisoSettings->Add(remoteSubdir);
628-
remoteSubdir->SetEnabledPtr(&g_Config.bRemoteISOManual);
629-
630-
PopupSliderChoice *portChoice = new PopupSliderChoice(&g_Config.iRemoteISOPort, 0, 65535, 0, ri->T("Local Server Port", "Local Server Port"), 100, screenManager());
631-
remoteisoSettings->Add(portChoice);
632-
portChoice->SetDisabledPtr(&serverRunning_);
633-
remoteisoSettings->Add(new Spacer(25.0));
634-
635-
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
636-
root_->Add(remoteisoSettingsScroll);
637-
AddStandardBack(root_);
638-
}
639-
640-
static void CleanupRemoteISOSubdir() {
641-
// Replace spaces and force forward slashes.
642-
// TODO: Maybe we should uri escape this after?
643-
ReplaceAll(g_Config.sRemoteISOSubdir, " ", "%20");
644-
ReplaceAll(g_Config.sRemoteISOSubdir, "\\", "/");
645-
// Make sure it begins with /.
646-
if (g_Config.sRemoteISOSubdir.empty() || g_Config.sRemoteISOSubdir[0] != '/')
647-
g_Config.sRemoteISOSubdir = "/" + g_Config.sRemoteISOSubdir;
648-
}
649-
650-
UI::EventReturn RemoteISOSettingsScreen::OnChangeRemoteISOSubdir(UI::EventParams &e) {
651-
CleanupRemoteISOSubdir();
652-
return UI::EVENT_DONE;
653-
}

UI/RemoteISOScreen.h

+9-18
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,27 @@
2424
#include "Common/UI/ViewGroup.h"
2525
#include "UI/MiscScreens.h"
2626
#include "UI/MainScreen.h"
27+
#include "UI/TabbedDialogScreen.h"
2728

28-
class RemoteISOScreen : public UIDialogScreenWithGameBackground {
29+
class RemoteISOScreen : public TabbedUIDialogScreenWithGameBackground {
2930
public:
3031
RemoteISOScreen(const Path &filename);
3132

3233
const char *tag() const override { return "RemoteISO"; }
34+
void CreateTabs() override;
3335

3436
protected:
37+
UI::EventReturn OnChangeRemoteISOSubdir(UI::EventParams &e);
38+
39+
void CreateConnectTab(UI::ViewGroup *viewGroup);
40+
void CreateSettingsTab(UI::ViewGroup *viewGroup);
41+
bool ShowSearchControls() const override { return false; }
42+
3543
void update() override;
36-
void CreateViews() override;
3744

3845
UI::EventReturn HandleStartServer(UI::EventParams &e);
3946
UI::EventReturn HandleStopServer(UI::EventParams &e);
4047
UI::EventReturn HandleBrowse(UI::EventParams &e);
41-
UI::EventReturn HandleSettings(UI::EventParams &e);
4248

4349
UI::TextView *firewallWarning_ = nullptr;
4450
bool serverRunning_ = false;
@@ -97,20 +103,5 @@ class RemoteISOBrowseScreen : public MainScreen {
97103
std::vector<Path> games_;
98104
};
99105

100-
class RemoteISOSettingsScreen : public UIDialogScreenWithBackground {
101-
public:
102-
RemoteISOSettingsScreen();
103-
104-
const char *tag() const override { return "RemoteISOSettings"; }
105-
106-
protected:
107-
void update() override;
108-
void CreateViews() override;
109-
110-
UI::EventReturn OnChangeRemoteISOSubdir(UI::EventParams &e);
111-
112-
bool serverRunning_ = false;
113-
};
114-
115106
std::string RemoteSubdir();
116107
std::string FormatRemoteISOUrl(const char *host, int port, const char *subdir);

0 commit comments

Comments
 (0)