metaforce/Runtime/MP1/CSaveGameScreenTouchBarMac.mm

102 lines
3.4 KiB
Plaintext
Raw Normal View History

2017-02-12 03:17:18 +00:00
#include "CSaveGameScreenTouchBar.hpp"
2017-02-10 23:58:05 +00:00
#include "GameGlobalObjects.hpp"
#include "MP1/MP1.hpp"
2021-06-07 19:29:18 +00:00
#include <AppKit/AppKit.h>
2017-02-10 23:58:05 +00:00
#if !__has_feature(objc_arc)
#error ARC Required
#endif
2021-06-07 19:29:18 +00:00
@interface SaveGameScreenTouchBar : NSObject <NSTouchBarDelegate> {
2017-02-10 23:58:05 +00:00
@public
2021-06-07 19:29:18 +00:00
NSString *_opts[3];
int _opt;
2017-02-10 23:58:05 +00:00
}
2021-06-07 19:29:18 +00:00
- (IBAction)onOpt0:(id)sender;
- (IBAction)onOpt1:(id)sender;
- (IBAction)onOpt2:(id)sender;
2017-02-10 23:58:05 +00:00
@end
2017-02-12 03:17:18 +00:00
@implementation SaveGameScreenTouchBar
2021-06-07 19:29:18 +00:00
- (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];
2017-02-10 23:58:05 +00:00
touchBar.delegate = self;
2021-06-07 19:29:18 +00:00
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]];
2017-02-10 23:58:05 +00:00
touchBar.customizationRequiredItemIdentifiers = items;
touchBar.defaultItemIdentifiers = items;
2021-06-07 19:29:18 +00:00
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;
2017-02-10 23:58:05 +00:00
}
2021-06-07 19:29:18 +00:00
- (IBAction)onOpt0:(id)sender {
_opt = 0;
2017-02-10 23:58:05 +00:00
}
2021-06-07 19:29:18 +00:00
- (IBAction)onOpt1:(id)sender {
_opt = 1;
2017-02-10 23:58:05 +00:00
}
2021-06-07 19:29:18 +00:00
- (IBAction)onOpt2:(id)sender {
_opt = 2;
2017-02-10 23:58:05 +00:00
}
@end
2021-06-07 19:29:18 +00:00
namespace metaforce::MP1 {
class CSaveGameScreenTouchBarMac : public CSaveGameScreenTouchBar {
SaveGameScreenTouchBar *m_touchBar;
2017-02-10 23:58:05 +00:00
public:
2021-06-07 19:29:18 +00:00
CSaveGameScreenTouchBarMac() {
m_touchBar = [SaveGameScreenTouchBar new];
m_touchBar->_opt = -1;
}
int PopOption() {
if (m_touchBar->_opt != -1) {
int opt = m_touchBar->_opt;
m_touchBar->_opt = -1;
return opt;
2017-02-10 23:58:05 +00:00
}
2021-06-07 19:29:18 +00:00
return -1;
}
void SetUIOpts(std::u16string_view opt0, std::u16string_view opt1, std::u16string_view 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);
}
2017-02-10 23:58:05 +00:00
};
2021-06-07 19:29:18 +00:00
std::unique_ptr<CSaveGameScreenTouchBar> NewSaveUITouchBar() { return std::make_unique<CSaveGameScreenTouchBarMac>(); }
2017-02-10 23:58:05 +00:00
}