BGE Button types panel, can edit existing buttons but not add new ones yet.
[blender-staging.git] / source / blender / editors / space_logic / logic_window.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2009 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_actuator_types.h"
33 #include "DNA_controller_types.h"
34 #include "DNA_object_types.h"
35 #include "DNA_property_types.h"
36 #include "DNA_space_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_sensor_types.h"
40 #include "DNA_sound_types.h"
41 #include "DNA_windowmanager_types.h"
42
43 #include "MEM_guardedalloc.h"
44
45 #include "BLI_blenlib.h"
46
47 #include "BKE_context.h"
48 #include "BKE_global.h"
49 #include "BKE_library.h"
50 #include "BKE_main.h"
51 #include "BKE_property.h"
52 #include "BKE_screen.h"
53 #include "BKE_sca.h"
54 #include "BKE_utildefines.h"
55
56 #include "ED_screen.h"
57 #include "ED_types.h"
58 #include "ED_util.h"
59
60 #include "WM_api.h"
61 #include "WM_types.h"
62
63 #include "BIF_gl.h"
64 #include "BIF_glutil.h"
65
66 #include "UI_interface.h"
67 #include "UI_resources.h"
68 #include "UI_view2d.h"
69
70 /* XXX BAD BAD */
71 #include "../interface/interface_intern.h"
72
73 #include "logic_intern.h"
74
75
76
77 /* XXX */
78 static int pupmenu() {return 1;}
79 /* XXX */
80
81 #define MAX_RENDER_PASS   100
82 #define B_REDR          1
83 #define B_IDNAME        2
84
85 #define B_ADD_PROP              2701
86 #define B_CHANGE_PROP           2702
87
88 #define B_ADD_SENS              2703
89 #define B_CHANGE_SENS           2704
90 #define B_DEL_SENS              2705
91
92 #define B_ADD_CONT              2706
93 #define B_CHANGE_CONT           2707
94 #define B_DEL_CONT              2708
95
96 #define B_ADD_ACT               2709
97 #define B_CHANGE_ACT            2710
98 #define B_DEL_ACT               2711
99
100 #define B_SOUNDACT_BROWSE       2712
101
102 #define B_SETSECTOR             2713
103 #define B_SETPROP               2714
104 #define B_SETACTOR              2715
105 #define B_SETMAINACTOR          2716
106 #define B_SETDYNA               2717
107 #define B_SET_STATE_BIT 2718
108 #define B_INIT_STATE_BIT        2719
109
110 /* proto */
111 static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisflag);
112
113 static int vergname(const void *v1, const void *v2)
114 {
115         char **x1, **x2;
116         
117         x1= (char **)v1;
118         x2= (char **)v2;
119         
120         return strcmp(*x1, *x2);
121 }
122
123 void make_unique_prop_names(bContext *C, char *str)
124 {
125         Object *ob;
126         bProperty *prop;
127         bSensor *sens;
128         bController *cont;
129         bActuator *act;
130         ID **idar;
131         short a, obcount, propcount=0, nr;
132         char **names;
133         
134         /* this function is called by a Button, and gives the current
135                 * stringpointer as an argument, this is the one that can change
136                 */
137         
138         idar= get_selected_and_linked_obs(C, &obcount, BUTS_SENS_SEL|BUTS_SENS_ACT|BUTS_ACT_SEL|BUTS_ACT_ACT|BUTS_CONT_SEL|BUTS_CONT_ACT);
139         
140         /* for each object, make properties and sca names unique */
141         
142         /* count total names */
143         for(a=0; a<obcount; a++) {
144                 ob= (Object *)idar[a];
145                 propcount+= BLI_countlist(&ob->prop);
146                 propcount+= BLI_countlist(&ob->sensors);
147                 propcount+= BLI_countlist(&ob->controllers);
148                 propcount+= BLI_countlist(&ob->actuators);
149         }       
150         if(propcount==0) {
151                 if(idar) MEM_freeN(idar);
152                 return;
153         }
154         
155         /* make names array for sorting */
156         names= MEM_callocN(propcount*sizeof(void *), "names");
157         
158         /* count total names */
159         nr= 0;
160         for(a=0; a<obcount; a++) {
161                 ob= (Object *)idar[a];
162                 prop= ob->prop.first;
163                 while(prop) {
164                         names[nr++]= prop->name;
165                         prop= prop->next;
166                 }
167                 sens= ob->sensors.first;
168                 while(sens) {
169                         names[nr++]= sens->name;
170                         sens= sens->next;
171                 }
172                 cont= ob->controllers.first;
173                 while(cont) {
174                         names[nr++]= cont->name;
175                         cont= cont->next;
176                 }
177                 act= ob->actuators.first;
178                 while(act) {
179                         names[nr++]= act->name;
180                         act= act->next;
181                 }
182         }
183         
184         qsort(names, propcount, sizeof(void *), vergname);
185         
186         /* now we check for double names, and change them */
187         
188         for(nr=0; nr<propcount; nr++) {
189                 if(names[nr]!=str && strcmp( names[nr], str )==0 ) {
190                         BLI_newname(str, +1);
191                 }
192         }
193         
194         MEM_freeN(idar);
195         MEM_freeN(names);
196 }
197
198 static void make_unique_prop_names_cb(bContext *C, void *strv, void *redraw_view3d_flagv)
199 {
200         char *str= strv;
201 //      int redraw_view3d_flag= GET_INT_FROM_POINTER(redraw_view3d_flagv);
202         
203         make_unique_prop_names(C, str);
204 }
205
206
207 static void sca_move_sensor(bContext *C, void *datav, void *data2_unused)
208 {
209         Scene *scene= CTX_data_scene(C);
210         bSensor *sens_to_delete= datav;
211         int val;
212         Base *base;
213         bSensor *sens, *tmp;
214         
215         val= pupmenu("Move up%x1|Move down %x2");
216         
217         if(val>0) {
218                 /* now find out which object has this ... */
219                 base= FIRSTBASE;
220                 while(base) {
221                 
222                         sens= base->object->sensors.first;
223                         while(sens) {
224                                 if(sens == sens_to_delete) break;
225                                 sens= sens->next;
226                         }
227                         
228                         if(sens) {
229                                 if( val==1 && sens->prev) {
230                                         for (tmp=sens->prev; tmp; tmp=tmp->prev) {
231                                                 if (tmp->flag & SENS_VISIBLE)
232                                                         break;
233                                         }
234                                         if (tmp) {
235                                                 BLI_remlink(&base->object->sensors, sens);
236                                                 BLI_insertlinkbefore(&base->object->sensors, tmp, sens);
237                                         }
238                                 }
239                                 else if( val==2 && sens->next) {
240                                         for (tmp=sens->next; tmp; tmp=tmp->next) {
241                                                 if (tmp->flag & SENS_VISIBLE)
242                                                         break;
243                                         }
244                                         if (tmp) {
245                                                 BLI_remlink(&base->object->sensors, sens);
246                                                 BLI_insertlink(&base->object->sensors, tmp, sens);
247                                         }
248                                 }
249                                 ED_undo_push(C, "Move sensor");
250                                 break;
251                         }
252                         
253                         base= base->next;
254                 }
255         }
256 }
257
258 static void sca_move_controller(bContext *C, void *datav, void *data2_unused)
259 {
260         Scene *scene= CTX_data_scene(C);
261         bController *controller_to_del= datav;
262         int val;
263         Base *base;
264         bController *cont, *tmp;
265         
266         val= pupmenu("Move up%x1|Move down %x2");
267         
268         if(val>0) {
269                 /* now find out which object has this ... */
270                 base= FIRSTBASE;
271                 while(base) {
272                 
273                         cont= base->object->controllers.first;
274                         while(cont) {
275                                 if(cont == controller_to_del) break;
276                                 cont= cont->next;
277                         }
278                         
279                         if(cont) {
280                                 if( val==1 && cont->prev) {
281                                         /* locate the controller that has the same state mask but is earlier in the list */
282                                         tmp = cont->prev;
283                                         while(tmp) {
284                                                 if(tmp->state_mask & cont->state_mask) 
285                                                         break;
286                                                 tmp = tmp->prev;
287                                         }
288                                         if (tmp) {
289                                                 BLI_remlink(&base->object->controllers, cont);
290                                                 BLI_insertlinkbefore(&base->object->controllers, tmp, cont);
291                                         }
292                                 }
293                                 else if( val==2 && cont->next) {
294                                         tmp = cont->next;
295                                         while(tmp) {
296                                                 if(tmp->state_mask & cont->state_mask) 
297                                                         break;
298                                                 tmp = tmp->next;
299                                         }
300                                         BLI_remlink(&base->object->controllers, cont);
301                                         BLI_insertlink(&base->object->controllers, tmp, cont);
302                                 }
303                                 ED_undo_push(C, "Move controller");
304                                 break;
305                         }
306                         
307                         base= base->next;
308                 }
309         }
310 }
311
312 static void sca_move_actuator(bContext *C, void *datav, void *data2_unused)
313 {
314         Scene *scene= CTX_data_scene(C);
315         bActuator *actuator_to_move= datav;
316         int val;
317         Base *base;
318         bActuator *act, *tmp;
319         
320         val= pupmenu("Move up%x1|Move down %x2");
321         
322         if(val>0) {
323                 /* now find out which object has this ... */
324                 base= FIRSTBASE;
325                 while(base) {
326                 
327                         act= base->object->actuators.first;
328                         while(act) {
329                                 if(act == actuator_to_move) break;
330                                 act= act->next;
331                         }
332                         
333                         if(act) {
334                                 if( val==1 && act->prev) {
335                                         /* locate the first visible actuators before this one */
336                                         for (tmp = act->prev; tmp; tmp=tmp->prev) {
337                                                 if (tmp->flag & ACT_VISIBLE)
338                                                         break;
339                                         }
340                                         if (tmp) {
341                                                 BLI_remlink(&base->object->actuators, act);
342                                                 BLI_insertlinkbefore(&base->object->actuators, tmp, act);
343                                         }
344                                 }
345                                 else if( val==2 && act->next) {
346                                         for (tmp=act->next; tmp; tmp=tmp->next) {
347                                                 if (tmp->flag & ACT_VISIBLE)
348                                                         break;
349                                         }
350                                         if (tmp) {
351                                                 BLI_remlink(&base->object->actuators, act);
352                                                 BLI_insertlink(&base->object->actuators, tmp, act);
353                                         }
354                                 }
355                                 ED_undo_push(C, "Move actuator");
356                                 break;
357                         }
358                         
359                         base= base->next;
360                 }
361         }
362 }
363
364 void do_logic_buts(bContext *C, void *arg, int event)
365 {
366         bProperty *prop;
367         bSensor *sens;
368         bController *cont;
369         bActuator *act;
370         Object *ob;
371         int didit, bit;
372         
373         ob= CTX_data_active_object(C);
374         if(ob==NULL) return;
375         
376         switch(event) {
377
378         case B_SETPROP:
379                 /* check for inconsistant types */
380                 ob->gameflag &= ~(OB_SECTOR|OB_MAINACTOR|OB_DYNAMIC|OB_ACTOR);
381                 break;
382
383         case B_SETACTOR:
384         case B_SETDYNA:
385         case B_SETMAINACTOR:
386                 ob->gameflag &= ~(OB_SECTOR|OB_PROP);
387                 break;
388
389
390         case B_ADD_PROP:
391                 prop= new_property(PROP_FLOAT);
392                 make_unique_prop_names(C, prop->name);
393                 BLI_addtail(&ob->prop, prop);
394                 ED_undo_push(C, "Add property");
395                 break;
396 #if 0 // XXX Now done in python
397         case B_CHANGE_PROP:
398                 prop= ob->prop.first;
399                 while(prop) {
400                         if(prop->type!=prop->otype) {
401                                 init_property(prop);
402                         }
403                         prop= prop->next;
404                 }
405                 break;
406 #endif
407         case B_ADD_SENS:
408                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
409                         if(ob->scaflag & OB_ADDSENS) {
410                                 ob->scaflag &= ~OB_ADDSENS;
411                                 sens= new_sensor(SENS_ALWAYS);
412                                 BLI_addtail(&(ob->sensors), sens);
413                                 make_unique_prop_names(C, sens->name);
414                                 ob->scaflag |= OB_SHOWSENS;
415                         }
416                 }
417                 
418                 ED_undo_push(C, "Add sensor");
419                 break;
420
421         case B_CHANGE_SENS:
422                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
423                         sens= ob->sensors.first;
424                         while(sens) {
425                                 if(sens->type != sens->otype) {
426                                         init_sensor(sens);
427                                         sens->otype= sens->type;
428                                         break;
429                                 }
430                                 sens= sens->next;
431                         }
432                 }
433                 break;
434         
435         case B_DEL_SENS:
436                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
437                         sens= ob->sensors.first;
438                         while(sens) {
439                                 if(sens->flag & SENS_DEL) {
440                                         BLI_remlink(&(ob->sensors), sens);
441                                         free_sensor(sens);
442                                         break;
443                                 }
444                                 sens= sens->next;
445                         }
446                 }
447                 ED_undo_push(C, "Delete sensor");
448                 break;
449         
450         case B_ADD_CONT:
451                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
452                         if(ob->scaflag & OB_ADDCONT) {
453                                 ob->scaflag &= ~OB_ADDCONT;
454                                 cont= new_controller(CONT_LOGIC_AND);
455                                 make_unique_prop_names(C, cont->name);
456                                 ob->scaflag |= OB_SHOWCONT;
457                                 BLI_addtail(&(ob->controllers), cont);
458                                 /* set the controller state mask from the current object state.
459                                    A controller is always in a single state, so select the lowest bit set
460                                    from the object state */
461                                 for (bit=0; bit<32; bit++) {
462                                         if (ob->state & (1<<bit))
463                                                 break;
464                                 }
465                                 cont->state_mask = (1<<bit);
466                                 if (cont->state_mask == 0) {
467                                         /* shouldn't happen, object state is never 0 */
468                                         cont->state_mask = 1;
469                                 }
470                         }
471                 }
472                 ED_undo_push(C, "Add controller");
473                 break;
474
475         case B_SET_STATE_BIT:
476                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
477                         if(ob->scaflag & OB_SETSTBIT) {
478                                 ob->scaflag &= ~OB_SETSTBIT;
479                                 ob->state = 0x3FFFFFFF;
480                         }
481                 }
482                 break;
483
484         case B_INIT_STATE_BIT:
485                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
486                         if(ob->scaflag & OB_INITSTBIT) {
487                                 ob->scaflag &= ~OB_INITSTBIT;
488                                 ob->state = ob->init_state;
489                                 if (!ob->state)
490                                         ob->state = 1;
491                         }
492                 }
493                 break;
494
495         case B_CHANGE_CONT:
496                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
497                         cont= ob->controllers.first;
498                         while(cont) {
499                                 if(cont->type != cont->otype) {
500                                         init_controller(cont);
501                                         cont->otype= cont->type;
502                                         break;
503                                 }
504                                 cont= cont->next;
505                         }
506                 }
507                 break;
508         
509
510         case B_DEL_CONT:
511                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
512                         cont= ob->controllers.first;
513                         while(cont) {
514                                 if(cont->flag & CONT_DEL) {
515                                         BLI_remlink(&(ob->controllers), cont);
516                                         unlink_controller(cont);
517                                         free_controller(cont);
518                                         break;
519                                 }
520                                 cont= cont->next;
521                         }
522                 }
523                 ED_undo_push(C, "Delete controller");
524                 break;
525
526         case B_ADD_ACT:
527                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
528                         if(ob->scaflag & OB_ADDACT) {
529                                 ob->scaflag &= ~OB_ADDACT;
530                                 act= new_actuator(ACT_OBJECT);
531                                 make_unique_prop_names(C, act->name);
532                                 BLI_addtail(&(ob->actuators), act);
533                                 ob->scaflag |= OB_SHOWACT;
534                         }
535                 }
536                 ED_undo_push(C, "Add actuator");
537                 break;
538
539         case B_CHANGE_ACT:
540                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
541                         act= ob->actuators.first;
542                         while(act) {
543                                 if(act->type != act->otype) {
544                                         init_actuator(act);
545                                         act->otype= act->type;
546                                         break;
547                                 }
548                                 act= act->next;
549                         }
550                 }
551                 break;
552
553         case B_DEL_ACT:
554                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
555                         act= ob->actuators.first;
556                         while(act) {
557                                 if(act->flag & ACT_DEL) {
558                                         BLI_remlink(&(ob->actuators), act);
559                                         unlink_actuator(act);
560                                         free_actuator(act);
561                                         break;
562                                 }
563                                 act= act->next;
564                         }
565                 }
566                 ED_undo_push(C, "Delete actuator");
567                 break;
568         
569         case B_SOUNDACT_BROWSE:
570                 /* since we don't know which... */
571                 didit= 0;
572                 for(ob=G.main->object.first; ob; ob=ob->id.next) {
573                         act= ob->actuators.first;
574                         while(act)
575                         {
576                                 if(act->type==ACT_SOUND)
577                                 {
578                                         bSoundActuator *sa= act->data;
579                                         if(sa->sndnr)
580                                         {
581                                                 bSound *sound= G.main->sound.first;
582                                                 int nr= 1;
583
584                                                 if(sa->sndnr == -2) {
585 // XXX                                                  activate_databrowse((ID *)G.main->sound.first, ID_SO, 0, B_SOUNDACT_BROWSE,
586 //                                                                                      &sa->sndnr, do_logic_buts);
587                                                         break;
588                                                 }
589
590                                                 while(sound)
591                                                 {
592                                                         if(nr==sa->sndnr)
593                                                                 break;
594                                                         nr++;
595                                                         sound= sound->id.next;
596                                                 }
597                                                 
598                                                 if(sa->sound)
599                                                         sa->sound->id.us--;
600                                                 
601                                                 sa->sound= sound;
602                                                 
603                                                 if(sound)
604                                                         sound->id.us++;
605                                                 
606                                                 sa->sndnr= 0;
607                                                 didit= 1;
608                                         }
609                                 }
610                                 act= act->next;
611                         }
612                         if(didit)
613                                 break;
614                 }
615
616                 break;
617         }
618 }
619
620
621 static char *sensor_name(int type)
622 {
623         switch (type) {
624         case SENS_ALWAYS:
625                 return "Always";
626         case SENS_TOUCH:
627                 return "Touch";
628         case SENS_NEAR:
629                 return "Near";
630         case SENS_KEYBOARD:
631                 return "Keyboard";
632         case SENS_PROPERTY:
633                 return "Property";
634         case SENS_ACTUATOR:
635                 return "Actuator";
636         case SENS_DELAY:
637                 return "Delay";
638         case SENS_MOUSE:
639                 return "Mouse";
640         case SENS_COLLISION:
641                 return "Collision";
642         case SENS_RADAR:
643                 return "Radar";
644         case SENS_RANDOM:
645                 return "Random";
646         case SENS_RAY:
647                 return "Ray";
648         case SENS_MESSAGE:
649                 return "Message";
650         case SENS_JOYSTICK:
651                 return "Joystick";
652         }
653         return "unknown";
654 }
655
656 static char *sensor_pup(void)
657 {
658         /* the number needs to match defines in game.h */
659         return "Sensors %t|Always %x0|Delay %x13|Keyboard %x3|Mouse %x5|"
660                 "Touch %x1|Collision %x6|Near %x2|Radar %x7|"
661                 "Property %x4|Random %x8|Ray %x9|Message %x10|Joystick %x11|Actuator %x12";
662 }
663
664 static char *controller_name(int type)
665 {
666         switch (type) {
667         case CONT_LOGIC_AND:
668                 return "AND";
669         case CONT_LOGIC_OR:
670                 return "OR";
671         case CONT_LOGIC_NAND:
672                 return "NAND";
673         case CONT_LOGIC_NOR:
674                 return "NOR";
675         case CONT_LOGIC_XOR:
676                 return "XOR";
677         case CONT_LOGIC_XNOR:
678                 return "XNOR";
679         case CONT_EXPRESSION:
680                 return "Expression";
681         case CONT_PYTHON:
682                 return "Python";
683         }
684         return "unknown";
685 }
686
687 static char *controller_pup(void)
688 {
689         return "Controllers   %t|AND %x0|OR %x1|XOR %x6|NAND %x4|NOR %x5|XNOR %x7|Expression %x2|Python %x3";
690 }
691
692 static char *actuator_name(int type)
693 {
694         switch (type) {
695         case ACT_SHAPEACTION:
696                 return "Shape Action";
697         case ACT_ACTION:
698                 return "Action";
699         case ACT_OBJECT:
700                 return "Motion";
701         case ACT_IPO:
702                 return "Ipo";
703         case ACT_LAMP:
704                 return "Lamp";
705         case ACT_CAMERA:
706                 return "Camera";
707         case ACT_MATERIAL:
708                 return "Material";
709         case ACT_SOUND:
710                 return "Sound";
711         case ACT_CD:
712                 return "CD";
713         case ACT_PROPERTY:
714                 return "Property";
715         case ACT_EDIT_OBJECT:
716                 return "Edit Object";
717         case ACT_CONSTRAINT:
718                 return "Constraint";
719         case ACT_SCENE:
720                 return "Scene";
721         case ACT_GROUP:
722                 return "Group";
723         case ACT_RANDOM:
724                 return "Random";
725         case ACT_MESSAGE:
726                 return "Message";
727         case ACT_GAME:
728                 return "Game";
729         case ACT_VISIBILITY:
730                 return "Visibility";
731         case ACT_2DFILTER:
732                 return "2D Filter";
733         case ACT_PARENT:
734                 return "Parent";
735         case ACT_STATE:
736                 return "State";
737         }
738         return "unknown";
739 }
740
741
742
743
744 static char *actuator_pup(Object *owner)
745 {
746         switch (owner->type)
747         {
748         case OB_ARMATURE:
749                 return "Actuators  %t|Action %x15|Motion %x0|Constraint %x9|Ipo %x1"
750                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
751                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
752                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
753                 break;
754
755         case OB_MESH:
756                 return "Actuators  %t|Shape Action %x21|Motion %x0|Constraint %x9|Ipo %x1"
757                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
758                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
759                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
760                 break;
761
762         default:
763                 return "Actuators  %t|Motion %x0|Constraint %x9|Ipo %x1"
764                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
765                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
766                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
767         }
768 }
769
770
771
772 static void set_sca_ob(Object *ob)
773 {
774         bController *cont;
775         bActuator *act;
776
777         cont= ob->controllers.first;
778         while(cont) {
779                 cont->mynew= (bController *)ob;
780                 cont= cont->next;
781         }
782         act= ob->actuators.first;
783         while(act) {
784                 act->mynew= (bActuator *)ob;
785                 act= act->next;
786         }
787 }
788
789 static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisflag)
790 {
791         Base *base;
792         Scene *scene= CTX_data_scene(C);
793         Object *ob, *obt, *obact= CTX_data_active_object(C);
794         ID **idar;
795         bSensor *sens;
796         bController *cont;
797         unsigned int lay;
798         int a, nr, doit;
799         
800         /* we need a sorted object list */
801         /* set scavisflags flags in Objects to indicate these should be evaluated */
802         /* also hide ob pointers in ->new entries of controllerss/actuators */
803         
804         *count= 0;
805         
806         if(scene==NULL) return NULL;
807         
808         ob= G.main->object.first;
809         while(ob) {
810                 ob->scavisflag= 0;
811                 set_sca_ob(ob);
812                 ob= ob->id.next;
813         }
814         
815         /* XXX here it checked 3d lay */
816         lay= scene->lay;
817         
818         base= FIRSTBASE;
819         while(base) {
820                 if(base->lay & lay) {
821                         if(base->flag & SELECT) {
822                                 if(scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
823                                 if(scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
824                                 if(scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
825                         }
826                 }
827                 base= base->next;
828         }
829
830         if(obact) {
831                 if(scavisflag & BUTS_SENS_ACT) obact->scavisflag |= OB_VIS_SENS;
832                 if(scavisflag & BUTS_CONT_ACT) obact->scavisflag |= OB_VIS_CONT;
833                 if(scavisflag & BUTS_ACT_ACT) obact->scavisflag |= OB_VIS_ACT;
834         }
835         
836         /* BUTS_XXX_STATE are similar to BUTS_XXX_LINK for selecting the object */
837         if(scavisflag & (BUTS_SENS_LINK|BUTS_CONT_LINK|BUTS_ACT_LINK|BUTS_SENS_STATE|BUTS_ACT_STATE)) {
838                 doit= 1;
839                 while(doit) {
840                         doit= 0;
841                         
842                         ob= G.main->object.first;
843                         while(ob) {
844                         
845                                 /* 1st case: select sensor when controller selected */
846                                 if((scavisflag & (BUTS_SENS_LINK|BUTS_SENS_STATE)) && (ob->scavisflag & OB_VIS_SENS)==0) {
847                                         sens= ob->sensors.first;
848                                         while(sens) {
849                                                 for(a=0; a<sens->totlinks; a++) {
850                                                         if(sens->links[a]) {
851                                                                 obt= (Object *)sens->links[a]->mynew;
852                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)) {
853                                                                         doit= 1;
854                                                                         ob->scavisflag |= OB_VIS_SENS;
855                                                                         break;
856                                                                 }
857                                                         }
858                                                 }
859                                                 if(doit) break;
860                                                 sens= sens->next;
861                                         }
862                                 }
863                                 
864                                 /* 2nd case: select cont when act selected */
865                                 if((scavisflag & BUTS_CONT_LINK)  && (ob->scavisflag & OB_VIS_CONT)==0) {
866                                         cont= ob->controllers.first;
867                                         while(cont) {
868                                                 for(a=0; a<cont->totlinks; a++) {
869                                                         if(cont->links[a]) {
870                                                                 obt= (Object *)cont->links[a]->mynew;
871                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)) {
872                                                                         doit= 1;
873                                                                         ob->scavisflag |= OB_VIS_CONT;
874                                                                         break;
875                                                                 }
876                                                         }
877                                                 }
878                                                 if(doit) break;
879                                                 cont= cont->next;
880                                         }
881                                 }
882                                 
883                                 /* 3rd case: select controller when sensor selected */
884                                 if((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_SENS)) {
885                                         sens= ob->sensors.first;
886                                         while(sens) {
887                                                 for(a=0; a<sens->totlinks; a++) {
888                                                         if(sens->links[a]) {
889                                                                 obt= (Object *)sens->links[a]->mynew;
890                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)==0) {
891                                                                         doit= 1;
892                                                                         obt->scavisflag |= OB_VIS_CONT;
893                                                                 }
894                                                         }
895                                                 }
896                                                 sens= sens->next;
897                                         }
898                                 }
899                                 
900                                 /* 4th case: select actuator when controller selected */
901                                 if( (scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE))  && (ob->scavisflag & OB_VIS_CONT)) {
902                                         cont= ob->controllers.first;
903                                         while(cont) {
904                                                 for(a=0; a<cont->totlinks; a++) {
905                                                         if(cont->links[a]) {
906                                                                 obt= (Object *)cont->links[a]->mynew;
907                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)==0) {
908                                                                         doit= 1;
909                                                                         obt->scavisflag |= OB_VIS_ACT;
910                                                                 }
911                                                         }
912                                                 }
913                                                 cont= cont->next;
914                                         }
915                                         
916                                 }
917                                 ob= ob->id.next;
918                         }
919                 }
920         } 
921         
922         /* now we count */
923         ob= G.main->object.first;
924         while(ob) {
925                 if( ob->scavisflag ) (*count)++;
926                 ob= ob->id.next;
927         }
928
929         if(*count==0) return NULL;
930         if(*count>24) *count= 24;               /* temporal */
931         
932         idar= MEM_callocN( (*count)*sizeof(void *), "idar");
933         
934         ob= G.main->object.first;
935         nr= 0;
936         while(ob) {
937                 if( ob->scavisflag ) {
938                         idar[nr]= (ID *)ob;
939                         nr++;
940                 }
941                 if(nr>=24) break;
942                 ob= ob->id.next;
943         }
944         
945         /* just to be sure... these were set in set_sca_done_ob() */
946         clear_sca_new_poins();
947         
948         return idar;
949 }
950
951
952 static int get_col_sensor(int type)
953 {
954         /* XXX themecolors not here */
955         
956         switch(type) {
957         case SENS_ALWAYS:               return TH_PANEL;
958         case SENS_DELAY:                return TH_PANEL;
959         case SENS_TOUCH:                return TH_PANEL;
960         case SENS_COLLISION:    return TH_PANEL;
961         case SENS_NEAR:                 return TH_PANEL; 
962         case SENS_KEYBOARD:             return TH_PANEL;
963         case SENS_PROPERTY:             return TH_PANEL;
964         case SENS_ACTUATOR:             return TH_PANEL;
965         case SENS_MOUSE:                return TH_PANEL;
966         case SENS_RADAR:                return TH_PANEL;
967         case SENS_RANDOM:               return TH_PANEL;
968         case SENS_RAY:                  return TH_PANEL;
969         case SENS_MESSAGE:              return TH_PANEL;
970         case SENS_JOYSTICK:             return TH_PANEL;
971         default:                                return TH_PANEL;
972         }
973 }
974 static void set_col_sensor(int type, int medium)
975 {
976         int col= get_col_sensor(type);
977         UI_ThemeColorShade(col, medium?30:0);
978 }
979
980
981 static void verify_logicbutton_func(bContext *C, void *data1, void *data2)
982 {
983         bSensor *sens= (bSensor*)data1;
984         
985         if(sens->level && sens->tap) {
986                 if(data2 == &(sens->level))     
987                         sens->tap= 0;
988                 else
989                         sens->level= 0;
990         }
991 }
992
993
994 /**
995  * Draws a toggle for pulse mode, a frequency field and a toggle to invert
996  * the value of this sensor. Operates on the shared data block of sensors.
997  */
998 static void draw_default_sensor_header(bSensor *sens,
999                                                                 uiBlock *block,
1000                                                                 short x,
1001                                                                 short y,
1002                                                                 short w) 
1003 {
1004         uiBut *but;
1005         
1006         /* Pulsing and frequency */
1007         uiDefIconButBitS(block, TOG, SENS_PULSE_REPEAT, 1, ICON_DOTSUP,
1008                          (short)(x + 10 + 0. * (w-20)), (short)(y - 21), (short)(0.1 * (w-20)), 19,
1009                          &sens->pulse, 0.0, 0.0, 0, 0,
1010                          "Activate TRUE level triggering (pulse mode)");
1011
1012         uiDefIconButBitS(block, TOG, SENS_NEG_PULSE_MODE, 1, ICON_DOTSDOWN,
1013                          (short)(x + 10 + 0.1 * (w-20)), (short)(y - 21), (short)(0.1 * (w-20)), 19,
1014                          &sens->pulse, 0.0, 0.0, 0, 0,
1015                          "Activate FALSE level triggering (pulse mode)");
1016         uiDefButS(block, NUM, 1, "f:",
1017                          (short)(x + 10 + 0.2 * (w-20)), (short)(y - 21), (short)(0.275 * (w-20)), 19,
1018                          &sens->freq, 0.0, 10000.0, 0, 0,
1019                          "Delay between repeated pulses (in logic tics, 0 = no delay)");
1020         
1021         /* value or shift? */
1022         but= uiDefButS(block, TOG, 1, "Level",
1023                          (short)(x + 10 + 0.5 * (w-20)), (short)(y - 21), (short)(0.20 * (w-20)), 19,
1024                          &sens->level, 0.0, 0.0, 0, 0,
1025                          "Level detector, trigger controllers of new states (only applicable upon logic state transition)");
1026         uiButSetFunc(but, verify_logicbutton_func, sens, &(sens->level));
1027         but= uiDefButS(block, TOG, 1, "Tap",
1028                          (short)(x + 10 + 0.702 * (w-20)), (short)(y - 21), (short)(0.12 * (w-20)), 19,
1029                          &sens->tap, 0.0, 0.0, 0, 0,
1030                          "Trigger controllers only for an instant, even while the sensor remains true");
1031         uiButSetFunc(but, verify_logicbutton_func, sens, &(sens->tap));
1032         
1033         uiDefButS(block, TOG, 1, "Inv",
1034                          (short)(x + 10 + 0.85 * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19,
1035                          &sens->invert, 0.0, 0.0, 0, 0,
1036                          "Invert the level (output) of this sensor");
1037 }
1038
1039 static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short yco, short width,char* objectname)
1040 {
1041         bNearSensor      *ns           = NULL;
1042         bTouchSensor     *ts           = NULL;
1043         bKeyboardSensor  *ks           = NULL;
1044         bPropertySensor  *ps           = NULL;
1045         bMouseSensor     *ms           = NULL;
1046         bCollisionSensor *cs           = NULL;
1047         bRadarSensor     *rs           = NULL;
1048         bRandomSensor    *randomSensor = NULL;
1049         bRaySensor       *raySens      = NULL;
1050         bMessageSensor   *mes          = NULL;
1051         bJoystickSensor  *joy              = NULL;
1052         bActuatorSensor  *as           = NULL;
1053         bDelaySensor     *ds               = NULL;
1054         short ysize;
1055         char *str;
1056         
1057         /* yco is at the top of the rect, draw downwards */
1058         
1059         set_col_sensor(sens->type, 0);
1060         
1061         switch (sens->type)
1062         {
1063         case SENS_ALWAYS:
1064                 {
1065                         ysize= 24;
1066                         
1067                         glRects(xco, yco-ysize, xco+width, yco);
1068                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1069                         
1070                         draw_default_sensor_header(sens, block, xco, yco, width);
1071                         
1072                         yco-= ysize;
1073                         
1074                         break;
1075                 }
1076         case SENS_TOUCH:
1077                 {
1078                         ysize= 48; 
1079                         
1080                         glRects(xco, yco-ysize, xco+width, yco); 
1081                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1082                         
1083                         draw_default_sensor_header(sens, block, xco, yco, width);
1084                         
1085                         ts= sens->data; 
1086                         
1087                         /* uiDefBut(block, TEX, 1, "Property:", xco,yco-22,width, 19, &ts->name, 0, 31, 0, 0, "Only look for Objects with this property"); */
1088                         uiDefIDPoinBut(block, test_matpoin_but, ID_MA, 1, "MA:",(short)(xco + 10),(short)(yco-44), (short)(width - 20), 19, &ts->ma,  "Only look for floors with this Material"); 
1089                         ///* uiDefButF(block, NUM, 1, "Margin:",        xco+width/2,yco-44,width/2, 19, &ts->dist, 0.0, 10.0, 100, 0, "Extra margin (distance) for larger sensitivity"); 
1090                         yco-= ysize; 
1091                         break; 
1092                 }
1093         case SENS_COLLISION:
1094                 {
1095                         ysize= 48;
1096                         
1097                         glRects(xco, yco-ysize, xco+width, yco);
1098                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1099                         
1100                         draw_default_sensor_header(sens, block, xco, yco, width);
1101                         cs= sens->data;
1102                         
1103                         /* The collision sensor will become a generic collision (i.e. it     */
1104                         /* absorb the old touch sensor).                                     */
1105
1106                         uiDefButBitS(block, TOG, SENS_COLLISION_PULSE, B_REDR, "Pulse",(short)(xco + 10),(short)(yco - 44),
1107                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1108                                 "Changes to the set of colliding objects generated pulses");
1109                         
1110                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",(short)(xco + 10 + (0.20 * (width-20))),(short)(yco - 44),
1111                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1112                                 "Toggle collision on material or property");
1113                         
1114                         if (cs->mode & SENS_COLLISION_MATERIAL) {
1115                                 uiDefBut(block, TEX, 1, "Material:", (short)(xco + 10 + 0.40 * (width-20)),
1116                                         (short)(yco-44), (short)(0.6*(width-20)), 19, &cs->materialName, 0, 31, 0, 0,
1117                                         "Only look for Objects with this material");
1118                         } else {
1119                                 uiDefBut(block, TEX, 1, "Property:", (short)(xco + 10 + 0.40 * (width-20)), (short)(yco-44),
1120                                         (short)(0.6*(width-20)), 19, &cs->name, 0, 31, 0, 0,
1121                                         "Only look for Objects with this property");
1122                         }
1123         
1124                         /*              uiDefButS(block, NUM, 1, "Damp:",       xco+10+width-90,yco-24, 70, 19, &cs->damp, 0, 250, 0, 0, "For 'damp' time don't detect another collision"); */
1125                         
1126                         yco-= ysize;
1127                         break;
1128                 }
1129         case SENS_NEAR:
1130                 {
1131                         ysize= 72;
1132                         
1133                         glRects(xco, yco-ysize, xco+width, yco);
1134                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1135                         
1136                         draw_default_sensor_header(sens, block, xco, yco, width);
1137                         ns= sens->data;
1138                         
1139                         uiDefBut(block, TEX, 1, "Property:",(short)(10+xco),(short)(yco-44), (short)(width-20), 19,
1140                                 &ns->name, 0, 31, 0, 0, "Only look for Objects with this property");
1141                         uiDefButF(block, NUM, 1, "Dist",(short)(10+xco),(short)(yco-68),(short)((width-22)/2), 19,
1142                                 &ns->dist, 0.0, 1000.0, 1000, 0, "Trigger distance");
1143                         uiDefButF(block, NUM, 1, "Reset",(short)(10+xco+(width-22)/2), (short)(yco-68), (short)((width-22)/2), 19,
1144                                 &ns->resetdist, 0.0, 1000.0, 1000, 0, "Reset distance"); 
1145                         yco-= ysize;
1146                         break;
1147                 }
1148         case SENS_RADAR:
1149                 {
1150                         ysize= 72; 
1151                         
1152                         glRects(xco, yco-ysize, xco+width, yco);
1153                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1154                         
1155                         draw_default_sensor_header(sens, block, xco, yco, width);
1156                         
1157                         rs= sens->data;
1158                         
1159                         uiDefBut(block, TEX, 1, "Prop:",
1160                                          (short)(10+xco),(short)(yco-44), (short)(0.7 * (width-20)), 19,
1161                                          &rs->name, 0, 31, 0, 0,
1162                                          "Only look for Objects with this property");
1163
1164                         str = "Type %t|+X axis %x0|+Y axis %x1|+Z axis %x2|-X axis %x3|-Y axis %x4|-Z axis %x5"; 
1165                         uiDefButS(block, MENU, B_REDR, str,
1166                                 (short)(10+xco+0.7 * (width-20)), (short)(yco-44), (short)(0.3 * (width-22)), 19,
1167                                 &rs->axis, 2.0, 31, 0, 0,
1168                                 "Specify along which axis the radar cone is cast");
1169                                 
1170                         uiDefButF(block, NUM, 1, "Ang:",
1171                                          (short)(10+xco), (short)(yco-68), (short)((width-20)/2), 19,
1172                                          &rs->angle, 0.0, 179.9, 10, 0,
1173                                          "Opening angle of the radar cone");
1174                         uiDefButF(block, NUM, 1, "Dist:",
1175                                          (short)(xco+10 + (width-20)/2), (short)(yco-68), (short)((width-20)/2), 19,
1176                                          &rs->range, 0.01, 10000.0, 100, 0,
1177                                          "Depth of the radar cone");
1178                         yco-= ysize;
1179                         break;
1180                 }
1181         case SENS_KEYBOARD:
1182                 {
1183                         ks= sens->data;
1184                         
1185                         /* 5 lines: 120 height */
1186                         ysize= (ks->type&1) ? 96:120;
1187                         
1188                         glRects(xco, yco-ysize, xco+width, yco);
1189                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1190                         
1191                         /* header line */
1192                         draw_default_sensor_header(sens, block, xco, yco, width);
1193                         
1194                         /* part of line 1 */
1195                         uiDefBut(block, LABEL, 0, "Key",          xco, yco-44, 40, 19, NULL, 0, 0, 0, 0, "");
1196                         uiDefButBitS(block, TOG, 1, B_REDR, "All keys",   xco+40+(width/2), yco-44, (width/2)-50, 19,
1197                                 &ks->type, 0, 0, 0, 0, "");
1198                         
1199                         
1200                         if ((ks->type&1)==0) { /* is All Keys option off? */
1201                                 /* line 2: hotkey and allkeys toggle */
1202                                 uiDefKeyevtButS(block, 0, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
1203                                 
1204                                 /* line 3: two key modifyers (qual1, qual2) */
1205                                 uiDefBut(block, LABEL, 0, "Hold",         xco, yco-68, 40, 19, NULL, 0, 0, 0, 0, "");
1206                                 uiDefKeyevtButS(block, 0, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
1207                                 uiDefKeyevtButS(block, 0, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
1208                         }
1209                         
1210                         /* line 4: toggle property for string logging mode */
1211                         uiDefBut(block, TEX, 1, "LogToggle: ",
1212                                 xco+10, yco-((ks->type&1) ? 68:92), (width-20), 19,
1213                                 ks->toggleName, 0, 31, 0, 0,
1214                                 "Property that indicates whether to log "
1215                                 "keystrokes as a string");
1216                         
1217                         /* line 5: target property for string logging mode */
1218                         uiDefBut(block, TEX, 1, "Target: ",
1219                                 xco+10, yco-((ks->type&1) ? 92:116), (width-20), 19,
1220                                 ks->targetName, 0, 31, 0, 0,
1221                                 "Property that receives the keystrokes in case "
1222                                 "a string is logged");
1223                         
1224                         yco-= ysize;
1225                         break;
1226                 }
1227         case SENS_PROPERTY:
1228                 {
1229                         ysize= 96;
1230                         
1231                         glRects(xco, yco-ysize, xco+width, yco);
1232                         uiEmboss((float)xco, (float)yco-ysize,
1233                                 (float)xco+width, (float)yco, 1);
1234                         
1235                         draw_default_sensor_header(sens, block, xco, yco, width);
1236                         ps= sens->data;
1237                         
1238                         str= "Type %t|Equal %x0|Not Equal %x1|Interval %x2|Changed %x3"; 
1239                         /* str= "Type %t|Equal %x0|Not Equal %x1"; */
1240                         uiDefButI(block, MENU, B_REDR, str,                     xco+30,yco-44,width-60, 19,
1241                                 &ps->type, 0, 31, 0, 0, "Type");
1242                         
1243                         if (ps->type != SENS_PROP_EXPRESSION)
1244                         {
1245                                 uiDefBut(block, TEX, 1, "Prop: ",                       xco+30,yco-68,width-60, 19,
1246                                         ps->name, 0, 31, 0, 0,  "Property name");
1247                         }
1248                         
1249                         if(ps->type == SENS_PROP_INTERVAL)
1250                         {
1251                                 uiDefBut(block, TEX, 1, "Min: ",                xco,yco-92,width/2, 19,
1252                                         ps->value, 0, 31, 0, 0, "check for min value");
1253                                 uiDefBut(block, TEX, 1, "Max: ",                xco+width/2,yco-92,width/2, 19,
1254                                         ps->maxvalue, 0, 31, 0, 0, "check for max value");
1255                         }
1256                         else if(ps->type == SENS_PROP_CHANGED);
1257                         else
1258                         {
1259                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-92,width-60, 19,
1260                                         ps->value, 0, 31, 0, 0, "check for value");
1261                         }
1262                         
1263                         yco-= ysize;
1264                         break;
1265                 }
1266         case SENS_ACTUATOR:
1267                 {
1268                         ysize= 48;
1269                         
1270                         glRects(xco, yco-ysize, xco+width, yco);
1271                         uiEmboss((float)xco, (float)yco-ysize,
1272                                 (float)xco+width, (float)yco, 1);
1273                         
1274                         draw_default_sensor_header(sens, block, xco, yco, width);
1275                         as= sens->data;
1276                         
1277                         uiDefBut(block, TEX, 1, "Act: ",                        xco+30,yco-44,width-60, 19,
1278                                         as->name, 0, 31, 0, 0,  "Actuator name, actuator active state modifications will be detected");
1279                         yco-= ysize;
1280                         break;
1281                 }
1282         case SENS_DELAY:
1283                 {
1284                         ysize= 48;
1285                         
1286                         glRects(xco, yco-ysize, xco+width, yco);
1287                         uiEmboss((float)xco, (float)yco-ysize,
1288                                 (float)xco+width, (float)yco, 1);
1289                         
1290                         draw_default_sensor_header(sens, block, xco, yco, width);
1291                         ds = sens->data;
1292                         
1293                         uiDefButS(block, NUM, 0, "Delay",(short)(10+xco),(short)(yco-44),(short)((width-22)*0.4+10), 19,
1294                                 &ds->delay, 0.0, 5000.0, 0, 0, "Delay in number of logic tics before the positive trigger (default 60 per second)");
1295                         uiDefButS(block, NUM, 0, "Dur",(short)(10+xco+(width-22)*0.4+10),(short)(yco-44),(short)((width-22)*0.4-10), 19,
1296                                 &ds->duration, 0.0, 5000.0, 0, 0, "If >0, delay in number of logic tics before the negative trigger following the positive trigger");
1297                         uiDefButBitS(block, TOG, SENS_DELAY_REPEAT, 0, "REP",(short)(xco + 10 + (width-22)*0.8),(short)(yco - 44),
1298                                 (short)(0.20 * (width-22)), 19, &ds->flag, 0.0, 0.0, 0, 0,
1299                                 "Toggle repeat option. If selected, the sensor restarts after Delay+Dur logic tics");
1300                         yco-= ysize;
1301                         break;
1302                 }
1303         case SENS_MOUSE:
1304                 {
1305                         ms= sens->data;
1306                         /* Two lines: 48 pixels high. */
1307                         ysize = 48;
1308                         
1309                         glRects(xco, yco-ysize, xco+width, yco);
1310                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1311                         
1312                         /* line 1: header */
1313                         draw_default_sensor_header(sens, block, xco, yco, width);
1314                         
1315                         /* Line 2: type selection. The number are a bit mangled to get
1316                         * proper compatibility with older .blend files. */
1317                         str= "Type %t|Left button %x1|Middle button %x2|"
1318                                 "Right button %x4|Wheel Up %x5|Wheel Down %x6|Movement %x8|Mouse over %x16|Mouse over any%x32"; 
1319                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, width-20, 19,
1320                                 &ms->type, 0, 31, 0, 0,
1321                                 "Specify the type of event this mouse sensor should trigger on");
1322                         
1323                         yco-= ysize;
1324                         break;
1325                 }
1326         case SENS_RANDOM:
1327                 {
1328                         ysize = 48;
1329                         
1330                         glRects(xco, yco-ysize, xco+width, yco);
1331                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1332                         
1333                         draw_default_sensor_header(sens, block, xco, yco, width);
1334                         randomSensor = sens->data;
1335                         /* some files were wrongly written, avoid crash now */
1336                         if (randomSensor)
1337                         {
1338                                 uiDefButI(block, NUM, 1, "Seed: ",              xco+10,yco-44,(width-20), 19,
1339                                         &randomSensor->seed, 0, 1000, 0, 0,
1340                                         "Initial seed of the generator. (Choose 0 for not random)");
1341                         }
1342                         yco-= ysize;
1343                         break;
1344                 }
1345         case SENS_RAY:
1346                 {
1347                         ysize = 72;
1348                         glRects(xco, yco-ysize, xco+width, yco);
1349                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1350                         
1351                         draw_default_sensor_header(sens, block, xco, yco, width);
1352                         raySens = sens->data;
1353                         
1354                         /* 1. property or material */
1355                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",
1356                                 xco + 10,yco - 44, 0.20 * (width-20), 19,
1357                                 &raySens->mode, 0.0, 0.0, 0, 0,
1358                                 "Toggle collision on material or property");
1359                         
1360                         if (raySens->mode & SENS_COLLISION_MATERIAL)
1361                         {
1362                                 uiDefBut(block, TEX, 1, "Material:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1363                                         &raySens->matname, 0, 31, 0, 0,
1364                                         "Only look for Objects with this material");
1365                         }
1366                         else
1367                         {
1368                                 uiDefBut(block, TEX, 1, "Property:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1369                                         &raySens->propname, 0, 31, 0, 0,
1370                                         "Only look for Objects with this property");
1371                         }
1372
1373                         /* X-Ray option */
1374                         uiDefButBitS(block, TOG, SENS_RAY_XRAY, 1, "X",
1375                                 xco + 10,yco - 68, 0.10 * (width-20), 19,
1376                                 &raySens->mode, 0.0, 0.0, 0, 0,
1377                                 "Toggle X-Ray option (see through objects that don't have the property)");
1378                         /* 2. sensing range */
1379                         uiDefButF(block, NUM, 1, "Range", xco+10 + 0.10 * (width-20), yco-68, 0.5 * (width-20), 19,
1380                                 &raySens->range, 0.01, 10000.0, 100, 0,
1381                                 "Sense objects no farther than this distance");
1382                         
1383                         /* 3. axis choice */
1384                         str = "Type %t|+ X axis %x1|+ Y axis %x0|+ Z axis %x2|- X axis %x3|- Y axis %x4|- Z axis %x5"; 
1385                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1386                                 &raySens->axisflag, 2.0, 31, 0, 0,
1387                                 "Specify along which axis the ray is cast");
1388                         
1389                         yco-= ysize;            
1390                         break;
1391                 }
1392         case SENS_MESSAGE:
1393                 {
1394                         mes = sens->data;
1395                         ysize = 2 * 24; /* total number of lines * 24 pixels/line */
1396                         
1397                         glRects(xco, yco-ysize, xco+width, yco);
1398                         uiEmboss((float)xco, (float)yco-ysize,
1399                                 (float)xco+width, (float)yco, 1);
1400                         
1401                         /* line 1: header line */
1402                         draw_default_sensor_header(sens, block, xco, yco, width);
1403                         
1404                         /* line 2: Subject filter */
1405                         uiDefBut(block, TEX, 1, "Subject: ",
1406                                 (xco+10), (yco-44), (width-20), 19,
1407                                 mes->subject, 0, 31, 0, 0,
1408                                 "Optional subject filter: only accept messages with this subject"
1409                                 ", or empty for all");
1410                         
1411                         yco -= ysize;
1412                         break;
1413                 }
1414                 case SENS_JOYSTICK:
1415                 {
1416
1417                         ysize =  72;
1418                         
1419                         glRects(xco, yco-ysize, xco+width, yco);
1420                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1421                         
1422                         /* line 1: header */
1423                         draw_default_sensor_header(sens, block, xco, yco, width);
1424
1425                         joy= sens->data;
1426
1427                         uiDefButC(block, NUM, 1, "Index:", xco+10, yco-44, 0.33 * (width-20), 19,
1428                         &joy->joyindex, 0, SENS_JOY_MAXINDEX-1, 100, 0,
1429                         "Specify which joystick to use");                       
1430
1431                         str= "Type %t|Button %x0|Axis %x1|Single Axis %x3|Hat%x2"; 
1432                         uiDefButC(block, MENU, B_REDR, str, xco+87, yco-44, 0.26 * (width-20), 19,
1433                                 &joy->type, 0, 31, 0, 0,
1434                                 "The type of event this joystick sensor is triggered on");
1435                         
1436                         if (joy->type != SENS_JOY_AXIS_SINGLE) {
1437                                 if (joy->flag & SENS_JOY_ANY_EVENT) {
1438                                         switch (joy->type) {
1439                                         case SENS_JOY_AXIS:     
1440                                                 str = "All Axis Events";
1441                                                 break;
1442                                         case SENS_JOY_BUTTON:   
1443                                                 str = "All Button Events";
1444                                                 break;
1445                                         default:
1446                                                 str = "All Hat Events";
1447                                                 break;
1448                                         }
1449                                 } else {
1450                                         str = "All";
1451                                 }
1452                                 
1453                                 uiDefButBitS(block, TOG, SENS_JOY_ANY_EVENT, B_REDR, str,
1454                                         xco+10 + 0.475 * (width-20), yco-68, ((joy->flag & SENS_JOY_ANY_EVENT) ? 0.525 : 0.12) * (width-20), 19,
1455                                         &joy->flag, 0, 0, 0, 0,
1456                                         "Triggered by all events on this joysticks current type (axis/button/hat)");
1457                         }
1458                         if(joy->type == SENS_JOY_BUTTON)
1459                         {
1460                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1461                                         uiDefButI(block, NUM, 1, "Number:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1462                                         &joy->button, 0, 18, 100, 0,
1463                                         "Specify which button to use");
1464                                 }
1465                         }
1466                         else if(joy->type == SENS_JOY_AXIS)
1467                         {
1468                                 uiDefButS(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1469                                 &joy->axis, 1, 8.0, 100, 0,
1470                                 "Specify which axis pair to use, 1 is useually the main direction input");
1471
1472                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1473                                 &joy->precision, 0, 32768.0, 100, 0,
1474                                 "Specify the precision of the axis");
1475
1476                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1477                                         str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis %x0"; 
1478                                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1479                                         &joy->axisf, 2.0, 31, 0, 0,
1480                                         "The direction of the axis, use 'All Events' to recieve events on any direction");
1481                                 }
1482                         }
1483                         else if (joy->type == SENS_JOY_HAT)
1484                         {
1485                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1486                                 &joy->hat, 1, 4.0, 100, 0,
1487                                 "Specify which hat to use");
1488                                 
1489                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1490                                         str = "Direction%t|Up%x1|Down%x4|Left%x8|Right%x2|%l|Up/Right%x3|Down/Left%x12|Up/Left%x9|Down/Right%x6"; 
1491                                         uiDefButI(block, MENU, 0, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1492                                         &joy->hatf, 2.0, 31, 0, 0,
1493                                         "The direction of the hat, use 'All Events' to recieve events on any direction");
1494                                 }
1495                         }
1496                         else { /* (joy->type == SENS_JOY_AXIS_SINGLE)*/
1497                                 uiDefButS(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1498                                 &joy->axis_single, 1, 16.0, 100, 0,
1499                                 "Specify a single axis (verticle/horizontal/other) to detect");
1500                                 
1501                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1502                                 &joy->precision, 0, 32768.0, 100, 0,
1503                                 "Specify the precision of the axis");
1504                         }
1505                         yco-= ysize;
1506                         break;
1507                 }
1508         }
1509         
1510         return yco-4;
1511 }
1512
1513
1514
1515 static short draw_controllerbuttons(bController *cont, uiBlock *block, short xco, short yco, short width)
1516 {
1517         bExpressionCont *ec;
1518         bPythonCont *pc;
1519         short ysize;
1520         
1521         switch (cont->type) {
1522         case CONT_EXPRESSION:
1523                 ysize= 28;
1524
1525                 UI_ThemeColor(TH_PANEL);
1526                 glRects(xco, yco-ysize, xco+width, yco);
1527                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1528                 
1529                 /* uiDefBut(block, LABEL, 1, "Not yet...", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, ""); */
1530                 ec= cont->data; 
1531                 /* uiDefBut(block, BUT, 1, "Variables", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, "Available variables for expression"); */
1532                 uiDefBut(block, TEX, 1, "Exp:",         xco + 10 , yco-21, width-20, 19,
1533                                  ec->str, 0, 127, 0, 0,
1534                                  "Expression"); 
1535                 
1536                 yco-= ysize;
1537                 break;
1538         case CONT_PYTHON:
1539                 ysize= 28;
1540                 
1541                 if(cont->data==NULL) init_controller(cont);
1542                 pc= cont->data;
1543                 
1544                 UI_ThemeColor(TH_PANEL);
1545                 glRects(xco, yco-ysize, xco+width, yco);
1546                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1547
1548         
1549                 uiBlockBeginAlign(block);
1550                 uiDefButI(block, MENU, B_REDR, "Execution Method%t|Script%x0|Module%x1", xco+4,yco-23, 66, 19, &pc->mode, 0, 0, 0, 0, "Python script type (textblock or module - faster)");
1551                 if(pc->mode==0)
1552                         uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "", xco+70,yco-23,width-74, 19, &pc->text, "Blender textblock to run as a script");
1553                 else {
1554                         uiDefBut(block, TEX, 1, "", xco+70,yco-23,(width-70)-25, 19, pc->module, 0, 63, 0, 0, "Module name and function to run e.g. \"someModule.main\". Internal texts and external python files can be used");
1555                         uiDefButBitI(block, TOG, CONT_PY_DEBUG, B_REDR, "D", (xco+width)-25, yco-23, 19, 19, &pc->flag, 0, 0, 0, 0, "Continuously reload the module from disk for editing external modules without restarting");
1556                 }
1557                 uiBlockEndAlign(block);
1558                 
1559                 yco-= ysize;
1560                 break;
1561                 
1562         default:
1563                 ysize= 4;
1564
1565                 UI_ThemeColor(TH_PANEL);
1566                 glRects(xco, yco-ysize, xco+width, yco);
1567                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1568                 
1569                 yco-= ysize;
1570         }
1571         
1572         return yco;
1573 }
1574
1575 static int get_col_actuator(int type)
1576 {
1577         switch(type) {
1578         case ACT_ACTION:                return TH_PANEL;
1579         case ACT_SHAPEACTION:   return TH_PANEL;
1580         case ACT_OBJECT:                return TH_PANEL;
1581         case ACT_IPO:                   return TH_PANEL;
1582         case ACT_PROPERTY:              return TH_PANEL;
1583         case ACT_SOUND:                 return TH_PANEL;
1584         case ACT_CD:                    return TH_PANEL;
1585         case ACT_CAMERA:                return TH_PANEL;
1586         case ACT_EDIT_OBJECT:           return TH_PANEL;
1587         case ACT_GROUP:                 return TH_PANEL;
1588         case ACT_RANDOM:                return TH_PANEL;
1589         case ACT_SCENE:                 return TH_PANEL;
1590         case ACT_MESSAGE:               return TH_PANEL;
1591         case ACT_GAME:                  return TH_PANEL;
1592         case ACT_VISIBILITY:            return TH_PANEL;
1593         case ACT_CONSTRAINT:            return TH_PANEL;
1594         case ACT_STATE:                 return TH_PANEL;
1595         default:                                return TH_PANEL;
1596         }
1597 }
1598 static void set_col_actuator(int item, int medium) 
1599 {
1600         int col= get_col_actuator(item);
1601         UI_ThemeColorShade(col, medium?30:10);
1602         
1603 }
1604
1605 static void change_object_actuator(bContext *C, void *act, void *arg)
1606 {
1607         bObjectActuator *oa = act;
1608
1609         if (oa->type != oa->otype) {
1610                 switch (oa->type) {
1611                 case ACT_OBJECT_NORMAL:
1612                         memset(oa, 0, sizeof(bObjectActuator));
1613                         oa->flag = ACT_FORCE_LOCAL|ACT_TORQUE_LOCAL|ACT_DLOC_LOCAL|ACT_DROT_LOCAL;
1614                         oa->type = ACT_OBJECT_NORMAL;
1615                         break;
1616
1617                 case ACT_OBJECT_SERVO:
1618                         memset(oa, 0, sizeof(bObjectActuator));
1619                         oa->flag = ACT_LIN_VEL_LOCAL;
1620                         oa->type = ACT_OBJECT_SERVO;
1621                         oa->forcerot[0] = 30.0f;
1622                         oa->forcerot[1] = 0.5f;
1623                         oa->forcerot[2] = 0.0f;
1624                         break;
1625                 }
1626         }
1627 }
1628
1629 static void change_ipo_actuator(bContext *C, void *arg1_but, void *arg2_ia)
1630 {
1631         bIpoActuator *ia = arg2_ia;
1632         uiBut *but = arg1_but;
1633
1634         if (but->retval & ACT_IPOFORCE)
1635                 ia->flag &= ~ACT_IPOADD;
1636         else if (but->retval & ACT_IPOADD)
1637                 ia->flag &= ~ACT_IPOFORCE;
1638         but->retval = B_REDR;
1639 }
1640
1641 void update_object_actuator_PID(bContext *C, void *act, void *arg)
1642 {
1643         bObjectActuator *oa = act;
1644         oa->forcerot[0] = 60.0f*oa->forcerot[1];
1645 }
1646
1647 char *get_state_name(Object *ob, short bit)
1648 {
1649         bController *cont;
1650         unsigned int mask;
1651
1652         mask = (1<<bit);
1653         cont = ob->controllers.first;
1654         while (cont) {
1655                 if (cont->state_mask & mask) {
1656                         return cont->name;
1657                 }
1658                 cont = cont->next;
1659         }
1660         return (char*)"";
1661 }
1662
1663 static void check_state_mask(bContext *C, void *arg1_but, void *arg2_mask)
1664 {
1665         int shift= 0; // XXX
1666         unsigned int *cont_mask = arg2_mask;
1667         uiBut *but = arg1_but;
1668
1669         if (*cont_mask == 0 || !(shift))
1670                 *cont_mask = (1<<but->retval);
1671         but->retval = B_REDR;
1672 }
1673
1674 static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, short xco, short yco, short width)
1675 {
1676         bSoundActuator      *sa      = NULL;
1677         bCDActuator                     *cda     = NULL;
1678         bObjectActuator     *oa      = NULL;
1679         bIpoActuator        *ia      = NULL;
1680         bPropertyActuator   *pa      = NULL;
1681         bCameraActuator     *ca      = NULL;
1682         bEditObjectActuator *eoa     = NULL;
1683         bConstraintActuator *coa     = NULL;
1684         bSceneActuator      *sca     = NULL;
1685         bGroupActuator      *ga      = NULL;
1686         bRandomActuator     *randAct = NULL;
1687         bMessageActuator    *ma      = NULL;
1688         bActionActuator     *aa      = NULL;
1689         bGameActuator       *gma     = NULL;
1690         bVisibilityActuator *visAct  = NULL;
1691         bTwoDFilterActuator     *tdfa    = NULL;
1692         bParentActuator     *parAct  = NULL;
1693         bStateActuator          *staAct  = NULL;
1694         
1695         float *fp;
1696         short ysize = 0, wval;
1697         char *str;
1698         int myline, stbit;
1699         uiBut *but;
1700
1701
1702         /* yco is at the top of the rect, draw downwards */
1703         set_col_actuator(act->type, 0);
1704         
1705         switch (act->type)
1706         {
1707         case ACT_OBJECT:
1708                 {
1709                         oa = act->data;
1710                         wval = (width-100)/3;
1711                         if (oa->type == ACT_OBJECT_NORMAL)
1712                         {
1713                                 if ( ob->gameflag & OB_DYNAMIC )
1714                                 {
1715                                         ysize= 175;
1716                                 }
1717                                 else
1718                                 {
1719                                         ysize= 72;
1720                                 }
1721
1722                                 glRects(xco, yco-ysize, xco+width, yco);
1723                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1724                                 
1725                                 uiBlockBeginAlign(block);
1726                                 uiDefBut(block, LABEL, 0, "Loc",        xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "Sets the location");
1727                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-45, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1728                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-45, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1729                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-45, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1730                                 uiBlockEndAlign(block);
1731                                 
1732                                 uiDefBut(block, LABEL, 0, "Rot",        xco, yco-64, 45, 19, NULL, 0, 0, 0, 0, "Sets the rotation");
1733                                 uiBlockBeginAlign(block);
1734                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-64, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1735                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-64, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1736                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-64, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1737                                 uiBlockEndAlign(block);
1738
1739                                 uiDefButBitS(block, TOG, ACT_DLOC_LOCAL, 0, "L",                xco+45+3*wval, yco-45, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1740                                 uiDefButBitS(block, TOG, ACT_DROT_LOCAL, 0, "L",                xco+45+3*wval, yco-64, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1741         
1742                                 if ( ob->gameflag & OB_DYNAMIC )
1743                                 {
1744                                         uiDefBut(block, LABEL, 0, "Force",      xco, yco-87, 55, 19, NULL, 0, 0, 0, 0, "Sets the force");
1745                                         uiBlockBeginAlign(block);
1746                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-87, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, "");
1747                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-87, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, "");
1748                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-87, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, "");
1749                                         uiBlockEndAlign(block);
1750
1751                                         uiDefBut(block, LABEL, 0, "Torque", xco, yco-106, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque");
1752                                         uiBlockBeginAlign(block);
1753                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, "");
1754                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, "");
1755                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, "");                                
1756                                         uiBlockEndAlign(block);
1757                                 }
1758                                 
1759                                 if ( ob->gameflag & OB_DYNAMIC )
1760                                 {
1761                                         uiDefBut(block, LABEL, 0, "LinV",       xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity");
1762                                         uiBlockBeginAlign(block);
1763                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-129, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1764                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-129, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1765                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-129, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1766                                         uiBlockEndAlign(block);
1767                                 
1768                                         uiDefBut(block, LABEL, 0, "AngV",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity");
1769                                         uiBlockBeginAlign(block);
1770                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-148, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, "");
1771                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-148, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, "");
1772                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-148, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, "");
1773                                         uiBlockEndAlign(block);
1774                                 
1775                                         uiDefBut(block, LABEL, 0, "Damp",       xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Number of frames to reach the target velocity");
1776                                         uiDefButS(block, NUM, 0, "",            xco+45, yco-171, wval, 19, &oa->damping, 0.0, 1000.0, 100, 0, "");
1777
1778                                         uiDefButBitS(block, TOG, ACT_FORCE_LOCAL, 0, "L",               xco+45+3*wval, yco-87, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1779                                         uiDefButBitS(block, TOG, ACT_TORQUE_LOCAL, 0, "L",              xco+45+3*wval, yco-106, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1780                                         uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-129, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1781                                         uiDefButBitS(block, TOG, ACT_ANG_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-148, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1782                                 
1783                                         uiDefButBitS(block, TOG, ACT_ADD_LIN_VEL, 0, "add",xco+45+3*wval+15, yco-129, 35, 19, &oa->flag, 0.0, 0.0, 0, 0, "Toggles between ADD and SET linV");
1784                                 }                               
1785                         } else if (oa->type == ACT_OBJECT_SERVO)
1786                         {
1787                                 ysize= 195;
1788                                 
1789                                 glRects(xco, yco-ysize, xco+width, yco);
1790                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1791                                 
1792                                 uiDefBut(block, LABEL, 0, "Ref",        xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "");
1793                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+45, yco-45, wval*3, 19, &(oa->reference), "Reference object for velocity calculation, leave empty for world reference");
1794                                 uiDefBut(block, LABEL, 0, "linV",       xco, yco-68, 45, 19, NULL, 0, 0, 0, 0, "Sets the target relative linear velocity, it will be achieved by automatic application of force. Null velocity is a valid target");
1795                                 uiBlockBeginAlign(block);
1796                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-68, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1797                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-68, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1798                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1799                                 uiBlockEndAlign(block);
1800                                 uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-68, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Velocity is defined in local coordinates");
1801
1802                                 uiDefBut(block, LABEL, 0, "Limit",      xco, yco-91, 45, 19, NULL, 0, 0, 0, 0, "Select if the force needs to be limited along certain axis (local or global depending on LinV Local flag)");
1803                                 uiBlockBeginAlign(block);
1804                                 uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_X, B_REDR, "X",                xco+45, yco-91, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the X axis");
1805                                 uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Y, B_REDR, "Y",                xco+45+wval, yco-91, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Y axis");
1806                                 uiDefButBitS(block, TOG, ACT_SERVO_LIMIT_Z, B_REDR, "Z",                xco+45+2*wval, yco-91, wval, 19, &oa->flag, 0.0, 0.0, 0, 0, "Set limit to force along the Z axis");
1807                                 uiBlockEndAlign(block);
1808                                 uiDefBut(block, LABEL, 0, "Max",        xco, yco-110, 45, 19, NULL, 0, 0, 0, 0, "Set the upper limit for force");
1809                                 uiDefBut(block, LABEL, 0, "Min",        xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Set the lower limit for force");
1810                                 if (oa->flag & ACT_SERVO_LIMIT_X) {
1811                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-110, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1812                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-129, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1813                                 }
1814                                 if (oa->flag & ACT_SERVO_LIMIT_Y) {
1815                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-110, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1816                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-129, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1817                                 }
1818                                 if (oa->flag & ACT_SERVO_LIMIT_Z) {
1819                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-110, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1820                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-129, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1821                                 }
1822                                 uiDefBut(block, LABEL, 0, "Servo",      xco, yco-152, 45, 19, NULL, 0, 0, 0, 0, "Coefficients of the PID servo controller");
1823                                 uiDefButF(block, NUMSLI, B_REDR, "P: ",         xco+45, yco-152, wval*3, 19, oa->forcerot, 0.00, 200.0, 100, 0, "Proportional coefficient, typical value is 60x Integral coefficient");
1824                                 uiDefBut(block, LABEL, 0, "Slow",       xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Low value of I coefficient correspond to slow response");
1825                                 but = uiDefButF(block, NUMSLI, B_REDR, " I : ",         xco+45, yco-171, wval*3, 19, oa->forcerot+1, 0.0, 3.0, 1, 0, "Integral coefficient, low value (0.01) for slow response, high value (0.5) for fast response");
1826                                 uiButSetFunc(but, update_object_actuator_PID, oa, NULL);
1827                                 uiDefBut(block, LABEL, 0, "Fast",       xco+45+3*wval, yco-171, 45, 19, NULL, 0, 0, 0, 0, "High value of I coefficient correspond to fast response");
1828                                 uiDefButF(block, NUMSLI, B_REDR, "D: ",         xco+45, yco-190, wval*3, 19, oa->forcerot+2, -100.0, 100.0, 100, 0, "Derivate coefficient, not required, high values can cause instability");
1829                         }
1830                         str= "Motion Type %t|Simple motion %x0|Servo Control %x1";
1831                         but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &oa->type, 0.0, 0.0, 0, 0, "");
1832                         oa->otype = oa->type;
1833                         uiButSetFunc(but, change_object_actuator, oa, NULL);
1834                         yco-= ysize;
1835                         break;
1836                 }
1837         case ACT_ACTION:
1838         case ACT_SHAPEACTION:
1839                 {
1840                         /* DrawAct */
1841 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1842                         ysize = 112;
1843 #else
1844                         ysize= 92;
1845 #endif
1846                         
1847                         glRects(xco, yco-ysize, xco+width, yco);
1848                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1849                         
1850                         aa = act->data;
1851                         wval = (width-60)/3;
1852                         
1853                         //              str= "Action types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1854 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1855                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6|Displacement %x7";
1856 #else
1857                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1858 #endif
1859                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-24, width/3, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
1860                         uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, 1, "AC: ", xco+10+ (width/3), yco-24, ((width/3)*2) - (20 + 60), 19, &aa->act, "Action name");
1861                         
1862                         uiDefButBitS(block, TOGN, 1, 0, "Continue", xco+((width/3)*2)+20, yco-24, 60, 19,
1863                                          &aa->end_reset, 0.0, 0.0, 0, 0, "Restore last frame when switching on/off, otherwise play from the start each time");
1864                         
1865                         
1866                         if(aa->type == ACT_ACTION_FROM_PROP)
1867                         {
1868                                 uiDefBut(block, TEX, 0, "Prop: ",xco+10, yco-44, width-20, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
1869                         }
1870                         else
1871                         {
1872                                 uiDefButI(block, NUM, 0, "Sta: ",xco+10, yco-44, (width-20)/2, 19, &aa->sta, 1.0, MAXFRAMEF, 0, 0, "Start frame");
1873                                 uiDefButI(block, NUM, 0, "End: ",xco+10+(width-20)/2, yco-44, (width-20)/2, 19, &aa->end, 1.0, MAXFRAMEF, 0, 0, "End frame");
1874                         }
1875                                                 
1876                         uiDefButS(block, NUM, 0, "Blendin: ", xco+10, yco-64, (width-20)/2, 19, &aa->blendin, 0.0, 32767, 0.0, 0.0, "Number of frames of motion blending");
1877                         uiDefButS(block, NUM, 0, "Priority: ", xco+10+(width-20)/2, yco-64, (width-20)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers, With 2 or more actions at once, the overriding channels must be lower in the stack");
1878                         
1879                         uiDefBut(block, TEX, 0, "FrameProp: ",xco+10, yco-84, width-20, 19, aa->frameProp, 0.0, 31.0, 0, 0, "Assign the action's current frame number to this property");
1880
1881                         
1882 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1883                         if(aa->type == ACT_ACTION_MOTION)
1884                         {
1885                                 uiDefButF(block, NUM, 0, "Cycle: ",xco+30, yco-84, (width-60)/2, 19, &aa->stridelength, 0.0, 2500.0, 0, 0, "Distance covered by a single cycle of the action");
1886                         }
1887 #endif
1888                         
1889                         
1890                         
1891                         yco-=ysize;
1892                         break;
1893                 }
1894         case ACT_IPO:
1895                 {
1896                         ia= act->data;
1897                         
1898                         ysize= 72;
1899                         
1900                         glRects(xco, yco-ysize, xco+width, yco);
1901                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1902                         
1903                         str = "Ipo types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1904                         
1905                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-24, (width-20)/2, 19, &ia->type, 0, 0, 0, 0, "");
1906
1907                         but = uiDefButBitS(block, TOG, ACT_IPOFORCE, ACT_IPOFORCE, 
1908                                 "Force", xco+10+(width-20)/2, yco-24, (width-20)/4-10, 19, 
1909                                 &ia->flag, 0, 0, 0, 0, 
1910                                 "Apply Ipo as a global or local force depending on the local option (dynamic objects only)"); 
1911                         uiButSetFunc(but, change_ipo_actuator, but, ia);
1912
1913                         but = uiDefButBitS(block, TOG, ACT_IPOADD, ACT_IPOADD, 
1914                                 "Add", xco+3*(width-20)/4, yco-24, (width-20)/4-10, 19, 
1915                                 &ia->flag, 0, 0, 0, 0, 
1916                                 "Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag"); 
1917                         uiButSetFunc(but, change_ipo_actuator, but, ia);
1918                         
1919                         /* Only show the do-force-local toggle if force is requested */
1920                         if (ia->flag & (ACT_IPOFORCE|ACT_IPOADD)) {
1921                                 uiDefButBitS(block, TOG, ACT_IPOLOCAL, 0, 
1922                                         "L", xco+width-30, yco-24, 20, 19, 
1923                                         &ia->flag, 0, 0, 0, 0, 
1924                                         "Let the ipo acts in local coordinates, used in Force and Add mode"); 
1925                         }
1926
1927                         if(ia->type==ACT_IPO_FROM_PROP) {
1928                                 uiDefBut(block, TEX, 0, 
1929                                         "Prop: ",               xco+10, yco-44, width-80, 19, 
1930                                         ia->name, 0.0, 31.0, 0, 0, 
1931                                         "Use this property to define the Ipo position");
1932                         }
1933                         else {
1934                                 uiDefButI(block, NUM, 0, 
1935                                         "Sta",          xco+10, yco-44, (width-80)/2, 19, 
1936                                         &ia->sta, 1.0, MAXFRAMEF, 0, 0, 
1937                                         "Start frame");
1938                                 uiDefButI(block, NUM, 0, 
1939                                         "End",          xco+10+(width-80)/2, yco-44, (width-80)/2, 19, 
1940                                         &ia->end, 1.0, MAXFRAMEF, 0, 0, 
1941                                         "End frame");
1942                         }
1943                         uiDefButBitS(block, TOG, ACT_IPOCHILD,  B_REDR, 
1944                                 "Child",        xco+10+(width-80), yco-44, 60, 19, 
1945                                 &ia->flag, 0, 0, 0, 0, 
1946                                 "Update IPO on all children Objects as well");
1947                         uiDefBut(block, TEX, 0, 
1948                                 "FrameProp: ",          xco+10, yco-64, width-20, 19, 
1949                                 ia->frameProp, 0.0, 31.0, 0, 0, 
1950                                 "Assign the action's current frame number to this property");
1951
1952                         yco-= ysize;
1953                         break;
1954                 }
1955         case ACT_PROPERTY:
1956                 {
1957                         ysize= 68;
1958                         
1959                         glRects(xco, yco-ysize, xco+width, yco);
1960                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1961                         
1962                         pa= act->data;
1963                         
1964                         str= "Type%t|Assign%x0|Add %x1|Copy %x2|Toggle (bool/int/float/timer)%x3";
1965                         uiDefButI(block, MENU, B_REDR, str,             xco+30,yco-24,width-60, 19, &pa->type, 0, 31, 0, 0, "Type");
1966                         
1967                         uiDefBut(block, TEX, 1, "Prop: ",               xco+30,yco-44,width-60, 19, pa->name, 0, 31, 0, 0, "Property name");
1968                         
1969                         
1970                         if(pa->type==ACT_PROP_TOGGLE) {
1971                                 /* no ui */
1972                                 ysize -= 22;
1973                         }
1974                         else if(pa->type==ACT_PROP_COPY) {
1975                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:", xco+10, yco-64, (width-20)/2, 19, &(pa->ob), "Copy from this Object");
1976                                 uiDefBut(block, TEX, 1, "Prop: ",               xco+10+(width-20)/2, yco-64, (width-20)/2, 19, pa->value, 0, 31, 0, 0, "Copy this property");
1977                         }
1978                         else {
1979                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-64,width-60, 19, pa->value, 0, 31, 0, 0, "change with this value, use \"\" around strings");
1980                         }
1981                         yco-= ysize;
1982                         
1983                         break;
1984                 }
1985     case ACT_SOUND:
1986                 {
1987                         ysize = 70;
1988                         
1989                         sa = act->data;
1990                         sa->sndnr = 0;
1991                         
1992                         wval = (width-20)/2;
1993                         glRects(xco, yco-ysize, xco+width, yco);
1994                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1995                         
1996                         if(G.main->sound.first) {
1997                                 IDnames_to_pupstring(&str, "Sound files", NULL, &(G.main->sound), (ID *)sa->sound, &(sa->sndnr));
1998                                 /* reset this value, it is for handling the event */
1999                                 sa->sndnr = 0;
2000                                 uiDefButS(block, MENU, B_SOUNDACT_BROWSE, str, xco+10,yco-22,20,19, &(sa->sndnr), 0, 0, 0, 0, "");      
2001
2002                                 if(sa->sound) {
2003                                         char dummy_str[] = "Sound mode %t|Play Stop %x0|Play End %x1|Loop Stop %x2|Loop End %x3|Loop Ping Pong Stop %x5|Loop Ping Pong %x4";
2004                                         uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,width-40,19, sa->sound->id.name+2,    0.0, 21.0, 0, 0, "");
2005                                         uiDefButS(block, MENU, 1, dummy_str,xco+10,yco-44,width-20, 19, &sa->type, 0.0, 0.0, 0, 0, "");
2006                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-66,wval, 19, &sa->sound->volume, 0.0,  1.0, 0, 0, "Sets the volume of this sound");
2007                                         uiDefButF(block, NUM, 0, "Pitch:",xco+wval+10,yco-66,wval, 19, &sa->sound->pitch,-12.0, 12.0, 0, 0, "Sets the pitch of this sound");
2008                                 }
2009                                 MEM_freeN(str);
2010                         } 
2011                         else {
2012                                 uiDefBut(block, LABEL, 0, "Use Sound window (F10) to load samples", xco, yco-24, width, 19, NULL, 0, 0, 0, 0, "");
2013                         }
2014                                         
2015                         yco-= ysize;
2016                         
2017                         break;
2018                 }
2019         case ACT_CD:
2020                 {
2021                         char cd_type_str[] = "Sound mode %t|Play all tracks %x0|Play one track %x1|"
2022                                 "Volume %x3|Stop %x4|Pause %x5|Resume %x6";
2023                         cda = act->data;
2024
2025                         if (cda) {
2026                                 if (cda->track == 0) {
2027                                         cda->track = 1;
2028                                         cda->volume = 1;
2029                                         cda->type = ACT_CD_PLAY_ALL;
2030                                 }
2031                                 
2032                                 if (cda->type == ACT_CD_PLAY_TRACK || cda->type == ACT_CD_LOOP_TRACK) {
2033                                         ysize = 48;
2034                                         glRects(xco, yco-ysize, xco+width, yco);
2035                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2036                                         uiDefButS(block, NUM, 0, "Track:", xco+10,yco-44,width-20, 19, &cda->track, 1, 99, 0, 0, "Select the track to be played");
2037                                 }
2038                                 else if (cda->type == ACT_CD_VOLUME) {
2039                                         ysize = 48;
2040                                         glRects(xco, yco-ysize, xco+width, yco);
2041                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2042                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-44,width-20, 19, &cda->volume, 0, 1, 0, 0, "Set the volume for CD playback");
2043                                 }
2044                                 else {
2045                                         ysize = 28;
2046                                         glRects(xco, yco-ysize, xco+width, yco);
2047                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2048                                 }
2049                                 uiDefButS(block, MENU, B_REDR, cd_type_str,xco+10,yco-22,width-20, 19, &cda->type, 0.0, 0.0, 0, 0, "");
2050                         }
2051                         yco-= ysize;
2052                         break;
2053                 }
2054         case ACT_CAMERA:
2055
2056                 ysize= 48;
2057         
2058                 glRects(xco, yco-ysize, xco+width, yco);
2059                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2060                 
2061                 ca= act->data;
2062         
2063                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-24, (width-20)/2, 19, &(ca->ob), "Look at this Object");
2064                 uiDefButF(block, NUM, 0, "Height:",     xco+10+(width-20)/2, yco-24, (width-20)/2, 19, &ca->height, 0.0, 20.0, 0, 0, "");
2065                 
2066                 uiDefButF(block, NUM, 0, "Min:",        xco+10, yco-44, (width-60)/2, 19, &ca->min, 0.0, 20.0, 0, 0, "");
2067                 
2068                 if(ca->axis==0) ca->axis= 'x';
2069                 uiDefButS(block, ROW, 0, "X",   xco+10+(width-60)/2, yco-44, 20, 19, &ca->axis, 4.0, (float)'x', 0, 0, "Camera tries to get behind the X axis");
2070                 uiDefButS(block, ROW, 0, "Y",   xco+30+(width-60)/2, yco-44, 20, 19, &ca->axis, 4.0, (float)'y', 0, 0, "Camera tries to get behind the Y axis");
2071                 
2072                 uiDefButF(block, NUM, 0, "Max:",        xco+20+(width)/2, yco-44, (width-60)/2, 19, &ca->max, 0.0, 20.0, 0, 0, "");
2073
2074                 yco-= ysize;
2075         
2076          break;
2077                                 
2078         case ACT_EDIT_OBJECT:
2079                 
2080                 eoa= act->data;
2081
2082                 if(eoa->type==ACT_EDOB_ADD_OBJECT) {
2083                         int wval; /* just a temp width */
2084                         ysize = 92;
2085                         glRects(xco, yco-ysize, xco+width, yco);
2086                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2087          
2088                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Add this Object and all its children (cant be on an visible layer)");
2089                         uiDefButI(block, NUM, 0, "Time:",       xco+10+(width-20)/2, yco-44, (width-20)/2, 19, &eoa->time, 0.0, 2000.0, 0, 0, "Duration the new Object lives");
2090
2091                         wval= (width-60)/3;
2092                         uiDefBut(block, LABEL, 0, "linV",       xco,           yco-68,   45, 19,
2093                                          NULL, 0, 0, 0, 0,
2094                                          "Velocity upon creation");
2095                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-68, wval, 19,
2096                                          eoa->linVelocity, -100.0, 100.0, 10, 0,
2097                                          "Velocity upon creation, x component");
2098                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-68, wval, 19,
2099                                          eoa->linVelocity+1, -100.0, 100.0, 10, 0,
2100                                          "Velocity upon creation, y component");
2101                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19,
2102                                          eoa->linVelocity+2, -100.0, 100.0, 10, 0,
2103                                          "Velocity upon creation, z component");
2104                         uiDefButBitS(block, TOG, ACT_EDOB_LOCAL_LINV, 0, "L", xco+45+3*wval, yco-68, 15, 19,
2105                                          &eoa->localflag, 0.0, 0.0, 0, 0,
2106                                          "Apply the transformation locally");
2107                         
2108                         
2109                         uiDefBut(block, LABEL, 0, "AngV",       xco,           yco-90,   45, 19,
2110                                          NULL, 0, 0, 0, 0,
2111                                          "Angular velocity upon creation");
2112                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-90, wval, 19,
2113                                          eoa->angVelocity, -10000.0, 10000.0, 10, 0,
2114                                          "Angular velocity upon creation, x component");
2115                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-90, wval, 19,
2116                                          eoa->angVelocity+1, -10000.0, 10000.0, 10, 0,
2117                                          "Angular velocity upon creation, y component");
2118                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-90, wval, 19,
2119                                          eoa->angVelocity+2, -10000.0, 10000.0, 10, 0,
2120                                          "Angular velocity upon creation, z component");
2121                         uiDefButBitS(block, TOG, ACT_EDOB_LOCAL_ANGV, 0, "L", xco+45+3*wval, yco-90, 15, 19,
2122                                          &eoa->localflag, 0.0, 0.0, 0, 0,
2123                                          "Apply the rotation locally");
2124                                          
2125
2126                 }
2127                 else if(eoa->type==ACT_EDOB_END_OBJECT) {
2128                         ysize= 28;
2129                         glRects(xco, yco-ysize, xco+width, yco);
2130                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2131                 }
2132                 else if(eoa->type==ACT_EDOB_REPLACE_MESH) {
2133                         ysize= 48;
2134                         glRects(xco, yco-ysize, xco+width, yco);
2135                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2136          
2137                         uiDefIDPoinBut(block, test_meshpoin_but, ID_ME, 1, "ME:",               xco+40, yco-44, (width-80), 19, &(eoa->me), "replace the existing mesh with this one");
2138                 }
2139                 else if(eoa->type==ACT_EDOB_TRACK_TO) {
2140                         ysize= 48;
2141                         glRects(xco, yco-ysize, xco+width, yco);
2142                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2143          
2144                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Track to this Object");
2145                         uiDefButI(block, NUM, 0, "Time:",       xco+10+(width-20)/2, yco-44, (width-20)/2-40, 19, &eoa->time, 0.0, 2000.0, 0, 0, "Duration the tracking takes");
2146                         uiDefButS(block, TOG, 0, "3D",  xco+width-50, yco-44, 40, 19, &eoa->flag, 0.0, 0.0, 0, 0, "Enable 3D tracking");
2147                 }
2148                 else if(eoa->type==ACT_EDOB_DYNAMICS) {
2149                         ysize= 69;
2150                         glRects(xco, yco-ysize, xco+width, yco);
2151                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2152                         
2153                         str= "Dynamic Operation %t|Restore Dynamics %x0|Suspend Dynamics %x1|Enable Rigid Body %x2|Disable Rigid Body %x3|Set Mass %x4";
2154                         uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-44, (width-80), 19,  &(eoa->dyn_operation), 0.0, 0.0, 0, 0, "");
2155                         if(eoa->dyn_operation==4) {
2156                                 uiDefButF(block, NUM, 0, "",            xco+40, yco-63, width-80, 19,
2157                                          &eoa->mass, 0.0, 10000.0, 10, 0,
2158                                          "Mass for object");
2159                         }
2160                 }
2161                 str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3|Dynamics %x4";
2162                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &eoa->type, 0.0, 0.0, 0, 0, "");
2163
2164                 yco-= ysize;
2165         
2166         break;
2167  
2168         case ACT_CONSTRAINT:
2169                 coa= act->data;
2170         
2171                 if (coa->type == ACT_CONST_TYPE_LOC) {
2172                         ysize= 69;
2173         
2174                         glRects(xco, yco-ysize, xco+width, yco);
2175                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2176                         
2177         /*              str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4|Rot X %x8|Rot Y %x16|Rot Z %x32"; */
2178         /*                      coa->flag &= ~(63); */
2179                         str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4";
2180                         coa->flag &= 7;
2181                         coa->time = 0;
2182                         uiDefButS(block, MENU, 1, str,          xco+10, yco-65, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, "");
2183                 
2184                         uiDefButS(block, NUM,           0, "damp",      xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter");
2185                         uiDefBut(block, LABEL,                  0, "Min",       xco+80, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2186                         uiDefBut(block, LABEL,                  0, "Max",       xco+80+(width-90)/2, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2187
2188                         if(coa->flag & ACT_CONST_LOCX) fp= coa->minloc;
2189                         else if(coa->flag & ACT_CONST_LOCY) fp= coa->minloc+1;
2190                         else if(coa->flag & ACT_CONST_LOCZ) fp= coa->minloc+2;
2191                         else if(coa->flag & ACT_CONST_ROTX) fp= coa->minrot;
2192                         else if(coa->flag & ACT_CONST_ROTY) fp= coa->minrot+1;
2193                         else fp= coa->minrot+2;
2194                         
2195                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-90)/2, 19, fp, -2000.0, 2000.0, 10, 0, "");
2196                         uiDefButF(block, NUM, 0, "",            xco+80+(width-90)/2, yco-65, (width-90)/2, 19, fp+3, -2000.0, 2000.0, 10, 0, "");
2197                 } else if (coa->type == ACT_CONST_TYPE_DIST) {
2198                         ysize= 106;
2199
2200                         glRects(xco, yco-ysize, xco+width, yco);
2201                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2202                         
2203                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32";
2204                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Set the direction of the ray");
2205                 
2206                         uiDefButS(block, NUM,           0, "damp",      xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter");
2207                         uiDefBut(block, LABEL,                  0, "Range",     xco+80, yco-45, (width-115)/2, 19, NULL, 0.0, 0.0, 0, 0, "Set the maximum length of ray");
2208                         uiDefButBitS(block, TOG, ACT_CONST_DISTANCE, B_REDR, "Dist",    xco+80+(width-115)/2, yco-45, (width-115)/2, 19, &coa->flag, 0.0, 0.0, 0, 0, "Force distance of object to point of impact of ray");
2209                         uiDefButBitS(block, TOG, ACT_CONST_LOCAL, 0, "L", xco+80+(width-115), yco-45, 25, 19,
2210                                          &coa->flag, 0.0, 0.0, 0, 0, "Set ray along object's axis or global axis");
2211
2212                         if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc;
2213                         else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1;
2214                         else fp= coa->minloc+2;
2215
2216                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-115)/2, 19, fp+3, 0.0, 2000.0, 10, 0, "Maximum length of ray");
2217                         if (coa->flag & ACT_CONST_DISTANCE)
2218                                 uiDefButF(block, NUM, 0, "",            xco+80+(width-115)/2, yco-65, (width-115)/2, 19, fp, -2000.0, 2000.0, 10, 0, "Keep this distance to target");
2219                         uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
2220                                          &coa->flag, 0.0, 0.0, 0, 0, "Set object axis along (local axis) or parallel (global axis) to the normal at hit position");
2221                         uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
2222                                          &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
2223                         if (coa->flag & ACT_CONST_MATERIAL)
2224                         {
2225                                 uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
2226                                         coa->matprop, 0, 31, 0, 0,
2227                                         "Ray detects only Objects with this material");
2228                         }
2229                         else
2230                         {
2231                                 uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
2232                                         coa->matprop, 0, 31, 0, 0,
2233                                         "Ray detect only Objects with this property");
2234                         }
2235                         uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
2236                                 &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
2237                         uiDefButS(block, NUM, 0, "time", xco+50, yco-103, (width-60)/2, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited");
2238                         uiDefButS(block, NUM, 0, "rotDamp", xco+50+(width-60)/2, yco-103, (width-60)/2, 19, &(coa->rotdamp), 0.0, 100.0, 0, 0, "Use a different damping for orientation");
2239                 } else if (coa->type == ACT_CONST_TYPE_ORI) {
2240                         ysize= 87;
2241
2242                         glRects(xco, yco-ysize, xco+width, yco);
2243                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2244                         
2245                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4";
2246                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Select the axis to be aligned along the reference direction");
2247                 
2248                         uiDefButS(block, NUM,           0, "damp",      xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter");
2249                         uiDefBut(block, LABEL,                  0, "X", xco+80, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2250                         uiDefBut(block, LABEL,                  0, "Y", xco+80+(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2251                         uiDefBut(block, LABEL,                  0, "Z", xco+80+2*(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2252
2253                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-115)/3, 19, &coa->maxrot[0], -2000.0, 2000.0, 10, 0, "X component of reference direction");
2254                         uiDefButF(block, NUM, 0, "",            xco+80+(width-115)/3, yco-65, (width-115)/3, 19, &coa->maxrot[1], -2000.0, 2000.0, 10, 0, "Y component of reference direction");
2255                         uiDefButF(block, NUM, 0, "",            xco+80+2*(width-115)/3, yco-65, (width-115)/3, 19, &coa->maxrot[2], -2000.0, 2000.0, 10, 0, "Z component of reference direction");
2256
2257                         uiDefButS(block, NUM, 0, "time", xco+10, yco-84, 70, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited");
2258                         uiDefButF(block, NUM, 0, "min", xco+80, yco-84, (width-115)/2, 19, &(coa->minloc[0]), 0.0, 180.0, 10, 1, "Minimum angle (in degree) to maintain with target direction. No correction is done if angle with target direction is between min and max");
2259                         uiDefButF(block, NUM, 0, "max", xco+80+(width-115)/2, yco-84, (width-115)/2, 19, &(coa->maxloc[0]), 0.0, 180.0, 10, 1, "Maximum angle (in degree) allowed with target direction. No correction is done if angle with target direction is between min and max");
2260                 } else if (coa->type == ACT_CONST_TYPE_FH) {
2261                         ysize= 106;
2262
2263                         glRects(xco, yco-ysize, xco+width, yco);
2264                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2265                         
2266                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32";
2267                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Set the direction of the ray (in world coordinate)");
2268
2269                         if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc;
2270                         else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1;
2271                         else fp= coa->minloc+2;
2272
2273                         uiDefButF(block, NUM,           0, "damp",      xco+10, yco-45, (width-70)/2, 19, &coa->maxrot[0], 0.0, 1.0, 1, 0, "Damping factor of the Fh spring force");
2274                         uiDefButF(block, NUM,           0, "dist",      xco+10+(width-70)/2, yco-45, (width-70)/2, 19, fp, 0.010, 2000.0, 10, 0, "Height of the Fh area");
2275                         uiDefButBitS(block, TOG, ACT_CONST_DOROTFH, 0, "Rot Fh",        xco+10+(width-70), yco-45, 50, 19, &coa->flag, 0.0, 0.0, 0, 0, "Keep object axis parallel to normal");
2276
2277                         uiDefButF(block, NUMSLI, 0, "Fh ",              xco+80, yco-65, (width-115), 19, fp+3, 0.0, 1.0, 0, 0, "Spring force within the Fh area");
2278                         uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
2279                                          &coa->flag, 0.0, 0.0, 0, 0, "Add a horizontal spring force on slopes");
2280                         uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
2281                                          &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
2282                         if (coa->flag & ACT_CONST_MATERIAL)
2283                         {
2284                                 uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
2285                                         coa->matprop, 0, 31, 0, 0,
2286                                         "Ray detects only Objects with this material");
2287                         }
2288                         else
2289                         {
2290                                 uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
2291                                         coa->matprop, 0, 31, 0, 0,
2292                                         "Ray detect only Objects with this property");
2293                         }
2294                         uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
2295                                 &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
2296                         uiDefButS(block, NUM, 0, "time", xco+50, yco-103, 90, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited");
2297                         uiDefButF(block, NUM, 0, "rotDamp", xco+140, yco-103, (width-150), 19, &coa->maxrot[1], 0.0, 1.0, 1, 0, "Use a different damping for rotation");
2298                 }
2299                 str= "Constraint Type %t|Location %x0|Distance %x1|Orientation %x2|Force field %x3";
2300                 but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &coa->type, 0.0, 0.0, 0, 0, "");
2301                 yco-= ysize;
2302         break;
2303  
2304         case ACT_SCENE:
2305                 sca= act->data; 
2306                 
2307                 if(sca->type==ACT_SCENE_RESTART) { 
2308                         ysize= 28; 
2309                         glRects(xco, yco-ysize, xco+width, yco); 
2310                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2311                 } 
2312                 else if(sca->type==ACT_SCENE_CAMERA) { 
2313                         
2314                         ysize= 48; 
2315                         glRects(xco, yco-ysize, xco+width, yco); 
2316                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2317          
2318                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+40, yco-44, (width-80), 19, &(sca->camera), "Set this Camera. Leave empty to refer to self object"); 
2319                 } 
2320                 else if(sca->type==ACT_SCENE_SET) { 
2321                         
2322                         ysize= 48; 
2323                         glRects(xco, yco-ysize, xco+width, yco); 
2324                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2325         
2326                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Set this Scene"); 
2327                 } 
2328                 else if(sca->type==ACT_SCENE_ADD_FRONT) { 
2329                         
2330                         ysize= 48; 
2331                         glRects(xco, yco-ysize, xco+width, yco); 
2332                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2333         
2334                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add an Overlay Scene"); 
2335                 } 
2336                 else if(sca->type==ACT_SCENE_ADD_BACK) { 
2337                         
2338                         ysize= 48; 
2339                         glRects(xco, yco-ysize, xco+width, yco); 
2340                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2341         
2342                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add a Background Scene"); 
2343                 } 
2344                 else if(sca->type==ACT_SCENE_REMOVE) { 
2345                         
2346                         ysize= 48; 
2347                         glRects(xco, yco-ysize, xco+width, yco); 
2348                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2349         
2350                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Remove a Scene");
2351                 } 
2352                 else if(sca->type==ACT_SCENE_SUSPEND) { 
2353                         
2354                         ysize= 48; 
2355                         glRects(xco, yco-ysize, xco+width, yco); 
2356                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2357         
2358                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Pause a Scene");
2359                 } 
2360                 else if(sca->type==ACT_SCENE_RESUME) { 
2361                         
2362                         ysize= 48; 
2363                         glRects(xco, yco-ysize, xco+width, yco); 
2364                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2365         
2366                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Unpause a Scene");
2367                 } 
2368
2369                 str= "Scene %t|Restart %x0|Set Scene %x1|Set Camera %x2|Add OverlayScene %x3|Add BackgroundScene %x4|Remove Scene %x5|Suspend Scene %x6|Resume Scene %x7";
2370                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &sca->type, 0.0, 0.0, 0, 0, ""); 
2371
2372                 yco-= ysize; 
2373                 break; 
2374         case ACT_GAME:
2375                 {
2376                         gma = act->data; 
2377                         if (gma->type == ACT_GAME_LOAD)
2378                         {
2379                                 //ysize = 68;
2380                                 ysize = 48;
2381                                 glRects(xco, yco-ysize, xco+width, yco); 
2382                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2383                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this blend file, use the \"//\" prefix for a path relative to the current blend file");
2384 //                              uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2385                         }
2386 /*                      else if (gma->type == ACT_GAME_START)
2387                         {
2388                                 ysize = 68; 
2389                                 glRects(xco, yco-ysize, xco+width, yco); 
2390                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2391
2392                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
2393                                 uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2394                         }
2395 */                      else if (ELEM4(gma->type, ACT_GAME_RESTART, ACT_GAME_QUIT, ACT_GAME_SAVECFG, ACT_GAME_LOADCFG))
2396                         {
2397                                 ysize = 28; 
2398                                 glRects(xco, yco-ysize, xco+width, yco); 
2399                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2400                         }
2401
2402                         //str = "Scene %t|Load game%x0|Start loaded game%x1|Restart this game%x2|Quit this game %x3";
2403                         str = "Scene %t|Start new game%x0|Restart this game%x2|Quit this game %x3|Save GameLogic.globalDict %x4|Load GameLogic.globalDict %x5";
2404                         uiDefButS(block, MENU, B_REDR, str, xco+40, yco-24, (width-80), 19, &gma->type, 0.0, 0.0, 0, 0, ""); 
2405                         
2406                         yco -= ysize; 
2407                         break; 
2408                 }
2409         case ACT_GROUP:
2410                 ga= act->data;
2411
2412                 ysize= 52;
2413
2414                 glRects(xco, yco-ysize, xco+width, yco);
2415                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2416                 
2417                 str= "GroupKey types   %t|Set Key %x6|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x5";
2418
2419                 uiDefButS(block, MENU, 1, str,                  xco+20, yco-24, width-40, 19, &ga->type, 0, 0, 0, 0, "");
2420                 if(ga->type==ACT_GROUP_SET) {
2421                         uiDefBut(block, TEX, 0, "Key: ",                xco+20, yco-44, (width-10)/2, 19, ga->name, 0.0, 31.0, 0, 0, "This name defines groupkey to be set");
2422                         uiDefButI(block, NUM, 0, "Frame:",      xco+20+(width-10)/2, yco-44, (width-70)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Set this frame");
2423                 }
2424                 else if(ga->type==ACT_GROUP_FROM_PROP) {
2425                         uiDefBut(block, TEX, 0, "Prop: ",               xco+20, yco-44, width-40, 19, ga->name, 0.0, 31.0, 0, 0, "Use this property to define the Group position");
2426                 }
2427                 else {
2428                         uiDefButI(block, NUM, 0, "State",               xco+20, yco-44, (width-40)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Start frame");
2429                         uiDefButI(block, NUM, 0, "End",         xco+20+(width-40)/2, yco-44, (width-40)/2, 19, &ga->end, 0.0, 2500.0, 0, 0, "End frame");
2430                 }
2431                 yco-= ysize;
2432                 break;
2433
2434         case ACT_VISIBILITY:
2435                 ysize = 24;
2436
2437                 glRects(xco, yco-ysize, xco+width, yco);
2438                 uiEmboss((float)xco,
2439                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
2440                 
2441                 visAct = act->data;
2442
2443                 uiBlockBeginAlign(block);
2444                 uiDefButBitI(block, TOGN, ACT_VISIBILITY_INVISIBLE, B_REDR,
2445                           "Visible",
2446                           xco + 10, yco - 20, (width - 20)/3, 19, &visAct->flag,
2447                           0.0, 0.0, 0, 0,
2448                           "Set the objects visible. Initialized from the objects render restriction toggle (access in the outliner)");
2449                 uiDefButBitI(block, TOG, ACT_VISIBILITY_OCCLUSION, B_REDR,
2450                           "Occlusion",
2451                           xco + 10 + ((width - 20)/3), yco - 20, (width - 20)/3, 19, &visAct->flag,
2452                           0.0, 0.0, 0, 0,
2453                           "Set the object to occlude objects behind it. Initialized from the object type in physics button");
2454                 uiBlockEndAlign(block);
2455                 
2456                 uiDefButBitI(block, TOG, ACT_VISIBILITY_RECURSIVE, 0,
2457                           "Children",
2458                           xco + 10 + (((width - 20)/3)*2)+10, yco - 20, ((width - 20)/3)-10, 19, &visAct->flag,
2459                           0.0, 0.0, 0, 0,
2460                           "Sets all the children of this object to the same visibility/occlusion recursively");
2461
2462                 yco-= ysize;
2463
2464                 break;
2465                 
2466         case ACT_STATE:
2467                 ysize = 34;
2468
2469                 glRects(xco, yco-ysize, xco+width, yco);
2470                 uiEmboss((float)xco,
2471                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
2472                 
2473                 staAct = act->data;
2474
2475                 str= "Operation %t|Cpy %x0|Add %x1|Sub %x2|Inv %x3";
2476
2477                 uiDefButI(block, MENU, B_REDR, str,
2478                           xco + 10, yco - 24, 65, 19, &staAct->type,
2479                           0.0, 0.0, 0, 0,
2480                           "Select the bit operation on object state mask");
2481
2482                 for (wval=0; wval<15; wval+=5) {
2483                         uiBlockBeginAlign(block);
2484                         for (stbit=0; stbit<5; stbit++) {
2485                                 but = uiDefButBitI(block,  TOG, 1<<(stbit+wval), stbit+wval, "",        (short)(xco+85+12*stbit+13*wval), yco-17, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+wval)));
2486                                 uiButSetFunc(but, check_state_mask, but, &(staAct->mask));
2487                         }
2488                         for (stbit=0; stbit<5; stbit++) {
2489                                 but = uiDefButBitI(block, TOG, 1<<(stbit+wval+15), stbit+wval+15, "",   (short)(xco+85+12*stbit+13*wval), yco-29, 12, 12, (int *)&(staAct->mask), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+wval+15)));
2490                                 uiButSetFunc(but, check_state_mask, but, &(staAct->mask));
2491                         }
2492                 }
2493                 uiBlockEndAlign(block);
2494
2495                 yco-= ysize;
2496
2497                 break;
2498
2499         case ACT_RANDOM:
2500                 ysize  = 69;
2501
2502                 glRects(xco, yco-ysize, xco+width, yco);
2503                 uiEmboss((float)xco,
2504                                   (float)yco-ysize, (float)xco+width, (float)yco, 1);
2505                 
2506                 randAct = act->data;
2507
2508                 /* 1. seed */
2509                 uiDefButI(block, NUM, 1, "Seed: ",              (xco+10),yco-24, 0.4 *(width-20), 19,
2510                                  &randAct->seed, 0, 1000, 0, 0,
2511                                  "Initial seed of the random generator. Use Python for more freedom. "
2512                                  " (Choose 0 for not random)");
2513
2514                 /* 2. distribution type */
2515                 /* One pick per distribution. These numbers MUST match the #defines  */
2516                 /* in game.h !!!                                                     */
2517                 str= "Distribution %t|Bool Constant %x0|Bool Uniform %x1"
2518                         "|Bool Bernoulli %x2|Int Constant %x3|Int Uniform %x4"
2519                         "|Int Poisson %x5|Float Constant %x6|Float Uniform %x7"
2520                         "|Float Normal %x8|Float Neg. Exp. %x9";
2521                 uiDefButI(block, MENU, B_REDR, str, (xco+10) + 0.4 * (width-20), yco-24, 0.6 * (width-20), 19,
2522                                  &randAct->distribution, 0.0,&nb