2010-09-12 09:12:02 +00:00
|
|
|
#include "QF/sys.h"
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
#include "Things.h"
|
|
|
|
#include "QuakeEd.h"
|
|
|
|
#include "Map.h"
|
|
|
|
#include "EntityClass.h"
|
|
|
|
#include "KeypairView.h"
|
|
|
|
#include "Project.h"
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
id things_i;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
@implementation Things
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-init
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
[super init];
|
|
|
|
|
|
|
|
things_i = self;
|
|
|
|
lastSelected = 0;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-27 14:17:03 +00:00
|
|
|
-(void)awakeFromNib
|
|
|
|
{
|
|
|
|
//FIXME this should not be needed (bug in gnustep?)
|
|
|
|
[flags_i selectAll: self];
|
|
|
|
[flags_i deselectAllCells];
|
|
|
|
}
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Load the TEXT object with the entity comment
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
-loadEntityComment:(id) obj
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
[entity_comment_i selectAll:self];
|
2010-09-11 10:03:41 +00:00
|
|
|
[entity_comment_i replaceCharactersInRange: [entity_comment_i selectedRange] withString: [NSString stringWithCString:[obj
|
|
|
|
comments]]];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-initEntities
|
|
|
|
{
|
|
|
|
char *path;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
path =[project_i getProgDirectory];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
[prog_path_i setStringValue: [NSString stringWithCString:path]];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
[[EntityClassList alloc] initForSourceDirectory:path];
|
|
|
|
|
|
|
|
[self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]];
|
2003-03-18 19:48:24 +00:00
|
|
|
[entity_browser_i loadColumnZero];
|
2010-09-11 10:03:41 +00:00
|
|
|
[[entity_browser_i matrixInColumn: 0] selectCellAtRow: lastSelected column:0];
|
|
|
|
|
|
|
|
[entity_browser_i setDoubleAction: @selector (doubleClickEntity:)];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-selectEntity:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id matr;
|
|
|
|
|
|
|
|
matr =[sender matrixInColumn:0];
|
|
|
|
lastSelected =[matr selectedRow];
|
|
|
|
[self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]];
|
|
|
|
[quakeed_i makeFirstResponder:quakeed_i];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-doubleClickEntity:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
[map_i makeEntity:sender];
|
|
|
|
[quakeed_i makeFirstResponder:quakeed_i];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-(char *) spawnName
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
return[[entity_classes_i objectAtIndex:lastSelected] classname];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Flush entity classes & reload them!
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
-reloadEntityClasses:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
EntityClass *ent;
|
2010-09-11 10:03:41 +00:00
|
|
|
char *path;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
path = (char *)[prog_path_i stringValue];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (!path || !path[0]) {
|
|
|
|
path =[project_i getProgDirectory];
|
2010-09-09 11:46:38 +00:00
|
|
|
[prog_path_i setStringValue: [NSString stringWithCString:path]];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
// Free all entity info in memory...
|
2010-09-09 11:46:38 +00:00
|
|
|
[entity_classes_i removeAllObjects];
|
|
|
|
[entity_classes_i release];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
// Now, RELOAD!
|
|
|
|
[[EntityClassList alloc] initForSourceDirectory:path];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
lastSelected = 0;
|
2010-09-11 10:03:41 +00:00
|
|
|
ent =[entity_classes_i objectAtIndex:lastSelected];
|
|
|
|
[self loadEntityComment: [entity_classes_i objectAtIndex:lastSelected]];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
[entity_browser_i loadColumnZero];
|
2010-09-11 10:03:41 +00:00
|
|
|
[[entity_browser_i matrixInColumn: 0] selectCellAtRow: lastSelected column:0];
|
|
|
|
|
|
|
|
[self newCurrentEntity]; // in case flags changed
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-27 15:29:16 +00:00
|
|
|
-selectClass:(const char *) class
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id classent;
|
|
|
|
|
|
|
|
classent =[entity_classes_i classForName:class];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (!classent)
|
|
|
|
return self;
|
2010-09-11 10:03:41 +00:00
|
|
|
lastSelected =[entity_classes_i indexOfObject:classent];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
if (lastSelected < 0)
|
|
|
|
lastSelected = 0;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[self loadEntityComment:classent];
|
2010-09-11 10:03:41 +00:00
|
|
|
[[entity_browser_i matrixInColumn: 0] selectCellAtRow: lastSelected column:0];
|
|
|
|
[[entity_browser_i matrixInColumn: 0] scrollCellToVisibleAtRow: lastSelected column:0];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-newCurrentEntity
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id ent, classent, cell;
|
2010-09-27 15:29:16 +00:00
|
|
|
const char *classname;
|
2010-09-11 10:03:41 +00:00
|
|
|
int r, c;
|
2010-09-27 15:29:16 +00:00
|
|
|
const char *flagname;
|
2010-09-11 10:03:41 +00:00
|
|
|
int flags;
|
|
|
|
|
|
|
|
ent =[map_i currentEntity];
|
|
|
|
classname =[ent valueForQKey:"classname"];
|
|
|
|
if (ent !=[map_i objectAtIndex:0])
|
|
|
|
[self selectClass:classname]; // don't reset for world
|
|
|
|
classent =[entity_classes_i classForName:classname];
|
|
|
|
flagname =[ent valueForQKey:"spawnflags"];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (!flagname)
|
|
|
|
flags = 0;
|
|
|
|
else
|
2010-09-11 10:03:41 +00:00
|
|
|
flags = atoi (flagname);
|
|
|
|
|
2010-09-14 13:17:35 +00:00
|
|
|
//[flags_i setAutodisplay:NO];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (r = 0; r < 4; r++)
|
|
|
|
for (c = 0; c < 3; c++) {
|
|
|
|
cell =[flags_i cellAtRow: r column:c];
|
|
|
|
if (c < 2) {
|
|
|
|
flagname =[classent flagName:c * 4 + r];
|
2010-09-09 11:46:38 +00:00
|
|
|
[cell setTitle: [NSString stringWithCString:flagname]];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
[cell setIntValue:(flags & (1 << ((c * 4) + r))) > 0];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-14 13:17:35 +00:00
|
|
|
//[flags_i setAutodisplay:YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
[flags_i display];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
// [keyInput_i setStringValue: ""];
|
|
|
|
// [valueInput_i setStringValue: ""];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
[keypairview_i calcViewSize];
|
|
|
|
[keypairview_i display];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
[quakeed_i makeFirstResponder:quakeed_i];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Clicked in the Keypair view - set as selected
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
-setSelectedKey:(epair_t *) ep;
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
[keyInput_i setStringValue: [NSString stringWithCString:ep->key]];
|
|
|
|
[valueInput_i setStringValue: [NSString stringWithCString:ep->value]];
|
|
|
|
[valueInput_i selectText:self];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-clearInputs
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
// [keyInput_i setStringValue: ""];
|
|
|
|
// [valueInput_i setStringValue: ""];
|
|
|
|
|
|
|
|
[quakeed_i makeFirstResponder:quakeed_i];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Action methods
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
-addPair:sender
|
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
char *key, *value;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
key = (char *)[keyInput_i stringValue];
|
|
|
|
value = (char *)[valueInput_i stringValue];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
[[map_i currentEntity] setKey: key toValue:value];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
[keypairview_i calcViewSize];
|
|
|
|
[keypairview_i display];
|
|
|
|
|
|
|
|
[self clearInputs];
|
|
|
|
[quakeed_i updateXY];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-delPair:sender
|
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
[quakeed_i makeFirstResponder:quakeed_i];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
[[map_i currentEntity] removeKeyPair:(char *)[keyInput_i stringValue]];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
[keypairview_i calcViewSize];
|
|
|
|
[keypairview_i display];
|
|
|
|
|
|
|
|
[self clearInputs];
|
|
|
|
|
|
|
|
[quakeed_i updateXY];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Set the key/value fields to "angle <button value>"
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
-setAngle:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
const char *title;
|
2010-09-11 10:03:41 +00:00
|
|
|
char value[10];
|
|
|
|
|
|
|
|
title =[[[sender selectedCell] title] cString];
|
|
|
|
if (!strcmp (title, "Up"))
|
2003-03-18 19:48:24 +00:00
|
|
|
strcpy (value, "-1");
|
2010-09-11 10:03:41 +00:00
|
|
|
else if (!strcmp (title, "Dn"))
|
2003-03-18 19:48:24 +00:00
|
|
|
strcpy (value, "-2");
|
|
|
|
else
|
|
|
|
strcpy (value, title);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
[keyInput_i setStringValue:@"angle"];
|
2010-09-11 10:03:41 +00:00
|
|
|
[valueInput_i setStringValue: [NSString stringWithCString:value]];
|
2003-03-18 19:48:24 +00:00
|
|
|
[self addPair:NULL];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[self clearInputs];
|
|
|
|
|
|
|
|
[quakeed_i updateXY];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-setFlags:sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int flags;
|
|
|
|
int r, c, i;
|
|
|
|
id cell;
|
|
|
|
char str[20];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[self clearInputs];
|
|
|
|
flags = 0;
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
for (r = 0; r < 4; r++)
|
|
|
|
for (c = 0; c < 3; c++) {
|
|
|
|
cell =[flags_i cellAtRow: r column:c];
|
2003-03-18 19:48:24 +00:00
|
|
|
i = ([cell intValue] > 0);
|
2010-09-11 10:03:41 +00:00
|
|
|
flags |= (i << ((c * 4) + r));
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
if (!flags)
|
2010-09-11 10:03:41 +00:00
|
|
|
[[map_i currentEntity] removeKeyPair:"spawnflags"];
|
|
|
|
else {
|
2003-03-18 19:48:24 +00:00
|
|
|
sprintf (str, "%i", flags);
|
2010-09-11 10:03:41 +00:00
|
|
|
[[map_i currentEntity] setKey: "spawnflags" toValue:str];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[keypairview_i calcViewSize];
|
|
|
|
[keypairview_i display];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Fill the Entity browser
|
|
|
|
// (Delegate method - delegated in Interface Builder)
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-14 13:17:35 +00:00
|
|
|
-(void) browser: sender createRowsForColumn:(int) column inMatrix: matrix
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id cell;
|
|
|
|
int max;
|
|
|
|
int i;
|
|
|
|
id object;
|
|
|
|
|
|
|
|
max =[entity_classes_i count];
|
2003-03-18 19:48:24 +00:00
|
|
|
i = 0;
|
2010-09-11 10:03:41 +00:00
|
|
|
while (max--) {
|
|
|
|
object =[entity_classes_i objectAtIndex:i];
|
2003-03-18 19:48:24 +00:00
|
|
|
[matrix addRow];
|
2010-09-11 10:03:41 +00:00
|
|
|
cell =[matrix cellAtRow: i++ column:0];
|
|
|
|
[cell setStringValue: [NSString stringWithCString:[object
|
|
|
|
classname]]];
|
2003-03-18 19:48:24 +00:00
|
|
|
[cell setLeaf:YES];
|
|
|
|
[cell setLoaded:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|