77922f041d8d40d817ce172988041d9d4046907c
[blender.git] / source / blender / src / buttons_logic.c
1 /**
2  * $Id$ 
3  *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <stdlib.h>
34 #include <math.h>
35 #include <string.h>
36
37 #ifndef WIN32
38 #include <unistd.h>
39 #else
40 #include <io.h>
41 #endif   
42
43 #include "MEM_guardedalloc.h"
44
45 #include "BLI_blenlib.h"
46 #include "BLI_arithb.h"
47
48 #include "DNA_action_types.h"
49 #include "DNA_material_types.h"
50 #include "DNA_sensor_types.h"
51 #include "DNA_actuator_types.h"
52 #include "DNA_controller_types.h"
53 #include "DNA_property_types.h"
54 #include "DNA_object_types.h"
55 #include "DNA_screen_types.h"
56 #include "DNA_space_types.h"
57 #include "DNA_scene_types.h"
58 #include "DNA_sound_types.h"
59 #include "DNA_text_types.h"
60 #include "DNA_userdef_types.h"
61 #include "DNA_view3d_types.h"
62 #include "DNA_mesh_types.h"
63 #include "DNA_world_types.h"
64
65 #include "BKE_library.h"
66 #include "BKE_global.h"
67 #include "BKE_main.h"
68 #include "BKE_sca.h"
69 #include "BKE_property.h"
70
71 #include "BIF_gl.h"
72 #include "BIF_resources.h"
73 #include "BIF_space.h"
74 #include "BIF_interface.h"
75 #include "BIF_butspace.h"
76 #include "BIF_screen.h"
77 #include "BIF_keyval.h"
78 #include "BIF_editsound.h"
79
80 #include "BIF_editsca.h"
81
82
83 #include "BDR_editcurve.h"
84 #include "BDR_editobject.h"
85 #include "BSE_headerbuttons.h"
86 #include "BSE_filesel.h"
87
88 #include "blendef.h"
89 #include "mydevice.h"
90 #include "nla.h"        /* For __NLA : Important, do not remove */
91 #include "butspace.h" // own module
92
93 /* internals */
94 void buttons_enji(uiBlock *, Object *);
95 void buttons_ketsji(uiBlock *, Object *);
96 void buttons_bullet(uiBlock *, Object *);
97
98 /****/
99
100 static ID **get_selected_and_linked_obs(short *count, short scavisflag);
101 static char *actuator_pup(Object *owner);
102
103 /****/
104
105
106 static void del_property(void *selpropv, void *data2_unused)
107 {
108         bProperty *prop, *selprop= selpropv;
109         Object *ob;
110         int a=0;
111                 
112         ob= OBACT;
113         if(ob==NULL) return;
114
115         prop= ob->prop.first;
116         while(prop) {
117                 if(prop==selprop) {
118                         if (strcmp(prop->name,"Text") == 0) {
119                                 allqueue(REDRAWVIEW3D, 0);
120                         }
121                         BLI_remlink(&ob->prop, prop);
122                         free_property(prop);
123                         break;
124                 }
125                 a++;
126                 prop= prop->next;
127         }
128         BIF_undo_push("Delete property");
129         allqueue(REDRAWBUTSLOGIC, 0);
130         
131 }
132
133 static int vergname(const void *v1, const void *v2)
134 {
135         char **x1, **x2;
136         
137         x1= (char **)v1;
138         x2= (char **)v2;
139         
140         return strcmp(*x1, *x2);
141 }
142
143 void make_unique_prop_names(char *str)
144 {
145         Object *ob;
146         bProperty *prop;
147         bSensor *sens;
148         bController *cont;
149         bActuator *act;
150         ID **idar;
151         short a, obcount, propcount=0, nr;
152         char **names;
153         
154         /* this function is called by a Button, and gives the current
155          * stringpointer as an argument, this is the one that can change
156          */
157
158         idar= get_selected_and_linked_obs(&obcount, BUTS_SENS_SEL|BUTS_SENS_ACT|BUTS_ACT_SEL|BUTS_ACT_ACT|BUTS_CONT_SEL|BUTS_CONT_ACT);
159         
160         /* for each object, make properties and sca names unique */
161         
162         /* count total names */
163         for(a=0; a<obcount; a++) {
164                 ob= (Object *)idar[a];
165                 propcount+= BLI_countlist(&ob->prop);
166                 propcount+= BLI_countlist(&ob->sensors);
167                 propcount+= BLI_countlist(&ob->controllers);
168                 propcount+= BLI_countlist(&ob->actuators);
169         }       
170         if(propcount==0) {
171                 if(idar) MEM_freeN(idar);
172                 return;
173         }
174         
175         /* make names array for sorting */
176         names= MEM_callocN(propcount*sizeof(void *), "names");
177
178         /* count total names */
179         nr= 0;
180         for(a=0; a<obcount; a++) {
181                 ob= (Object *)idar[a];
182                 prop= ob->prop.first;
183                 while(prop) {
184                         names[nr++]= prop->name;
185                         prop= prop->next;
186                 }
187                 sens= ob->sensors.first;
188                 while(sens) {
189                         names[nr++]= sens->name;
190                         sens= sens->next;
191                 }
192                 cont= ob->controllers.first;
193                 while(cont) {
194                         names[nr++]= cont->name;
195                         cont= cont->next;
196                 }
197                 act= ob->actuators.first;
198                 while(act) {
199                         names[nr++]= act->name;
200                         act= act->next;
201                 }
202         }
203
204         qsort(names, propcount, sizeof(void *), vergname);
205         
206         /* now we check for double names, and change them */
207         
208         for(nr=0; nr<propcount; nr++) {
209                 if(names[nr]!=str && strcmp( names[nr], str )==0 ) {
210                         BLI_newname(str, +1);
211                 }
212         }
213         
214         MEM_freeN(idar);
215         MEM_freeN(names);
216 }
217
218 static void make_unique_prop_names_cb(void *strv, void *redraw_view3d_flagv)
219 {
220         char *str= strv;
221         int redraw_view3d_flag= (int) redraw_view3d_flagv;
222
223         make_unique_prop_names(str);
224         if (redraw_view3d_flag) allqueue(REDRAWVIEW3D, 0);
225 }
226
227 static void sca_move_sensor(void *datav, void *data2_unused)
228 {
229         bSensor *sens_to_delete= datav;
230         int val;
231         Base *base;
232         bSensor *sens;
233         
234         val= pupmenu("Move up%x1|Move down %x2");
235         
236         if(val>0) {
237                 /* now find out which object has this ... */
238                 base= FIRSTBASE;
239                 while(base) {
240                 
241                         sens= base->object->sensors.first;
242                         while(sens) {
243                                 if(sens == sens_to_delete) break;
244                                 sens= sens->next;
245                         }
246                         
247                         if(sens) {
248                                 if( val==1 && sens->prev) {
249                                         BLI_remlink(&base->object->sensors, sens);
250                                         BLI_insertlinkbefore(&base->object->sensors, sens->prev, sens);
251                                 }
252                                 else if( val==2 && sens->next) {
253                                         BLI_remlink(&base->object->sensors, sens);
254                                         BLI_insertlink(&base->object->sensors, sens->next, sens);
255                                 }
256                                 BIF_undo_push("Move sensor");
257                                 allqueue(REDRAWBUTSLOGIC, 0);
258                                 break;
259                         }
260                         
261                         base= base->next;
262                 }
263         }
264 }
265
266 static void sca_move_controller(void *datav, void *data2_unused)
267 {
268         bController *controller_to_del= datav;
269         int val;
270         Base *base;
271         bController *cont;
272         
273         val= pupmenu("Move up%x1|Move down %x2");
274         
275         if(val>0) {
276                 /* now find out which object has this ... */
277                 base= FIRSTBASE;
278                 while(base) {
279                 
280                         cont= base->object->controllers.first;
281                         while(cont) {
282                                 if(cont == controller_to_del) break;
283                                 cont= cont->next;
284                         }
285                         
286                         if(cont) {
287                                 if( val==1 && cont->prev) {
288                                         BLI_remlink(&base->object->controllers, cont);
289                                         BLI_insertlinkbefore(&base->object->controllers, cont->prev, cont);
290                                 }
291                                 else if( val==2 && cont->next) {
292                                         BLI_remlink(&base->object->controllers, cont);
293                                         BLI_insertlink(&base->object->controllers, cont->next, cont);
294                                 }
295                                 BIF_undo_push("Move controller");
296                                 allqueue(REDRAWBUTSLOGIC, 0);
297                                 break;
298                         }
299                         
300                         base= base->next;
301                 }
302         }
303 }
304
305 static void sca_move_actuator(void *datav, void *data2_unused)
306 {
307         bActuator *actuator_to_move= datav;
308         int val;
309         Base *base;
310         bActuator *act;
311         
312         val= pupmenu("Move up%x1|Move down %x2");
313         
314         if(val>0) {
315                 /* now find out which object has this ... */
316                 base= FIRSTBASE;
317                 while(base) {
318                 
319                         act= base->object->actuators.first;
320                         while(act) {
321                                 if(act == actuator_to_move) break;
322                                 act= act->next;
323                         }
324                         
325                         if(act) {
326                                 if( val==1 && act->prev) {
327                                         BLI_remlink(&base->object->actuators, act);
328                                         BLI_insertlinkbefore(&base->object->actuators, act->prev, act);
329                                 }
330                                 else if( val==2 && act->next) {
331                                         BLI_remlink(&base->object->actuators, act);
332                                         BLI_insertlink(&base->object->actuators, act->next, act);
333                                 }
334                                 BIF_undo_push("Move actuator");
335                                 allqueue(REDRAWBUTSLOGIC, 0);
336                                 break;
337                         }
338                         
339                         base= base->next;
340                 }
341         }
342 }
343
344 void do_logic_buts(unsigned short event)
345 {
346         bProperty *prop;
347         bSensor *sens;
348         bController *cont;
349         bActuator *act;
350         Base *base;
351         Object *ob;
352         int didit;
353         
354         ob= OBACT;
355         if(ob==0) return;
356         
357         switch(event) {
358
359         case B_SETSECTOR:
360                 /* check for inconsistant types */
361                 ob->gameflag &= ~(OB_PROP|OB_MAINACTOR|OB_DYNAMIC|OB_ACTOR);
362                 ob->dtx |= OB_BOUNDBOX;
363                 allqueue(REDRAWBUTSGAME, 0);
364                 allqueue(REDRAWVIEW3D, 0);
365                 break;
366                 
367         case B_SETPROP:
368                 /* check for inconsistant types */
369                 ob->gameflag &= ~(OB_SECTOR|OB_MAINACTOR|OB_DYNAMIC|OB_ACTOR);
370                 allqueue(REDRAWBUTSGAME, 0);
371                 allqueue(REDRAWVIEW3D, 0);
372                 break;
373
374         case B_SETACTOR:
375         case B_SETDYNA:
376         case B_SETMAINACTOR:
377                 ob->gameflag &= ~(OB_SECTOR|OB_PROP);
378                 allqueue(REDRAWBUTSGAME, 0);
379                 allqueue(REDRAWVIEW3D, 0);
380                 break;
381
382
383         case B_ADD_PROP:
384                 prop= new_property(PROP_FLOAT);
385                 make_unique_prop_names(prop->name);
386                 BLI_addtail(&ob->prop, prop);
387                 BIF_undo_push("Add property");
388                 allqueue(REDRAWBUTSLOGIC, 0);
389                 break;
390         
391         case B_CHANGE_PROP:
392                 prop= ob->prop.first;
393                 while(prop) {
394                         if(prop->type!=prop->otype) {
395                                 init_property(prop);
396                                 if (strcmp(prop->name, "Text") == 0) {
397                                         allqueue(REDRAWVIEW3D, 0);
398                                 }
399                         }
400                         prop= prop->next;
401                 }
402                 allqueue(REDRAWBUTSLOGIC, 0);
403                 break;
404         
405         case B_ADD_SENS:
406                 base= FIRSTBASE;
407                 while(base) {
408                         if(base->object->scaflag & OB_ADDSENS) {
409                                 base->object->scaflag &= ~OB_ADDSENS;
410                                 sens= new_sensor(SENS_ALWAYS);
411                                 BLI_addtail(&(base->object->sensors), sens);
412                                 make_unique_prop_names(sens->name);
413                                 base->object->scaflag |= OB_SHOWSENS;
414                         }
415                         base= base->next;
416                 }
417                 
418                 BIF_undo_push("Add sensor");
419                 allqueue(REDRAWBUTSLOGIC, 0);
420                 break;
421
422         case B_CHANGE_SENS:
423                 base= FIRSTBASE;
424                 while(base) {
425                         sens= base->object->sensors.first;
426                         while(sens) {
427                                 if(sens->type != sens->otype) {
428                                         init_sensor(sens);
429                                         sens->otype= sens->type;
430                                         break;
431                                 }
432                                 sens= sens->next;
433                         }
434                         base= base->next;
435                 }
436                 allqueue(REDRAWBUTSLOGIC, 0);
437                 break;
438         
439         case B_DEL_SENS:
440                 base= FIRSTBASE;
441                 while(base) {
442                         sens= base->object->sensors.first;
443                         while(sens) {
444                                 if(sens->flag & SENS_DEL) {
445                                         BLI_remlink(&(base->object->sensors), sens);
446                                         free_sensor(sens);
447                                         break;
448                                 }
449                                 sens= sens->next;
450                         }
451                         base= base->next;
452                 }
453                 BIF_undo_push("Delete sensor");
454                 allqueue(REDRAWBUTSLOGIC, 0);
455                 break;
456         
457         case B_ADD_CONT:
458                 base= FIRSTBASE;
459                 while(base) {
460                         if(base->object->scaflag & OB_ADDCONT) {
461                                 base->object->scaflag &= ~OB_ADDCONT;
462                                 cont= new_controller(CONT_LOGIC_AND);
463                                 make_unique_prop_names(cont->name);
464                                 base->object->scaflag |= OB_SHOWCONT;
465                                 BLI_addtail(&(base->object->controllers), cont);
466                         }
467                         base= base->next;
468                 }
469                 BIF_undo_push("Add controller");
470                 allqueue(REDRAWBUTSLOGIC, 0);
471                 break;
472
473         case B_CHANGE_CONT:
474                 base= FIRSTBASE;
475                 while(base) {
476                         cont= base->object->controllers.first;
477                         while(cont) {
478                                 if(cont->type != cont->otype) {
479                                         init_controller(cont);
480                                         cont->otype= cont->type;
481                                         break;
482                                 }
483                                 cont= cont->next;
484                         }
485                         base= base->next;
486                 }
487                 allqueue(REDRAWBUTSLOGIC, 0);
488                 break;
489         
490
491         case B_DEL_CONT:
492                 base= FIRSTBASE;
493                 while(base) {
494                         cont= base->object->controllers.first;
495                         while(cont) {
496                                 if(cont->flag & CONT_DEL) {
497                                         BLI_remlink(&(base->object->controllers), cont);
498                                         unlink_controller(cont);
499                                         free_controller(cont);
500                                         break;
501                                 }
502                                 cont= cont->next;
503                         }
504                         base= base->next;
505                 }
506                 BIF_undo_push("Delete controller");
507                 allqueue(REDRAWBUTSLOGIC, 0);
508                 break;
509         
510         case B_ADD_ACT:
511                 base= FIRSTBASE;
512                 while(base) {
513                         if(base->object->scaflag & OB_ADDACT) {
514                                 base->object->scaflag &= ~OB_ADDACT;
515                                 act= new_actuator(ACT_OBJECT);
516                                 make_unique_prop_names(act->name);
517                                 BLI_addtail(&(base->object->actuators), act);
518                                 base->object->scaflag |= OB_SHOWACT;
519                         }
520                         base= base->next;
521                 }
522                 BIF_undo_push("Add actuator");
523                 allqueue(REDRAWBUTSLOGIC, 0);
524                 break;
525
526         case B_CHANGE_ACT:
527                 base= FIRSTBASE;
528                 while(base) {
529                         act= base->object->actuators.first;
530                         while(act) {
531                                 if(act->type != act->otype) {
532                                         init_actuator(act);
533                                         act->otype= act->type;
534                                         break;
535                                 }
536                                 act= act->next;
537                         }
538                         base= base->next;
539                 }
540                 allqueue(REDRAWBUTSLOGIC, 0);
541                 break;
542
543         case B_DEL_ACT:
544                 base= FIRSTBASE;
545                 while(base) {
546                         act= base->object->actuators.first;
547                         while(act) {
548                                 if(act->flag & ACT_DEL) {
549                                         BLI_remlink(&(base->object->actuators), act);
550                                         unlink_actuator(act);
551                                         free_actuator(act);
552                                         break;
553                                 }
554                                 act= act->next;
555                         }
556                         base= base->next;
557                 }
558                 BIF_undo_push("Delete actuator");
559                 allqueue(REDRAWBUTSLOGIC, 0);
560                 break;
561         
562         case B_SOUNDACT_BROWSE:
563                 /* since we don't know which... */
564                 didit= 0;
565                 base= FIRSTBASE;
566                 while(base)
567                 {
568                         act= base->object->actuators.first;
569                         while(act)
570                         {
571                                 if(act->type==ACT_SOUND)
572                                 {
573                                         bSoundActuator *sa= act->data;
574                                         if(sa->sndnr)
575                                         {
576                                                 bSound *sound= G.main->sound.first;
577                                                 int nr= 1;
578
579                                                 if(sa->sndnr == -2) {
580                                                         activate_databrowse((ID *)G.main->sound.first, ID_SO, 0, B_SOUNDACT_BROWSE,
581                                                                                         &sa->sndnr, do_logic_buts);
582                                                         break;
583                                                 }
584
585                                                 while(sound)
586                                                 {
587                                                         if(nr==sa->sndnr)
588                                                                 break;
589                                                         nr++;
590                                                         sound= sound->id.next;
591                                                 }
592                                                 
593                                                 if(sa->sound)
594                                                         sa->sound->id.us--;
595                                                 
596                                                 sa->sound= sound;
597                                                 
598                                                 if(sound)
599                                                         sound->id.us++;
600                                                 
601                                                 sa->sndnr= 0;
602                                                 didit= 1;
603                                         }
604                                 }
605                                 act= act->next;
606                         }
607                         if(didit)
608                                 break;
609                         base= base->next;
610                 }
611                 allqueue(REDRAWBUTSLOGIC, 0);
612                 allqueue(REDRAWSOUND, 0);
613
614                 break;
615         }
616 }
617
618
619 static char *sensor_name(int type)
620 {
621         switch (type) {
622         case SENS_ALWAYS:
623                 return "Always";
624         case SENS_TOUCH:
625                 return "Touch";
626         case SENS_NEAR:
627                 return "Near";
628         case SENS_KEYBOARD:
629                 return "Keyboard";
630         case SENS_PROPERTY:
631                 return "Property";
632         case SENS_MOUSE:
633                 return "Mouse";
634         case SENS_COLLISION:
635                 return "Collision";
636         case SENS_RADAR:
637                 return "Radar";
638         case SENS_RANDOM:
639                 return "Random";
640         case SENS_RAY:
641                 return "Ray";
642         case SENS_MESSAGE:
643                 return "Message";
644         case SENS_JOYSTICK:
645                 return "Joystick";
646         }
647         return "unknown";
648 }
649
650 static char *sensor_pup(void)
651 {
652         /* the number needs to match defines in game.h */
653         return "Sensors %t|Always %x0|Keyboard %x3|Mouse %x5|"
654                 "Touch %x1|Collision %x6|Near %x2|Radar %x7|"
655                 "Property %x4|Random %x8|Ray %x9|Message %x10|Joystick %x11";
656 }
657
658 static char *controller_name(int type)
659 {
660         switch (type) {
661         case CONT_LOGIC_AND:
662                 return "AND";
663         case CONT_LOGIC_OR:
664                 return "OR";
665         case CONT_EXPRESSION:
666                 return "Expression";
667         case CONT_PYTHON:
668                 return "Python";
669         }
670         return "unknown";
671 }
672
673 static char *controller_pup(void)
674 {
675         return "Controllers   %t|AND %x0|OR %x1|Expression %x2|Python %x3";
676 }
677
678 static char *actuator_name(int type)
679 {
680         switch (type) {
681         case ACT_ACTION:
682                 return "Action";
683         case ACT_OBJECT:
684                 return "Motion";
685         case ACT_IPO:
686                 return "Ipo";
687         case ACT_LAMP:
688                 return "Lamp";
689         case ACT_CAMERA:
690                 return "Camera";
691         case ACT_MATERIAL:
692                 return "Material";
693         case ACT_SOUND:
694                 return "Sound";
695         case ACT_CD:
696                 return "CD";
697         case ACT_PROPERTY:
698                 return "Property";
699         case ACT_EDIT_OBJECT:
700                 return "Edit Object";
701         case ACT_CONSTRAINT:
702                 return "Constraint";
703         case ACT_SCENE:
704                 return "Scene";
705         case ACT_GROUP:
706                 return "Group";
707         case ACT_RANDOM:
708                 return "Random";
709         case ACT_MESSAGE:
710                 return "Message";
711         case ACT_GAME:
712                 return "Game";
713         case ACT_VISIBILITY:
714                 return "Visibility";
715         }
716         return "unknown";
717 }
718
719
720
721
722 static char *actuator_pup(Object *owner)
723 {
724         switch (owner->type)
725         {
726         case OB_ARMATURE:
727                 return "Actuators  %t|Action %x15|Motion %x0|Constraint %x9|Ipo %x1"
728                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
729                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
730                         "|Visibility %x18";
731                 break;
732         default:
733                 return "Actuators  %t|Motion %x0|Constraint %x9|Ipo %x1"
734                         "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
735                         "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
736                         "|Visibility %x18";
737         }
738 }
739
740
741
742 static void set_sca_ob(Object *ob)
743 {
744         bController *cont;
745         bActuator *act;
746
747         cont= ob->controllers.first;
748         while(cont) {
749                 cont->mynew= (bController *)ob;
750                 cont= cont->next;
751         }
752         act= ob->actuators.first;
753         while(act) {
754                 act->mynew= (bActuator *)ob;
755                 act= act->next;
756         }
757 }
758
759 static ID **get_selected_and_linked_obs(short *count, short scavisflag)
760 {
761         Base *base;
762         Object *ob, *obt;
763         ID **idar;
764         bSensor *sens;
765         bController *cont;
766         unsigned int lay;
767         int a, nr, doit;
768         
769         /* we need a sorted object list */
770         /* set scavisflags flags in Objects to indicate these should be evaluated */
771         /* also hide ob pointers in ->new entries of controllerss/actuators */
772         
773         *count= 0;
774         
775         if(G.scene==NULL) return NULL;
776         
777         ob= G.main->object.first;
778         while(ob) {
779                 ob->scavisflag= 0;
780                 set_sca_ob(ob);
781                 ob= ob->id.next;
782         }
783         
784         if(G.vd) lay= G.vd->lay;
785         else lay= G.scene->lay;
786         
787         base= FIRSTBASE;
788         while(base) {
789                 if(base->lay & lay) {
790                         if(base->flag & SELECT) {
791                                 if(scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
792                                 if(scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
793                                 if(scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
794                         }
795                 }
796                 base= base->next;
797         }
798
799         if(OBACT) {
800                 if(scavisflag & BUTS_SENS_ACT) OBACT->scavisflag |= OB_VIS_SENS;
801                 if(scavisflag & BUTS_CONT_ACT) OBACT->scavisflag |= OB_VIS_CONT;
802                 if(scavisflag & BUTS_ACT_ACT) OBACT->scavisflag |= OB_VIS_ACT;
803         }
804         
805         if(scavisflag & (BUTS_SENS_LINK|BUTS_CONT_LINK|BUTS_ACT_LINK)) {
806                 doit= 1;
807                 while(doit) {
808                         doit= 0;
809                         
810                         ob= G.main->object.first;
811                         while(ob) {
812                         
813                                 /* 1st case: select sensor when controller selected */
814                                 if((scavisflag & BUTS_SENS_LINK) && (ob->scavisflag & OB_VIS_SENS)==0) {
815                                         sens= ob->sensors.first;
816                                         while(sens) {
817                                                 for(a=0; a<sens->totlinks; a++) {
818                                                         if(sens->links[a]) {
819                                                                 obt= (Object *)sens->links[a]->mynew;
820                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)) {
821                                                                         doit= 1;
822                                                                         ob->scavisflag |= OB_VIS_SENS;
823                                                                         break;
824                                                                 }
825                                                         }
826                                                 }
827                                                 if(doit) break;
828                                                 sens= sens->next;
829                                         }
830                                 }
831                                 
832                                 /* 2nd case: select cont when act selected */
833                                 if((scavisflag & BUTS_CONT_LINK)  && (ob->scavisflag & OB_VIS_CONT)==0) {
834                                         cont= ob->controllers.first;
835                                         while(cont) {
836                                                 for(a=0; a<cont->totlinks; a++) {
837                                                         if(cont->links[a]) {
838                                                                 obt= (Object *)cont->links[a]->mynew;
839                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)) {
840                                                                         doit= 1;
841                                                                         ob->scavisflag |= OB_VIS_CONT;
842                                                                         break;
843                                                                 }
844                                                         }
845                                                 }
846                                                 if(doit) break;
847                                                 cont= cont->next;
848                                         }
849                                 }
850                                 
851                                 /* 3rd case: select controller when sensor selected */
852                                 if((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_SENS)) {
853                                         sens= ob->sensors.first;
854                                         while(sens) {
855                                                 for(a=0; a<sens->totlinks; a++) {
856                                                         if(sens->links[a]) {
857                                                                 obt= (Object *)sens->links[a]->mynew;
858                                                                 if(obt && (obt->scavisflag & OB_VIS_CONT)==0) {
859                                                                         doit= 1;
860                                                                         obt->scavisflag |= OB_VIS_CONT;
861                                                                 }
862                                                         }
863                                                 }
864                                                 sens= sens->next;
865                                         }
866                                 }
867                                 
868                                 /* 4th case: select actuator when controller selected */
869                                 if( (scavisflag & BUTS_ACT_LINK)  && (ob->scavisflag & OB_VIS_CONT)) {
870                                         cont= ob->controllers.first;
871                                         while(cont) {
872                                                 for(a=0; a<cont->totlinks; a++) {
873                                                         if(cont->links[a]) {
874                                                                 obt= (Object *)cont->links[a]->mynew;
875                                                                 if(obt && (obt->scavisflag & OB_VIS_ACT)==0) {
876                                                                         doit= 1;
877                                                                         obt->scavisflag |= OB_VIS_ACT;
878                                                                 }
879                                                         }
880                                                 }
881                                                 cont= cont->next;
882                                         }
883                                         
884                                 }
885                                 ob= ob->id.next;
886                         }
887                 }
888         } 
889         
890         /* now we count */
891         ob= G.main->object.first;
892         while(ob) {
893                 if( ob->scavisflag ) (*count)++;
894                 ob= ob->id.next;
895         }
896
897         if(*count==0) return NULL;
898         if(*count>24) *count= 24;               /* temporal */
899         
900         idar= MEM_callocN( (*count)*sizeof(void *), "idar");
901         
902         ob= G.main->object.first;
903         nr= 0;
904         while(ob) {
905                 if( ob->scavisflag ) {
906                         idar[nr]= (ID *)ob;
907                         nr++;
908                 }
909                 if(nr>=24) break;
910                 ob= ob->id.next;
911         }
912         
913         /* just to be sure... these were set in set_sca_done_ob() */
914         clear_sca_new_poins();
915         
916         return idar;
917 }
918
919
920 static int get_col_sensor(int type)
921 {
922         switch(type) {
923         case SENS_ALWAYS:               return TH_BUT_ACTION;
924         case SENS_TOUCH:                return TH_BUT_NEUTRAL;
925         case SENS_COLLISION:    return TH_BUT_SETTING;
926         case SENS_NEAR:                 return TH_BUT_SETTING1; 
927         case SENS_KEYBOARD:             return TH_BUT_SETTING2;
928         case SENS_PROPERTY:             return TH_BUT_NUM;
929         case SENS_MOUSE:                return TH_BUT_TEXTFIELD;
930         case SENS_RADAR:                return TH_BUT_POPUP;
931         case SENS_RANDOM:               return TH_BUT_NEUTRAL;
932         case SENS_RAY:                  return TH_BUT_SETTING1;
933         case SENS_MESSAGE:              return TH_BUT_SETTING2;
934         case SENS_JOYSTICK:             return TH_BUT_NEUTRAL;
935         default:                                return TH_BUT_NEUTRAL;
936         }
937 }
938 static void set_col_sensor(int type, int medium)
939 {
940         int col= get_col_sensor(type);
941         BIF_ThemeColorShade(col, medium?30:0);
942 }
943
944 /**
945  * Draws a toggle for pulse mode, a frequency field and a toggle to invert
946  * the value of this sensor. Operates on the shared data block of sensors.
947  */
948 static void draw_default_sensor_header(bSensor *sens,
949                                                                 uiBlock *block,
950                                                                 short x,
951                                                                 short y,
952                                                                 short w) 
953 {
954         /* Pulsing and frequency */
955         uiDefIconButBitS(block, TOG, SENS_PULSE_REPEAT, 1, ICON_DOTSUP,
956                          (short)(x + 10 + 0. * (w-20)), (short)(y - 19), (short)(0.15 * (w-20)), 19,
957                          &sens->pulse, 0.0, 0.0, 0, 0,
958                          "Activate TRUE level triggering (pulse mode)");
959
960         uiDefIconButBitS(block, TOG, SENS_NEG_PULSE_MODE, 1, ICON_DOTSDOWN,
961                          (short)(x + 10 + 0.15 * (w-20)), (short)(y - 19), (short)(0.15 * (w-20)), 19,
962                          &sens->pulse, 0.0, 0.0, 0, 0,
963                          "Activate FALSE level triggering (pulse mode)");
964         uiDefButS(block, NUM, 1, "f:",
965                          (short)(x + 10 + 0.3 * (w-20)), (short)(y - 19), (short)(0.275 * (w-20)), 19,
966                          &sens->freq, 0.0, 10000.0, 0, 0,
967                          "Delay between repeated pulses (in logic tics, 0 = no delay)");
968         
969         /* value or shift? */
970         uiDefButS(block, TOG, 1, "Inv",
971                          (short)(x + 10 + 0.85 * (w-20)), (short)(y - 19), (short)(0.15 * (w-20)), 19,
972                          &sens->invert, 0.0, 0.0, 0, 0,
973                          "Invert the level (output) of this sensor");
974 }
975
976 static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short yco, short width,char* objectname)
977 {
978         bNearSensor      *ns           = NULL;
979         bTouchSensor     *ts           = NULL;
980         bKeyboardSensor  *ks           = NULL;
981         bPropertySensor  *ps           = NULL;
982         bMouseSensor     *ms           = NULL;
983         bCollisionSensor *cs           = NULL;
984         bRadarSensor     *rs           = NULL;
985         bRandomSensor    *randomSensor = NULL;
986         bRaySensor       *raySens      = NULL;
987         bMessageSensor   *mes          = NULL;
988         bJoystickSensor  *joy              = NULL;
989
990         short ysize;
991         char *str;
992         
993         /* yco is at the top of the rect, draw downwards */
994         
995         uiBlockSetEmboss(block, UI_EMBOSSM);
996         
997         set_col_sensor(sens->type, 0);
998         
999         switch (sens->type)
1000         {
1001         case SENS_ALWAYS:
1002                 {
1003                         ysize= 24;
1004                         
1005                         glRects(xco, yco-ysize, xco+width, yco);
1006                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1007                         
1008                         draw_default_sensor_header(sens, block, xco, yco, width);
1009                         
1010                         yco-= ysize;
1011                         
1012                         break;
1013                 }
1014         case SENS_TOUCH:
1015                 {
1016                         ysize= 48; 
1017                         
1018                         glRects(xco, yco-ysize, xco+width, yco); 
1019                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1020                         
1021                         draw_default_sensor_header(sens, block, xco, yco, width);
1022                         
1023                         ts= sens->data; 
1024                         
1025                         /* uiDefBut(block, TEX, 1, "Property:", xco,yco-22,width, 19, &ts->name, 0, 31, 0, 0, "Only look for Objects with this property"); */
1026                         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"); 
1027                         ///* 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"); 
1028                         yco-= ysize; 
1029                         break; 
1030                 }
1031         case SENS_COLLISION:
1032                 {
1033                         ysize= 48;
1034                         
1035                         glRects(xco, yco-ysize, xco+width, yco);
1036                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1037                         
1038                         draw_default_sensor_header(sens, block, xco, yco, width);
1039                         cs= sens->data;
1040                         
1041                         /* The collision sensor will become a generic collision (i.e. it     */
1042                         /* absorb the old touch sensor).                                     */
1043
1044                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",(short)(xco + 10),(short)(yco - 44),
1045                                 (short)(0.20 * (width-20)), 19, &cs->mode, 0.0, 0.0, 0, 0,
1046                                 "Toggle collision on material or property.");
1047                         
1048                         if (cs->mode & SENS_COLLISION_MATERIAL) {
1049                                 uiDefBut(block, TEX, 1, "Material:", (short)(xco + 10 + 0.20 * (width-20)),
1050                                         (short)(yco-44), (short)(0.8*(width-20)), 19, &cs->materialName, 0, 31, 0, 0,
1051                                         "Only look for Objects with this material");
1052                         } else {
1053                                 uiDefBut(block, TEX, 1, "Property:", (short)(xco + 10 + 0.20 * (width-20)), (short)(yco-44),
1054                                         (short)(0.8*(width-20)), 19, &cs->name, 0, 31, 0, 0,
1055                                         "Only look for Objects with this property");
1056                         }
1057         
1058                         /*              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"); */
1059                         
1060                         yco-= ysize;
1061                         break;
1062                 }
1063         case SENS_NEAR:
1064                 {
1065                         ysize= 72;
1066                         
1067                         glRects(xco, yco-ysize, xco+width, yco);
1068                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1069                         
1070                         draw_default_sensor_header(sens, block, xco, yco, width);
1071                         ns= sens->data;
1072                         
1073                         uiDefBut(block, TEX, 1, "Property:",(short)(10+xco),(short)(yco-44), (short)(width-20), 19,
1074                                 &ns->name, 0, 31, 0, 0, "Only look for Objects with this property");
1075                         uiDefButF(block, NUM, 1, "Dist",(short)(10+xco),(short)(yco-68),(short)((width-22)/2), 19,
1076                                 &ns->dist, 0.0, 1000.0, 1000, 0, "Trigger distance");
1077                         uiDefButF(block, NUM, 1, "Reset",(short)(10+xco+(width-22)/2), (short)(yco-68), (short)((width-22)/2), 19,
1078                                 &ns->resetdist, 0.0, 1000.0, 1000, 0, "Reset distance"); 
1079                         yco-= ysize;
1080                         break;
1081                 }
1082         case SENS_RADAR:
1083                 {
1084                         ysize= 72; 
1085                         
1086                         glRects(xco, yco-ysize, xco+width, yco);
1087                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1088                         
1089                         draw_default_sensor_header(sens, block, xco, yco, width);
1090                         
1091                         rs= sens->data;
1092                         
1093                         uiDefBut(block, TEX, 1, "Prop:",
1094                                          (short)(10+xco),(short)(yco-44), (short)(0.7 * (width-20)), 19,
1095                                          &rs->name, 0, 31, 0, 0,
1096                                          "Only look for Objects with this property");
1097                         uiDefButS(block, ROW, 1, "X",
1098                                          (short)(10+xco+0.7 * (width-20)),(short)(yco-44), (short)(0.1 * (width-22)),19,
1099                                          &rs->axis, 2.0, 0, 0, 0,
1100                                          "Cast the cone along the object's positive x-axis");
1101                         uiDefButS(block, ROW, 1, "Y",
1102                                          (short)(10+xco+0.8 * (width-20)),(short)(yco-44),(short)(0.1 * (width-22)), 19,
1103                                          &rs->axis, 2.0, 1, 0, 0,
1104                                          "Cast the cone along the object's positive y-axis");
1105                         uiDefButS(block, ROW, 1, "Z",
1106                                          (short)(10+xco+0.9 * (width-20)), (short)(yco-44), (short)(0.1 * (width-22)), 19,
1107                                          &rs->axis, 2.0, 2, 0, 0,
1108                                          "Cast the cone along the object's positive z-axis");
1109                         uiDefButF(block, NUM, 1, "Ang:",
1110                                          (short)(10+xco), (short)(yco-68), (short)((width-20)/2), 19,
1111                                          &rs->angle, 0.0, 179.9, 10, 0,
1112                                          "Opening angle of the radar cone.");
1113                         uiDefButF(block, NUM, 1, "Dist:",
1114                                          (short)(xco+10 + (width-20)/2), (short)(yco-68), (short)((width-20)/2), 19,
1115                                          &rs->range, 0.01, 10000.0, 100, 0,
1116                                          "Depth of the radar cone");
1117                         yco-= ysize;
1118                         break;
1119                 }
1120         case SENS_KEYBOARD:
1121                 {
1122                         /* 5 lines: 120 height */
1123                         ysize= 120;
1124                         
1125                         glRects(xco, yco-ysize, xco+width, yco);
1126                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1127                         
1128                         /* header line */
1129                         draw_default_sensor_header(sens, block, xco, yco, width);
1130                         ks= sens->data;
1131                         
1132                         /* line 2: hotkey and allkeys toggle */
1133                         uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
1134                         
1135                         /* line 3: two key modifyers (qual1, qual2) */
1136                         uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
1137                         uiDefKeyevtButS(block, B_DIFF, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
1138                         
1139                         /* labels for line 1 and 2 */
1140                         uiDefBut(block, LABEL, 0, "Key",          xco, yco-44, 40, 19, NULL, 0, 0, 0, 0, "");
1141                         uiDefBut(block, LABEL, 0, "Hold",         xco, yco-68, 40, 19, NULL, 0, 0, 0, 0, "");
1142                         
1143                         /* part of line 1 */
1144                         uiBlockSetCol(block, TH_BUT_SETTING2);
1145                         uiDefButBitS(block, TOG, 1, 0, "All keys",        xco+40+(width/2), yco-44, (width/2)-50, 19,
1146                                 &ks->type, 0, 0, 0, 0, "");
1147                         
1148                         /* line 4: toggle property for string logging mode */
1149                         uiDefBut(block, TEX, 1, "LogToggle: ",
1150                                 xco+10, yco-92, (width-20), 19,
1151                                 ks->toggleName, 0, 31, 0, 0,
1152                                 "Property that indicates whether to log "
1153                                 "keystrokes as a string.");
1154                         
1155                         /* line 5: target property for string logging mode */
1156                         uiDefBut(block, TEX, 1, "Target: ",
1157                                 xco+10, yco-116, (width-20), 19,
1158                                 ks->targetName, 0, 31, 0, 0,
1159                                 "Property that receives the keystrokes in case "
1160                                 "a string is logged.");
1161                         
1162                         yco-= ysize;
1163                         break;
1164                 }
1165         case SENS_PROPERTY:
1166                 {
1167                         ysize= 96;
1168                         
1169                         glRects(xco, yco-ysize, xco+width, yco);
1170                         uiEmboss((float)xco, (float)yco-ysize,
1171                                 (float)xco+width, (float)yco, 1);
1172                         
1173                         draw_default_sensor_header(sens, block, xco, yco, width);
1174                         ps= sens->data;
1175                         
1176                         str= "Type %t|Equal %x0|Not Equal %x1|Interval %x2|Changed %x3"; 
1177                         /* str= "Type %t|Equal %x0|Not Equal %x1"; */
1178                         uiDefButI(block, MENU, B_REDR, str,                     xco+30,yco-44,width-60, 19,
1179                                 &ps->type, 0, 31, 0, 0, "Type");
1180                         
1181                         if (ps->type != SENS_PROP_EXPRESSION)
1182                         {
1183                                 uiDefBut(block, TEX, 1, "Prop: ",                       xco+30,yco-68,width-60, 19,
1184                                         ps->name, 0, 31, 0, 0,  "Property name");
1185                         }
1186                         
1187                         if(ps->type == SENS_PROP_INTERVAL)
1188                         {
1189                                 uiDefBut(block, TEX, 1, "Min: ",                xco,yco-92,width/2, 19,
1190                                         ps->value, 0, 31, 0, 0, "test for min value");
1191                                 uiDefBut(block, TEX, 1, "Max: ",                xco+width/2,yco-92,width/2, 19,
1192                                         ps->maxvalue, 0, 31, 0, 0, "test for max value");
1193                         }
1194                         else if(ps->type == SENS_PROP_CHANGED);
1195                         else
1196                         {
1197                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-92,width-60, 19,
1198                                         ps->value, 0, 31, 0, 0, "test for value");
1199                         }
1200                         
1201                         yco-= ysize;
1202                         break;
1203                 }
1204         case SENS_MOUSE:
1205                 {
1206                         ms= sens->data;
1207                         /* Two lines: 48 pixels high. */
1208                         ysize = 48;
1209                         
1210                         glRects(xco, yco-ysize, xco+width, yco);
1211                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1212                         
1213                         /* line 1: header */
1214                         draw_default_sensor_header(sens, block, xco, yco, width);
1215                         
1216                         /* Line 2: type selection. The number are a bit mangled to get
1217                         * proper compatibility with older .blend files. */
1218                         str= "Type %t|Left button %x1|Middle button %x2|"
1219                                 "Right button %x4|Wheel Up %x5|Wheel Down %x6|Movement %x8|Mouse over %x16|Mouse over any%x32"; 
1220                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, width-20, 19,
1221                                 &ms->type, 0, 31, 0, 0,
1222                                 "Specify the type of event this mouse sensor should trigger on.");
1223                         
1224                         yco-= ysize;
1225                         break;
1226                 }
1227         case SENS_RANDOM:
1228                 {
1229                         ysize = 48;
1230                         
1231                         glRects(xco, yco-ysize, xco+width, yco);
1232                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1233                         
1234                         draw_default_sensor_header(sens, block, xco, yco, width);
1235                         randomSensor = sens->data;
1236                         /* some files were wrongly written, avoid crash now */
1237                         if (randomSensor)
1238                         {
1239                                 uiDefButI(block, NUM, 1, "Seed: ",              xco+10,yco-44,(width-20), 19,
1240                                         &randomSensor->seed, 0, 1000, 0, 0,
1241                                         "Initial seed of the generator. (Choose 0 for not random)");
1242                         }
1243                         yco-= ysize;
1244                         break;
1245                 }
1246         case SENS_RAY:
1247                 {
1248                         ysize = 72;
1249                         glRects(xco, yco-ysize, xco+width, yco);
1250                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1251                         
1252                         draw_default_sensor_header(sens, block, xco, yco, width);
1253                         raySens = sens->data;
1254                         
1255                         /* 1. property or material */
1256                         uiDefButBitS(block, TOG, SENS_COLLISION_MATERIAL, B_REDR, "M/P",
1257                                 xco + 10,yco - 44, 0.20 * (width-20), 19,
1258                                 &raySens->mode, 0.0, 0.0, 0, 0,
1259                                 "Toggle collision on material or property.");
1260                         
1261                         if (raySens->mode & SENS_COLLISION_MATERIAL)
1262                         {
1263                                 uiDefBut(block, TEX, 1, "Material:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1264                                         &raySens->matname, 0, 31, 0, 0,
1265                                         "Only look for Objects with this material");
1266                         }
1267                         else
1268                         {
1269                                 uiDefBut(block, TEX, 1, "Property:", xco + 10 + 0.20 * (width-20), yco-44, 0.8*(width-20), 19,
1270                                         &raySens->propname, 0, 31, 0, 0,
1271                                         "Only look for Objects with this property");
1272                         }
1273                         
1274                         /* 2. sensing range */
1275                         uiDefButF(block, NUM, 1, "Range", xco+10, yco-68, 0.6 * (width-20), 19,
1276                                 &raySens->range, 0.01, 10000.0, 100, 0,
1277                                 "Sense objects no farther than this distance");
1278                         
1279                         /* 3. axis choice */
1280                         str = "Type %t|+ X axis %x1|+ Y axis %x0|+ Z axis %x2|- X axis %x3|- Y axis %x4|- Z axis %x5"; 
1281                         uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1282                                 &raySens->axisflag, 2.0, 31, 0, 0,
1283                                 "Specify along which axis the ray is cast.");
1284                         
1285                         yco-= ysize;            
1286                         break;
1287                 }
1288         case SENS_MESSAGE:
1289                 {
1290                         mes = sens->data;
1291                         ysize = 2 * 24; /* total number of lines * 24 pixels/line */
1292                         
1293                         glRects(xco, yco-ysize, xco+width, yco);
1294                         uiEmboss((float)xco, (float)yco-ysize,
1295                                 (float)xco+width, (float)yco, 1);
1296                         
1297                         /* line 1: header line */
1298                         draw_default_sensor_header(sens, block, xco, yco, width);
1299                         
1300                         /* line 2: Subject filter */
1301                         uiDefBut(block, TEX, 1, "Subject: ",
1302                                 (xco+10), (yco-44), (width-20), 19,
1303                                 mes->subject, 0, 31, 0, 0,
1304                                 "Optional subject filter: only accept messages with this subject"
1305                                 ", or empty for all");
1306                         
1307                         yco -= ysize;
1308                         break;
1309                 }
1310                 case SENS_JOYSTICK:
1311                 {
1312
1313                         ysize =  72;
1314                         
1315                         glRects(xco, yco-ysize, xco+width, yco);
1316                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1317                         
1318                         /* line 1: header */
1319                         draw_default_sensor_header(sens, block, xco, yco, width);
1320
1321                         joy= sens->data;
1322                         
1323
1324                         str= "Type %t|Button %x0|Axis %x1|Hat%x2"; 
1325                         uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, 0.6 * (width-20), 19,
1326                                 &joy->type, 0, 31, 0, 0,
1327                                 "The type of event this joystick sensor is triggered on.");
1328                         
1329                         if(joy->type == SENS_JOY_BUTTON)
1330                         {
1331                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1332                                 &joy->button, 0, 18, 100, 0,
1333                                 "Specify which button to use");
1334                                 
1335                                 str = "Type %t|Pressed %x0|Released %x1"; 
1336                                 uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1337                                 &joy->buttonf, 2.0, 31, 0, 0,
1338                                 "Button pressed or released.");
1339                         }
1340                         else if(joy->type == SENS_JOY_AXIS)
1341                         {
1342                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1343                                 &joy->axis, 1, 2.0, 100, 0,
1344                                 "Specify which axis to use");
1345
1346                                 uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
1347                                 &joy->precision, 0, 32768.0, 100, 0,
1348                                 "Specify the precision of the axis");
1349
1350                                 str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis %x0"; 
1351                                 uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1352                                 &joy->axisf, 2.0, 31, 0, 0,
1353                                 "The direction of the axis");
1354                         }
1355                         else
1356                         {
1357                                 uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 19,
1358                                 &joy->hat, 1, 2.0, 100, 0,
1359                                 "Specify which hat to use");
1360                                 
1361                                 uiDefButI(block, NUM, 1, "Direction:", xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
1362                                 &joy->hatf, 0, 12, 100, 0,
1363                                 "Specify hat direction");
1364                         }
1365                         yco-= ysize;
1366                         break;
1367                 }
1368         }
1369         
1370         uiBlockSetEmboss(block, UI_EMBOSSM);
1371         uiBlockSetCol(block, TH_AUTO);
1372         
1373         return yco-4;
1374 }
1375
1376
1377
1378 static short draw_controllerbuttons(bController *cont, uiBlock *block, short xco, short yco, short width)
1379 {
1380         bExpressionCont *ec;
1381         bPythonCont *pc;
1382         short ysize;
1383         
1384         uiBlockSetEmboss(block, UI_EMBOSSM);
1385         
1386         switch (cont->type) {
1387         case CONT_EXPRESSION:
1388                 ysize= 28;
1389
1390                 BIF_ThemeColor(TH_BUT_SETTING);
1391                 glRects(xco, yco-ysize, xco+width, yco);
1392                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1393                 
1394                 /* uiDefBut(block, LABEL, 1, "Not yet...", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, ""); */
1395                 ec= cont->data; 
1396                 /* uiDefBut(block, BUT, 1, "Variables", xco,yco-24,80, 19, NULL, 0, 0, 0, 0, "Available variables for expression"); */
1397                 uiDefBut(block, TEX, 1, "Exp:",         xco + 10 , yco-21, width-20, 19,
1398                                  ec->str, 0, 127, 0, 0,
1399                                  "Expression"); 
1400                 
1401                 yco-= ysize;
1402                 break;
1403         case CONT_PYTHON:
1404                 ysize= 28;
1405                 
1406                 if(cont->data==NULL) init_controller(cont);
1407                 pc= cont->data;
1408                 
1409                 BIF_ThemeColor(TH_BUT_SETTING1);
1410                 glRects(xco, yco-ysize, xco+width, yco);
1411                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1412
1413                 uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "Script: ", xco+45,yco-24,width-90, 19, &pc->text, "");
1414                 
1415                 yco-= ysize;
1416                 break;
1417                 
1418         default:
1419                 ysize= 4;
1420
1421                 BIF_ThemeColor(TH_BUT_NEUTRAL);
1422                 glRects(xco, yco-ysize, xco+width, yco);
1423                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1424                 
1425                 yco-= ysize;
1426         }
1427         
1428         uiBlockSetEmboss(block, UI_EMBOSSM);
1429         uiBlockSetCol(block, TH_AUTO);
1430
1431         return yco;
1432 }
1433
1434 static int get_col_actuator(int type)
1435 {
1436         switch(type) {
1437         case ACT_ACTION:                return TH_BUT_ACTION;
1438         case ACT_OBJECT:                return TH_BUT_NEUTRAL;
1439         case ACT_IPO:                   return TH_BUT_SETTING;
1440         case ACT_PROPERTY:              return TH_BUT_SETTING1;
1441         case ACT_SOUND:                 return TH_BUT_SETTING2;
1442         case ACT_CD:                    return TH_BUT_NUM;
1443         case ACT_CAMERA:                return TH_BUT_TEXTFIELD;
1444         case ACT_EDIT_OBJECT:           return TH_BUT_POPUP;
1445         case ACT_GROUP:                 return TH_BUT_ACTION;
1446         case ACT_RANDOM:                return TH_BUT_NEUTRAL;
1447         case ACT_SCENE:                 return TH_BUT_SETTING;
1448         case ACT_MESSAGE:               return TH_BUT_SETTING1;
1449         case ACT_GAME:                  return TH_BUT_SETTING2;
1450         case ACT_VISIBILITY:            return TH_BUT_NUM;
1451         case ACT_CONSTRAINT:            return TH_BUT_ACTION;
1452         default:                                return TH_BUT_NEUTRAL;
1453         }
1454 }
1455 static void set_col_actuator(int item, int medium) 
1456 {
1457         int col= get_col_actuator(item);
1458         BIF_ThemeColorShade(col, medium?30:10);
1459         
1460 }
1461
1462 static short draw_actuatorbuttons(bActuator *act, uiBlock *block, short xco, short yco, short width)
1463 {
1464         bSoundActuator      *sa      = NULL;
1465         bCDActuator                     *cda     = NULL;
1466         bObjectActuator     *oa      = NULL;
1467         bIpoActuator        *ia      = NULL;
1468         bPropertyActuator   *pa      = NULL;
1469         bCameraActuator     *ca      = NULL;
1470         bEditObjectActuator *eoa     = NULL;
1471         bConstraintActuator *coa     = NULL;
1472         bSceneActuator      *sca     = NULL;
1473         bGroupActuator      *ga      = NULL;
1474         bRandomActuator     *randAct = NULL;
1475         bMessageActuator    *ma      = NULL;
1476         bActionActuator     *aa      = NULL;
1477         bGameActuator       *gma     = NULL;
1478         bVisibilityActuator *visAct  = NULL;
1479         
1480         float *fp;
1481         short ysize = 0, wval;
1482         char *str;
1483         int myline;
1484
1485         /* yco is at the top of the rect, draw downwards */
1486         uiBlockSetEmboss(block, UI_EMBOSSM);
1487         set_col_actuator(act->type, 0);
1488         
1489         switch (act->type)
1490         {
1491         case ACT_OBJECT:
1492                 {
1493                         ysize= 129;
1494                         
1495                         glRects(xco, yco-ysize, xco+width, yco);
1496                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1497                         
1498                         oa = act->data;
1499                         wval = (width-100)/3;
1500                         
1501                         uiDefBut(block, LABEL, 0, "Force",      xco, yco-22, 55, 19, NULL, 0, 0, 0, 0, "Sets the force");
1502                         uiDefButF(block, NUM, 0, "",            xco+45, yco-22, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, "");
1503                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-22, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, "");
1504                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-22, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, "");
1505                         
1506                         uiDefBut(block, LABEL, 0, "Torque", xco, yco-41, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque");
1507                         uiDefButF(block, NUM, 0, "",            xco+45, yco-41, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, "");
1508                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-41, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, "");
1509                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-41, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, "");
1510                         
1511                         uiDefBut(block, LABEL, 0, "dLoc",       xco, yco-64, 45, 19, NULL, 0, 0, 0, 0, "Sets the dLoc");
1512                         uiDefButF(block, NUM, 0, "",            xco+45, yco-64, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, "");
1513                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-64, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, "");
1514                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-64, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, "");
1515                         
1516                         uiDefBut(block, LABEL, 0, "dRot",       xco, yco-83, 45, 19, NULL, 0, 0, 0, 0, "Sets the dRot");
1517                         uiDefButF(block, NUM, 0, "",            xco+45, yco-83, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, "");
1518                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-83, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, "");
1519                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-83, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, "");
1520                         
1521                         uiDefBut(block, LABEL, 0, "linV",       xco, yco-106, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity");
1522                         uiDefButF(block, NUM, 0, "",            xco+45, yco-106, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, "");
1523                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-106, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, "");
1524                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-106, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, "");
1525                         
1526                         uiDefBut(block, LABEL, 0, "angV",       xco, yco-125, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity");
1527                         uiDefButF(block, NUM, 0, "",            xco+45, yco-125, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, "");
1528                         uiDefButF(block, NUM, 0, "",            xco+45+wval, yco-125, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, "");
1529                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-125, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, "");
1530                         
1531                         uiDefButBitI(block, TOG, ACT_FORCE_LOCAL, 0, "L",               xco+45+3*wval, yco-22, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1532                         uiDefButBitI(block, TOG, ACT_TORQUE_LOCAL, 0, "L",              xco+45+3*wval, yco-41, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1533                         uiDefButBitI(block, TOG, ACT_DLOC_LOCAL, 0, "L",                xco+45+3*wval, yco-64, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1534                         uiDefButBitI(block, TOG, ACT_DROT_LOCAL, 0, "L",                xco+45+3*wval, yco-83, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1535                         uiDefButBitI(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-106, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1536                         uiDefButBitI(block, TOG, ACT_ANG_VEL_LOCAL, 0, "L",             xco+45+3*wval, yco-125, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation");
1537                         
1538                         uiDefButBitI(block, TOG, ACT_ADD_LIN_VEL, 0, "add",xco+45+3*wval+15, yco-106, 35, 19, &oa->flag, 0.0, 0.0, 0, 0, "Toggles between ADD and SET linV");
1539                         
1540                         yco-= ysize;
1541                         break;
1542                 }
1543         case ACT_ACTION:
1544                 {
1545                         /* DrawAct */
1546 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1547                         ysize = 112;
1548 #else
1549                         ysize= 92;
1550 #endif
1551                         
1552                         glRects(xco, yco-ysize, xco+width, yco);
1553                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1554                         
1555                         aa = act->data;
1556                         wval = (width-60)/3;
1557                         
1558                         //              str= "Action types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1559 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1560                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6|Displacement %x7";
1561 #else
1562                         str= "Action types   %t|Play %x0|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1563 #endif
1564                         uiDefButS(block, MENU, B_REDR, str, xco+30, yco-24, width-60, 19, &aa->type, 0.0, 0.0, 0.0, 0.0, "Action playback type");
1565                         uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, 1, "AC: ", xco+30, yco-44, width-60, 19, &aa->act, "Action name");
1566                         
1567                         if(aa->type == ACT_ACTION_FROM_PROP)
1568                         {
1569                                 uiDefBut(block, TEX, 0, "Prop: ",xco+30, yco-64, width-60, 19, aa->name, 0.0, 31.0, 0, 0, "Use this property to define the Action position");
1570                         }
1571                         else
1572                         {
1573                                 uiDefButI(block, NUM, 0, "Sta: ",xco+30, yco-64, (width-60)/2, 19, &aa->sta, 0.0, MAXFRAMEF, 0, 0, "Start frame");
1574                                 uiDefButI(block, NUM, 0, "End: ",xco+30+(width-60)/2, yco-64, (width-60)/2, 19, &aa->end, 0.0, MAXFRAMEF, 0, 0, "End frame");
1575                         }
1576                         
1577                         
1578                         
1579                         uiDefButI(block, NUM, 0, "Blendin: ", xco+30, yco-84, (width-60)/2, 19, &aa->blendin, 0.0, MAXFRAMEF, 0.0, 0.0, "Number of frames of motion blending");
1580                         uiDefButS(block, NUM, 0, "Priority: ", xco+30+(width-60)/2, yco-84, (width-60)/2, 19, &aa->priority, 0.0, 100.0, 0.0, 0.0, "Execution priority - lower numbers will override actions with higher numbers");
1581                         
1582 #ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
1583                         if(aa->type == ACT_ACTION_MOTION)
1584                         {
1585                                 uiDefButF(block, NUM, 0, "Cycle: ",xco+30, yco-104, (width-60)/2, 19, &aa->stridelength, 0.0, 2500.0, 0, 0, "Distance covered by a single cycle of the action");
1586                         }
1587 #endif
1588                         
1589                         yco-=ysize;
1590                         break;
1591                 }
1592         case ACT_IPO:
1593                 {
1594                         ia= act->data;
1595                         
1596                         ysize= 52;
1597                         
1598                         glRects(xco, yco-ysize, xco+width, yco);
1599                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1600                         
1601                         str = "Ipo types   %t|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x6";
1602                         
1603                         uiDefButS(block, MENU, B_REDR, str,             xco+20, yco-24, width-40 - (width-40)/3, 19, &ia->type, 0, 0, 0, 0, "");
1604                         uiDefButBitS(block, TOG, ACT_IPOCHILD,  B_REDR, 
1605                                 "Child",        xco+20+0.666*(width-40), yco-24, (width-40)/3, 19, 
1606                                 &ia->flag, 0, 0, 0, 0, 
1607                                 "Add all children Objects as well");
1608
1609                         if(ia->type==ACT_IPO_FROM_PROP) {
1610                                 uiDefBut(block, TEX, 0, 
1611                                         "Prop: ",               xco+20, yco-44, width-40, 19, 
1612                                         ia->name, 0.0, 31.0, 0, 0, 
1613                                         "Use this property to define the Ipo position");
1614                         }
1615                         else {
1616                                 uiDefButI(block, NUM, 0, 
1617                                         "Sta",          xco+20, yco-44, (width-100)/2, 19, 
1618                                         &ia->sta, 0.0, MAXFRAMEF, 0, 0, 
1619                                         "Start frame");
1620                                 uiDefButI(block, NUM, 0, 
1621                                         "End",          xco+18+(width-90)/2, yco-44, (width-100)/2, 19, 
1622                                         &ia->end, 0.0, MAXFRAMEF, 0, 0, 
1623                                         "End frame");
1624                                 
1625                                 uiDefButBitS(block, TOG, ACT_IPOFORCE, B_REDR, 
1626                                         "Force", xco+width-78, yco-44, 43, 19, 
1627                                         &ia->flag, 0, 0, 0, 0, 
1628                                         "Convert Ipo to force"); 
1629                                 
1630                                 /* Only show the do-force-local toggle if force is requested */
1631                                 if (ia->flag & ACT_IPOFORCE) {
1632                                         uiDefButBitS(block, TOG, ACT_IPOFORCE_LOCAL, 0, 
1633                                                 "L", xco+width-35, yco-44, 15, 19, 
1634                                                 &ia->flag, 0, 0, 0, 0, 
1635                                                 "Let the force-ipo act in local coordinates."); 
1636                                 }
1637                                 
1638                         }
1639                         yco-= ysize;
1640                         break;
1641                 }
1642         case ACT_PROPERTY:
1643                 {
1644                         ysize= 68;
1645                         
1646                         glRects(xco, yco-ysize, xco+width, yco);
1647                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1648                         
1649                         pa= act->data;
1650                         
1651                         str= "Type   %t|Assign   %x0|Add %x1|Copy %x2";
1652                         uiDefButI(block, MENU, B_REDR, str,             xco+30,yco-24,width-60, 19, &pa->type, 0, 31, 0, 0, "Type");
1653                         
1654                         uiDefBut(block, TEX, 1, "Prop: ",               xco+30,yco-44,width-60, 19, pa->name, 0, 31, 0, 0, "Property name");
1655                         
1656                         if(pa->type==ACT_PROP_COPY) {
1657                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:", xco+10, yco-64, (width-20)/2, 19, &(pa->ob), "Copy from this Object");
1658                                 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");
1659                         }
1660                         else {
1661                                 uiDefBut(block, TEX, 1, "Value: ",              xco+30,yco-64,width-60, 19, pa->value, 0, 31, 0, 0, "change with this value");
1662                         }
1663                         yco-= ysize;
1664                         
1665                         break;
1666                 }
1667     case ACT_SOUND:
1668                 {
1669                         ysize = 70;
1670                         
1671                         sa = act->data;
1672                         sa->sndnr = 0;
1673                         
1674                         wval = (width-20)/2;
1675                         glRects(xco, yco-ysize, xco+width, yco);
1676                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1677                         
1678                         if(G.main->sound.first) {
1679                                 IDnames_to_pupstring(&str, "Sound files", NULL, &(G.main->sound), (ID *)sa->sound, &(sa->sndnr));
1680                                 /* reset this value, it is for handling the event */
1681                                 sa->sndnr = 0;
1682                                 uiDefButS(block, MENU, B_SOUNDACT_BROWSE, str, xco+10,yco-22,20,19, &(sa->sndnr), 0, 0, 0, 0, "");      
1683
1684                                 if(sa->sound) {
1685                                         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";
1686                                         uiDefBut(block, TEX, B_IDNAME, "SO:",xco+30,yco-22,width-40,19, sa->sound->id.name+2,    0.0, 21.0, 0, 0, "");
1687                                         uiDefButS(block, MENU, 1, dummy_str,xco+10,yco-44,width-20, 19, &sa->type, 0.0, 0.0, 0, 0, "");
1688                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-66,wval, 19, &sa->sound->volume, 0.0,  1.0, 0, 0, "Sets the volume of this sound");
1689                                         uiDefButF(block, NUM, 0, "Pitch:",xco+wval+10,yco-66,wval, 19, &sa->sound->pitch,-12.0, 12.0, 0, 0, "Sets the pitch of this sound");
1690                                 }
1691                                 MEM_freeN(str);
1692                         } 
1693                         else {
1694                                 uiDefBut(block, LABEL, 0, "Use Sound window (F10) to load samples", xco, yco-24, width, 19, NULL, 0, 0, 0, 0, "");
1695                         }
1696                                         
1697                         yco-= ysize;
1698                         
1699                         break;
1700                 }
1701         case ACT_CD:
1702                 {
1703                         char cd_type_str[] = "Sound mode %t|Play all tracks %x0|Play one track %x1|"
1704                                 "Volume %x3|Stop %x4|Pause %x5|Resume %x6";
1705                         cda = act->data;
1706
1707                         if (cda) {
1708                                 if (cda->track == 0) {
1709                                         cda->track = 1;
1710                                         cda->volume = 1;
1711                                         cda->type = ACT_CD_PLAY_ALL;
1712                                 }
1713                                 
1714                                 if (cda->type == ACT_CD_PLAY_TRACK || cda->type == ACT_CD_LOOP_TRACK) {
1715                                         ysize = 48;
1716                                         glRects(xco, yco-ysize, xco+width, yco);
1717                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1718                                         uiDefButS(block, NUM, 0, "Track:", xco+10,yco-44,width-20, 19, &cda->track, 1, 99, 0, 0, "Select the track to be played");
1719                                 }
1720                                 else if (cda->type == ACT_CD_VOLUME) {
1721                                         ysize = 48;
1722                                         glRects(xco, yco-ysize, xco+width, yco);
1723                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1724                                         uiDefButF(block, NUM, 0, "Volume:", xco+10,yco-44,width-20, 19, &cda->volume, 0, 1, 0, 0, "Set the volume for CD playback");
1725                                 }
1726                                 else {
1727                                         ysize = 28;
1728                                         glRects(xco, yco-ysize, xco+width, yco);
1729                                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1730                                 }
1731                                 uiDefButS(block, MENU, B_REDR, cd_type_str,xco+10,yco-22,width-20, 19, &cda->type, 0.0, 0.0, 0, 0, "");
1732                         }
1733                         yco-= ysize;
1734                         break;
1735                 }
1736         case ACT_CAMERA:
1737
1738                 ysize= 48;
1739         
1740                 glRects(xco, yco-ysize, xco+width, yco);
1741                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1742                 
1743                 ca= act->data;
1744         
1745                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-24, (width-20)/2, 19, &(ca->ob), "Look at this Object");
1746                 uiDefButF(block, NUM, 0, "Height:",     xco+10+(width-20)/2, yco-24, (width-20)/2, 19, &ca->height, 0.0, 20.0, 0, 0, "");
1747                 
1748                 uiDefButF(block, NUM, 0, "Min:",        xco+10, yco-44, (width-60)/2, 19, &ca->min, 0.0, 20.0, 0, 0, "");
1749                 
1750                 if(ca->axis==0) ca->axis= 'x';
1751                 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");
1752                 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");
1753                 
1754                 uiDefButF(block, NUM, 0, "Max:",        xco+20+(width)/2, yco-44, (width-60)/2, 19, &ca->max, 0.0, 20.0, 0, 0, "");
1755
1756                 yco-= ysize;
1757         
1758          break;
1759                                 
1760         case ACT_EDIT_OBJECT:
1761                 
1762                 eoa= act->data;
1763
1764                 if(eoa->type==ACT_EDOB_ADD_OBJECT) {
1765                         int wval; /* just a temp width */
1766                         ysize = 72;
1767                         glRects(xco, yco-ysize, xco+width, yco);
1768                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1769          
1770                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Add this Object (cant be on an visible layer)");
1771                         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");
1772
1773                         wval= (width-60)/3;
1774                         uiDefBut(block, LABEL, 0, "linV",       xco,           yco-68,   45, 19,
1775                                          NULL, 0, 0, 0, 0,
1776                                          "Velocity upon creation.");
1777                         uiDefButF(block, NUM, 0, "",            xco+45,        yco-68, wval, 19,
1778                                          eoa->linVelocity, -100.0, 100.0, 10, 0,
1779                                          "Velocity upon creation, x component.");
1780                         uiDefButF(block, NUM, 0, "",            xco+45+wval,   yco-68, wval, 19,
1781                                          eoa->linVelocity+1, -100.0, 100.0, 10, 0,
1782                                          "Velocity upon creation, y component.");
1783                         uiDefButF(block, NUM, 0, "",            xco+45+2*wval, yco-68, wval, 19,
1784                                          eoa->linVelocity+2, -100.0, 100.0, 10, 0,
1785                                          "Velocity upon creation, z component.");
1786                         uiDefButBitS(block, TOG, 2, 0, "L", xco+45+3*wval, yco-68, 15, 19,
1787                                          &eoa->localflag, 0.0, 0.0, 0, 0,
1788                                          "Apply the transformation locally");
1789
1790                 }
1791                 else if(eoa->type==ACT_EDOB_END_OBJECT) {
1792                         ysize= 28;
1793                         glRects(xco, yco-ysize, xco+width, yco);
1794                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1795                 }
1796                 else if(eoa->type==ACT_EDOB_REPLACE_MESH) {
1797                         ysize= 48;
1798                         glRects(xco, yco-ysize, xco+width, yco);
1799                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1800          
1801                         uiDefIDPoinBut(block, test_meshpoin_but, ID_ME, 1, "ME:",               xco+40, yco-44, (width-80), 19, &(eoa->me), "replace the existing mesh with this one");
1802                 }
1803                 else if(eoa->type==ACT_EDOB_TRACK_TO) {
1804                         ysize= 48;
1805                         glRects(xco, yco-ysize, xco+width, yco);
1806                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1807          
1808                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+10, yco-44, (width-20)/2, 19, &(eoa->ob), "Track to this Object");
1809                         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");
1810                         uiDefButS(block, TOG, 0, "3D",  xco+width-50, yco-44, 40, 19, &eoa->flag, 0.0, 0.0, 0, 0, "Enable 3D tracking");
1811                 }
1812                 
1813                 str= "Edit Object %t|Add Object %x0|End Object %x1|Replace Mesh %x2|Track to %x3";
1814                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &eoa->type, 0.0, 0.0, 0, 0, "");
1815
1816                 yco-= ysize;
1817         
1818         break;
1819  
1820         case ACT_CONSTRAINT:
1821         
1822                 ysize= 44;
1823         
1824                 glRects(xco, yco-ysize, xco+width, yco);
1825                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1826                 
1827                 coa= act->data;
1828                 
1829 /*              str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4|Rot X %x8|Rot Y %x16|Rot Z %x32"; */
1830                 str= "Limit %t|None %x0|Loc X %x1|Loc Y %x2|Loc Z %x4";
1831                 uiDefButS(block, MENU, 1, str,          xco+10, yco-40, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, "");
1832         
1833                 uiDefButS(block, NUM,           0, "Damp:",     xco+10, yco-20, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "");
1834                 uiDefBut(block, LABEL,                  0, "Min",       xco+80, yco-20, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
1835                 uiDefBut(block, LABEL,                  0, "Max",       xco+80+(width-90)/2, yco-20, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, "");
1836
1837                 if(coa->flag & ACT_CONST_LOCX) fp= coa->minloc;
1838                 else if(coa->flag & ACT_CONST_LOCY) fp= coa->minloc+1;
1839                 else if(coa->flag & ACT_CONST_LOCZ) fp= coa->minloc+2;
1840                 else if(coa->flag & ACT_CONST_ROTX) fp= coa->minrot;
1841                 else if(coa->flag & ACT_CONST_ROTY) fp= coa->minrot+1;
1842                 else fp= coa->minrot+2;
1843                 
1844                 uiDefButF(block, NUM, 0, "",            xco+80, yco-40, (width-90)/2, 19, fp, -2000.0, 2000.0, 10, 0, "");
1845                 uiDefButF(block, NUM, 0, "",            xco+80+(width-90)/2, yco-40, (width-90)/2, 19, fp+3, -2000.0, 2000.0, 10, 0, "");
1846
1847                 yco-= ysize;
1848         
1849         break;
1850  
1851         case ACT_SCENE:
1852                 sca= act->data; 
1853                 
1854                 if(sca->type==ACT_SCENE_RESTART) { 
1855                         ysize= 28; 
1856                         glRects(xco, yco-ysize, xco+width, yco); 
1857                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1858                 } 
1859                 else if(sca->type==ACT_SCENE_CAMERA) { 
1860                         
1861                         ysize= 48; 
1862                         glRects(xco, yco-ysize, xco+width, yco); 
1863                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1864          
1865                         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, 1, "OB:",         xco+40, yco-44, (width-80), 19, &(sca->camera), "Set this Camera"); 
1866                 } 
1867                 else if(sca->type==ACT_SCENE_SET) { 
1868                         
1869                         ysize= 48; 
1870                         glRects(xco, yco-ysize, xco+width, yco); 
1871                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1872         
1873                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Set this Scene"); 
1874                 } 
1875                 else if(sca->type==ACT_SCENE_ADD_FRONT) { 
1876                         
1877                         ysize= 48; 
1878                         glRects(xco, yco-ysize, xco+width, yco); 
1879                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1880         
1881                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add an Overlay Scene"); 
1882                 } 
1883                 else if(sca->type==ACT_SCENE_ADD_BACK) { 
1884                         
1885                         ysize= 48; 
1886                         glRects(xco, yco-ysize, xco+width, yco); 
1887                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1888         
1889                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Add a Background Scene"); 
1890                 } 
1891                 else if(sca->type==ACT_SCENE_REMOVE) { 
1892                         
1893                         ysize= 48; 
1894                         glRects(xco, yco-ysize, xco+width, yco); 
1895                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1896         
1897                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Remove a Scene");
1898                 } 
1899                 else if(sca->type==ACT_SCENE_SUSPEND) { 
1900                         
1901                         ysize= 48; 
1902                         glRects(xco, yco-ysize, xco+width, yco); 
1903                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1904         
1905                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Pause a Scene");
1906                 } 
1907                 else if(sca->type==ACT_SCENE_RESUME) { 
1908                         
1909                         ysize= 48; 
1910                         glRects(xco, yco-ysize, xco+width, yco); 
1911                         uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1912         
1913                         uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, 1, "SCE:",            xco+40, yco-44, (width-80), 19, &(sca->scene), "Unpause a Scene");
1914                 } 
1915
1916                 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";
1917                 uiDefButS(block, MENU, B_REDR, str,             xco+40, yco-24, (width-80), 19, &sca->type, 0.0, 0.0, 0, 0, ""); 
1918
1919                 yco-= ysize; 
1920                 break; 
1921         case ACT_GAME:
1922                 {
1923                         gma = act->data; 
1924                         if (gma->type == ACT_GAME_LOAD)
1925                         {
1926                                 //ysize = 68;
1927                                 ysize = 48;
1928                                 glRects(xco, yco-ysize, xco+width, yco); 
1929                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1930                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
1931 //                              uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
1932                         }
1933 /*                      else if (gma->type == ACT_GAME_START)
1934                         {
1935                                 ysize = 68; 
1936                                 glRects(xco, yco-ysize, xco+width, yco); 
1937                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1938
1939                                 uiDefBut(block, TEX, 1, "File: ", xco+10, yco-44,width-20,19, &(gma->filename), 0, 63, 0, 0, "Load this file");
1940                                 uiDefBut(block, TEX, 1, "Anim: ", xco+10, yco-64,width-20,19, &(gma->loadaniname), 0, 63, 0, 0, "Use this loadinganimation");
1941                         }
1942 */                      else if (gma->type == ACT_GAME_RESTART)
1943                         {
1944                                 ysize = 28; 
1945                                 glRects(xco, yco-ysize, xco+width, yco); 
1946                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1947                         }
1948                         else if (gma->type == ACT_GAME_QUIT)
1949                         {
1950                                 ysize = 28; 
1951                                 glRects(xco, yco-ysize, xco+width, yco); 
1952                                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); 
1953                         }
1954
1955                         //str = "Scene %t|Load game%x0|Start loaded game%x1|Restart this game%x2|Quit this game %x3";
1956                         str = "Scene %t|Start new game%x0|Restart this game%x2|Quit this game %x3";
1957                         uiDefButS(block, MENU, B_REDR, str, xco+40, yco-24, (width-80), 19, &gma->type, 0.0, 0.0, 0, 0, ""); 
1958                         
1959                         yco -= ysize; 
1960                         break; 
1961                 }
1962         case ACT_GROUP:
1963                 ga= act->data;
1964
1965                 ysize= 52;
1966
1967                 glRects(xco, yco-ysize, xco+width, yco);
1968                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
1969                 
1970                 str= "GroupKey types   %t|Set Key %x6|Play %x0|Ping Pong %x1|Flipper %x2|Loop Stop %x3|Loop End %x4|Property %x5";
1971
1972                 uiDefButS(block, MENU, 1, str,                  xco+20, yco-24, width-40, 19, &ga->type, 0, 0, 0, 0, "");
1973                 if(ga->type==ACT_GROUP_SET) {
1974                         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");
1975                         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");
1976                 }
1977                 else if(ga->type==ACT_GROUP_FROM_PROP) {
1978                         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");
1979                 }
1980                 else {
1981                         uiDefButI(block, NUM, 0, "Sta",         xco+20, yco-44, (width-40)/2, 19, &ga->sta, 0.0, 2500.0, 0, 0, "Start frame");
1982                         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");
1983                 }
1984                 yco-= ysize;
1985                 break;
1986
1987         case ACT_VISIBILITY:
1988                 ysize = 24;
1989
1990                 glRects(xco, yco-ysize, xco+width, yco);
1991                 uiEmboss((float)xco,
1992                          (float)yco-ysize, (float)xco+width, (float)yco, 1);
1993                 
1994                 visAct = act->data;
1995
1996                 str= "Visibility %t|Visible %x0|Invisible %x1";
1997
1998                 uiDefButI(block, MENU, B_REDR, str,
1999                           xco + 10, yco - 24, width - 20, 19, &visAct->flag,
2000                           0.0, 0.0, 0, 0,
2001                           "Make the object invisible or visible.");
2002 /*
2003                 uiDefButBitI(block, TOG, ACT_VISIBILITY_INVISIBLE, 0,
2004                           "Invisible",
2005                           xco + 10, yco - 24, width - 20, 19, &visAct->flag,
2006                           0.0, 0.0, 0, 0,
2007                           "Make the object invisible or visible.");
2008 */
2009                 yco-= ysize;
2010
2011                 break;
2012                 
2013         case ACT_RANDOM:
2014                 ysize  = 69;
2015
2016                 glRects(xco, yco-ysize, xco+width, yco);
2017                 uiEmboss((float)xco,
2018                                   (float)yco-ysize, (float)xco+width, (float)yco, 1);
2019                 
2020                 randAct = act->data;
2021
2022                 /* 1. seed */
2023                 uiDefButI(block, NUM, 1, "Seed: ",              (xco+10),yco-24, 0.4 *(width-20), 19,
2024                                  &randAct->seed, 0, 1000, 0, 0,
2025                                  "Initial seed of the random generator. Use Python for more freedom. "
2026                                  " (Choose 0 for not random)");
2027
2028                 /* 2. distribution type */
2029                 /* One pick per distribution. These numbers MUST match the #defines  */
2030                 /* in game.h !!!                                                     */
2031                 str= "Distribution %t|Bool Constant %x0|Bool Uniform %x1"
2032                         "|Bool Bernoulli %x2|Int Constant %x3|Int Uniform %x4"
2033                         "|Int Poisson %x5|Float Constant %x6|Float Uniform %x7"
2034                         "|Float Normal %x8|Float Neg. Exp. %x9";
2035                 uiDefButI(block, MENU, B_REDR, str, (xco+10) + 0.4 * (width-20), yco-24, 0.6 * (width-20), 19,
2036                                  &randAct->distribution, 0.0, 0.0, 0, 0,
2037                                  "Choose the type of distribution");
2038
2039                 /* 3. property */
2040                 uiDefBut(block, TEX, 1, "Property:", (xco+10), yco-44, (width-20), 19,
2041                                  &randAct->propname, 0, 31, 0, 0,
2042                                  "Assign the random value to this property"); 
2043
2044                 /*4. and 5. arguments for the distribution*/
2045                 switch (randAct->distribution) {
2046                 case ACT_RANDOM_BOOL_CONST:
2047                         uiDefButBitI(block, TOG, 1, 1, "Always true", (xco+10), yco-64, (width-20), 19,
2048                                          &randAct->int_arg_1, 2.0, 1, 0, 0,
2049                                          "Always false or always true");                        
2050                         break;
2051                 case ACT_RANDOM_BOOL_UNIFORM:
2052                         uiDefBut(block, LABEL, 0, "     Do a 50-50 pick.",      (xco+10), yco-64, (width-20), 19,
2053                                          NULL, 0, 0, 0, 0,
2054                                          "Choose between true and false, 50% chance each.");
2055                         break;
2056                 case ACT_RANDOM_BOOL_BERNOUILLI:
2057                         uiDefButF(block, NUM, 1, "Chance", (xco+10), yco-64, (width-20), 19,
2058                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2059                                          "Pick a number between 0 and 1. Success if you stay "
2060                                          "below this value");                   
2061                         break;
2062                 case ACT_RANDOM_INT_CONST:
2063                         uiDefButI(block, NUM, 1, "Value: ",             (xco+10), yco-64, (width-20), 19,
2064                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2065                                          "Always return this number");
2066                         break;
2067                 case ACT_RANDOM_INT_UNIFORM:
2068                         uiDefButI(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2069                                          &randAct->int_arg_1, -1000, 1000, 0, 0,
2070                                          "Choose a number from a range. "
2071                                          "Lower boundary of the range.");
2072                         uiDefButI(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2073                                          &randAct->int_arg_2, -1000, 1000, 0, 0,
2074                                          "Choose a number from a range. "
2075                                          "Upper boundary of the range.");
2076                         break;
2077                 case ACT_RANDOM_INT_POISSON:
2078                         uiDefButF(block, NUM, 1, "Mean: ", (xco+10), yco-64, (width-20), 19,
2079                                          &randAct->float_arg_1, 0.01, 100.0, 0, 0,
2080                                          "Expected mean value of the distribution.");                                           
2081                         break;
2082                 case ACT_RANDOM_FLOAT_CONST:
2083                         uiDefButF(block, NUM, 1, "Value: ", (xco+10), yco-64, (width-20), 19,
2084                                          &randAct->float_arg_1, 0.0, 1.0, 0, 0,
2085                                          "Always return this number");
2086                         break;
2087                 case ACT_RANDOM_FLOAT_UNIFORM:
2088                         uiDefButF(block, NUM, 1, "Min: ",               (xco+10), yco-64, (width-20)/2, 19,
2089                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2090                                          "Choose a number from a range. "
2091                                          "Lower boundary of the range.");
2092                         uiDefButF(block, NUM, 1, "Max: ",               (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2093                                          &randAct->float_arg_2, -10000.0, 10000.0, 0, 0,
2094                                          "Choose a number from a range. "
2095                                          "Upper boundary of the range.");
2096                         break;
2097                 case ACT_RANDOM_FLOAT_NORMAL:
2098                         uiDefButF(block, NUM, 1, "Mean: ",              (xco+10), yco-64, (width-20)/2, 19,
2099                                          &randAct->float_arg_1, -10000.0, 10000.0, 0, 0,
2100                                          "A normal distribution. Mean of the distribution.");
2101                         uiDefButF(block, NUM, 1, "SD: ",                (xco+10) + (width-20)/2, yco-64, (width-20)/2, 19,
2102                                          &randAct->float_arg_2, 0.0, 10000.0, 0, 0,
2103                                          "A normal distribution. Standard deviation of the "
2104                                          "distribution.");
2105                         break;
2106                 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
2107                         uiDefButF(block, NUM, 1, "Half-life time: ", (xco+10), yco-64, (width-20), 19,
2108                                          &randAct->float_arg_1, 0.001, 10000.0, 0, 0,
2109                                          "Negative exponential dropoff.");
2110                         break;
2111                 default:
2112                         ; /* don't know what this distro is... can be useful for testing */
2113                         /* though :)                                                     */
2114                 }
2115
2116                 yco-= ysize;
2117                 break;
2118         case ACT_MESSAGE:
2119                 ma = act->data;
2120
2121 #define MESSAGE_SENSOR_TO_FIELD_WORKS   /* Really?  Not really.  Don't remove this ifdef yet */
2122
2123 #ifdef MESSAGE_SENSOR_TO_FIELD_WORKS
2124                 ysize = 4 + (3 * 24); /* footer + number of lines * 24 pixels/line */
2125 #else
2126                 ysize = 4 + (2 * 24); /* footer + number of lines * 24 pixels/line */
2127 #endif
2128                 glRects(xco, yco-ysize, xco+width, yco);
2129                 uiEmboss((float)xco,        (float)yco-ysize,
2130                                  (float)xco+width,  (float)yco, 1);
2131
2132                 myline=1;
2133
2134
2135 #ifdef MESSAGE_SENSOR_TO_FIELD_WORKS
2136                 /* line 1: To */
2137                 uiDefBut(block, TEX, 1, "To: ",
2138                         (xco+10), (yco-(myline++*24)), (width-20), 19,
2139                         &ma->toPropName, 0, 31, 0, 0,
2140                         "Optional send message to objects with this name only"
2141                         ", or empty to broadcast");
2142
2143 #endif
2144
2145                 /* line 2: Message Subject */
2146                 uiDefBut(block, TEX, 1, "Subject: ",
2147                 (xco+10), (yco-(myline++*24)), (width-20), 19,
2148                 &ma->subject, 0, 31, 0, 0,
2149                 "Optional message subject. This is what can be filtered on.");
2150
2151                 /* line 3: Text/Property */
2152                 uiDefButBitS(block, TOG, 1, B_REDR, "T/P",
2153                         (xco+10),(yco-(myline*24)), (0.20 * (width-20)), 19,
2154                         &ma->bodyType, 0.0, 0.0, 0, 0,
2155                         "Toggle message type: either Text or a PropertyName.");
2156
2157                 if (ma->bodyType == ACT_MESG_MESG)
2158                 {
2159                 /* line 3: Message Body */
2160                 uiDefBut(block, TEX, 1, "Body: ",
2161                 (xco+10+(0.20*(width-20))),(yco-(myline++*24)),(0.8*(width-20)),19,
2162                 &ma->body, 0, 31, 0, 0,
2163                 "Optional message body Text");
2164                 } else
2165                 {
2166                         /* line 3: Property body (set by property) */
2167                         uiDefBut(block, TEX, 1, "Propname: ",
2168                 (xco+10+(0.20*(width-20))),(yco-(myline++*24)),(0.8*(width-20)),19,
2169                         &ma->body, 0, 31, 0, 0,
2170                         "The message body will be set by the Property Value");
2171                 }
2172                 
2173                 yco -= ysize;
2174                 break;
2175         default:
2176                 ysize= 4;
2177
2178                 glRects(xco, yco-ysize, xco+width, yco);
2179                 uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
2180                 
2181                 yco-= ysize;
2182                 break;
2183         }
2184
2185         uiBlockSetEmboss(block, UI_EMBOSSM);
2186
2187         return yco-4;
2188 }
2189
2190 static void do_sensor_menu(void *arg, int event)
2191 {       
2192         ID **idar;
2193         Object *ob;
2194         bSensor *sens;
2195         short count, a;
2196         
2197         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2198         
2199         for(a=0; a<count; a++) {
2200                 ob= (Object *)idar[a];
2201                 if(event==0 || event==2) ob->scaflag |= OB_SHOWSENS;
2202                 else if(event==1) ob->scaflag &= ~OB_SHOWSENS;
2203         }
2204                 
2205         for(a=0; a<count; a++) {
2206                 ob= (Object *)idar[a];
2207                 sens= ob->sensors.first;
2208                 while(sens) {
2209                         if(event==2) sens->flag |= SENS_SHOW;
2210                         else if(event==3) sens->flag &= ~SENS_SHOW;
2211                         sens= sens->next;
2212                 }
2213         }
2214
2215         if(idar) MEM_freeN(idar);
2216         allqueue(REDRAWBUTSLOGIC, 0);
2217 }
2218
2219 static uiBlock *sensor_menu(void *arg_unused)
2220 {
2221         uiBlock *block;
2222         int yco=0;
2223         
2224         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->win);
2225         uiBlockSetButmFunc(block, do_sensor_menu, NULL);
2226         
2227         uiDefBut(block, BUTM, 1, "Show Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
2228         uiDefBut(block, BUTM, 1, "Hide Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
2229         uiDefBut(block, SEPR, 0, "",    0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2230         uiDefBut(block, BUTM, 1, "Show Sensors",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 2, "");
2231         uiDefBut(block, BUTM, 1, "Hide Sensors",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 3, "");
2232
2233         uiBlockSetDirection(block, UI_TOP);
2234         
2235         return block;
2236 }
2237
2238 static void do_controller_menu(void *arg, int event)
2239 {       
2240         ID **idar;
2241         Object *ob;
2242         bController *cont;
2243         short count, a;
2244         
2245         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2246         
2247         for(a=0; a<count; a++) {
2248                 ob= (Object *)idar[a];
2249                 if(event==0 || event==2) ob->scaflag |= OB_SHOWCONT;
2250                 else if(event==1) ob->scaflag &= ~OB_SHOWCONT;
2251         }
2252
2253         for(a=0; a<count; a++) {
2254                 ob= (Object *)idar[a];
2255                 cont= ob->controllers.first;
2256                 while(cont) {
2257                         if(event==2) cont->flag |= CONT_SHOW;
2258                         else if(event==3) cont->flag &= ~CONT_SHOW;
2259                         cont= cont->next;
2260                 }
2261         }
2262
2263         if(idar) MEM_freeN(idar);
2264         allqueue(REDRAWBUTSLOGIC, 0);
2265 }
2266
2267 static uiBlock *controller_menu(void *arg_unused)
2268 {
2269         uiBlock *block;
2270         int yco=0;
2271         
2272         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->win);
2273         uiBlockSetButmFunc(block, do_controller_menu, NULL);
2274         
2275         uiDefBut(block, BUTM, 1, "Show Objects",        0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
2276         uiDefBut(block, BUTM, 1, "Hide Objects",        0,(short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
2277         uiDefBut(block, SEPR, 0, "",                                    0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2278         uiDefBut(block, BUTM, 1, "Show Controllers",    0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 2, 2, "");
2279         uiDefBut(block, BUTM, 1, "Hide Controllers",    0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 3, 3, "");
2280
2281         uiBlockSetDirection(block, UI_TOP);
2282         
2283         return block;
2284 }
2285
2286 static void do_actuator_menu(void *arg, int event)
2287 {       
2288         ID **idar;
2289         Object *ob;
2290         bActuator *act;
2291         short count, a;
2292         
2293         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2294         
2295         for(a=0; a<count; a++) {
2296                 ob= (Object *)idar[a];
2297                 if(event==0 || event==2) ob->scaflag |= OB_SHOWACT;
2298                 else if(event==1) ob->scaflag &= ~OB_SHOWACT;
2299         }
2300
2301         for(a=0; a<count; a++) {
2302                 ob= (Object *)idar[a];
2303                 act= ob->actuators.first;
2304                 while(act) {
2305                         if(event==2) act->flag |= ACT_SHOW;
2306                         else if(event==3) act->flag &= ~ACT_SHOW;
2307                         act= act->next;
2308                 }
2309         }
2310
2311         if(idar) MEM_freeN(idar);
2312         allqueue(REDRAWBUTSLOGIC, 0);
2313 }
2314
2315 static uiBlock *actuator_menu(void *arg_unused)
2316 {
2317         uiBlock *block;
2318         int xco=0;
2319         
2320         block= uiNewBlock(&curarea->uiblocks, "filemenu", UI_EMBOSSP, UI_HELV, curarea->win);
2321         uiBlockSetButmFunc(block, do_actuator_menu, NULL);
2322         
2323         uiDefBut(block, BUTM, 1, "Show Objects",        0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
2324         uiDefBut(block, BUTM, 1, "Hide Objects",        0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
2325         uiDefBut(block, SEPR, 0, "",    0, (short)(xco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
2326         uiDefBut(block, BUTM, 1, "Show Actuators",      0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 2, "");
2327         uiDefBut(block, BUTM, 1, "Hide Actuators",      0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 3, "");
2328
2329         uiBlockSetDirection(block, UI_TOP);
2330         
2331         return block;
2332 }
2333
2334
2335 void buttons_enji(uiBlock *block, Object *ob)
2336 {
2337         uiDefButBitI(block, TOG, OB_SECTOR, B_SETSECTOR, "Sector",
2338                          10,205,65,19, &ob->gameflag, 0, 0, 0, 0, 
2339                          "All game elements should be in the Sector boundbox");
2340         uiDefButBitI(block, TOG, OB_PROP, B_SETPROP, "Prop",
2341                          75,205,65,19, &ob->gameflag, 0, 0, 0, 0, 
2342                          "An Object fixed within a sector");
2343         uiBlockSetCol(block, BUTPURPLE);
2344         uiDefButBitI(block, TOG, OB_ACTOR, B_SETACTOR, "Actor",
2345                          140,205,65,19, &ob->gameflag, 0, 0, 0, 0, 
2346                          "Objects that are evaluated by the engine ");
2347         if(ob->gameflag & OB_ACTOR) {   
2348                 uiDefButBitI(block, TOG, OB_DYNAMIC, B_SETDYNA, "Dynamic",
2349                                  205,205,75,19, &ob->gameflag, 0, 0, 0, 0, 
2350                                  "Motion defined by laws of physics");
2351                 uiDefButBitI(block, TOG, OB_MAINACTOR, B_SETMAINACTOR, "MainActor",
2352                                  280,205,70,19, &ob->gameflag, 0, 0, 0, 0, "");
2353                 
2354                 if(ob->gameflag & OB_DYNAMIC) {
2355                         uiDefButBitI(block, TOG, OB_DO_FH, B_DIFF, "Do Fh",
2356                                          10,185,50,19, &ob->gameflag, 0, 0, 0, 0, 
2357                                          "Use Fh settings in Materials");
2358                         uiDefButBitI(block, TOG, OB_ROT_FH, B_DIFF, "Rot Fh",
2359                                          60,185,50,19, &ob->gameflag, 0, 0, 0, 0, 
2360                                          "Use face normal to rotate Object");
2361                 
2362                         uiBlockSetCol(block, BUTGREY);
2363                         uiDefButF(block, NUM, B_DIFF, "Mass:",
2364                                          110, 185, 120, 19, &ob->mass, 0.01, 100.0, 10, 0, 
2365                                          "The mass of the Object");
2366                         uiDefButF(block, NUM, REDRAWVIEW3D, "Size:",
2367                                          230, 185, 120, 19, &ob->inertia, 0.01, 10.0, 10, 0, 
2368                                          "Bounding sphere size");
2369                         uiDefButF(block, NUM, B_DIFF, "Damp:",
2370                                          10, 165, 100, 19, &ob->damping, 0.0, 1.0, 10, 0, 
2371                                          "General movement damping");
2372                         uiDefButF(block, NUM, B_DIFF, "RotDamp:",
2373                                          110, 165, 120, 19, &ob->rdamping, 0.0, 1.0, 10, 0, 
2374                                          "General rotation damping");
2375                 }
2376         }
2377
2378 }
2379
2380 void buttons_ketsji(uiBlock *block, Object *ob)
2381 {
2382         uiDefButBitI(block, TOG, OB_ACTOR, B_REDR, "Actor",
2383                           10,205,55,19, &ob->gameflag, 0, 0, 0, 0,
2384                           "Objects that are evaluated by the engine ");
2385         if(ob->gameflag & OB_ACTOR) {   
2386                 uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", 65,205,55,19, 
2387                                   &ob->gameflag, 0, 0, 0, 0, 
2388                                   "Objects that don't restitute collisions (like a ghost)");
2389                 uiDefButBitI(block, TOG, OB_DYNAMIC, B_REDR, "Dynamic", 120,205,70,19, 
2390                                   &ob->gameflag, 0, 0, 0, 0, 
2391                                   "Motion defined by laws of physics");
2392         
2393                 if(ob->gameflag & OB_DYNAMIC) {
2394                         uiDefButBitI(block, TOG, OB_RIGID_BODY, B_REDR, "Rigid Body", 190,205,80,19, 
2395                                           &ob->gameflag, 0, 0, 0, 0, 
2396                                           "Enable rolling physics");
2397                         uiDefButBitI(block, TOG, OB_COLLISION_RESPONSE, B_REDR, "No sleeping", 270,205,80,19, 
2398                                           &ob->gameflag, 0, 0, 0, 0, 
2399                                           "Disable auto (de)activation");
2400
2401                         uiDefButBitI(block, TOG, OB_DO_FH, B_DIFF, "Do Fh", 10,185,50,19, 
2402                                           &ob->gameflag, 0, 0, 0, 0, 
2403                                           "Use Fh settings in Materials");
2404                         uiDefButBitI(block, TOG, OB_ROT_FH, B_DIFF, "Rot Fh", 60,185,50,19, 
2405                                           &ob->gameflag, 0, 0, 0, 0, 
2406                                           "Use face normal to rotate Object");
2407                         uiDefButF(block, NUM, B_DIFF, "Mass:", 110, 185, 80, 19, 
2408                                           &ob->mass, 0.01, 10000.0, 10, 0, 
2409                                           "The mass of the Object");
2410                         uiDefButF(block, NUM, REDRAWVIEW3D, "Radius:", 190, 185, 80, 19, 
2411                                           &ob->inertia, 0.01, 10.0, 10, 0, 
2412                                           "Bounding sphere radius");
2413                         uiDefButF(block, NUM, B_DIFF, "Form:", 270, 185, 80, 19, 
2414                                           &ob->formfactor, 0.01, 100.0, 10, 0, 
2415                                           "Form factor");
2416
2417                         uiDefButF(block, NUM, B_DIFF, "Damp:", 10, 165, 100, 19, 
2418                                           &ob->damping, 0.0, 1.0, 10, 0, 
2419                                           "General movement damping");
2420                         uiDefButF(block, NUM, B_DIFF, "RotDamp:", 110, 165, 120, 19, 
2421                                           &ob->rdamping, 0.0, 1.0, 10, 0, 
2422                                           "General rotation damping");
2423                         uiDefButBitI(block, TOG, OB_ANISOTROPIC_FRICTION, B_REDR, "Anisotropic", 
2424                                           230, 165, 120, 19,
2425                                           &ob->gameflag, 0.0, 1.0, 10, 0,
2426                                           "Enable anisotropic friction");                       
2427                 }
2428
2429                 if (ob->gameflag & OB_ANISOTROPIC_FRICTION) {
2430                         uiDefButF(block, NUM, B_DIFF, "x friction:", 10, 145, 114, 19,
2431                                           &ob->anisotropicFriction[0], 0.0, 1.0, 10, 0,
2432                                           "Relative friction coefficient in the x-direction.");
2433                         uiDefButF(block, NUM, B_DIFF, "y friction:", 124, 145, 113, 19,
2434                                           &ob->anisotropicFriction[1], 0.0, 1.0, 10, 0,
2435                                           "Relative friction coefficient in the y-direction.");
2436                         uiDefButF(block, NUM, B_DIFF, "z friction:", 237, 145, 113, 19,
2437                                           &ob->anisotropicFriction[2], 0.0, 1.0, 10, 0,
2438                                           "Relative friction coefficient in the z-direction.");
2439                 }
2440         }
2441
2442         if (!(ob->gameflag & OB_GHOST)) {
2443                 uiBlockBeginAlign(block);
2444                 uiDefButBitI(block, TOG, OB_BOUNDS, B_REDR, "Bounds", 10, 125, 75, 19,
2445                                 &ob->gameflag, 0, 0,0, 0,
2446                                 "Specify a bounds object for physics");
2447                 if (ob->gameflag & OB_BOUNDS) {
2448                         uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Convex Hull Polytope%x5|Static TriangleMesh %x4",
2449                                 85, 125, 160, 19, &ob->boundtype, 0, 0, 0, 0, "Selects the collision type");
2450                         uiDefButBitI(block, TOG, OB_CHILD, B_REDR, "Compound", 250,125,100,19, 
2451                                           &ob->gameflag, 0, 0, 0, 0, 
2452                                           "Add Children");
2453                 }
2454                 uiBlockEndAlign(block);
2455         }
2456 }
2457
2458 void buttons_bullet(uiBlock *block, Object *ob)
2459 {
2460         uiBlockBeginAlign(block);
2461         uiDefButBitI(block, TOG, OB_ACTOR, B_REDR, "Actor",
2462                           10,205,55,19, &ob->gameflag, 0, 0, 0, 0,
2463                           "Objects that are evaluated by the engine ");
2464         if(ob->gameflag & OB_ACTOR) {   
2465                 uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", 65,205,55,19, 
2466                                   &ob->gameflag, 0, 0, 0, 0, 
2467                                   "Objects that don't restitute collisions (like a ghost)");
2468                 uiDefButBitI(block, TOG, OB_DYNAMIC, B_REDR, "Dynamic", 120,205,70,19, 
2469                                   &ob->gameflag, 0, 0, 0, 0, 
2470                                   "Motion defined by laws of physics");
2471         
2472                 if(ob->gameflag & OB_DYNAMIC) {
2473                         uiDefButBitI(block, TOG, OB_RIGID_BODY, B_REDR, "Rigid Body", 190,205,80,19, 
2474                                           &ob->gameflag, 0, 0, 0, 0, 
2475                                           "Enable rolling physics");
2476                         uiDefButBitI(block, TOG, OB_COLLISION_RESPONSE, B_REDR, "No sleeping", 270,205,80,19, 
2477                                           &ob->gameflag, 0, 0, 0, 0, 
2478                                           "Disable auto (de)activation");
2479
2480                         uiDefButF(block, NUM, B_DIFF, "Mass:", 10, 185, 170, 19, 
2481                                           &ob->mass, 0.01, 10000.0, 10, 2, 
2482                                           "The mass of the Object");
2483                         uiDefButF(block, NUM, REDRAWVIEW3D, "Radius:", 180, 185, 170, 19, 
2484                                           &ob->inertia, 0.01, 10.0, 10, 2, 
2485                                           "Bounding sphere radius");
2486
2487                         uiDefButF(block, NUMSLI, B_DIFF, "Damp ", 10, 165, 150, 19, 
2488                                           &ob->damping, 0.0, 1.0, 10, 0, 
2489                                           "General movement damping");
2490                         uiDefButF(block, NUMSLI, B_DIFF, "RotDamp ", 160, 165, 190, 19, 
2491                                           &ob->rdamping, 0.0, 1.0, 10, 0, 
2492                                           "General rotation damping");
2493                 }
2494         }
2495         uiBlockEndAlign(block);
2496
2497         uiBlockBeginAlign(block);
2498         uiDefButBitI(block, TOG, OB_BOUNDS, B_REDR, "Bounds", 10, 125, 75, 19,
2499                      &ob->gameflag, 0, 0,0, 0,
2500                      "Specify a bounds object for physics");
2501         if (ob->gameflag & OB_BOUNDS) {
2502                 uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Convex Hull Polytope%x5|Static TriangleMesh %x4",
2503                   //almost ready to enable this one:                    uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Convex Hull Polytope%x5|Static TriangleMesh %x4|Dynamic Mesh %x5|",
2504                           85, 125, 160, 19, &ob->boundtype, 0, 0, 0, 0, "Selects the collision type");
2505                 uiDefButBitI(block, TOG, OB_CHILD, B_REDR, "Compound", 250,125,100,19, 
2506                              &ob->gameflag, 0, 0, 0, 0, 
2507                              "Add Children");
2508         }
2509         uiBlockEndAlign(block);
2510 }
2511
2512 /* never used, see CVS 1.134 for the code */
2513 /*  static FreeCamera *new_freecamera(void) */
2514
2515 /* never used, see CVS 1.120 for the code */
2516 /*  static uiBlock *freecamera_menu(void) */
2517
2518
2519 void logic_buts(void)
2520 {
2521         ID **idar;
2522         Object *ob;
2523         bProperty *prop;
2524         bSensor *sens;
2525         bController *cont;
2526         bActuator *act;
2527         uiBlock *block;
2528         uiBut *but;
2529         World *wrld;
2530         int a;
2531         short xco, yco, count, width, ycoo;
2532         char *pupstr, name[32];
2533
2534         wrld= G.scene->world;
2535
2536         ob= OBACT;
2537
2538         if(ob==0) return;
2539         uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2540
2541         sprintf(name, "buttonswin %d", curarea->win);
2542         block= uiNewBlock(&curarea->uiblocks, name, UI_EMBOSS, UI_HELV, curarea->win);
2543         
2544         uiBlockSetCol(block, TH_BUT_SETTING2);
2545
2546         if(wrld) {
2547                 switch(wrld->physicsEngine) {
2548                 case WOPHY_ENJI:
2549                         buttons_enji(block, ob);
2550                         break;
2551                 case WOPHY_BULLET:
2552                         buttons_bullet(block, ob);
2553                         break;
2554                 default:
2555                         buttons_ketsji(block, ob);
2556                         break;
2557                 }
2558         }
2559         else buttons_ketsji(block, ob);
2560         
2561         uiBlockSetCol(block, TH_AUTO);
2562         uiBlockBeginAlign(block);
2563         uiDefBut(block, BUT, B_ADD_PROP, "Add Property",                10, 90, 340, 24,
2564                          NULL, 0.0, 100.0, 100, 0,
2565                          "");
2566         
2567         pupstr= "Types %t|Bool %x0|Int %x1|Float %x2|String %x3|Timer %x5";
2568         
2569         a= 0;
2570         prop= ob->prop.first;
2571         while(prop) {
2572                 but= uiDefBut(block, BUT, 1, "Del",             10, (short)(70-20*a), 40, 20, NULL, 0.0, 0.0, 1, (float)a, "");
2573                 uiButSetFunc(but, del_property, prop, NULL);
2574                 uiDefButS(block, MENU, B_CHANGE_PROP, pupstr,           50, (short)(70-20*a), 60, 20, &prop->type, 0, 0, 0, 0, "");
2575                 but= uiDefBut(block, TEX, 1, "Name:",                                   110, (short)(70-20*a), 110, 20, prop->name, 0, 31, 0, 0, "");
2576                 uiButSetFunc(but, make_unique_prop_names_cb, prop->name, (void*) 1);
2577                 
2578                 if(prop->type==PROP_BOOL) {
2579                         uiDefButBitI(block, TOG, 1, B_REDR, "True",             220, (short)(70-20*a), 55, 20, &prop->data, 0, 0, 0, 0, "");
2580                         uiDefButBitI(block, TOGN, 1, B_REDR, "False",   270, (short)(70-20*a), 55, 20, &prop->data, 0, 0, 0, 0, "");
2581                 }
2582                 else if(prop->type==PROP_INT) 
2583                         uiDefButI(block, NUM, B_REDR, "",                       220, (short)(70-20*a), 110, 20, &prop->data, -10000, 10000, 0, 0, "");
2584                 else if(prop->type==PROP_FLOAT) 
2585                         uiDefButF(block, NUM, B_REDR, "",                       220, (short)(70-20*a), 110, 20, (float*) &prop->data, -10000, 10000, 100, 3, "");
2586                 else if(prop->type==PROP_STRING) 
2587                         uiDefBut(block, TEX, B_REDR, "",                                220, (short)(70-20*a), 110, 20, prop->poin, 0, 127, 0, 0, "");
2588                 else if(prop->type==PROP_TIME) 
2589                         uiDefButF(block, NUM, B_REDR, "",                       220, (short)(70-20*a), 110, 20, (float*) &prop->data, -10000, 10000, 100, 3, "");
2590                 
2591                 uiDefButBitS(block, TOG, PROP_DEBUG, B_REDR, "D",               330, (short)(70-20*a), 20, 20, &prop->flag, 0, 0, 0, 0, "Print Debug info");
2592                 
2593                 a++;
2594                 prop= prop->next;
2595                 
2596         }
2597         uiBlockEndAlign(block);
2598
2599         uiClearButLock();
2600
2601         idar= get_selected_and_linked_obs(&count, G.buts->scaflag);
2602         
2603         /* ******************************* */
2604         xco= 375; yco= 170; width= 230;
2605
2606         uiBlockSetEmboss(block, UI_EMBOSSP);
2607         uiDefBlockBut(block, sensor_menu, NULL, "Sensors", xco-10, yco+35, 80, 19, "");
2608         uiBlockSetEmboss(block, UI_EMBOSS);
2609         
2610         uiBlockBeginAlign(block);
2611         uiDefButBitS(block, TOG, BUTS_SENS_SEL, B_REDR, "Sel", xco+110, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show all selected Objects");
2612         uiDefButBitS(block, TOG, BUTS_SENS_ACT, B_REDR, "Act", xco+110+(width-100)/3, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show active Object");
2613         uiDefButBitS(block, TOG, BUTS_SENS_LINK, B_REDR, "Link", xco+110+2*(width-100)/3, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show linked Objects to Controller");
2614         uiBlockEndAlign(block);
2615         
2616         for(a=0; a<count; a++) {
2617                 ob= (Object *)idar[a];
2618                 uiClearButLock();
2619                 uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2620                 
2621                 if( (ob->scavisflag & OB_VIS_SENS) == 0) continue;
2622                 
2623                 /* presume it is only objects for now */
2624                 uiBlockSetEmboss(block, UI_EMBOSS);
2625                 uiBlockBeginAlign(block);
2626                 if(ob->sensors.first) uiSetCurFont(block, UI_HELVB);
2627                 uiDefButBitS(block, TOG, OB_SHOWSENS, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), 19, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide sensors");
2628                 if(ob->sensors.first) uiSetCurFont(block, UI_HELV);
2629                 uiDefButBitS(block, TOG, OB_ADDSENS, B_ADD_SENS, "Add",(short)(xco+width-40), yco, 50, 19, &ob->scaflag, 0, 0, 0, 0, "Add a new Sensor");
2630                 uiBlockEndAlign(block);
2631                 yco-=20;
2632                 
2633                 if(ob->scaflag & OB_SHOWSENS) {
2634                         
2635                         sens= ob->sensors.first;
2636                         while(sens) {
2637                                 uiBlockSetEmboss(block, UI_EMBOSSM);
2638                                 uiDefIconButBitS(block, TOG, SENS_DEL, B_DEL_SENS, ICON_X,      xco, yco, 22, 19, &sens->flag, 0, 0, 0, 0, "Delete Sensor");
2639                                 uiDefIconButBitS(block, ICONTOG, SENS_SHOW, B_REDR, ICON_RIGHTARROW, (short)(xco+width-22), yco, 22, 19, &sens->flag, 0, 0, 0, 0, "Sensor settings");
2640
2641                                 ycoo= yco;
2642                                 if(sens->flag & SENS_SHOW)
2643                                 {
2644                                         uiDefButS(block, MENU, B_CHANGE_SENS, sensor_pup(),     (short)(xco+22), yco, 100, 19, &sens->type, 0, 0, 0, 0, "Sensor type");
2645                                         but= uiDefBut(block, TEX, 1, "", (short)(xco+122), yco, (short)(width-144), 19, sens->name, 0, 31, 0, 0, "Sensor name");
2646                                         uiButSetFunc(but, make_unique_prop_names_cb, sens->name, (void*) 0);
2647
2648                                         sens->otype= sens->type;
2649                                         yco= draw_sensorbuttons(sens, block, xco, yco, width,ob->id.name);
2650                                         if(yco-6 < ycoo) ycoo= (yco+ycoo-20)/2;
2651                                 }
2652                                 else {
2653                                         set_col_sensor(sens->type, 1);
2654                                         glRecti(xco+22, yco, xco+width-22,yco+19);
2655                                         but= uiDefBut(block, LABEL, 0, sensor_name(sens->type), (short)(xco+22), yco, 100, 19, sens, 0, 0, 0, 0, "");
2656                                         uiButSetFunc(but, sca_move_sensor, sens, NULL);
2657                                         but= uiDefBut(block, LABEL, 0, sens->name, (short)(xco+122), yco, (short)(width-144), 19, sens, 0, 31, 0, 0, "");
2658                                         uiButSetFunc(but, sca_move_sensor, sens, NULL);
2659                                 }
2660
2661                                 but= uiDefIconBut(block, LINK, 0, ICON_LINK,    (short)(xco+width), ycoo, 19, 19, NULL, 0, 0, 0, 0, "");
2662                                 uiSetButLink(but, NULL, (void ***)&(sens->links), &sens->totlinks, LINK_SENSOR, LINK_CONTROLLER);
2663
2664                                 yco-=20;
2665
2666                                 sens= sens->next;
2667                         }
2668                         yco-= 6;
2669                 }
2670         }
2671
2672         /* ******************************* */
2673         xco= 675; yco= 170; width= 230;
2674
2675         uiBlockSetEmboss(block, UI_EMBOSSP);
2676         uiDefBlockBut(block, controller_menu, NULL, "Controllers", xco-10, yco+35, 100, 19, "");
2677         uiBlockSetEmboss(block, UI_EMBOSS);
2678         
2679         uiBlockBeginAlign(block);
2680         uiDefButBitS(block, TOG, BUTS_CONT_SEL,  B_REDR, "Sel", xco+110, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show all selected Objects");
2681         uiDefButBitS(block, TOG, BUTS_CONT_ACT, B_REDR, "Act", xco+110+(width-100)/3, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show active Object");
2682         uiDefButBitS(block, TOG, BUTS_CONT_LINK, B_REDR, "Link", xco+110+2*(width-100)/3, yco+35, (width-100)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show linked Objects to Sensor/Actuator");
2683         uiBlockEndAlign(block);
2684         
2685         ob= OBACT;
2686         
2687         for(a=0; a<count; a++) {
2688                 ob= (Object *)idar[a];
2689                 uiClearButLock();
2690                 uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2691                 if( (ob->scavisflag & OB_VIS_CONT) == 0) continue;
2692
2693                 /* presume it is only objects for now */
2694                 uiBlockSetEmboss(block, UI_EMBOSS);
2695                 uiBlockBeginAlign(block);
2696                 if(ob->controllers.first) uiSetCurFont(block, UI_HELVB);
2697                 uiDefButBitS(block, TOG, OB_SHOWCONT, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), 19, &ob->scaflag, 0, 0, 0, 0, "Active Object name");
2698                 if(ob->controllers.first) uiSetCurFont(block, UI_HELV);
2699                 uiDefButBitS(block, TOG, OB_ADDCONT, B_ADD_CONT, "Add",(short)(xco+width-40), yco, 50, 19, &ob->scaflag, 0, 0, 0, 0, "Add a new Controller");
2700                 uiBlockEndAlign(block);
2701                 yco-=20;
2702                 
2703                 if(ob->scaflag & OB_SHOWCONT) {
2704                 
2705                         cont= ob->controllers.first;
2706                         while(cont) {
2707                                 uiBlockSetEmboss(block, UI_EMBOSSM);
2708                                 uiDefIconButBitS(block, TOG, CONT_DEL, B_DEL_CONT, ICON_X,      xco, yco, 22, 19, &cont->flag, 0, 0, 0, 0, "Delete Controller");
2709                                 uiDefIconButBitS(block, ICONTOG, CONT_SHOW, B_REDR, ICON_RIGHTARROW, (short)(xco+width-22), yco, 22, 19, &cont->flag, 0, 0, 0, 0, "Controller settings");
2710                 
2711                                 if(cont->flag & CONT_SHOW) {
2712                                         cont->otype= cont->type;
2713                                         uiDefButS(block, MENU, B_CHANGE_CONT, controller_pup(),(short)(xco+22), yco, 100, 19, &cont->type, 0, 0, 0, 0, "Controller type");
2714                                         but= uiDefBut(block, TEX, 1, "", (short)(xco+122), yco, (short)(width-144), 19, cont->name, 0, 31, 0, 0, "Controller name");
2715                                         uiButSetFunc(but, make_unique_prop_names_cb, cont->name, (void*) 0);
2716                 
2717                                         ycoo= yco;
2718                                         yco= draw_controllerbuttons(cont, block, xco, yco, width);
2719                                         if(yco-6 < ycoo) ycoo= (yco+ycoo-20)/2;
2720                                 }
2721                                 else {
2722                                         cpack(0x999999);
2723                                         glRecti(xco+22, yco, xco+width-22,yco+19);
2724                                         but= uiDefBut(block, LABEL, 0, controller_name(cont->type), (short)(xco+22), yco, 100, 19, cont, 0, 0, 0, 0, "Controller type");
2725                                         uiButSetFunc(but, sca_move_controller, cont, NULL);
2726                                         but= uiDefBut(block, LABEL, 0, cont->name,(short)(xco+122), yco,(short)(width-144), 19, cont, 0, 0, 0, 0, "Controller name");
2727                                         uiButSetFunc(but, sca_move_controller, cont, NULL);
2728                                         ycoo= yco;
2729                                 }
2730                 
2731                                 but= uiDefIconBut(block, LINK, 0, ICON_LINK,    (short)(xco+width), ycoo, 19, 19, NULL, 0, 0, 0, 0, "");
2732                                 uiSetButLink(but, NULL, (void ***)&(cont->links), &cont->totlinks, LINK_CONTROLLER, LINK_ACTUATOR);
2733                 
2734                                 uiDefIconBut(block, INLINK, 0, ICON_INLINK,(short)(xco-19), ycoo, 19, 19, cont, LINK_CONTROLLER, 0, 0, 0, "");
2735                 
2736                                 yco-=20;
2737                                 
2738                                 cont= cont->next;
2739                         }
2740                         yco-= 6;
2741                 }
2742         }
2743         
2744         /* ******************************* */
2745         xco= 985; yco= 170; width= 280;
2746         
2747         uiBlockSetEmboss(block, UI_EMBOSSP);
2748         uiDefBlockBut(block, actuator_menu, NULL, "Actuators", xco-10, yco+35, 100, 19, "");
2749         uiBlockSetEmboss(block, UI_EMBOSS);
2750         uiBlockBeginAlign(block);
2751         uiDefButBitS(block, TOG, BUTS_ACT_SEL, B_REDR, "Sel", xco+110, yco+35, (width-110)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show all selected Objects");
2752         uiDefButBitS(block, TOG, BUTS_ACT_ACT, B_REDR, "Act", xco+110+(width-110)/3, yco+35, (width-110)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show active Object");
2753         uiDefButBitS(block, TOG, BUTS_ACT_LINK, B_REDR, "Link", xco+110+2*(width-110)/3, yco+35, (width-110)/3, 19, &G.buts->scaflag, 0, 0, 0, 0, "Show linked Objects to Controller");
2754         uiBlockEndAlign(block);
2755         for(a=0; a<count; a++) {
2756                 ob= (Object *)idar[a];
2757                 uiClearButLock();
2758                 uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2759                 if( (ob->scavisflag & OB_VIS_ACT) == 0) continue;
2760
2761                 /* presume it is only objects for now */
2762                 uiBlockSetEmboss(block, UI_EMBOSS);
2763                 uiBlockBeginAlign(block);
2764                 if(ob->actuators.first) uiSetCurFont(block, UI_HELVB);
2765                 uiDefButBitS(block, TOG, OB_SHOWACT, B_REDR, ob->id.name+2,(short)(xco-10), yco,(short)(width-30), 19, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide actuators");
2766                 if(ob->actuators.first) uiSetCurFont(block, UI_HELV);
2767                 uiDefButBitS(block, TOG, OB_ADDACT, B_ADD_ACT, "Add",(short)(xco+width-40), yco, 50, 19, &ob->scaflag, 0, 0, 0, 0, "Add a new Actuator");
2768                 uiBlockEndAlign(block);
2769                 yco-=20;
2770                 
2771                 if(ob->scaflag & OB_SHOWACT) {
2772                         
2773                         act= ob->actuators.first;
2774                         while(act) {
2775                                 uiBlockSetEmboss(block, UI_EMBOSSM);
2776                                 uiDefIconButBitS(block, TOG, ACT_DEL, B_DEL_ACT, ICON_X,        xco, yco, 22, 19, &act->flag, 0, 0, 0, 0, "Delete Actuator");
2777                                 uiDefIconButBitS(block, ICONTOG, ACT_SHOW, B_REDR, ICON_RIGHTARROW, (short)(xco+width-22), yco, 22, 19, &act->flag, 0, 0, 0, 0, "Actuator settings"