svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22704:22717
[blender.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_PROPERTY:
712                 return "Property";
713         case ACT_EDIT_OBJECT:
714                 return "Edit Object";
715         case ACT_CONSTRAINT:
716                 return "Constraint";
717         case ACT_SCENE:
718                 return "Scene";
719         case ACT_GROUP:
720                 return "Group";
721         case ACT_RANDOM:
722                 return "Random";
723         case ACT_MESSAGE:
724                 return "Message";
725         case ACT_GAME:
726                 return "Game";
727         case ACT_VISIBILITY:
728                 return "Visibility";
729         case ACT_2DFILTER:
730                 return "2D Filter";
731         case ACT_PARENT:
732                 return "Parent";
733         case ACT_STATE:
734                 return "State";
735         }
736         return "unknown";
737 }
738
739
740
741
742 static char *actuator_pup(Object *owner)
743 {
744         switch (owner->type)
745         {
746         case OB_ARMATURE:
747                 return "Actuators  %t|Action %x15|Motion %x0|Constraint %x9|Ipo %x1"
748                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
749                         "|Scene %x11|Random %x13|Message %x14|Game %x17"
750                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
751                 break;
752
753         case OB_MESH:
754                 return "Actuators  %t|Shape Action %x21|Motion %x0|Constraint %x9|Ipo %x1"
755                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
756                         "|Scene %x11|Random %x13|Message %x14|Game %x17"
757                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
758                 break;
759
760         default:
761                 return "Actuators  %t|Motion %x0|Constraint %x9|Ipo %x1"
762                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
763                         "|Scene %x11|Random %x13|Message %x14|Game %x17"
764                         "|Visibility %x18|2D Filter %x19|Parent %x20|State %x22";
765         }
766 }
767
768
769
770 static void set_sca_ob(Object *ob)
771 {
772         bController *cont;
773         bActuator *act;
774
775         cont= ob->controllers.first;
776         while(cont) {
777                 cont->mynew= (bController *)ob;
778                 cont= cont->next;
779         }
780         act= ob->actuators.first;
781         while(act) {
782                 act->mynew= (bActuator *)ob;
783                 act= act->next;
784         }
785 }
786
787 static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisflag)
788 {
789         Base *base;
790         Scene *scene= CTX_data_scene(C);
791         Object *ob, *obt, *obact= CTX_data_active_object(C);
792         ID **idar;
793         bSensor *sens;
794         bController *cont;
795         unsigned int lay;
796         int a, nr, doit;
797         
798         /* we need a sorted object list */
799         /* set scavisflags flags in Objects to indicate these should be evaluated */
800         /* also hide ob pointers in ->new entries of controllerss/actuators */
801         
802         *count= 0;
803         
804         if(scene==NULL) return NULL;
805         
806         ob= G.main->object.first;
807         while(ob) {
808                 ob->scavisflag= 0;
809                 set_sca_ob(ob);
810                 ob= ob->id.next;
811         }
812         
813         /* XXX here it checked 3d lay */
814         lay= scene->lay;
815         
816         base= FIRSTBASE;
817         while(base) {
818                 if(base->lay & lay) {
819                         if(base->flag & SELECT) {
820                                 if(scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
821                                 if(scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
822                                 if(scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
823                         }
824                 }
825                 base= base->next;
826         }
827
828         if(obact) {
829                 if(scavisflag & BUTS_SENS_ACT) obact->scavisflag |= OB_VIS_SENS;
830                 if(scavisflag & BUTS_CONT_ACT) obact->scavisflag |= OB_VIS_CONT;
831                 if(scavisflag & BUTS_ACT_ACT) obact->scavisflag |= OB_VIS_ACT;
832         }
833         
834         /* BUTS_XXX_STATE are similar to BUTS_XXX_LINK for selecting the object */
835         if(scavisflag & (BUTS_SENS_LINK|BUTS_CONT_LINK|BUTS_ACT_LINK|BUTS_SENS_STATE|BUTS_ACT_STATE)) {
836                 doit= 1;
837                 while(doit) {
838                         doit= 0;
839                         
840                         ob= G.main->object.first;
841                         while(ob) {
842                         
843                                 /* 1st case: select sensor when controller selected */
844                                 if((scavisflag & (BUTS_SENS_LINK|BUTS_SENS_STATE)) && (ob->scavisflag & OB_VIS_SENS)==0) {
845                                         sens= ob->sensors.first;
846                                         while(sens) {
847                                                 for(a=0; a<sens->totlinks; a++) {
848                                                         if(sens->links[a]) {
849                                                                 obt= (Object *)sens->links[a]->mynew;
850                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)) {
851                                                                         doit= 1;
852                                                                         ob->scavisflag |= OB_VIS_SENS;
853                                                                         break;
854                                                                 }
855                                                         }
856                                                 }
857                                                 if(doit) break;
858                                                 sens= sens->next;
859                                         }
860                                 }
861                                 
862                                 /* 2nd case: select cont when act selected */
863                                 if((scavisflag & BUTS_CONT_LINK)  && (ob->scavisflag & OB_VIS_CONT)==0) {
864                                         cont= ob->controllers.first;
865                                         while(cont) {
866                                                 for(a=0; a<cont->totlinks; a++) {
867                                                         if(cont->links[a]) {
868                                                                 obt= (Object *)cont->links[a]->mynew;
869                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)) {
870                                                                         doit= 1;
871                                                                         ob->scavisflag |= OB_VIS_CONT;
872                                                                         break;
873                                                                 }
874                                                         }
875                                                 }
876                                                 if(doit) break;
877                                                 cont= cont->next;
878                                         }
879                                 }
880                                 
881                                 /* 3rd case: select controller when sensor selected */
882                                 if((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_SENS)) {
883                                         sens= ob->sensors.first;
884                                         while(sens) {
885                                                 for(a=0; a<sens->totlinks; a++) {
886                                                         if(sens->links[a]) {
887                                                                 obt= (Object *)sens->links[a]->mynew;
888                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)==0) {
889                                                                         doit= 1;
890                                                                         obt->scavisflag |= OB_VIS_CONT;
891                                                                 }
892                                                         }
893                                                 }
894                                                 sens= sens->next;
895                                         }
896                                 }
897                                 
898                                 /* 4th case: select actuator when controller selected */
899                                 if( (scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE))  && (ob->scavisflag & OB_VIS_CONT)) {
900                                         cont= ob->controllers.first;
901                                         while(cont) {
902                                                 for(a=0; a<cont->totlinks; a++) {
903                                                         if(cont->links[a]) {
904                                                                 obt= (Object *)cont->links[a]->mynew;
905                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)==0) {
906                                                                         doit= 1;
907                                                                         obt->scavisflag |= OB_VIS_ACT;
908                                                                 }
909                                                         }
910                                                 }
911                                                 cont= cont->next;
912                                         }
913                                         
914                                 }
915                                 ob= ob->id.next;
916                         }
917                 }
918         } 
919         
920         /* now we count */
921         ob= G.main->object.first;
922         while(ob) {
923                 if( ob->scavisflag ) (*count)++;
924                 ob= ob->id.next;
925         }
926
927         if(*count==0) return NULL;
928         if(*count>24) *count= 24;               /* temporal */
929         
930         idar= MEM_callocN( (*count)*sizeof(void *), "idar");
931         
932         ob= G.main->object.first;
933         nr= 0;
934         while(ob) {
935                 if( ob->scavisflag ) {
936                         idar[nr]= (ID *)ob;
937                         nr++;
938                 }
939                 if(nr>=24) break;
940                 ob= ob->id.next;
941         }
942         
943         /* just to be sure... these were set in set_sca_done_ob() */
944         clear_sca_new_poins();
945         
946         return idar;
947 }
948
949
950 static int get_col_sensor(int type)
951 {
952         /* XXX themecolors not here */
953         
954         switch(type) {
955         case SENS_ALWAYS:               return TH_PANEL;
956         case SENS_DELAY:                return TH_PANEL;
957         case SENS_TOUCH:                return TH_PANEL;
958         case SENS_COLLISION:    return TH_PANEL;
959         case SENS_NEAR:                 return TH_PANEL; 
960         case SENS_KEYBOARD:             return TH_PANEL;
961         case SENS_PROPERTY:             return TH_PANEL;
962         case SENS_ACTUATOR:             return TH_PANEL;
963         case SENS_MOUSE:                return TH_PANEL;
964         case SENS_RADAR:                return TH_PANEL;
965         case SENS_RANDOM:               return TH_PANEL;
966         case SENS_RAY:                  return TH_PANEL;
967         case SENS_MESSAGE:              return TH_PANEL;
968         case SENS_JOYSTICK:             return TH_PANEL;
969         default:                                return TH_PANEL;
970         }
971 }
972 static void set_col_sensor(int type, int medium)
973 {
974         int col= get_col_sensor(type);
975         UI_ThemeColorShade(col, medium?30:0);
976 }
977
978
979 static void verify_logicbutton_func(bContext *C, void *data1, void *data2)
980 {
981         bSensor *sens= (bSensor*)data1;
982         
983         if(sens->level && sens->tap) {
984                 if(data2 == &(sens->level))     
985                         sens->tap= 0;
986                 else
987                         sens->level= 0;
988         }
989 }
990
991
992 /**
993  * Draws a toggle for pulse mode, a frequency field and a toggle to invert
994  * the value of this sensor. Operates on the shared data block of sensors.
995  */
996 static void draw_default_sensor_header(bSensor *sens,
997                                                                 uiBlock *block,
998                                                                 short x,
999                                                                 short y,
1000                                                                 short w) 
1001 {
1002         uiBut *but;
1003         
1004         /* Pulsing and frequency */
1005         uiDefIconButBitS(block, TOG, SENS_PULSE_REPEAT, 1, ICON_DOTSUP,
1006                          (short)(x + 10 + 0. * (w-20)), (short)(y - 21), (short)(0.1 * (w-20)), 19,
1007                          &sens->pulse, 0.0, 0.0, 0, 0,
1008                          "Activate TRUE level triggering (pulse mode)");
1009
1010         uiDefIconButBitS(block, TOG, SENS_NEG_PULSE_MODE, 1, ICON_DOTSDOWN,
1011                          (short)(x + 10 + 0.1 * (w-20)), (short)(y - 21), (short)(0.1 * (w-20)), 19,
1012                          &sens->pulse, 0.0, 0.0, 0, 0,
1013                          "Activate FALSE level triggering (pulse mode)");
1014         uiDefButS(block, NUM, 1, "f:",
1015                          (short)(x + 10 + 0.2 * (w-20)), (short)(y - 21), (short)(0.275 * (w-20)), 19,
1016                          &sens->freq, 0.0, 10000.0, 0, 0,
1017                          "Delay between repeated pulses (in logic tics, 0 = no delay)");
1018         
1019         /* value or shift? */
1020         but= uiDefButS(block, TOG, 1, "Level",
1021                          (short)(x + 10 + 0.5 * (w-20)), (short)(y - 21), (short)(0.20 * (w-20)), 19,
1022                          &sens->level, 0.0, 0.0, 0, 0,
1023                          "Level detector, trigger controllers of new states (only applicable upon logic state transition)");
1024         uiButSetFunc(but, verify_logicbutton_func, sens, &(sens->level));
1025         but= uiDefButS(block, TOG, 1, "Tap",
1026                          (short)(x + 10 + 0.702 * (w-20)), (short)(y - 21), (short)(0.12 * (w-20)), 19,
1027                          &sens->tap, 0.0, 0.0, 0, 0,
1028                          "Trigger controllers only for an instant, even while the sensor remains true");
1029         uiButSetFunc(but, verify_logicbutton_func, sens, &(sens->tap));
1030         
1031         uiDefButS(block, TOG, 1, "Inv",
1032                          (short)(x + 10 + 0.85 * (w-20)), (short)(y - 21), (short)(0.15 * (w-20)), 19,
1033                          &sens->invert, 0.0, 0.0, 0, 0,
1034                          "Invert the level (output) of this sensor");
1035 }
1036
1037 static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short yco, short width,char* objectname)
1038 {
1039         bNearSensor      *ns           = NULL;
1040         bTouchSensor     *ts           = NULL;
1041         bKeyboardSensor  *ks           = NULL;
1042         bPropertySensor  *ps           = NULL;
1043         bMouseSensor     *ms           = NULL;
1044         bCollisionSensor *cs           = NULL;
1045         bRadarSensor     *rs           = NULL;
1046         bRandomSensor    *randomSensor = NULL;
1047         bRaySensor       *raySens      = NULL;
1048         bMessageSensor   *mes          = NULL;
1049         bJoystickSensor  *joy              = NULL;
1050         bActuatorSensor  *as           = NULL;
1051         bDelaySensor     *ds               = NULL;
1052         short ysize;
1053         char *str;
1054         
1055         /* yco is at the top of the rect, draw downwards */
1056         
1057         set_col_sensor(sens->type, 0);
1058         
1059         switch (sens->type)
1060         {
1061         case SENS_ALWAYS:
1062                 {
1063                         ysize= 24;
1064                         
1065                         glRects(xco, yco-ysize, xco+width, yco);
1066                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1067                         
1068                         draw_default_sensor_header(sens, block, xco, yco, width);
1069                         
1070                         yco-= ysize;
1071                         
1072                         break;
1073                 }
1074         case SENS_TOUCH:
1075                 {
1076                         ysize= 48; 
1077                         
1078                         glRects(xco, yco-ysize, xco+width, yco); 
1079                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1080                         
1081                         draw_default_sensor_header(sens, block, xco, yco, width);
1082                         
1083                         ts= sens->data; 
1084                         
1085                         /* uiDefBut(block, TEX, 1, "Property:", xco,yco-22,width, 19, &ts->name, 0, 31, 0, 0, "Only look for Objects with this property"); */
1086                         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"); 
1087                         ///* 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"); 
1088                         yco-= ysize; 
1089                         break; 
1090                 }
1091         case SENS_COLLISION:
1092                 {
1093                         ysize= 48;
1094                         
1095                         glRects(xco, yco-ysize, xco+width, yco);
1096                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1097                         
1098                         draw_default_sensor_header(sens, block, xco, yco, width);
1099                         cs= sens->data;
1100                         
1101                         /* The collision sensor will become a generic collision (i.e. it     */
1102                         /* absorb the old touch sensor).                                     */
1103
1104                         uiDefButBitS(block, TOG, SENS_COLLISION_PULSE, B_REDR, "Pulse",(short)(xco + 10),(short)(yco - 44),
1105                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1106                                 "Changes to the set of colliding objects generated pulses");
1107                         
1108                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",(short)(xco + 10 + (0.20 * (width-20))),(short)(yco - 44),
1109                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1110                                 "Toggle collision on material or property");
1111                         
1112                         if (cs->mode & SENS_COLLISION_MATERIAL) {
1113                                 uiDefBut(block, TEX, 1, "Material:", (short)(xco + 10 + 0.40 * (width-20)),
1114                                         (short)(yco-44), (short)(0.6*(width-20)), 19, &cs->materialName, 0, 31, 0, 0,
1115                                         "Only look for Objects with this material");
1116                         } else {
1117                                 uiDefBut(block, TEX, 1, "Property:", (short)(xco + 10 + 0.40 * (width-20)), (short)(yco-44),
1118                                         (short)(0.6*(width-20)), 19, &cs->name, 0, 31, 0, 0,
1119                                         "Only look for Objects with this property");
1120                         }
1121         
1122                         /*              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"); */
1123                         
1124                         yco-= ysize;
1125                         break;
1126                 }
1127         case SENS_NEAR:
1128                 {
1129                         ysize= 72;
1130                         
1131                         glRects(xco, yco-ysize, xco+width, yco);
1132                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1133                         
1134                         draw_default_sensor_header(sens, block, xco, yco, width);
1135                         ns= sens->data;
1136                         
1137                         uiDefBut(block, TEX, 1, "Property:",(short)(10+xco),(short)(yco-44), (short)(width-20), 19,
1138                                 &ns->name, 0, 31, 0, 0, "Only look for Objects with this property");
1139                         uiDefButF(block, NUM, 1, "Dist",(short)(10+xco),(short)(yco-68),(short)((width-22)/2), 19,
1140                                 &ns->dist, 0.0, 1000.0, 1000, 0, "Trigger distance");
1141                         uiDefButF(block, NUM, 1, "Reset",(short)(10+xco+(width-22)/2), (short)(yco-68), (short)((width-22)/2), 19,
1142                                 &ns->resetdist, 0.0, 1000.0, 1000, 0, "Reset distance"); 
1143                         yco-= ysize;
1144                         break;
1145                 }
1146         case SENS_RADAR:
1147                 {
1148                         ysize= 72; 
1149                         
1150                         glRects(xco, yco-ysize, xco+width, yco);
1151                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1152                         
1153                         draw_default_sensor_header(sens, block, xco, yco, width);
1154                         
1155                         rs= sens->data;
1156                         
1157                         uiDefBut(block, TEX, 1, "Prop:",
1158                                          (short)(10+xco),(short)(yco-44), (short)(0.7 * (width-20)), 19,
1159                                          &rs->name, 0, 31, 0, 0,
1160                                          "Only look for Objects with this property");
1161
1162                         str = "Type %t|+X axis %x0|+Y axis %x1|+Z axis %x2|-X axis %x3|-Y axis %x4|-Z axis %x5"; 
1163                         uiDefButS(block, MENU, B_REDR, str,
1164                                 (short)(10+xco+0.7 * (width-20)), (short)(yco-44), (short)(0.3 * (width-22)), 19,
1165                                 &rs->axis, 2.0, 31, 0, 0,
1166                                 "Specify along which axis the radar cone is cast");
1167                                 
1168                         uiDefButF(block, NUM, 1, "Ang:",
1169                                          (short)(10+xco), (short)(yco-68), (short)((width-20)/2), 19,
1170                                          &rs->angle, 0.0, 179.9, 10, 0,
1171                                          "Opening angle of the radar cone");
1172                         uiDefButF(block, NUM, 1, "Dist:",
1173                                          (short)(xco+10 + (width-20)/2), (short)(yco-68), (short)((width-20)/2), 19,
1174                                          &rs->range, 0.01, 10000.0, 100, 0,
1175                                          "Depth of the radar cone");
1176                         yco-= ysize;
1177                         break;
1178                 }
1179         case SENS_KEYBOARD:
1180                 {
1181                         ks= sens->data;
1182                         
1183                         /* 5 lines: 120 height */
1184                         ysize= (ks->type&1) ? 96:120;
1185                         
1186                         glRects(xco, yco-ysize, xco+width, yco);
1187                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1188                         
1189                         /* header line */
1190                         draw_default_sensor_header(sens, block, xco, yco, width);
1191                         
1192                         /* part of line 1 */
1193                         uiDefBut(block, LABEL, 0, "Key",          xco, yco-44, 40, 19, NULL, 0, 0, 0, 0, "");
1194                         uiDefButBitS(block, TOG, 1, B_REDR, "All keys",   xco+40+(width/2), yco-44, (width/2)-50, 19,
1195                                 &ks->type, 0, 0, 0, 0, "");
1196                         
1197                         
1198                         if ((ks->type&1)==0) { /* is All Keys option off? */
1199                                 /* line 2: hotkey and allkeys toggle */
1200                                 uiDefKeyevtButS(block, 0, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
1201                                 
1202                                 /* line 3: two key modifyers (qual1, qual2) */
1203                                 uiDefBut(block, LABEL, 0, "Hold",         xco, yco-68, 40, 19, NULL, 0, 0, 0, 0, "");
1204                                 uiDefKeyevtButS(block, 0, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
1205                                 uiDefKeyevtButS(block, 0, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
1206                         }
1207                         
1208                         /* line 4: toggle property for string logging mode */
1209                         uiDefBut(block, TEX, 1, "LogToggle: ",
1210                                 xco+10, yco-((ks->type&1) ? 68:92), (width-20), 19,
1211                                 ks->toggleName, 0, 31, 0, 0,
1212                                 "Property that indicates whether to log "
1213                                 "keystrokes as a string");
1214                         
1215                         /* line 5: target property for string logging mode */
1216                         uiDefBut(block, TEX, 1, "Target: ",
1217                                 xco+10, yco-((ks->type&1) ? 92:116), (width-20), 19,
1218                                 ks->targetName, 0, 31, 0, 0,
1219                                 "Property that receives the keystrokes in case "
1220                                 "a string is logged");
1221                         
1222                         yco-= ysize;
1223                         break;
1224                 }
1225         case SENS_PROPERTY:
1226                 {
1227                         ysize= 96;
1228                         
1229                         glRects(xco, yco-ysize, xco+width, yco);
1230                         uiEmboss((float)xco, (float)yco-ysize,
1231                                 (float)xco+width, (float)yco, 1);
1232                         
1233                         draw_default_sensor_header(sens, block, xco, yco, width);
1234                         ps= sens->data;
1235                         
1236                         str= "Type %t|Equal %x0|Not Equal %x1|Interval %x2|Changed %x3"; 
1237                         /* str= "Type %t|Equal %x0|Not Equal %x1"; */
1238                         uiDefButI(block, MENU, B_REDR, str,                     xco+30,yco-44,width-60, 19,
1239                                 &ps->type, 0, 31, 0, 0, "Type");
1240                         
1241                         if (ps->type != SENS_PROP_EXPRESSION)
1242                         {
1243                                 uiDefBut(block, TEX, 1, "Prop: ",                       xco+30,yco-68,width-60, 19,
1244                                         ps->name, 0, 31, 0, 0,  "Property name");
1245                         }
1246                         
1247                         if(ps->type == SENS_PROP_INTERVAL)
1248                         {
1249                                 uiDefBut(block, TEX, 1, "Min: ",                xco,yco-92,width/2, 19,
1250                                         ps->value, 0, 31, 0, 0, "check for min value");
1251                                 uiDefBut(block, TEX, 1, "Max: ",                xco+width/2,yco-92,width/2, 19,
1252                                         ps->maxvalue, 0, 31, 0, 0, "check for max value");
1253                         }
1254                         else if(ps->type == SENS_PROP_CHANGED);
1255                         else
1256                         {
1257                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-92,width-60, 19,
1258                                         ps->value, 0, 31, 0, 0, "check for value");
1259                         }
1260                         
1261                         yco-= ysize;
1262                         break;
1263                 }
1264         case SENS_ACTUATOR:
1265                 {
1266                         ysize= 48;
1267                         
1268                         glRects(xco, yco-ysize, xco+width, yco);
1269                         uiEmboss((float)xco, (float)yco-ysize,
1270                                 (float)xco+width, (float)yco, 1);
1271                         
1272                         draw_default_sensor_header(sens, block, xco, yco, width);
1273                         as= sens->data;
1274                         
1275                         uiDefBut(block, TEX, 1, "Act: ",                        xco+30,yco-44,width-60, 19,
1276                                         as->name, 0, 31, 0, 0,  "Actuator name, actuator active state modifications will be detected");
1277                         yco-= ysize;
1278                         break;
1279                 }
1280         case SENS_DELAY:
1281                 {
1282                         ysize= 48;
1283                         
1284                         glRects(xco, yco-ysize, xco+width, yco);
1285                         uiEmboss((float)xco, (float)yco-ysize,
1286                                 (float)xco+width, (float)yco, 1);
1287                         
1288                         draw_default_sensor_header(sens, block, xco, yco, width);
1289                         ds = sens->data;
1290                         
1291                         uiDefButS(block, NUM, 0, "Delay",(short)(10+xco),(short)(yco-44),(short)((width-22)*0.4+10), 19,
1292                                 &ds->delay, 0.0, 5000.0, 0, 0, "Delay in number of logic tics before the positive trigger (default 60 per second)");
1293                         uiDefButS(block, NUM, 0, "Dur",(short)(10+xco+(width-22)*0.4+10),(short)(yco-44),(short)((width-22)*0.4-10), 19,
1294                                 &ds->duration, 0.0, 5000.0, 0, 0, "If >0, delay in number of logic tics before the negative trigger following the positive trigger");
1295                         uiDefButBitS(block, TOG, SENS_DELAY_REPEAT, 0, "REP",(short)(xco + 10 + (width-22)*0.8),(short)(yco - 44),
1296                                 (short)(0.20 * (width-22)), 19, &ds->flag, 0.0, 0.0, 0, 0,
1297                                 "Toggle repeat option. If selected, the sensor restarts after Delay+Dur logic tics");
1298                         yco-= ysize;
1299                         break;
1300                 }
1301         case SENS_MOUSE:
1302                 {
1303                         ms= sens->data;
1304                         /* Two lines: 48 pixels high. */
1305                         ysize = 48;
1306                         
1307                         glRects(xco, yco-ysize, xco+width, yco);
1308                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1309                         
1310                         /* line 1: header */
1311                         draw_default_sensor_header(sens, block, xco, yco, width);
1312                         
1313                         /* Line 2: type selection. The number are a bit mangled to get
1314                         * proper compatibility with older .blend files. */
1315                         str= "Type %t|Left button %x1|Middle button %x2|"
1316                                 "Right button %x4|Wheel Up %x5|Wheel Down %x6|Movement %x8|Mouse over %x16|Mouse over any%x32"; 
1317                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, (width*0.8f)-20, 19,
1318                                 &ms->type, 0, 31, 0, 0,
1319                                 "Specify the type of event this mouse sensor should trigger on");
1320                         
1321                         if(ms->type==32) {
1322                                 uiDefButBitS(block, TOG, SENS_MOUSE_FOCUS_PULSE, B_REDR, "Pulse",(short)(xco + 10) + (width*0.8f)-20,(short)(yco - 44),
1323                                         (short)(0.20 * (width-20)), 19, &ms->flag, 0.0, 0.0, 0, 0,
1324                                         "Moving the mouse over a different object generates a pulse");  
1325                         }
1326                         
1327                         yco-= ysize;
1328                         break;
1329                 }
1330         case SENS_RANDOM:
1331                 {
1332                         ysize = 48;
1333                         
1334                         glRects(xco, yco-ysize, xco+width, yco);
1335                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1336                         
1337                         draw_default_sensor_header(sens, block, xco, yco, width);
1338                         randomSensor = sens->data;
1339                         /* some files were wrongly written, avoid crash now */
1340                         if (randomSensor)
1341                         {
1342                                 uiDefButI(block, NUM, 1, "Seed: ",              xco+10,yco-44,(width-20), 19,
1343                                         &randomSensor->seed, 0, 1000, 0, 0,
1344                                         "Initial seed of the generator. (Choose 0 for not random)");
1345                         }
1346                         yco-= ysize;
1347                         break;
1348                 }
1349         case SENS_RAY:
1350                 {
1351                         ysize = 72;
1352                         glRects(xco, yco-ysize, xco+width, yco);
1353                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1354                         
1355                         draw_default_sensor_header(sens, block, xco, yco, width);
1356                         raySens = sens->data;
1357                         
1358                         /* 1. property or material */
1359                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",
1360                                 xco + 10,yco - 44, 0.20 * (width-20), 19,
1361                                 &raySens->mode, 0.0, 0.0, 0, 0,
1362                                 "Toggle collision on material or property");
1363                         
1364                         if (raySens->mode & SENS_COLLISION_MATERIAL)
1365                         {
1366                                 uiDefBut(block, TEX, 1, "Material:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1367                                         &raySens->matname, 0, 31, 0, 0,
1368                                         "Only look for Objects with this material");
1369                         }
1370                         else
1371                         {
1372                                 uiDefBut(block, TEX, 1, "Property:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1373                                         &raySens->propname, 0, 31, 0, 0,
1374                                         "Only look for Objects with this property");
1375                         }
1376
1377                         /* X-Ray option */
1378                         uiDefButBitS(block, TOG, SENS_RAY_XRAY, 1, "X",
1379                                 xco + 10,yco - 68, 0.10 * (width-20), 19,
1380                                 &raySens->mode, 0.0, 0.0, 0, 0,
1381                                 "Toggle X-Ray option (see through objects that don't have the property)");
1382                         /* 2. sensing range */
1383                         uiDefButF(block, NUM, 1, "Range", xco+10 + 0.10 * (width-20), yco-68, 0.5 * (width-20), 19,
1384                                 &raySens->range, 0.01, 10000.0, 100, 0,
1385                                 "Sense objects no farther than this distance");
1386                         
1387                         /* 3. axis choice */
1388                         str = "Type %t|+ X axis %x1|+ Y axis %x0|+ Z axis %x2|- X axis %x3|- Y axis %x4|- Z axis %x5"; 
1389                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1390                                 &raySens->axisflag, 2.0, 31, 0, 0,
1391                                 "Specify along which axis the ray is cast");
1392                         
1393                         yco-= ysize;            
1394                         break;
1395                 }
1396         case SENS_MESSAGE:
1397                 {
1398                         mes = sens->data;
1399                         ysize = 2 * 24; /* total number of lines * 24 pixels/line */
1400                         
1401                         glRects(xco, yco-ysize, xco+width, yco);
1402                         uiEmboss((float)xco, (float)yco-ysize,
1403                                 (float)xco+width, (float)yco, 1);
1404                         
1405                         /* line 1: header line */
1406                         draw_default_sensor_header(sens, block, xco, yco, width);
1407                         
1408                         /* line 2: Subject filter */
1409                         uiDefBut(block, TEX, 1, "Subject: ",
1410                                 (xco+10), (yco-44), (width-20), 19,
1411                                 mes->subject, 0, 31, 0, 0,
1412                                 "Optional subject filter: only accept messages with this subject"
1413                                 ", or empty for all");
1414                         
1415                         yco -= ysize;
1416                         break;
1417                 }
1418                 case SENS_JOYSTICK:
1419                 {
1420
1421                         ysize =  72;
1422                         
1423                         glRects(xco, yco-ysize, xco+width, yco);
1424                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1425                         
1426                         /* line 1: header */
1427                         draw_default_sensor_header(sens, block, xco, yco, width);
1428
1429                         joy= sens->data;
1430
1431                         uiDefButC(block, NUM, 1, "Index:", xco+10, yco-44, 0.33 * (width-20), 19,
1432                         &joy->joyindex, 0, SENS_JOY_MAXINDEX-1, 100, 0,
1433                         "Specify which joystick to use");                       
1434
1435                         str= "Type %t|Button %x0|Axis %x1|Single Axis %x3|Hat%x2"; 
1436                         uiDefButC(block, MENU, B_REDR, str, xco+87, yco-44, 0.26 * (width-20), 19,
1437                                 &joy->type, 0, 31, 0, 0,
1438                                 "The type of event this joystick sensor is triggered on");
1439                         
1440                         if (joy->type != SENS_JOY_AXIS_SINGLE) {
1441                                 if (joy->flag & SENS_JOY_ANY_EVENT) {
1442                                         switch (joy->type) {
1443                                         case SENS_JOY_AXIS:     
1444                                                 str = "All Axis Events";
1445                                                 break;
1446                                         case SENS_JOY_BUTTON:   
1447                                                 str = "All Button Events";
1448                                                 break;
1449                                         default:
1450                                                 str = "All Hat Events";
1451                                                 break;
1452                                         }
1453                                 } else {
1454                                         str = "All";
1455                                 }
1456                                 
1457                                 uiDefButBitS(block, TOG, SENS_JOY_ANY_EVENT, B_REDR, str,
1458                                         xco+10 + 0.475 * (width-20), yco-68, ((joy->flag & SENS_JOY_ANY_EVENT) ? 0.525 : 0.12) * (width-20), 19,
1459                                         &joy->flag, 0, 0, 0, 0,
1460                                         "Triggered by all events on this joysticks current type (axis/button/hat)");
1461                         }
1462                         if(joy->type == SENS_JOY_BUTTON)
1463                         {
1464                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1465                                         uiDefButI(block, NUM, 1, "Number:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1466                                         &joy->button, 0, 18, 100, 0,
1467                                         "Specify which button to use");
1468                                 }
1469                         }
1470                         else if(joy->type == SENS_JOY_AXIS)
1471                         {
1472                                 uiDefButS(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1473                                 &joy->axis, 1, 8.0, 100, 0,
1474                                 "Specify which axis pair to use, 1 is useually the main direction input");
1475
1476                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1477                                 &joy->precision, 0, 32768.0, 100, 0,
1478                                 "Specify the precision of the axis");
1479
1480                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1481                                         str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis %x0"; 
1482                                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1483                                         &joy->axisf, 2.0, 31, 0, 0,
1484                                         "The direction of the axis, use 'All Events' to recieve events on any direction");
1485                                 }
1486                         }
1487                         else if (joy->type == SENS_JOY_HAT)
1488                         {
1489                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1490                                 &joy->hat, 1, 4.0, 100, 0,
1491                                 "Specify which hat to use");
1492                                 
1493                                 if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
1494                                         str = "Direction%t|Up%x1|Down%x4|Left%x8|Right%x2|%l|Up/Right%x3|Down/Left%x12|Up/Left%x9|Down/Right%x6"; 
1495                                         uiDefButI(block, MENU, 0, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1496                                         &joy->hatf, 2.0, 31, 0, 0,
1497                                         "The direction of the hat, use 'All Events' to recieve events on any direction");
1498                                 }
1499                         }
1500                         else { /* (joy->type == SENS_JOY_AXIS_SINGLE)*/
1501                                 uiDefButS(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
1502                                 &joy->axis_single, 1, 16.0, 100, 0,
1503                                 "Specify a single axis (verticle/horizontal/other) to detect");
1504                                 
1505                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1506                                 &joy->precision, 0, 32768.0, 100, 0,
1507                                 "Specify the precision of the axis");
1508                         }
1509                         yco-= ysize;
1510                         break;
1511                 }
1512         }
1513         
1514         return yco-4;
1515 }
1516
1517
1518
1519 static short draw_controllerbuttons(bController *cont, uiBlock *block, short xco, short yco, short width)
1520 {
1521         bExpressionCont *ec;
1522         bPythonCont *pc;
1523         short ysize;
1524         
1525         switch (cont->type) {
1526         case CONT_EXPRESSION:
1527                 ysize= 28;
1528
1529                 UI_ThemeColor(TH_PANEL);
1530                 glRects(xco, yco-ysize, xco+width, yco);
1531                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1532                 
1533                 /* uiDefBut(block, LABEL, 1, "Not yet...", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, ""); */
1534                 ec= cont->data; 
1535                 /* uiDefBut(block, BUT, 1, "Variables", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, "Available variables for expression"); */
1536                 uiDefBut(block, TEX, 1, "Exp:",         xco + 10 , yco-21, width-20, 19,
1537                                  ec->str, 0, 127, 0, 0,
1538                                  "Expression"); 
1539                 
1540                 yco-= ysize;
1541                 break;
1542         case CONT_PYTHON:
1543                 ysize= 28;
1544                 
1545                 if(cont->data==NULL) init_controller(cont);
1546                 pc= cont->data;
1547                 
1548                 UI_ThemeColor(TH_PANEL);
1549                 glRects(xco, yco-ysize, xco+width, yco);
1550                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1551
1552         
1553                 uiBlockBeginAlign(block);
1554                 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)");
1555                 if(pc->mode==0)
1556                         uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "", xco+70,yco-23,width-74, 19, &pc->text, "Blender textblock to run as a script");
1557                 else {
1558                         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");
1559                         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");
1560                 }
1561                 uiBlockEndAlign(block);
1562                 
1563                 yco-= ysize;
1564                 break;
1565                 
1566         default:
1567                 ysize= 4;
1568
1569                 UI_ThemeColor(TH_PANEL);
1570                 glRects(xco, yco-ysize, xco+width, yco);
1571                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1572                 
1573                 yco-= ysize;
1574         }
1575         
1576         return yco;
1577 }
1578
1579 static int get_col_actuator(int type)
1580 {
1581         switch(type) {
1582         case ACT_ACTION:                return TH_PANEL;
1583         case ACT_SHAPEACTION:   return TH_PANEL;
1584         case ACT_OBJECT:                return TH_PANEL;
1585         case ACT_IPO:                   return TH_PANEL;
1586         case ACT_PROPERTY:              return TH_PANEL;
1587         case ACT_SOUND:                 return TH_PANEL;
1588         case ACT_CAMERA:                return TH_PANEL;
1589         case ACT_EDIT_OBJECT:           return TH_PANEL;
1590         case ACT_GROUP:                 return TH_PANEL;
1591         case ACT_RANDOM:                return TH_PANEL;
1592         case ACT_SCENE:                 return TH_PANEL;
1593         case ACT_MESSAGE:               return TH_PANEL;
1594         case ACT_GAME:                  return TH_PANEL;
1595         case ACT_VISIBILITY:            return TH_PANEL;
1596         case ACT_CONSTRAINT:            return TH_PANEL;
1597         case ACT_STATE:                 return TH_PANEL;
1598         default:                                return TH_PANEL;
1599         }
1600 }
1601 static void set_col_actuator(int item, int medium) 
1602 {
1603         int col= get_col_actuator(item);
1604         UI_ThemeColorShade(col, medium?30:10);
1605         
1606 }
1607
1608 static void change_object_actuator(bContext *C, void *act, void *arg)
1609 {
1610         bObjectActuator *oa = act;
1611
1612         if (oa->type != oa->otype) {
1613                 switch (oa->type) {
1614                 case ACT_OBJECT_NORMAL:
1615                         memset(oa, 0, sizeof(bObjectActuator));
1616                         oa->flag = ACT_FORCE_LOCAL|ACT_TORQUE_LOCAL|ACT_DLOC_LOCAL|ACT_DROT_LOCAL;
1617                         oa->type = ACT_OBJECT_NORMAL;
1618                         break;
1619
1620                 case ACT_OBJECT_SERVO:
1621                         memset(oa, 0, sizeof(bObjectActuator));
1622                         oa->flag = ACT_LIN_VEL_LOCAL;
1623                         oa->type = ACT_OBJECT_SERVO;
1624                         oa->forcerot[0] = 30.0f;
1625                         oa->forcerot[1] = 0.5f;
1626                         oa->forcerot[2] = 0.0f;
1627                         break;
1628                 }
1629         }
1630 }
1631
1632 static void change_ipo_actuator(bContext *C, void *arg1_but, void *arg2_ia)
1633 {
1634         bIpoActuator *ia = arg2_ia;
1635         uiBut *but = arg1_but;
1636
1637         if (but->retval & ACT_IPOFORCE)
1638                 ia->flag &= ~ACT_IPOADD;
1639         else if (but->retval & ACT_IPOADD)
1640                 ia->flag &= ~ACT_IPOFORCE;
1641         but->retval = B_REDR;
1642 }
1643
1644 void update_object_actuator_PID(bContext *C, void *act, void *arg)
1645 {
1646         bObjectActuator *oa = act;
1647         oa->forcerot[0] = 60.0f*oa->forcerot[1];
1648 }
1649
1650 char *get_state_name(Object *ob, short bit)
1651 {
1652         bController *cont;
1653         unsigned int mask;
1654
1655         mask = (1<<bit);
1656         cont = ob->controllers.first;
1657         while (cont) {
1658                 if (cont->state_mask & mask) {
1659                         return cont->name;
1660                 }
1661                 cont = cont->next;
1662         }
1663         return (char*)"";
1664 }
1665
1666 static void check_state_mask(bContext *C, void *arg1_but, void *arg2_mask)
1667 {
1668         int shift= 0; // XXX
1669         unsigned int *cont_mask = arg2_mask;
1670         uiBut *but = arg1_but;
1671
1672         if (*cont_mask == 0 || !(shift))
1673                 *cont_mask = (1<<but->retval);
1674         but->retval = B_REDR;
1675 }
1676
1677 static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, short xco, short yco, short width)
1678 {
1679         bSoundActuator      *sa      = NULL;
1680         bObjectActuator     *oa      = NULL;
1681         bIpoActuator        *ia      = NULL;
1682         bPropertyActuator   *pa      = NULL;
1683         bCameraActuator     *ca      = NULL;
1684         bEditObjectActuator *eoa     = NULL;
1685         bConstraintActuator *coa     = NULL;
1686         bSceneActuator      *sca     = NULL;
1687         bGroupActuator      *ga      = NULL;
1688         bRandomActuator     *randAct = NULL;
1689         bMessageActuator    *ma      = NULL;
1690         bActionActuator     *aa      = NULL;
1691         bGameActuator       *gma     = NULL;
1692         bVisibilityActuator *visAct  = NULL;
1693         bTwoDFilterActuator     *tdfa    = NULL;
1694         bParentActuator     *parAct  = NULL;
1695         bStateActuator          *staAct  = NULL;
1696         
1697         float *fp;
1698         short ysize = 0, wval;
1699         char *str;
1700         int myline, stbit;
1701         uiBut *but;
1702
1703
1704         /* yco is at the top of the rect, draw downwards */
1705         set_col_actuator(act->type, 0);
1706         
1707         switch (act->type)
1708         {
1709         case ACT_OBJECT:
1710                 {
1711                         oa = act->data;
1712                         wval = (width-100)/3;
1713                         if (oa->type == ACT_OBJECT_NORMAL)
1714                         {
1715                                 if ( ob->gameflag & OB_DYNAMIC )
1716                                 {
1717                                         ysize= 175;
1718                                 }
1719                                 else
1720                                 {
1721                                         ysize= 72;
1722                                 }
1723
1724                                 glRects(xco, yco-ysize, xco+width, yco);
1725                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1726                                 
1727                                 uiBlockBeginAlign(block);
1728                                 uiDefBut(block, LABEL, 0, "Loc",        xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "Sets the location");
1729                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-45, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1730                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-45, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1731                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-45, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1732                                 uiBlockEndAlign(block);
1733                                 
1734                                 uiDefBut(block, LABEL, 0, "Rot",        xco, yco-64, 45, 19, NULL, 0, 0, 0, 0, "Sets the rotation");
1735                                 uiBlockBeginAlign(block);
1736                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-64, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1737                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-64, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1738                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-64, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1739                                 uiBlockEndAlign(block);
1740
1741                                 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");
1742                                 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");
1743         
1744                                 if ( ob->gameflag & OB_DYNAMIC )
1745                                 {
1746                                         uiDefBut(block, LABEL, 0, "Force",      xco, yco-87, 55, 19, NULL, 0, 0, 0, 0, "Sets the force");
1747                                         uiBlockBeginAlign(block);
1748                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-87, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, "");
1749                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-87, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, "");
1750                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-87, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, "");
1751                                         uiBlockEndAlign(block);
1752
1753                                         uiDefBut(block, LABEL, 0, "Torque", xco, yco-106, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque");
1754                                         uiBlockBeginAlign(block);
1755                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, "");
1756                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, "");
1757                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, "");                                
1758                                         uiBlockEndAlign(block);
1759                                 }
1760                                 
1761                                 if ( ob->gameflag & OB_DYNAMIC )
1762                                 {
1763                                         uiDefBut(block, LABEL, 0, "LinV",       xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity");
1764                                         uiBlockBeginAlign(block);
1765                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-129, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1766                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-129, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1767                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-129, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1768                                         uiBlockEndAlign(block);
1769                                 
1770                                         uiDefBut(block, LABEL, 0, "AngV",       xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity");
1771                                         uiBlockBeginAlign(block);
1772                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-148, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, "");
1773                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-148, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, "");
1774                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-148, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, "");
1775                                         uiBlockEndAlign(block);
1776                                 
1777                                         uiDefBut(block, LABEL, 0, "Damp",       xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Number of frames to reach the target velocity");
1778                                         uiDefButS(block, NUM, 0, "",            xco+45, yco-171, wval, 19, &oa->damping, 0.0, 1000.0, 100, 0, "");
1779
1780                                         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");
1781                                         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");
1782                                         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");
1783                                         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");
1784                                 
1785                                         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");
1786                                 }                               
1787                         } else if (oa->type == ACT_OBJECT_SERVO)
1788                         {
1789                                 ysize= 195;
1790                                 
1791                                 glRects(xco, yco-ysize, xco+width, yco);
1792                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1793                                 
1794                                 uiDefBut(block, LABEL, 0, "Ref",        xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "");
1795                                 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");
1796                                 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");
1797                                 uiBlockBeginAlign(block);
1798                                 uiDefButF(block, NUM, 0, "",            xco+45, yco-68, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1799                                 uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-68, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1800                                 uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1801                                 uiBlockEndAlign(block);
1802                                 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");
1803
1804                                 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)");
1805                                 uiBlockBeginAlign(block);
1806                                 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");
1807                                 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");
1808                                 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");
1809                                 uiBlockEndAlign(block);
1810                                 uiDefBut(block, LABEL, 0, "Max",        xco, yco-110, 45, 19, NULL, 0, 0, 0, 0, "Set the upper limit for force");
1811                                 uiDefBut(block, LABEL, 0, "Min",        xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Set the lower limit for force");
1812                                 if (oa->flag & ACT_SERVO_LIMIT_X) {
1813                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-110, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1814                                         uiDefButF(block, NUM, 0, "",            xco+45, yco-129, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1815                                 }
1816                                 if (oa->flag & ACT_SERVO_LIMIT_Y) {
1817                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-110, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1818                                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-129, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1819                                 }
1820                                 if (oa->flag & ACT_SERVO_LIMIT_Z) {
1821                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-110, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1822                                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-129, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1823                                 }
1824                                 uiDefBut(block, LABEL, 0, "Servo",      xco, yco-152, 45, 19, NULL, 0, 0, 0, 0, "Coefficients of the PID servo controller");
1825                                 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");
1826                                 uiDefBut(block, LABEL, 0, "Slow",       xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Low value of I coefficient correspond to slow response");
1827                                 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");
1828                                 uiButSetFunc(but, update_object_actuator_PID, oa, NULL);
1829                                 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");
1830                                 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");
1831                         }
1832                         str= "Motion Type %t|Simple motion %x0|Servo Control %x1";
1833                         but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &oa->type, 0.0, 0.0, 0, 0, "");
1834                         oa->otype = oa->type;
1835                         uiButSetFunc(but, change_object_actuator, oa, NULL);
1836                         yco-= ysize;
1837                         break;
1838                 }
1839         case ACT_ACTION:
1840         case ACT_SHAPEACTION:
1841                 {
1842                         /* DrawAct */
1843 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1844                         ysize = 112;
1845 #else
1846                         ysize= 92;
1847 #endif
1848                         
1849                         glRects(xco, yco-ysize, xco+width, yco);
1850                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1851                         
1852                         aa = act->data;
1853                         wval = (width-60)/3;
1854                         
1855                         //              str= "Action types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1856 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1857                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6|Displacement %x7";
1858 #else
1859                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1860 #endif
1861                         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");
1862                         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");
1863                         
1864                         uiDefButBitS(block, TOGN, 1, 0, "Continue", xco+((width/3)*2)+20, yco-24, 60, 19,
1865                                          &aa->end_reset, 0.0, 0.0, 0, 0, "Restore last frame when switching on/off, otherwise play from the start each time");
1866                         
1867                         
1868                         if(aa->type == ACT_ACTION_FROM_PROP)
1869                         {
1870                                 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");
1871                         }
1872                         else
1873                         {
1874                                 uiDefButI(block, NUM, 0, "Sta: ",xco+10, yco-44, (width-20)/2, 19, &aa->sta, 1.0, MAXFRAMEF, 0, 0, "Start frame");
1875                                 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");
1876                         }
1877                                                 
1878                         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");
1879                         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");
1880                         
1881                         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");
1882
1883                         
1884 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1885                         if(aa->type == ACT_ACTION_MOTION)
1886                         {
1887                                 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");
1888                         }
1889 #endif
1890                         
1891                         
1892                         
1893                         yco-=ysize;
1894                         break;
1895                 }
1896         case ACT_IPO:
1897                 {
1898                         ia= act->data;
1899                         
1900                         ysize= 72;
1901                         
1902                         glRects(xco, yco-ysize, xco+width, yco);
1903                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1904                         
1905                         str = "Ipo types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1906                         
1907                         uiDefButS(block, MENU, B_REDR, str,             xco+10, yco-24, (width-20)/2, 19, &ia->type, 0, 0, 0, 0, "");
1908
1909                         but = uiDefButBitS(block, TOG, ACT_IPOFORCE, ACT_IPOFORCE, 
1910                                 "Force", xco+10+(width-20)/2, yco-24, (width-20)/4-10, 19, 
1911                                 &ia->flag, 0, 0, 0, 0, 
1912                                 "Apply Ipo as a global or local force depending on the local option (dynamic objects only)"); 
1913                         uiButSetFunc(but, change_ipo_actuator, but, ia);
1914
1915                         but = uiDefButBitS(block, TOG, ACT_IPOADD, ACT_IPOADD, 
1916                                 "Add", xco+3*(width-20)/4, yco-24, (width-20)/4-10, 19, 
1917                                 &ia->flag, 0, 0, 0, 0, 
1918                                 "Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag"); 
1919                         uiButSetFunc(but, change_ipo_actuator, but, ia);
1920                         
1921                         /* Only show the do-force-local toggle if force is requested */
1922                         if (ia->flag & (ACT_IPOFORCE|ACT_IPOADD)) {
1923                                 uiDefButBitS(block, TOG, ACT_IPOLOCAL, 0, 
1924                                         "L", xco+width-30, yco-24, 20, 19, 
1925                                         &ia->flag, 0, 0, 0, 0, 
1926                                         "Let the ipo acts in local coordinates, used in Force and Add mode"); 
1927                         }
1928
1929                         if(ia->type==ACT_IPO_FROM_PROP) {
1930                                 uiDefBut(block, TEX, 0, 
1931                                         "Prop: ",               xco+10, yco-44, width-80, 19, 
1932                                         ia->name, 0.0, 31.0, 0, 0, 
1933                                         "Use this property to define the Ipo position");
1934                         }
1935                         else {
1936                                 uiDefButI(block, NUM, 0, 
1937                                         "Sta",          xco+10, yco-44, (width-80)/2, 19, 
1938                                         &ia->sta, 1.0, MAXFRAMEF, 0, 0, 
1939                                         "Start frame");
1940                                 uiDefButI(block, NUM, 0, 
1941                                         "End",          xco+10+(width-80)/2, yco-44, (width-80)/2, 19, 
1942                                         &ia->end, 1.0, MAXFRAMEF, 0, 0, 
1943                                         "End frame");
1944                         }
1945                         uiDefButBitS(block, TOG, ACT_IPOCHILD,  B_REDR, 
1946                                 "Child",        xco+10+(width-80), yco-44, 60, 19, 
1947                                 &ia->flag, 0, 0, 0, 0, 
1948                                 "Update IPO on all children Objects as well");
1949                         uiDefBut(block, TEX, 0, 
1950                                 "FrameProp: ",          xco+10, yco-64, width-20, 19, 
1951                                 ia->frameProp, 0.0, 31.0, 0, 0, 
1952                                 "Assign the action's current frame number to this property");
1953
1954                         yco-= ysize;
1955                         break;
1956                 }
1957         case ACT_PROPERTY:
1958                 {
1959                         ysize= 68;
1960                         
1961                         glRects(xco, yco-ysize, xco+width, yco);
1962                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1963                         
1964                         pa= act->data;
1965                         
1966                         str= "Type%t|Assign%x0|Add %x1|Copy %x2|Toggle (bool/int/float/timer)%x3";
1967                         uiDefButI(block, MENU, B_REDR, str,             xco+30,yco-24,width-60, 19, &pa->type, 0, 31, 0, 0, "Type");
1968                         
1969                         uiDefBut(block, TEX, 1, "Prop: ",               xco+30,yco-44,width-60, 19, pa->name, 0, 31, 0, 0, "Property name");
1970                         
1971                         
1972                         if(pa->type==ACT_PROP_TOGGLE) {
1973                                 /* no ui */
1974                                 ysize -= 22;
1975                         }
1976                         else if(pa->type==ACT_PROP_COPY) {
1977                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:", xco+10, yco-64, (width-20)/2, 19, &(pa->ob), "Copy from this Object");
1978                                 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");
1979                         }
1980                         else {
1981                                 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");
1982                         }
1983                         yco-= ysize;
1984                         
1985                         break;
1986                 }
1987     case ACT_SOUND:
1988                 {
1989                         sa = act->data;
1990                         sa->sndnr = 0;
1991                         
1992                         if(sa->flag & ACT_SND_3D_SOUND)
1993                                 ysize = 114;
1994                         else
1995                                 ysize = 92;
1996
1997                         wval = (width-20)/2;
1998                         glRects(xco, yco-ysize, xco+width, yco);
1999                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2000                         
2001                         if(G.main->sound.first) {
2002                                 IDnames_to_pupstring(&str, "Sound files", NULL, &(G.main->sound), (ID *)sa->sound, &(sa->sndnr));
2003                                 /* reset this value, it is for handling the event */
2004                                 sa->sndnr = 0;
2005                                 uiDefButS(block, MENU, B_SOUNDACT_BROWSE, str, xco+10,yco-22,20,19, &(sa->sndnr), 0, 0, 0, 0, "");      
2006
2007                                 if(sa->sound) {
2008                                         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";
2009                                         uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,width-40,19, sa->sound->id.name+2,    0.0, 21.0, 0, 0, "");
2010                                         uiDefButS(block, MENU, 1, dummy_str,xco+10,yco-44,width-20, 19, &sa->type, 0.0, 0.0, 0, 0, "");
2011                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-66,wval, 19, &sa->volume, 0.0,  1.0, 0, 0, "Sets the volume of this sound");
2012                                         uiDefButF(block, NUM, 0, "Pitch:",xco+wval+10,yco-66,wval, 19, &sa->pitch,-12.0, 12.0, 0, 0, "Sets the pitch of this sound");
2013                                         uiDefButS(block, TOG | BIT, 0, "3D Sound", xco+10, yco-88, width-20, 19, &sa->flag, 0.0, 1.0, 0.0, 0.0, "Plays the sound positioned in 3D space.");
2014                                         if(sa->flag & ACT_SND_3D_SOUND)
2015                                         {
2016                                                 uiDefButF(block, NUM, 0, "Rolloff: ", xco+10, yco-110, wval, 19, &sa->sound3D.rolloff_factor, 0.0, 5.0, 0.0, 0.0, "The rolloff factor defines the influence factor on volume depending on distance.");
2017                                                 uiDefButF(block, NUM, 0, "Reference distance: ", xco+wval+10, yco-110, wval, 19, &sa->sound3D.reference_distance, 0.0, 1000.0, 0.0, 0.0, "The reference distance is the distance where the sound has a gain of 1.0.");
2018                                         }
2019                                 }
2020                                 MEM_freeN(str);
2021                         } 
2022                         else {
2023                                 uiDefBut(block, LABEL, 0, "Use Sound window (F10) to load samples", xco, yco-24, width, 19, NULL, 0, 0, 0, 0, "");
2024                         }
2025                                         
2026                         yco-= ysize;
2027                         
2028                         break;
2029                 }
2030         case ACT_CAMERA:
2031
2032                 ysize= 48;
2033         
2034                 glRects(xco, yco-ysize, xco+width, yco);
2035                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2036                 
2037                 ca= act->data;
2038         
2039                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-24, (width-20)/2, 19, &(ca->ob), "Look at this Object");
2040                 uiDefButF(block, NUM, 0, "Height:",     xco+10+(width-20)/2, yco-24, (width-20)/2, 19, &ca->height, 0.0, 20.0, 0, 0, "");
2041                 
2042                 uiDefButF(block, NUM, 0, "Min:",        xco+10, yco-44, (width-60)/2, 19, &ca->min, 0.0, 20.0, 0, 0, "");
2043                 
2044                 if(ca->axis==0) ca->axis= 'x';
2045                 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");
2046                 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");
2047                 
2048                 uiDefButF(block, NUM, 0, "Max:",        xco+20+(width)/2, yco-44, (width-60)/2, 19, &ca->max, 0.0, 20.0, 0, 0, "");
2049
2050                 yco-= ysize;
2051         
2052          break;
2053                                 
2054         case ACT_EDIT_OBJECT:
2055                 
2056                 eoa= act->data;
2057
2058                 if(eoa->type==ACT_EDOB_ADD_OBJECT) {
2059                         int wval; /* just a temp width */
2060                         ysize = 92;
2061                         glRects(xco, yco-ysize, xco+width, yco);
2062                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2063          
2064                         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)");
2065                         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");
2066
2067                         wval= (width-60)/3;
2068                         uiDefBut(block, LABEL, 0, "linV",       xco,           yco-68,   45, 19,
2069                                          NULL, 0, 0, 0, 0,
2070                                          "Velocity upon creation");
2071                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-68, wval, 19,
2072                                          eoa->linVelocity, -100.0, 100.0, 10, 0,
2073                                          "Velocity upon creation, x component");
2074                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-68, wval, 19,
2075                                          eoa->linVelocity+1, -100.0, 100.0, 10, 0,
2076                                          "Velocity upon creation, y component");
2077                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19,
2078                                          eoa->linVelocity+2, -100.0, 100.0, 10, 0,
2079                                          "Velocity upon creation, z component");
2080                         uiDefButBitS(block, TOG, ACT_EDOB_LOCAL_LINV, 0, "L", xco+45+3*wval, yco-68, 15, 19,
2081                                          &eoa->localflag, 0.0, 0.0, 0, 0,
2082                                          "Apply the transformation locally");
2083                         
2084                         
2085                         uiDefBut(block, LABEL, 0, "AngV",       xco,           yco-90,   45, 19,
2086                                          NULL, 0, 0, 0, 0,
2087                                          "Angular velocity upon creation");
2088                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-90, wval, 19,
2089                                          eoa->angVelocity, -10000.0, 10000.0, 10, 0,
2090                                          "Angular velocity upon creation, x component");
2091                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-90, wval, 19,
2092                                          eoa->angVelocity+1, -10000.0, 10000.0, 10, 0,
2093                                          "Angular velocity upon creation, y component");
2094                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-90, wval, 19,
2095                                          eoa->angVelocity+2, -10000.0, 10000.0, 10, 0,
2096                                          "Angular velocity upon creation, z component");
2097                         uiDefButBitS(block, TOG, ACT_EDOB_LOCAL_ANGV, 0, "L", xco+45+3*wval, yco-90, 15, 19,
2098                                          &eoa->localflag, 0.0, 0.0, 0, 0,
2099                                          "Apply the rotation locally");
2100                                          
2101
2102                 }
2103                 else if(eoa->type==ACT_EDOB_END_OBJECT) {
2104                         ysize= 28;
2105                         glRects(xco, yco-ysize, xco+width, yco);
2106                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2107                 }
2108                 else if(eoa->type==ACT_EDOB_REPLACE_MESH) {
2109                         ysize= 48;
2110                         glRects(xco, yco-ysize, xco+width, yco);
2111                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2112          
2113                         uiDefIDPoinBut(block, test_meshpoin_but, ID_ME, 1, "ME:",               xco+40, yco-44, (width-80)/2, 19, &(eoa->me), "replace the existing, when left blank 'Phys' will remake the existing physics mesh");
2114                         
2115                         uiDefButBitS(block, TOGN, ACT_EDOB_REPLACE_MESH_NOGFX, 0, "Gfx",        xco+40 + (width-80)/2, yco-44, (width-80)/4, 19, &eoa->flag, 0, 0, 0, 0, "Replace the display mesh");
2116                         uiDefButBitS(block, TOG, ACT_EDOB_REPLACE_MESH_PHYS, 0, "Phys", xco+40 + (width-80)/2 +(width-80)/4, yco-44, (width-80)/4, 19, &eoa->flag, 0, 0, 0, 0, "Replace the physics mesh (triangle bounds only. compound shapes not supported)");
2117                 }
2118                 else if(eoa->type==ACT_EDOB_TRACK_TO) {
2119                         ysize= 48;
2120                         glRects(xco, yco-ysize, xco+width, yco);
2121                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2122          
2123                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Track to this Object");
2124                         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");
2125                         uiDefButS(block, TOG, 0, "3D",  xco+width-50, yco-44, 40, 19, &eoa->flag, 0.0, 0.0, 0, 0, "Enable 3D tracking");
2126                 }
2127                 else if(eoa->type==ACT_EDOB_DYNAMICS) {
2128                         ysize= 69;
2129                         glRects(xco, yco-ysize, xco+width, yco);
2130                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2131                         
2132                         str= "Dynamic Operation %t|Restore Dynamics %x0|Suspend Dynamics %x1|Enable Rigid Body %x2|Disable Rigid Body %x3|Set Mass %x4";
2133                         uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-44, (width-80), 19,  &(eoa->dyn_operation), 0.0, 0.0, 0, 0, "");
2134                         if(eoa->dyn_operation==4) {
2135                                 uiDefButF(block, NUM, 0, "",            xco+40, yco-63, width-80, 19,
2136                                          &eoa->mass, 0.0, 10000.0, 10, 0,
2137                                          "Mass for object");
2138                         }
2139                 }
2140                 str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3|Dynamics %x4";
2141                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &eoa->type, 0.0, 0.0, 0, 0, "");
2142
2143                 yco-= ysize;
2144         
2145         break;
2146  
2147         case ACT_CONSTRAINT:
2148                 coa= act->data;
2149         
2150                 if (coa->type == ACT_CONST_TYPE_LOC) {
2151                         ysize= 69;
2152         
2153                         glRects(xco, yco-ysize, xco+width, yco);
2154                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2155                         
2156         /*              str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4|Rot X %x8|Rot Y %x16|Rot Z %x32"; */
2157         /*                      coa->flag &= ~(63); */
2158                         str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4";
2159                         coa->flag &= 7;
2160                         coa->time = 0;
2161                         uiDefButS(block, MENU, 1, str,          xco+10, yco-65, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, "");
2162                 
2163                         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");
2164                         uiDefBut(block, LABEL,                  0, "Min",       xco+80, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2165                         uiDefBut(block, LABEL,                  0, "Max",       xco+80+(width-90)/2, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
2166
2167                         if(coa->flag & ACT_CONST_LOCX) fp= coa->minloc;
2168                         else if(coa->flag & ACT_CONST_LOCY) fp= coa->minloc+1;
2169                         else if(coa->flag & ACT_CONST_LOCZ) fp= coa->minloc+2;
2170                         else if(coa->flag & ACT_CONST_ROTX) fp= coa->minrot;
2171                         else if(coa->flag & ACT_CONST_ROTY) fp= coa->minrot+1;
2172                         else fp= coa->minrot+2;
2173                         
2174                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-90)/2, 19, fp, -2000.0, 2000.0, 10, 0, "");
2175                         uiDefButF(block, NUM, 0, "",            xco+80+(width-90)/2, yco-65, (width-90)/2, 19, fp+3, -2000.0, 2000.0, 10, 0, "");
2176                 } else if (coa->type == ACT_CONST_TYPE_DIST) {
2177                         ysize= 106;
2178
2179                         glRects(xco, yco-ysize, xco+width, yco);
2180                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2181                         
2182                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32";
2183                         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");
2184                 
2185                         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");
2186                         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");
2187                         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");
2188                         uiDefButBitS(block, TOG, ACT_CONST_LOCAL, 0, "L", xco+80+(width-115), yco-45, 25, 19,
2189                                          &coa->flag, 0.0, 0.0, 0, 0, "Set ray along object's axis or global axis");
2190
2191                         if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc;
2192                         else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1;
2193                         else fp= coa->minloc+2;
2194
2195                         uiDefButF(block, NUM, 0, "",            xco+80, yco-65, (width-115)/2, 19, fp+3, 0.0, 2000.0, 10, 0, "Maximum length of ray");
2196                         if (coa->flag & ACT_CONST_DISTANCE)
2197                                 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");
2198                         uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
2199                                          &coa->flag, 0.0, 0.0, 0, 0, "Set object axis along (local axis) or parallel (global axis) to the normal at hit position");
2200                         uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
2201                                          &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
2202                         if (coa->flag & ACT_CONST_MATERIAL)
2203                         {
2204                                 uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
2205                                         coa->matprop, 0, 31, 0, 0,
2206                                         "Ray detects only Objects with this material");
2207                         }
2208                         else
2209                         {
2210                                 uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
2211                                         coa->matprop, 0, 31, 0, 0,
2212                                         "Ray detect only Objects with this property");
2213                         }
2214                         uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
2215                                 &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
2216                         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");
2217                         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");
2218                 } else if (coa->type == ACT_CONST_TYPE_ORI) {
2219                         ysize= 87;
2220
2221                         glRects(xco, yco-ysize, xco+width, yco);
2222                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2223                         
2224                         str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4";
2225                         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");
2226                 
2227                         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");
2228                         uiDefBut(block, LABEL,                  0, "X", xco+80, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2229                         uiDefBut(block, LABEL,                  0, "Y", xco+80+(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2230                         uiDefBut(block, LABEL,                  0, "Z", xco+80+2*(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, "");
2231
2232                         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");
2233                         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");
2234                         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");
2235
2236                         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");
2237                         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");
2238                         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");
2239                 } else if (coa->type == ACT_CONST_TYPE_FH) {
2240                         ysize= 106;
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|-X axis %x8|-Y axis %x16|-Z axis %x32";
2246                         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)");
2247
2248                         if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc;
2249                         else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1;
2250                         else fp= coa->minloc+2;
2251
2252                         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");
2253                         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");
2254                         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");
2255
2256                         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");
2257                         uiDefButBitS(block, TOG, ACT_CONST_NORMAL, 0, "N", xco+80+(width-115), yco-65, 25, 19,
2258                                          &coa->flag, 0.0, 0.0, 0, 0, "Add a horizontal spring force on slopes");
2259                         uiDefButBitS(block, TOG, ACT_CONST_MATERIAL, B_REDR, "M/P", xco+10, yco-84, 40, 19,
2260                                          &coa->flag, 0.0, 0.0, 0, 0, "Detect material instead of property");
2261                         if (coa->flag & ACT_CONST_MATERIAL)
2262                         {
2263                                 uiDefBut(block, TEX, 1, "Material:", xco + 50, yco-84, (width-60), 19,
2264                                         coa->matprop, 0, 31, 0, 0,
2265                                         "Ray detects only Objects with this material");
2266                         }
2267                         else
2268                         {
2269                                 uiDefBut(block, TEX, 1, "Property:", xco + 50, yco-84, (width-60), 19,
2270                                         coa->matprop, 0, 31, 0, 0,
2271                                         "Ray detect only Objects with this property");
2272                         }
2273                         uiDefButBitS(block, TOG, ACT_CONST_PERMANENT, 0, "PER", xco+10, yco-103, 40, 19,
2274                                 &coa->flag, 0.0, 0.0, 0, 0, "Persistent actuator: stays active even if ray does not reach target");
2275                         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");
2276                         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");
2277                 }
2278                 str= "Constraint Type %t|Location %x0|Distance %x1|Orientation %x2|Force field %x3";
2279                 but = uiDefButS(block, MENU, B_REDR, str,               xco+40, yco-23, (width-80), 19, &coa->type, 0.0, 0.0, 0, 0, "");
2280                 yco-= ysize;
2281         break;
2282  
2283         case ACT_SCENE:
2284                 sca= act->data; 
2285                 
2286                 if(sca->type==ACT_SCENE_RESTART) { 
2287                         ysize= 28; 
2288                         glRects(xco, yco-ysize, xco+width, yco); 
2289                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2290                 } 
2291                 else if(sca->type==ACT_SCENE_CAMERA) { 
2292                         
2293                         ysize= 48; 
2294                         glRects(xco, yco-ysize, xco+width, yco); 
2295                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2296          
2297                         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"); 
2298                 } 
2299                 else if(sca->type==ACT_SCENE_SET) { 
2300                         
2301                         ysize= 48; 
2302                         glRects(xco, yco-ysize, xco+width, yco); 
2303                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2304         
2305                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Set this Scene"); 
2306                 } 
2307                 else if(sca->type==ACT_SCENE_ADD_FRONT) { 
2308                         
2309                         ysize= 48; 
2310                         glRects(xco, yco-ysize, xco+width, yco); 
2311                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2312         
2313                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add an Overlay Scene"); 
2314                 } 
2315                 else if(sca->type==ACT_SCENE_ADD_BACK) { 
2316                         
2317                         ysize= 48; 
2318                         glRects(xco, yco-ysize, xco+width, yco); 
2319                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2320         
2321                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add a Background Scene"); 
2322                 } 
2323                 else if(sca->type==ACT_SCENE_REMOVE) { 
2324                         
2325                         ysize= 48; 
2326                         glRects(xco, yco-ysize, xco+width, yco); 
2327                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2328         
2329                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Remove a Scene");
2330                 } 
2331                 else if(sca->type==ACT_SCENE_SUSPEND) { 
2332                         
2333                         ysize= 48; 
2334                         glRects(xco, yco-ysize, xco+width, yco); 
2335                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2336         
2337                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Pause a Scene");
2338                 } 
2339                 else if(sca->type==ACT_SCENE_RESUME) { 
2340                         
2341                         ysize= 48; 
2342                         glRects(xco, yco-ysize, xco+width, yco); 
2343                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2344         
2345                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Unpause a Scene");
2346                 } 
2347
2348                 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";
2349                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &sca->type, 0.0, 0.0, 0, 0, ""); 
2350
2351                 yco-= ysize; 
2352                 break; 
2353         case ACT_GAME:
2354                 {
2355                         gma = act->data; 
2356                         if (gma->type == ACT_GAME_LOAD)
2357                         {
2358                                 //ysize = 68;
2359                                 ysize = 48;
2360                                 glRects(xco, yco-ysize, xco+width, yco); 
2361                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2362                                 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");
2363 //                              uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2364                         }
2365 /*                      else if (gma->type == ACT_GAME_START)
2366                         {
2367                                 ysize = 68; 
2368                                 glRects(xco, yco-ysize, xco+width, yco); 
2369                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2370
2371                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
2372                                 uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
2373                         }
2374 */                      else if (ELEM4(gma->type, ACT_GAME_RESTART, ACT_GAME_QUIT, ACT_GAME_SAVECFG, ACT_GAME_LOADCFG))
2375                         {
2376                                 ysize = 28; 
2377                                 glRects(xco, yco-ysize, xco+width, yco); 
2378                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
2379                         }
2380
2381                         //str = "Scene %t|Load game%x0|Start loaded game%x1|Restart this game%x2|Quit this game %x3";
2382                         str = "Scene %t|Start new game%x0|Restart this game%x2|Quit this game %x3|Save GameLogic.globalDict %x4|Load GameLogic.globalDict %x5";
2383                         uiDefButS(block, MENU, B_REDR, str, xco+40, yco-24, (width-80), 19, &gma->type, 0.0, 0.0, 0, 0, ""); 
2384                         
2385                         yco -= ysize; 
2386                         break; 
2387                 }
2388         case ACT_GROUP:
2389                 ga= act->data;
2390
2391                 ysize= 52;
2392
2393                 glRects(xco, yco-ysize, xco+width, yco);
2394                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2395                 
2396                 str= "GroupKey types   %t|Set Key %x6|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x5";
2397
2398                 uiDefButS(block, MENU, 1, str,                  xco+20, yco-24, width-40, 19, &ga->type, 0, 0, 0, 0, "");
2399                 if(ga->type==ACT_GROUP_SET) {
2400                         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");
2401                         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");
2402                 }
2403                 else if(ga->type==ACT_GROUP_FROM_PROP) {
2404                         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");
2405                 }
2406                 else {
2407                         uiDefButI(block, NUM, 0, "State",               xco+20, yco-44, (width-40)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Start frame");
2408                         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");
2409                 }
2410                 yco-= ysize;
2411                 break;
2412
2413         case ACT_VISIBILITY:
2414                 ysize = 24;
2415
2416                 glRects(xco, yco-ysize, xco+width, yco);
2417                 uiEmboss((float)xco,
2418                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
2419                 
2420                 visAct = act->data;
2421
2422                 uiBlockBeginAlign(block);
2423                 uiDefButBitI(block, TOGN, ACT_VISIBILITY_INVISIBLE, B_REDR,
2424                           "Visible",
2425                           xco + 10, yco - 20, (width - 20)/3, 19, &visAct->flag,
2426                           0.0, 0.0, 0, 0,
2427                           "Set the objects visible. Initialized from the objects render restriction toggle (access in the outliner)");
2428                 uiDefButBitI(block, TOG, ACT_VISIBILITY_OCCLUSION, B_REDR,
2429                           "Occlusion",
2430                           xco + 10 + ((width - 20)/3), yco - 20, (width - 20)/3, 19, &visAct->flag,
2431                           0.0, 0.0, 0, 0,
2432                           "Set the object to occlude objects behind it. Initialized from the object type in physics button");
2433                 uiBlockEndAlign(block);
2434                 
2435                 uiDefButBitI(block, TOG, ACT_VISIBILITY_RECURSIVE, 0,
2436                           "Children",
2437                           xco + 10 + (((width - 20)/3)*2)+10, yco - 20, ((width - 20)/3)-10, 19, &visAct->flag,
2438                           0.0, 0.0, 0, 0,
2439                           "Sets all the children of this object to the same visibility/occlusion recursively");
2440
2441                 yco-= ysize;
2442
2443                 break;
2444                 
2445         case ACT_STATE:
2446                 ysize = 34;
2447
2448                 glRects(xco, yco-ysize, xco+width, yco);
2449                 uiEmboss((float)xco,
2450                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
2451                 
2452                 staAct = act->data;
2453
2454                 str= "Operation %t|Cpy %x0|Add %x1|Sub %x2|Inv %x3";
2455
2456                 uiDefButI(block, MENU, B_REDR, str,
2457                           xco + 10, yco - 24, 65, 19, &staAct->type,
2458                           0.0, 0.0, 0, 0,
2459                           "Select the bit operation on object state mask");
2460
2461                 for (wval=0; wval<15; wval+=5) {
2462                         uiBlockBeginAlign(block);
2463                         for (stbit=0; stbit<5; stbit++) {
2464                                 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)));
2465                                 uiButSetFunc(but, check_state_mask, but, &(staAct->mask));
2466                         }
2467                         for (stbit=0; stbit<5; stbit++) {
2468                                 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)));
2469                                 uiButSetFunc(but, check_state_mask, but, &(staAct->mask));
2470                         }
2471                 }
2472                 uiBlockEndAlign(block);
2473
2474                 yco-= ysize;
2475
2476                 break;
2477
2478         case ACT_RANDOM:
2479                 ysize  = 69;
2480
2481                 glRects(xco, yco-ysize, xco+width, yco);
2482                 uiEmboss((float)xco,
2483                                   (float)yco-ysize, (float)xco+width, (float)yco, 1);
2484                 
2485                 randAct = act->data;
2486
2487                 /* 1. seed */
2488                 uiDefButI(block, NUM, 1, "Seed: ",              (xco+10),yco-24, 0.4 *(width-20), 19,
2489                                  &randAct->seed, 0, 1000, 0, 0,
2490                                  "Initial seed of the random generator. Use Python for more freedom. "
2491                                  " (Choose 0 for not random)");
2492
2493                 /* 2. distribution type */
2494                 /* One pick per distribution. These numbers MUST match the #defines  */
2495                 /* in game.h !!!                                                     */
2496                 str= "Distribution %t|Bool Constant %x0|Bool Uniform %x1"
2497                         "|Bool Bernoulli %x2|Int Constant %x3|Int Uniform %x4"
2498                         "|Int Poisson %x5|Float Constant %x6|Float Uniform %x7"
2499                         "|Float Normal %x8|Float Neg. Exp. %x9";
2500                 uiDefButI(block, MENU, B_REDR, str, (xco+10) + 0.4 * (width-20), yco-24, 0.6 * (width-20), 19,
2501                                  &randAct->distribution, 0.0, 0.0, 0, 0,
2502                                  "Choose the type of distribution");
2503
2504                 /* 3. property */
2505                 uiDefBut(block, TEX, 1, "Property:", (xco+10), yco-44, (width-20), 19,
2506                                  &randAct->propname, 0, 31, 0, 0,
2507                                  "Assign the random value to this property"); 
2508
2509                 /*4. and 5. arguments for the distribution*/
2510                 switch (randAct->distribution) {
2511                 case ACT_RANDOM_BOOL_CONST:
2512                         uiDefButBitI(block, TOG, 1, 1, "Always true", (xco+10), yco-64, (width-20), 19,
2513                                          &randAct->int_arg_1, 2.0, 1, 0, 0,
2514                                          "Always false or always true");                        
2515                         break;
2516                 case ACT_RANDOM_BOOL_UNIFORM:
2517                         uiDefBut(block, LABEL, 0, "     Do a 50-50 pick",       (xco+10), yco-64, (width-20), 19,
2518                                          NULL, 0, 0, 0, 0,
2519                                          "Choose between true and false, 50% chance each");
2520                         break;
2521                 case ACT_RANDOM_BOOL_BERNOUILLI:
2522                         uiDefButF(block, NUM, 1, "Chance", (xco+10), yco-64, (width-20), 19,
2523                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2524                                          "Pick a number between 0 and 1. Success if you stay "
2525                                          "below this value");                   
2526                         break;
2527                 case ACT_RANDOM_INT_CONST:
2528                         uiDefButI(block, NUM, 1, "Value: ",             (xco+10), yco-64, (width-20), 19,
2529                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2530                                          "Always return this number");
2531                         break;
2532                 case ACT_RANDOM_INT_UNIFORM:
2533                         uiDefButI(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2534                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2535                                          "Choose a number from a range. "
2536                                          "Lower boundary of the range");
2537                         uiDefButI(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2538                                          &randAct->int_arg_2, -1000, 1000, 0, 0,
2539                                          "Choose a number from a range. "
2540                                          "Upper boundary of the range");
2541                         break;
2542                 case ACT_RANDOM_INT_POISSON:
2543                         uiDefButF(block, NUM, 1, "Mean: ", (xco+10), yco-64, (width-20), 19,
2544                                          &randAct->float_arg_1, 0.01, 100.0, 0, 0,
2545                                          "Expected mean value of the distribution");                                            
2546                         break;
2547                 case ACT_RANDOM_FLOAT_CONST:
2548                         uiDefButF(block, NUM, 1, "Value: ", (xco+10), yco-64, (width-20), 19,
2549                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2550                                          "Always return this number");
2551                         break;
2552                 case ACT_RANDOM_FLOAT_UNIFORM:
2553                         uiDefButF(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2554                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2555                                          "Choose a number from a range"
2556                                          "Lower boundary of the range");
2557                         uiDefButF(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2558                                          &randAct->float_arg_2, -10000.0, 10000.0, 0, 0,
2559                                          "Choose a number from a range"
2560                                      &nb