OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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

- (BOOL) argsLookLikeItShouldBeInstallation

Definition at line 191 of file C4AppDelegate.mm.

References addonSupplied, and gatheredArguments.

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
- (IBAction) closeScenario: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Console, and C4Console::FileClose().

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

Here is the call graph for this function:

- (BOOL) installAddOn

Definition at line 222 of file C4AppDelegate.mm.

References addonSupplied, C4Reloc::begin(), C4Reloc::end(), gatheredArguments, C4Reloc::PATH_PreferredInstallationLocation, and Reloc.

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 }
PathList::const_iterator iterator
Definition: C4Reloc.h:36
iterator begin() const
Definition: C4Reloc.cpp:58
C4Reloc Reloc
Definition: C4Reloc.cpp:21
iterator end() const
Definition: C4Reloc.cpp:63
NSString * addonSupplied
Definition: C4AppDelegate.h:34

Here is the call graph for this function:

+ (C4AppDelegate *) instance

Definition at line 32 of file C4AppDelegate.mm.

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

Definition at line 37 of file C4AppDelegate.mm.

References Application, Game, C4Application::isEditor, and C4Game::IsRunning.

38 {
40 }
bool IsRunning
Definition: C4Game.h:139
C4Game Game
Definition: C4Globals.cpp:52
C4Application Application
Definition: C4Globals.cpp:44
- (IBAction) joinPlayer: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Console, and C4Console::PlayerJoin().

76  :(id)sender
77 {
79 }
C4Console Console
Definition: C4Globals.cpp:45
void PlayerJoin()
Definition: C4Console.cpp:513

Here is the call graph for this function:

- (void) makeFakeArgs

Definition at line 265 of file C4AppDelegate.mm.

References args, and gatheredArguments.

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
- (IBAction) makeScreenshot: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References GraphicsSystem, and C4GraphicsSystem::SaveScreenshotKey().

195  :(id)sender;
196 {
198 }
bool SaveScreenshotKey(bool fSaveAll)
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51

Here is the call graph for this function:

- (IBAction) makeScreenshotOfWholeMap: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References GraphicsSystem, and C4GraphicsSystem::SaveScreenshotKey().

200  :(id)sender;
201 {
203 }
bool SaveScreenshotKey(bool fSaveAll)
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51

Here is the call graph for this function:

- (IBAction) newViewport: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Console, and C4Console::ViewportNew().

66  :(id)sender
67 {
69 }
C4Console Console
Definition: C4Globals.cpp:45
void ViewportNew()
Definition: C4Console.cpp:456

Here is the call graph for this function:

- (IBAction) newViewportForPlayer: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References C4ViewportList::CreateViewport(), and Viewports.

71  :(id)sender
72 {
73  ::Viewports.CreateViewport([sender tag]);
74 }
bool CreateViewport(int32_t iPlayer, bool fSilent=false)
Definition: C4Viewport.cpp:917
C4ViewportList Viewports
Definition: C4Viewport.cpp:841

Here is the call graph for this function:

- (IBAction) openPropTools: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Console, C4Console::EditCursor, and C4EditCursor::OpenPropTools().

81  :(id)sender;
82 {
84 }
C4EditCursor EditCursor
Definition: C4Console.h:90
C4Console Console
Definition: C4Globals.cpp:45
bool OpenPropTools()

Here is the call graph for this function:

- (IBAction) openScenario: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Console, and C4Console::FileOpen().

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

Here is the call graph for this function:

- (IBAction) openScenarioWithPlayers: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Console, and C4Console::FileOpenWPlrs().

34  :(id)sender
35 {
37 }
C4Console Console
Definition: C4Globals.cpp:45
bool FileOpenWPlrs()
Definition: C4Console.cpp:343

Here is the call graph for this function:

- (IBAction) record: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Console, and C4Console::FileRecord().

61  :(id)sender
62 {
64 }
C4Console Console
Definition: C4Globals.cpp:45
bool FileRecord()
Definition: C4Console.cpp:394

Here is the call graph for this function:

- (IBAction) saveGameAs: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Console, and C4Console::FileSaveAs().

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

Here is the call graph for this function:

- (IBAction) saveScenario: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Console, and C4Console::FileSave().

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

Here is the call graph for this function:

- (IBAction) saveScenarioAs: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Console, and C4Console::FileSaveAs().

56  :(id)sender
57 {
58  Console.FileSaveAs(false);
59 }
bool FileSaveAs(bool fSaveGame, bool export_packed=false)
Definition: C4Console.cpp:269
C4Console Console
Definition: C4Globals.cpp:45

Here is the call graph for this function:

- (IBAction) setConsoleMode: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

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

Provided by category C4AppDelegate(MainMenuActions).

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

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

Provided by category C4AppDelegate(MainMenuActions).

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

References Console, and C4Console::HelpAbout().

86  :(id)sender;
87 {
89 }
C4Console Console
Definition: C4Globals.cpp:45
void HelpAbout()
Definition: C4Console.cpp:449

Here is the call graph for this function:

- (void) simulateKeyPressed: (C4KeyCode key

Provided by category C4AppDelegate(MainMenuActions).

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

References C4Game::DoKeyboardInput(), Game, KEYEV_Down, and KEYEV_Up.

Referenced by suggestQuitting:, and togglePause:.

189  :(C4KeyCode)key
190 {
191  Game.DoKeyboardInput(key, KEYEV_Down, false, false, false, false, NULL);
192  Game.DoKeyboardInput(key, KEYEV_Up, false, false, false, false, NULL);
193 }
C4Game Game
Definition: C4Globals.cpp:52
bool DoKeyboardInput(C4KeyCode vk_code, C4KeyEventType eEventType, bool fAlt, bool fCtrl, bool fShift, bool fRepeated, class C4GUI::Dialog *pForDialog=nullptr, bool fPlrCtrlOnly=false, int32_t iStrength=-1)
Definition: C4Game.cpp:1865
unsigned long C4KeyCode

Here is the call graph for this function:

Here is the caller graph for this function:

- (IBAction) suggestQuitting: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Application, C4Application::Clear(), Console, C4Console::FileClose(), C4AbstractApp::fQuitMsgReceived, Game, C4Application::isEditor, C4Game::IsRunning, C4Application::Quit(), StdScheduler::ScheduleProcs(), and simulateKeyPressed:.

120  :(id)sender;
121 {
123  {
124  NSLog(@"Game running, only simulating Esc key");
125  [self simulateKeyPressed:K_ESCAPE];
126  }
127  else
128  {
129  if (Application.isEditor)
130  Console.FileClose();
133  Application.Clear();
134  Application.Quit();
135  }
136 }
bool IsRunning
Definition: C4Game.h:139
C4Console Console
Definition: C4Globals.cpp:45
C4Game Game
Definition: C4Globals.cpp:52
bool FileClose()
Definition: C4Console.cpp:382
void Clear() override
bool fQuitMsgReceived
Definition: C4App.h:81
void Quit() override
bool ScheduleProcs(int iTimeout=1000/36)
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

- (void) terminate: (NSApplication*)  sender

Definition at line 171 of file C4AppDelegate.mm.

References Application, and C4AbstractApp::fQuitMsgReceived.

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 }
bool fQuitMsgReceived
Definition: C4App.h:81
C4Application Application
Definition: C4Globals.cpp:44
- (IBAction) toggleFullScreen: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References Application, Config, C4Config::Graphics, C4Application::isEditor, and C4ConfigGraphics::Windowed.

91  :(id)sender
92 {
94  {
95  NSBeep();
96  return;
97  }
98  [gameWindowController setFullscreen:Config.Graphics.Windowed];
100 
101 }
C4Config Config
Definition: C4Config.cpp:833
int32_t Windowed
Definition: C4Config.h:106
C4ConfigGraphics Graphics
Definition: C4Config.h:253
C4Application Application
Definition: C4Globals.cpp:44
- (IBAction) togglePause: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References simulateKeyPressed:.

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

Here is the call graph for this function:

- (IBAction) visitWebsite: (id)  sender

Provided by category C4AppDelegate(MainMenuActions).

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

References OpenURL().

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

Here is the call graph for this function:

Member Data Documentation

- (NSString*) addonSupplied
protected

Definition at line 34 of file C4AppDelegate.h.

Referenced by argsLookLikeItShouldBeInstallation, and installAddOn.

- (vector<char*>) C4AppDelegate:
protected

Definition at line 40 of file C4AppDelegate.h.

Referenced by makeFakeArgs.

- (NSMutableArray*) gatheredArguments
protected

Definition at line 33 of file C4AppDelegate.h.

Referenced by argsLookLikeItShouldBeInstallation, installAddOn, and makeFakeArgs.

- (BOOL) running
protected

Definition at line 39 of file C4AppDelegate.h.


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