mirror of https://github.com/AxioDL/metaforce.git
Implement CSaveUITouchBar
This commit is contained in:
parent
0a062d0138
commit
def32a1cca
|
@ -41,6 +41,7 @@ add_subdirectory(MP3)
|
|||
|
||||
if(APPLE)
|
||||
set_source_files_properties(MP1/CFrontEndUITouchBarMac.mm
|
||||
MP1/CSaveUITouchBarMac.mm
|
||||
CGameOptionsTouchBarMac.mm
|
||||
PROPERTIES COMPILE_FLAGS -fobjc-arc)
|
||||
bintoc(startButton.c Resources/startButton@2x.png START_BUTTON_2X)
|
||||
|
|
|
@ -1868,6 +1868,7 @@ bool CFrontEndUI::SOptionsFrontEndFrame::ProcessUserInput(const CFinalInput& inp
|
|||
int value;
|
||||
m_touchBar->GetSelection(leftSel, rightSel, value);
|
||||
x28_tablegroup_rightmenu->SetUserSelection(rightSel);
|
||||
SetTableColors(x28_tablegroup_rightmenu);
|
||||
HandleRightSelectionChange();
|
||||
const auto& optionCategory = GameOptionsRegistry[leftSel];
|
||||
const SGameOption& option = optionCategory.second[rightSel];
|
||||
|
|
|
@ -2,7 +2,9 @@ include_directories(. ..)
|
|||
add_subdirectory(World)
|
||||
|
||||
if(APPLE)
|
||||
set(MP1_PLAT_SOURCES CFrontEndUITouchBarMac.mm)
|
||||
set(MP1_PLAT_SOURCES
|
||||
CFrontEndUITouchBarMac.mm
|
||||
CSaveUITouchBarMac.mm)
|
||||
endif()
|
||||
|
||||
set(MP1_SOURCES
|
||||
|
@ -18,6 +20,7 @@ set(MP1_SOURCES
|
|||
CPreFrontEnd.hpp CPreFrontEnd.cpp
|
||||
CSlideShow.hpp CSlideShow.cpp
|
||||
CSaveUI.hpp CSaveUI.cpp
|
||||
CSaveUITouchBar.hpp CSaveUITouchBar.cpp
|
||||
CMemoryCardDriver.hpp CMemoryCardDriver.cpp
|
||||
CQuitScreen.hpp CQuitScreen.cpp
|
||||
CCredits.hpp CCredits.cpp
|
||||
|
|
|
@ -338,6 +338,8 @@ void CSaveUI::SetUIText()
|
|||
|
||||
x68_textpane_choice3->TextSupport()->SetText(opt3Str);
|
||||
|
||||
m_touchBar->SetUIOpts(opt0Str, opt1Str, opt2Str);
|
||||
|
||||
x5c_textpane_choice0->SetIsSelectable(opt0 != -1);
|
||||
x60_textpane_choice1->SetIsSelectable(opt1 != -1);
|
||||
x64_textpane_choice2->SetIsSelectable(opt2 != -1);
|
||||
|
@ -617,7 +619,17 @@ void CSaveUI::DoSelectionChange(CGuiTableGroup* caller, int userSel)
|
|||
void CSaveUI::ProcessUserInput(const CFinalInput& input)
|
||||
{
|
||||
if (x50_loadedFrame)
|
||||
{
|
||||
x50_loadedFrame->ProcessUserInput(input);
|
||||
|
||||
int tbOpt = m_touchBar->PopOption();
|
||||
if (tbOpt != -1)
|
||||
{
|
||||
x58_tablegroup_choices->SetUserSelection(tbOpt);
|
||||
SetUIColors();
|
||||
DoAdvance(x58_tablegroup_choices);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSaveUI::StartGame(int idx)
|
||||
|
@ -654,7 +666,7 @@ const CGameState::GameFileStateInfo* CSaveUI::GetGameData(int idx) const
|
|||
}
|
||||
|
||||
CSaveUI::CSaveUI(ESaveContext saveCtx, u64 serial)
|
||||
: x0_saveCtx(saveCtx), x8_serial(serial)
|
||||
: x0_saveCtx(saveCtx), x8_serial(serial), m_touchBar(NewSaveUITouchBar())
|
||||
{
|
||||
x14_txtrSaveBanner = g_SimplePool->GetObj("TXTR_SaveBanner");
|
||||
x20_txtrSaveIcon0 = g_SimplePool->GetObj("TXTR_SaveIcon0");
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "CToken.hpp"
|
||||
#include "CIOWin.hpp"
|
||||
#include "CMemoryCardDriver.hpp"
|
||||
#include "CSaveUITouchBar.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
@ -90,6 +91,8 @@ private:
|
|||
bool x92_savingDisabled = false;
|
||||
bool x93_inGame;
|
||||
|
||||
std::unique_ptr<CSaveUITouchBar> m_touchBar;
|
||||
|
||||
void ContinueWithoutSaving();
|
||||
|
||||
public:
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#include "CSaveUITouchBar.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
namespace MP1
|
||||
{
|
||||
|
||||
int CSaveUITouchBar::PopOption() { return -1; }
|
||||
void CSaveUITouchBar::SetUIOpts(const std::u16string& opt0,
|
||||
const std::u16string& opt1,
|
||||
const std::u16string& opt2) {}
|
||||
|
||||
#ifndef __APPLE__
|
||||
std::unique_ptr<CSaveUITouchBar> NewSaveUITouchBar()
|
||||
{
|
||||
return std::make_unique<CSaveUITouchBar>();
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef __URDE_CSAVEUITOUCHBAR_HPP__
|
||||
#define __URDE_CSAVEUITOUCHBAR_HPP__
|
||||
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace urde
|
||||
{
|
||||
namespace MP1
|
||||
{
|
||||
|
||||
class CSaveUITouchBar
|
||||
{
|
||||
public:
|
||||
virtual ~CSaveUITouchBar() = default;
|
||||
virtual int PopOption();
|
||||
virtual void SetUIOpts(const std::u16string& opt0,
|
||||
const std::u16string& opt1,
|
||||
const std::u16string& opt2);
|
||||
};
|
||||
|
||||
std::unique_ptr<CSaveUITouchBar> NewSaveUITouchBar();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __URDE_CSAVEUITOUCHBAR_HPP__
|
|
@ -0,0 +1,128 @@
|
|||
#include <AppKit/AppKit.h>
|
||||
#include "CSaveUITouchBar.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
#include "MP1/MP1.hpp"
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
#error ARC Required
|
||||
#endif
|
||||
|
||||
@interface SaveUITouchBar : NSObject <NSTouchBarDelegate>
|
||||
{
|
||||
@public
|
||||
NSString* _opts[3];
|
||||
int _opt;
|
||||
}
|
||||
-(IBAction)onOpt0:(id)sender;
|
||||
-(IBAction)onOpt1:(id)sender;
|
||||
-(IBAction)onOpt2:(id)sender;
|
||||
@end
|
||||
|
||||
@implementation SaveUITouchBar
|
||||
- (NSTouchBar*)makeTouchBar
|
||||
{
|
||||
NSTouchBar* touchBar = [NSTouchBar new];
|
||||
touchBar.delegate = self;
|
||||
id items = @[@"saveUIGroup"];
|
||||
touchBar.customizationRequiredItemIdentifiers = items;
|
||||
touchBar.defaultItemIdentifiers = items;
|
||||
touchBar.principalItemIdentifier = @"saveUIGroup";
|
||||
return touchBar;
|
||||
}
|
||||
-(NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar
|
||||
makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
|
||||
{
|
||||
if ([identifier isEqualToString:@"saveUIGroup"])
|
||||
{
|
||||
NSGroupTouchBarItem* item = [[NSGroupTouchBarItem alloc] initWithIdentifier:identifier];
|
||||
NSTouchBar* touchBar = [NSTouchBar new];
|
||||
touchBar.delegate = self;
|
||||
id items;
|
||||
items = [NSMutableArray arrayWithCapacity:3];
|
||||
[items addObject:@"back"];
|
||||
for (int i=0 ; i<3 && _opts[i] ; ++i)
|
||||
[items addObject:[NSString stringWithFormat:@"opt%d", i]];
|
||||
touchBar.customizationRequiredItemIdentifiers = items;
|
||||
touchBar.defaultItemIdentifiers = items;
|
||||
item.groupTouchBar = touchBar;
|
||||
return item;
|
||||
}
|
||||
else if ([identifier isEqualToString:@"opt0"])
|
||||
{
|
||||
NSCustomTouchBarItem* item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
|
||||
NSButton* button = [NSButton buttonWithTitle:_opts[0] target:self action:@selector(onOpt0:)];
|
||||
item.view = button;
|
||||
return item;
|
||||
}
|
||||
else if ([identifier isEqualToString:@"opt1"])
|
||||
{
|
||||
NSCustomTouchBarItem* item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
|
||||
NSButton* button = [NSButton buttonWithTitle:_opts[1] target:self action:@selector(onOpt1:)];
|
||||
item.view = button;
|
||||
return item;
|
||||
}
|
||||
else if ([identifier isEqualToString:@"opt2"])
|
||||
{
|
||||
NSCustomTouchBarItem* item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
|
||||
NSButton* button = [NSButton buttonWithTitle:_opts[2] target:self action:@selector(onOpt2:)];
|
||||
item.view = button;
|
||||
return item;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
-(IBAction)onOpt0:(id)sender
|
||||
{
|
||||
_opt = 0;
|
||||
}
|
||||
-(IBAction)onOpt1:(id)sender
|
||||
{
|
||||
_opt = 1;
|
||||
}
|
||||
-(IBAction)onOpt2:(id)sender
|
||||
{
|
||||
_opt = 2;
|
||||
}
|
||||
@end
|
||||
|
||||
namespace urde
|
||||
{
|
||||
namespace MP1
|
||||
{
|
||||
|
||||
class CSaveUITouchBarMac : public CSaveUITouchBar
|
||||
{
|
||||
SaveUITouchBar* m_touchBar;
|
||||
public:
|
||||
CSaveUITouchBarMac()
|
||||
{
|
||||
m_touchBar = [SaveUITouchBar new];
|
||||
m_touchBar->_opt = -1;
|
||||
}
|
||||
int PopOption()
|
||||
{
|
||||
if (m_touchBar->_opt != -1)
|
||||
{
|
||||
int opt = m_touchBar->_opt;
|
||||
m_touchBar->_opt = -1;
|
||||
return opt;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
void SetUIOpts(const std::u16string& opt0,
|
||||
const std::u16string& opt1,
|
||||
const std::u16string& opt2)
|
||||
{
|
||||
m_touchBar->_opts[0] = opt0.size() ? [NSString stringWithUTF8String:hecl::Char16ToUTF8(opt0).c_str()] : nil;
|
||||
m_touchBar->_opts[1] = opt1.size() ? [NSString stringWithUTF8String:hecl::Char16ToUTF8(opt1).c_str()] : nil;
|
||||
m_touchBar->_opts[2] = opt2.size() ? [NSString stringWithUTF8String:hecl::Char16ToUTF8(opt2).c_str()] : nil;
|
||||
g_Main->GetMainWindow()->setTouchBarProvider((__bridge_retained void*)m_touchBar);
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<CSaveUITouchBar> NewSaveUITouchBar()
|
||||
{
|
||||
return std::make_unique<CSaveUITouchBarMac>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue