-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacos.mm
329 lines (271 loc) · 10.6 KB
/
macos.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#import <Cocoa/Cocoa.h>
#include "strings.h"
#include "launcher.h"
@interface MyView : NSView
@end
@implementation MyView
- (void)resetCursorRects
{
[self addCursorRect:[self bounds] cursor:[NSCursor arrowCursor]];
}
@end
@interface AppDelegate : NSObject <NSApplicationDelegate, NSComboBoxDataSource, NSComboBoxDelegate>
@property (strong, nonatomic) NSWindow *window;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *executablePath = [[NSBundle mainBundle] executablePath];
NSString *appPath = [executablePath stringByDeletingLastPathComponent];
[fileManager changeCurrentDirectoryPath:appPath];
//printf ("%s\n", [appPath UTF8String]);
// Insert standard menu items
[self createMainMenu];
// Create the window
self.window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 640, 480)
styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable
backing:NSBackingStoreBuffered
defer:NO];
[self.window center];
MyView *contentView = [[MyView alloc] initWithFrame:[self.window.contentView bounds]];
[self.window setContentView:contentView];
// Set the background image
NSString *imagePath = [appPath stringByAppendingPathComponent:@"startup.png"];
NSURL *imageURL = [NSURL fileURLWithPath:imagePath];
NSImage *image = [[NSImage alloc] initWithContentsOfURL:imageURL];
NSImageView *backgroundView = [[NSImageView alloc] initWithFrame:self.window.contentView.bounds];
backgroundView.imageScaling = NSImageScaleAxesIndependently;
backgroundView.image = image;
[self.window.contentView addSubview:backgroundView positioned:NSWindowBelow relativeTo:nil];
// Create the combo box
NSComboBox *comboBox = [[NSComboBox alloc] initWithFrame:NSMakeRect(14, 440, 200, 24)];
//[comboBox addItemsWithObjectValues:@[@VIDMODE1, @VIDMODE2, @VIDMODE3, @VIDMODE4]];
comboBox.usesDataSource = YES;
comboBox.dataSource = self; // assuming AppDelegate implements the NSComboBoxDataSource protocol
comboBox.delegate = self; // assuming AppDelegate implements the NSComboBoxDelegate protocol
[comboBox selectItemAtIndex:vidmode];
[comboBox setEditable:NO];
[self.window.contentView addSubview:comboBox];
// Create the buttons
NSButton *button1 = [[NSButton alloc] initWithFrame:NSMakeRect(398, 440, 100, 24)];
[button1 setTitle:@BTPLAY];
button1.target = self;
button1.action = @selector(button1Clicked:);
[self.window.contentView addSubview:button1];
NSButton *button2 = [[NSButton alloc] initWithFrame:NSMakeRect(526, 440, 100, 24)];
[button2 setTitle:@BTQUIT];
button2.target = self;
button2.action = @selector(button2Clicked:);
[self.window.contentView addSubview:button2];
// Create the radio buttons
NSButton *radioButton1 = [[NSButton alloc] initWithFrame:NSMakeRect(10, 160, 100, 24)];
[radioButton1 setButtonType:NSButtonTypeRadio];
[radioButton1 setTitle:@LANGEN];
if (userlang == 0)
[radioButton1 setState:NSControlStateValueOn];
radioButton1.target = self;
radioButton1.action = @selector(radioButton1Clicked:);
[self.window.contentView addSubview:radioButton1];
NSButton *radioButton2 = [[NSButton alloc] initWithFrame:NSMakeRect(10, 130, 100, 24)];
[radioButton2 setButtonType:NSButtonTypeRadio];
[radioButton2 setTitle:@LANGFR];
if (userlang == 1)
[radioButton2 setState:NSControlStateValueOn];
radioButton2.target = self;
radioButton2.action = @selector(radioButton2Clicked:);
[self.window.contentView addSubview:radioButton2];
NSButton *radioButton3 = [[NSButton alloc] initWithFrame:NSMakeRect(10, 100, 100, 24)];
[radioButton3 setButtonType:NSButtonTypeRadio];
[radioButton3 setTitle:@LANGDE];
if (userlang == 2)
[radioButton3 setState:NSControlStateValueOn];
radioButton3.target = self;
radioButton3.action = @selector(radioButton3Clicked:);
[self.window.contentView addSubview:radioButton3];
NSButton *radioButton4 = [[NSButton alloc] initWithFrame:NSMakeRect(10, 70, 100, 24)];
[radioButton4 setButtonType:NSButtonTypeRadio];
[radioButton4 setTitle:@LANGRU];
if (userlang == 3)
[radioButton4 setState:NSControlStateValueOn];
radioButton4.target = self;
radioButton4.action = @selector(radioButton4Clicked:);
[self.window.contentView addSubview:radioButton4];
NSButton *radioButton5 = [[NSButton alloc] initWithFrame:NSMakeRect(10, 40, 100, 24)];
[radioButton5 setButtonType:NSButtonTypeRadio];
[radioButton5 setTitle:@LANGES];
if (userlang == 4)
[radioButton5 setState:NSControlStateValueOn];
radioButton5.target = self;
radioButton5.action = @selector(radioButton5Clicked:);
[self.window.contentView addSubview:radioButton5];
NSButton *radioButton6 = [[NSButton alloc] initWithFrame:NSMakeRect(10, 10, 100, 24)];
[radioButton6 setButtonType:NSButtonTypeRadio];
[radioButton6 setTitle:@LANGPT];
if (userlang == 5)
[radioButton6 setState:NSControlStateValueOn];
radioButton6.target = self;
radioButton6.action = @selector(radioButton6Clicked:);
[self.window.contentView addSubview:radioButton6];
// Create the clickable image
NSString *extrasPath = [appPath stringByAppendingPathComponent:@"extras.png"];
NSURL *extrasURL = [NSURL fileURLWithPath:extrasPath];
NSImage *extrasImage = [[NSImage alloc] initWithContentsOfURL:extrasURL];
if (extrasImage)
{
[extrasImage setSize:NSMakeSize(160, 120)]; // Set the image size
NSButton *extrasButton = [[NSButton alloc] initWithFrame:NSMakeRect(self.window.contentView.bounds.size.width - 170, 10, 160, 120)];
[extrasButton setImage:extrasImage];
[extrasButton setButtonType:NSButtonTypeMomentaryChange];
[extrasButton setBordered:NO]; // Remove border
[extrasButton setTarget:self];
[extrasButton setAction:@selector(extrasButtonClicked:)];
[extrasButton setAlphaValue:1.0]; // Make the button fully transparent
[extrasButton setBackgroundColor:[NSColor clearColor]]; // Make the button's background color clear
[self.window.contentView addSubview:extrasButton];
}
NSString* const title = @GAMENAME;
[self.window setTitle:title];
// make frontmost window
[[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps];
[self.window center];
[self.window orderFront:self];
[self.window makeKeyAndOrderFront:self];
[NSApp runModalForWindow:self.window];
//[self.window makeKeyAndOrderFront:self];
}
- (void)extrasButtonClicked:(NSButton *)button
{
LaunchExtras();
}
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
{
return 4; // number of options
}
- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index
{
NSArray *options = @[@VIDMODE1, @VIDMODE2, @VIDMODE3, @VIDMODE4];
return options[index];
}
- (NSString *)comboBox:(NSComboBox *)aComboBox completedString:(NSString *)uncompletedString
{
// This method is called when the user types in the combo box.
// Returning nil means the combo box won't accept the input.
return nil;
}
- (void)comboBoxSelectionDidChange:(NSNotification *)notification
{
NSComboBox *comboBox = notification.object;
//NSLog(@"Combo box selection changed. Selected index: %ld", (long)comboBox.indexOfSelectedItem);
vidmode = comboBox.indexOfSelectedItem;
}
- (void)button1Clicked:(NSButton *)button
{
LaunchGame();
[[NSApplication sharedApplication] terminate:nil];
}
- (void)button2Clicked:(NSButton *)button
{
[[NSApplication sharedApplication] terminate:nil];
}
- (void)deselectOtherButtons:(NSButton *)button
{
for (NSView *subview in self.window.contentView.subviews)
{
if ([subview isKindOfClass:[NSButton class]] && ((NSButton*)subview != button))
{
[(NSButton *)subview setState:NSControlStateValueOff];
}
}
}
- (void)radioButton1Clicked:(NSButton *)button
{
userlang = 0;
[self deselectOtherButtons:button];
}
- (void)radioButton2Clicked:(NSButton *)button
{
userlang = 1;
[self deselectOtherButtons:button];
}
- (void)radioButton3Clicked:(NSButton *)button
{
userlang = 2;
[self deselectOtherButtons:button];
}
- (void)radioButton4Clicked:(NSButton *)button
{
userlang = 3;
[self deselectOtherButtons:button];
}
- (void)radioButton5Clicked:(NSButton *)button
{
userlang = 4;
[self deselectOtherButtons:button];
}
- (void)radioButton6Clicked:(NSButton *)button
{
userlang = 5;
[self deselectOtherButtons:button];
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
// Perform cleanup tasks here
return NSTerminateNow;
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
return YES;
}
- (void)createMainMenu
{
NSMenu *mainMenu = [[NSMenu alloc] initWithTitle:@"MainMenu"];
[NSApp setMainMenu:mainMenu];
// Create the application menu
NSMenuItem *appMenuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[mainMenu addItem:appMenuItem];
NSMenu *appMenu = [[NSMenu alloc] initWithTitle:@""];
[appMenuItem setSubmenu:appMenu];
// Add standard menu items
[appMenu addItemWithTitle:[NSString stringWithFormat:@"About %s", GAMENAME] action:@selector(showAboutDialog) keyEquivalent:@""];
[appMenu addItem:[NSMenuItem separatorItem]];
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Hide %s", GAMENAME] action:@selector(hide:) keyEquivalent:@"h"];
[appMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[[appMenu itemAtIndex:2] setKeyEquivalentModifierMask:(NSEventModifierFlagCommand | NSEventModifierFlagOption)];
[appMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
[appMenu addItem:[NSMenuItem separatorItem]];
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Quit %s", GAMENAME] action:@selector(terminate:) keyEquivalent:@"q"];
}
- (void)showAboutDialog
{
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = [NSString stringWithFormat:@"About %s", GAMENAME];
alert.informativeText = [NSString stringWithFormat:@" Launcher for %s \n Copyright ©️ 2024 HoN Team \n Licensed GPLv3 \n Source code available at: \n https://github.com/HandsOfNecromancy/ ", GAMENAME];
[alert addButtonWithTitle:@"OK"];
[alert runModal];
}
@end
int main(int argc, const char * argv[]) {
LoadSettings();
@autoreleasepool
{
NSMutableString *commandLine = [NSMutableString string];
for (int i = 0; i < argc; i++)
{
[commandLine appendFormat:@"%s ", argv[i]];
}
commandline = strdup((char *)[commandLine UTF8String]);
}
AdjustSettings();
if (skiplauncher)
{
// short circuit window creation, it's not necessary
LaunchGame();
return EXIT_SUCCESS;
}
AppDelegate *appDelegate = [[AppDelegate alloc] init];
NSApplication *application = [NSApplication sharedApplication];
[application setDelegate:appDelegate];
[application run];
return EXIT_SUCCESS;
}