OpenClonk
C4AppDelegate Class Reference

#import <C4AppDelegate.h>

Inheritance diagram for C4AppDelegate:
[legend]
Collaboration diagram for C4AppDelegate:
[legend]

Instance Methods

(BOOL) - argsLookLikeItShouldBeInstallation
 
(void) - makeFakeArgs
 
(BOOL) - installAddOn
 
(void) - terminate:
 
(IBAction) - openScenario:
 
(IBAction) - openScenarioWithPlayers:
 
(IBAction) - closeScenario:
 
(IBAction) - saveGameAs:
 
(IBAction) - saveScenario:
 
(IBAction) - saveScenarioAs:
 
(IBAction) - record:
 
(IBAction) - newViewport:
 
(IBAction) - openPropTools:
 
(IBAction) - newViewportForPlayer:
 
(IBAction) - joinPlayer:
 
(IBAction) - showAbout:
 
(IBAction) - toggleFullScreen:
 
(IBAction) - togglePause:
 
(IBAction) - setConsoleMode:
 
(IBAction) - setDrawingTool:
 
(IBAction) - suggestQuitting:
 
(IBAction) - simulateKeyPressed:
 
(IBAction) - visitWebsite:
 
(IBAction) - makeScreenshot:
 
(IBAction) - makeScreenshotOfWholeMap:
 

Class Methods

(C4AppDelegate *) + instance
 
(BOOL) + isEditorAndGameRunning
 

Protected Attributes

NSMutableArray * gatheredArguments
 
NSString * addonSupplied
 
BOOL running
 
std::vector< char * > args
 

Detailed Description

Definition at line 31 of file C4AppDelegate.h.

Method Documentation

◆ argsLookLikeItShouldBeInstallation

- (BOOL) argsLookLikeItShouldBeInstallation

Definition at line 305 of file C4AppDelegate.mm.

192 {
193  // not having this check leads to deletion of Clonk folder -.-
194  if (!addonSupplied)
195  return NO;
196  for (unsigned int i = 0; i < [gatheredArguments count]; i++)
197  {
198  NSString* arg = [gatheredArguments objectAtIndex:i];
199  if ([arg hasPrefix:@"-psn"])
200  return YES;
201  }
202  return NO;
203 }
NSString * addonSupplied
Definition: C4AppDelegate.h:34

◆ closeScenario:

- (IBAction) closeScenario: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

40  :(id)sender
41 {
43  [editorWindowController.window setRepresentedFilename:@""];
44 }
C4Console Console
Definition: C4Globals.cpp:45
bool FileClose()
Definition: C4Console.cpp:382

◆ installAddOn

- (BOOL) installAddOn

Definition at line 305 of file C4AppDelegate.mm.

223 {
224  if (!addonSupplied)
225  return NO;
226 
227  // load configuration + localization so LoadResStr can be used
228  [self minimalConfigurationInitialization];
229 
230  // Build destination path.
231  NSString* justFileName = [addonSupplied lastPathComponent];
232  NSString* destPath = [self clonkDirectory];
233  NSString* formatString;
234 
235  // Already installed?
236  for (C4Reloc::iterator it = Reloc.begin(); it != Reloc.end(); ++it)
237  {
238  if ([addonSupplied hasPrefix:[NSString stringWithCString:(*it).strBuf.getData() encoding:NSUTF8StringEncoding]])
239  {
240  [gatheredArguments addObject:addonSupplied];
241  return NO; // run scenarios when they are already containd in one of the Reloc directories
242  }
243  else if (it->pathType == C4Reloc::PATH_PreferredInstallationLocation)
244  destPath = [NSString stringWithCString:it->strBuf.getData() encoding:NSUTF8StringEncoding];
245  }
246  destPath = [destPath stringByAppendingPathComponent:justFileName];
247 
248  NSFileManager* fileManager = [NSFileManager defaultManager];
249  if ([fileManager fileExistsAtPath:destPath])
250  // better to throw it into the trash. everything else seems so dangerously destructive
251  [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[self clonkDirectory] destination:@"" files:[NSArray arrayWithObject:justFileName] tag:0];
252  if ([fileManager copyItemAtPath:addonSupplied toPath:destPath error:NULL])
253  {
254  formatString = [NSString stringWithCString:LoadResStr("IDS_ADDON_INSTALLSUCCESS") encoding:NSUTF8StringEncoding];
255  }
256  else
257  {
258  formatString = [NSString stringWithCString:LoadResStr("IDS_ADDON_INSTALLFAILURE") encoding:NSUTF8StringEncoding];
259  }
260  [self infoWithFormat:formatString andArgument:[justFileName cStringUsingEncoding:NSUTF8StringEncoding]];
261  return YES; // only return NO when the scenario should be run rather than installed
262 }
C4Reloc Reloc
Definition: C4Reloc.cpp:21
@ PATH_PreferredInstallationLocation
Definition: C4Reloc.h:28
iterator end() const
Definition: C4Reloc.cpp:149
iterator begin() const
Definition: C4Reloc.cpp:142

◆ instance

+ (C4AppDelegate *) instance

Definition at line 305 of file C4AppDelegate.mm.

33 {
34  return (C4AppDelegate*)[[NSApplication sharedApplication] delegate];
35 }

◆ isEditorAndGameRunning

+ (BOOL) isEditorAndGameRunning

Definition at line 305 of file C4AppDelegate.mm.

38 {
40 }
C4Game Game
Definition: C4Globals.cpp:52
C4Application Application
Definition: C4Globals.cpp:44
bool IsRunning
Definition: C4Game.h:140

◆ joinPlayer:

- (IBAction) joinPlayer: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

77  :(id)sender
78 {
80 }
void PlayerJoin()
Definition: C4Console.cpp:513

◆ makeFakeArgs

- (void) makeFakeArgs

Definition at line 305 of file C4AppDelegate.mm.

266 {
267  NSArray* nonCocoaArgs = [gatheredArguments filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSString* arg, NSDictionary *bindings)
268  {
269  return
270  !(
271  [arg hasPrefix:@"-NS"] ||
272  [arg isEqualToString:@"YES"]
273  );
274  }
275  ]];
276  int argCount = [nonCocoaArgs count];
277  args.resize(argCount);
278  for (int i = 0; i < argCount; i++)
279  {
280  args[i] = strdup([[nonCocoaArgs objectAtIndex:i] cStringUsingEncoding:NSUTF8StringEncoding]);
281  }
282 }
std::vector< char * > args
Definition: C4AppDelegate.h:40

◆ makeScreenshot:

- (IBAction) makeScreenshot: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

196  :(id)sender
197 {
199 }
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
bool SaveScreenshotKey(bool save_all)

◆ makeScreenshotOfWholeMap:

- (IBAction) makeScreenshotOfWholeMap: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

201  :(id)sender
202 {
204 }

◆ newViewport:

- (IBAction) newViewport: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

67  :(id)sender
68 {
70 }
void ViewportNew()
Definition: C4Console.cpp:456

◆ newViewportForPlayer:

- (IBAction) newViewportForPlayer: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

72  :(id)sender
73 {
74  ::Viewports.CreateViewport([sender tag]);
75 }
C4ViewportList Viewports
bool CreateViewport(int32_t player_nr, bool silent=false)

◆ openPropTools:

- (IBAction) openPropTools: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

82  :(id)sender
83 {
85 }
C4EditCursor EditCursor
Definition: C4Console.h:90
bool OpenPropTools()

◆ openScenario:

- (IBAction) openScenario: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

30  :(id)sender
31 {
32  Console.FileOpen();
33 }
bool FileOpen(const char *filename=nullptr, bool host_in_network=false)
Definition: C4Console.cpp:319

◆ openScenarioWithPlayers:

- (IBAction) openScenarioWithPlayers: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

35  :(id)sender
36 {
38 }
bool FileOpenWPlrs()
Definition: C4Console.cpp:343

◆ record:

- (IBAction) record: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

62  :(id)sender
63 {
65 }
bool FileRecord()
Definition: C4Console.cpp:394

◆ saveGameAs:

- (IBAction) saveGameAs: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

47  :(id)sender
48 {
49  Console.FileSaveAs(true);
50 }
bool FileSaveAs(bool fSaveGame, bool export_packed=false)
Definition: C4Console.cpp:269

◆ saveScenario:

- (IBAction) saveScenario: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

52  :(id)sender
53 {
54  Console.FileSave();
55 }
bool FileSave()
Definition: C4Console.cpp:262

◆ saveScenarioAs:

- (IBAction) saveScenarioAs: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

57  :(id)sender
58 {
59  Console.FileSaveAs(false);
60 }

◆ setConsoleMode:

- (IBAction) setConsoleMode: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

109  :(id)sender
110 {
111  [editorWindowController selectMode:sender];
112  [editorWindowController.modeSelector selectSegmentWithTag:[sender tag]];
113 }

◆ setDrawingTool:

- (IBAction) setDrawingTool: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

115  :(id)sender
116 {
117  [editorWindowController selectTool:sender];
118  [editorWindowController.toolSelector selectSegmentWithTag:[sender tag]];
119 }

◆ showAbout:

- (IBAction) showAbout: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

87  :(id)sender
88 {
90 }
void HelpAbout()
Definition: C4Console.cpp:449

◆ simulateKeyPressed:

- (void) simulateKeyPressed: (C4KeyCode key

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

190  :(C4KeyCode)key
191 {
192  Game.DoKeyboardInput(key, KEYEV_Down, false, false, false, false, NULL);
193  Game.DoKeyboardInput(key, KEYEV_Up, false, false, false, false, NULL);
194 }
@ KEYEV_Up
@ KEYEV_Down
unsigned long C4KeyCode
bool DoKeyboardInput(C4KeyCode vk_code, C4KeyEventType event_type, bool alt, bool ctrl, bool shift, bool repeated, class C4GUI::Dialog *for_dialog=nullptr, bool fPlrCtrlOnly=false, int32_t strength=-1)
Definition: C4Game.cpp:2288

◆ suggestQuitting:

- (IBAction) suggestQuitting: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

121  :(id)sender
122 {
124  {
125  NSLog(@"Game running, only simulating Esc key");
126  [self simulateKeyPressed:K_ESCAPE];
127  }
128  else
129  {
130  if (Application.isEditor)
131  Console.FileClose();
134  Application.Clear();
135  Application.Quit();
136  }
137 }
bool fQuitMsgReceived
Definition: C4App.h:81
void Clear() override
void Quit() override
bool ScheduleProcs(int iTimeout=1000/36)

◆ terminate:

- (void) terminate: (NSApplication*)  sender

Definition at line 305 of file C4AppDelegate.mm.

171  :(NSApplication*)sender
172 {
173 #ifdef USE_SDL_MAINLOOP
174  // Post an SDL_QUIT event
175  SDL_Event event;
176  event.type = SDL_QUIT;
177  SDL_PushEvent(&event);
178 #endif
179 #ifdef USE_COCOA
181 #endif
182 }

◆ toggleFullScreen:

- (IBAction) toggleFullScreen: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

92  :(id)sender
93 {
95  {
96  NSBeep();
97  return;
98  }
99  [gameWindowController setFullscreen:Config.Graphics.Windowed];
101 
102 }
C4Config Config
Definition: C4Config.cpp:930
int32_t Windowed
Definition: C4Config.h:107
C4ConfigGraphics Graphics
Definition: C4Config.h:257

◆ togglePause:

- (IBAction) togglePause: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

104  :(id)sender
105 {
106  [self simulateKeyPressed:K_PAUSE];
107 }

◆ visitWebsite:

- (IBAction) visitWebsite: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

Definition at line 1 of file C4AppDelegate+MainMenuActions.mm.

185  :(id)sender
186 {
187  OpenURL("http://wiki.openclonk.org");
188 }
bool OpenURL(const char *szURL)
Definition: C4AppMac.mm:199

Member Data Documentation

◆ addonSupplied

- (NSString*) addonSupplied
protected

Definition at line 34 of file C4AppDelegate.h.

◆ args

- (vector<char*>) C4AppDelegate:
protected

Definition at line 40 of file C4AppDelegate.h.

◆ gatheredArguments

- (NSMutableArray *) gatheredArguments
protected

Definition at line 33 of file C4AppDelegate.h.

◆ running

- (BOOL) running
protected

Definition at line 39 of file C4AppDelegate.h.


The documentation for this class was generated from the following files: