23 #import <Cocoa/Cocoa.h>
30 @interface InputFunctions : NSObject<NSComboBoxDataSource> {
33 - (void) setFunctions:(
std::list<const
char*>) functions;
35 @implementation InputFunctions
36 - (void) setFunctions:(
std::list<const
char *>)functions {
37 NSMutableArray* _items = [NSMutableArray arrayWithCapacity:functions.size()];
38 for (
auto f : functions)
40 [_items addObject:[NSString stringWithUTF8String:f]];;
41 [_items sortUsingSelector:@selector(compare:)];
44 - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox {
47 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index {
48 return [items objectAtIndex:index];
50 - (NSUInteger)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)string {
51 return [items indexOfObject:string];
53 - (NSString *)comboBox:(NSComboBox *)aComboBox completedString:(NSString *)string {
55 for (x = [
string length]-1;
56 x >= 0 && [[NSCharacterSet letterCharacterSet] characterIsMember:[string characterAtIndex:x]]; x--);
58 auto pfx = [string substringWithRange:NSMakeRange(0, x)];
59 auto sub = [string substringFromIndex:x];
60 auto ndx = [items indexOfObjectPassingTest:^(NSString* item, NSUInteger x, BOOL* stop) { return [item hasPrefix:sub]; }];
61 return ndx != NSNotFound ? [pfx stringByAppendingString:[items objectAtIndex:ndx]] : nil;
65 @implementation C4EditorWindowController
67 InputFunctions* inputFunctions;
71 frameLabel, timeLabel, outputTextView, objectPropertiesText,
72 materialsPopup, texturesPopup, outputScrollView, previewView,
73 objectsPanel, toolsPanel, toolSelector, modeSelector, objectCombo, consoleCombo;
79 NSWindow* window =
self.window;
80 [window makeKeyAndOrderFront:self];
81 [window makeMainWindow];
82 [toolsPanel setBecomesKeyOnlyIfNeeded:YES];
83 [objectsPanel setBecomesKeyOnlyIfNeeded:YES];
84 inputFunctions = [InputFunctions new];
85 [consoleCombo setUsesDataSource:YES];
86 [consoleCombo setDataSource:inputFunctions];
87 [consoleCombo setCompletes:YES];
90 - (void) setInputFunctions:(
std::list<const
char*>)functions {
91 [inputFunctions setFunctions:functions];
92 [consoleCombo reloadData];
95 - (void) windowWillClose:(NSNotification*)notification
97 if (notification.object == objectsPanel)
99 Console.PropertyDlgClose();
101 else if (notification.object == toolsPanel)
103 Console.ToolsDlg.Clear();
107 int indexFromSender(
id sender)
109 if ([sender respondsToSelector:
@selector(selectedSegment)])
110 return [sender selectedSegment];
111 else if ([sender respondsToSelector:
@selector(tag)])
117 - (IBAction) selectMode:(
id)sender
120 for (NSWindow* w in [[NSApplication sharedApplication] windows])
124 [w invalidateCursorRectsForView:[[w windowController] openGLView]];
129 - (IBAction) play:(
id)sender
134 - (IBAction) halt:(
id)sender
139 - (IBAction) selectMaterial:(
id)sender
144 - (IBAction) selectTexture:(
id)sender
149 - (IBAction) selectTool:(
id)sender
154 - (IBAction) selectIFT:(
id)sender
159 - (IBAction) selectLandscapeMode:(
id)sender
165 - (IBAction) setGrade:(
id)sender
172 - (IBAction) consoleIn:(
id)sender
176 Console.
In([[consoleCombo stringValue] cStringUsingEncoding:NSUTF8StringEncoding]);
179 - (IBAction) objectIn:(
id)sender
183 Console.
EditCursor.
In([[objectCombo stringValue] cStringUsingEncoding:NSUTF8StringEncoding]);
186 - (IBAction) kickPlayer:(
id)sender
193 - (BOOL)validateUserInterfaceItem:(
id<NSValidatedUserInterfaceItem>)item
196 SEL gameRunningInConsoleModeSelectors[] =
200 @selector(selectMode:),
205 while ((
s = gameRunningInConsoleModeSelectors[i++]) != nil)
207 if (
s == [item action])
const char * LoadResStr(const char *id)
C4Client * getClientByID(int32_t iID) const
void CtrlRemove(const C4Client *pClient, const char *szReason)
bool In(const char *szText)
bool SetMode(int32_t iMode)
bool In(const char *szText)
BOOL isEditorAndGameRunning()
C4AppDelegate * instance()