#include "Things.h" #include "QuakeEd.h" #include "Map.h" #include "EntityClass.h" #include "KeypairView.h" #include "Project.h" id things_i; @implementation Things - init { [super init]; things_i = self; lastSelected = 0; return self; } // // Load the TEXT object with the entity comment // - loadEntityComment:(id)obj { [entity_comment_i selectAll:self]; [entity_comment_i replaceCharactersInRange:[entity_comment_i selectedRange] withString:[NSString stringWithCString:[obj comments]]]; return self; } - initEntities { char *path; path = [project_i getProgDirectory]; [prog_path_i setStringValue: [NSString stringWithCString:path]]; [[EntityClassList alloc] initForSourceDirectory: path]; [self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]]; [entity_browser_i loadColumnZero]; [[entity_browser_i matrixInColumn:0] selectCellAtRow:lastSelected column:0]; [entity_browser_i setDoubleAction: @selector(doubleClickEntity:)]; return self; } - selectEntity: sender { id matr; matr = [sender matrixInColumn: 0]; lastSelected = [matr selectedRow]; [self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]]; [quakeed_i makeFirstResponder: quakeed_i]; return self; } - doubleClickEntity: sender { [map_i makeEntity: sender]; [quakeed_i makeFirstResponder: quakeed_i]; return self; } - (char *)spawnName { return [[entity_classes_i objectAtIndex:lastSelected] classname]; } // // Flush entity classes & reload them! // - reloadEntityClasses: sender { EntityClass *ent; char *path; path = (char *)[prog_path_i stringValue]; if (!path || !path[0]) { path = [project_i getProgDirectory]; [prog_path_i setStringValue: [NSString stringWithCString:path]]; } // Free all entity info in memory... [entity_classes_i removeAllObjects]; [entity_classes_i release]; // Now, RELOAD! [[EntityClassList alloc] initForSourceDirectory: path]; lastSelected = 0; ent = [entity_classes_i objectAtIndex:lastSelected]; [self loadEntityComment:[entity_classes_i objectAtIndex:lastSelected]]; [entity_browser_i loadColumnZero]; [[entity_browser_i matrixInColumn:0] selectCellAtRow:lastSelected column:0]; [self newCurrentEntity]; // in case flags changed return self; } - selectClass: (char *)class { id classent; classent = [entity_classes_i classForName:class]; if (!classent) return self; lastSelected = [entity_classes_i indexOfObject: classent]; if (lastSelected < 0) lastSelected = 0; [self loadEntityComment:classent]; [[entity_browser_i matrixInColumn:0] selectCellAtRow:lastSelected column:0]; [[entity_browser_i matrixInColumn:0] scrollCellToVisibleAtRow:lastSelected column:0]; return self; } - newCurrentEntity { id ent, classent, cell; char *classname; int r, c; char *flagname; 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"]; if (!flagname) flags = 0; else flags = atoi(flagname); [flags_i setAutodisplay: NO]; 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]; [cell setTitle: [NSString stringWithCString:flagname]]; } [cell setIntValue: (flags & (1<< ((c*4)+r)) ) > 0]; } [flags_i setAutodisplay: YES]; [flags_i display]; // [keyInput_i setStringValue: ""]; // [valueInput_i setStringValue: ""]; [keypairview_i calcViewSize]; [keypairview_i display]; [quakeed_i makeFirstResponder: quakeed_i]; return self; } // // Clicked in the Keypair view - set as selected // - setSelectedKey:(epair_t *)ep; { [keyInput_i setStringValue:[NSString stringWithCString:ep->key]]; [valueInput_i setStringValue:[NSString stringWithCString:ep->value]]; [valueInput_i selectText:self]; return self; } - clearInputs { // [keyInput_i setStringValue: ""]; // [valueInput_i setStringValue: ""]; [quakeed_i makeFirstResponder: quakeed_i]; return self; } // // Action methods // -addPair:sender { char *key, *value; key = (char *)[keyInput_i stringValue]; value = (char *)[valueInput_i stringValue]; [ [map_i currentEntity] setKey: key toValue: value ]; [keypairview_i calcViewSize]; [keypairview_i display]; [self clearInputs]; [quakeed_i updateXY]; return self; } -delPair:sender { [quakeed_i makeFirstResponder: quakeed_i]; [ [map_i currentEntity] removeKeyPair: (char *)[keyInput_i stringValue] ]; [keypairview_i calcViewSize]; [keypairview_i display]; [self clearInputs]; [quakeed_i updateXY]; return self; } // // Set the key/value fields to "angle