Things.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. #import "qedefs.h"
  2. id things_i;
  3. @implementation Things
  4. - init
  5. {
  6. [super init];
  7. things_i = self;
  8. lastSelected = 0;
  9. return self;
  10. }
  11. //
  12. // Load the TEXT object with the entity comment
  13. //
  14. - loadEntityComment:(id)obj
  15. {
  16. [entity_comment_i selectAll:self];
  17. [entity_comment_i replaceSel:[obj comments]];
  18. return self;
  19. }
  20. - initEntities
  21. {
  22. char *path;
  23. path = [project_i getProgDirectory];
  24. [prog_path_i setStringValue: path];
  25. [[EntityClassList alloc] initForSourceDirectory: path];
  26. [self loadEntityComment:[entity_classes_i objectAt:lastSelected]];
  27. [entity_browser_i loadColumnZero];
  28. [[entity_browser_i matrixInColumn:0] selectCellAt:lastSelected :0];
  29. [entity_browser_i setDoubleAction: @selector(doubleClickEntity:)];
  30. return self;
  31. }
  32. - selectEntity: sender
  33. {
  34. id matr;
  35. matr = [sender matrixInColumn: 0];
  36. lastSelected = [matr selectedRow];
  37. [self loadEntityComment:[entity_classes_i objectAt:lastSelected]];
  38. [quakeed_i makeFirstResponder: quakeed_i];
  39. return self;
  40. }
  41. - doubleClickEntity: sender
  42. {
  43. [map_i makeEntity: sender];
  44. [quakeed_i makeFirstResponder: quakeed_i];
  45. return self;
  46. }
  47. - (char *)spawnName
  48. {
  49. return [[entity_classes_i objectAt:lastSelected] classname];
  50. }
  51. //
  52. // Flush entity classes & reload them!
  53. //
  54. - reloadEntityClasses: sender
  55. {
  56. EntityClass *ent;
  57. char *path;
  58. path = (char *)[prog_path_i stringValue];
  59. if (!path || !path[0])
  60. {
  61. path = [project_i getProgDirectory];
  62. [prog_path_i setStringValue: path];
  63. }
  64. // Free all entity info in memory...
  65. [entity_classes_i freeObjects];
  66. [entity_classes_i free];
  67. // Now, RELOAD!
  68. [[EntityClassList alloc] initForSourceDirectory: path];
  69. lastSelected = 0;
  70. ent = [entity_classes_i objectAt:lastSelected];
  71. [self loadEntityComment:[entity_classes_i objectAt:lastSelected]];
  72. [entity_browser_i loadColumnZero];
  73. [[entity_browser_i matrixInColumn:0] selectCellAt:lastSelected :0];
  74. [self newCurrentEntity]; // in case flags changed
  75. return self;
  76. }
  77. - selectClass: (char *)class
  78. {
  79. id classent;
  80. classent = [entity_classes_i classForName:class];
  81. if (!classent)
  82. return self;
  83. lastSelected = [entity_classes_i indexOf: classent];
  84. if (lastSelected < 0)
  85. lastSelected = 0;
  86. [self loadEntityComment:classent];
  87. [[entity_browser_i matrixInColumn:0] selectCellAt:lastSelected :0];
  88. [[entity_browser_i matrixInColumn:0] scrollCellToVisible:lastSelected :0];
  89. return self;
  90. }
  91. - newCurrentEntity
  92. {
  93. id ent, classent, cell;
  94. char *classname;
  95. int r, c;
  96. char *flagname;
  97. int flags;
  98. ent = [map_i currentEntity];
  99. classname = [ent valueForQKey: "classname"];
  100. if (ent != [map_i objectAt: 0])
  101. [self selectClass: classname]; // don't reset for world
  102. classent = [entity_classes_i classForName:classname];
  103. flagname = [ent valueForQKey: "spawnflags"];
  104. if (!flagname)
  105. flags = 0;
  106. else
  107. flags = atoi(flagname);
  108. [flags_i setAutodisplay: NO];
  109. for (r=0 ; r<4 ; r++)
  110. for (c=0 ; c<3 ; c++)
  111. {
  112. cell = [flags_i cellAt: r : c];
  113. if (c < 2)
  114. {
  115. flagname = [classent flagName: c*4 + r];
  116. [cell setTitle: flagname];
  117. }
  118. [cell setIntValue: (flags & (1<< ((c*4)+r)) ) > 0];
  119. }
  120. [flags_i setAutodisplay: YES];
  121. [flags_i display];
  122. // [keyInput_i setStringValue: ""];
  123. // [valueInput_i setStringValue: ""];
  124. [keypairview_i calcViewSize];
  125. [keypairview_i display];
  126. [quakeed_i makeFirstResponder: quakeed_i];
  127. return self;
  128. }
  129. //
  130. // Clicked in the Keypair view - set as selected
  131. //
  132. - setSelectedKey:(epair_t *)ep;
  133. {
  134. [keyInput_i setStringValue:ep->key];
  135. [valueInput_i setStringValue:ep->value];
  136. [valueInput_i selectText:self];
  137. return self;
  138. }
  139. - clearInputs
  140. {
  141. // [keyInput_i setStringValue: ""];
  142. // [valueInput_i setStringValue: ""];
  143. [quakeed_i makeFirstResponder: quakeed_i];
  144. return self;
  145. }
  146. //
  147. // Action methods
  148. //
  149. -addPair:sender
  150. {
  151. char *key, *value;
  152. key = (char *)[keyInput_i stringValue];
  153. value = (char *)[valueInput_i stringValue];
  154. [ [map_i currentEntity] setKey: key toValue: value ];
  155. [keypairview_i calcViewSize];
  156. [keypairview_i display];
  157. [self clearInputs];
  158. [quakeed_i updateXY];
  159. return self;
  160. }
  161. -delPair:sender
  162. {
  163. [quakeed_i makeFirstResponder: quakeed_i];
  164. [ [map_i currentEntity] removeKeyPair: (char *)[keyInput_i stringValue] ];
  165. [keypairview_i calcViewSize];
  166. [keypairview_i display];
  167. [self clearInputs];
  168. [quakeed_i updateXY];
  169. return self;
  170. }
  171. //
  172. // Set the key/value fields to "angle <button value>"
  173. //
  174. - setAngle:sender
  175. {
  176. const char *title;
  177. char value[10];
  178. title = [[sender selectedCell] title];
  179. if (!strcmp(title,"Up"))
  180. strcpy (value, "-1");
  181. else if (!strcmp(title,"Dn"))
  182. strcpy (value, "-2");
  183. else
  184. strcpy (value, title);
  185. [keyInput_i setStringValue:"angle"];
  186. [valueInput_i setStringValue:value];
  187. [self addPair:NULL];
  188. [self clearInputs];
  189. [quakeed_i updateXY];
  190. return self;
  191. }
  192. - setFlags:sender
  193. {
  194. int flags;
  195. int r, c, i;
  196. id cell;
  197. char str[20];
  198. [self clearInputs];
  199. flags = 0;
  200. for (r=0 ; r<4 ; r++)
  201. for (c=0 ; c<3 ; c++)
  202. {
  203. cell = [flags_i cellAt: r : c];
  204. i = ([cell intValue] > 0);
  205. flags |= (i<< ((c*4)+r));
  206. }
  207. if (!flags)
  208. [[map_i currentEntity] removeKeyPair: "spawnflags"];
  209. else
  210. {
  211. sprintf (str, "%i", flags);
  212. [[map_i currentEntity] setKey: "spawnflags" toValue: str];
  213. }
  214. [keypairview_i calcViewSize];
  215. [keypairview_i display];
  216. return self;
  217. }
  218. //
  219. // Fill the Entity browser
  220. // (Delegate method - delegated in Interface Builder)
  221. //
  222. - (int)browser:sender fillMatrix:matrix inColumn:(int)column
  223. {
  224. id cell;
  225. int max;
  226. int i;
  227. id object;
  228. max = [entity_classes_i count];
  229. i = 0;
  230. while(max--)
  231. {
  232. object = [entity_classes_i objectAt:i];
  233. [matrix addRow];
  234. cell = [matrix cellAt:i++ :0];
  235. [cell setStringValue:[object classname]];
  236. [cell setLeaf:YES];
  237. [cell setLoaded:YES];
  238. }
  239. return i;
  240. }
  241. @end