Logic Editor UI work
authorMatt Ebb <matt@mke3.net>
Wed, 5 May 2010 00:12:31 +0000 (00:12 +0000)
committerMatt Ebb <matt@mke3.net>
Wed, 5 May 2010 00:12:31 +0000 (00:12 +0000)
* Re-structured code (can delete the old function entirely when this is done)
* Fixed links/inlinks
* Fixed some bugs in add and remove controller/actuator
* Cleaned up some ui layouts
* Use key event types in keyboard sensor
* Implemented object controller 'state' in RNA/layout engine (still needs tweaks)

source/blender/editors/space_logic/logic_ops.c
source/blender/editors/space_logic/logic_window.c
source/blender/makesdna/DNA_object_types.h
source/blender/makesdna/DNA_space_types.h
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_sensor.c
source/blender/makesrna/intern/rna_space.c

index 669af07e16cae8fc4c19ac6fe5f7f2d4799769d5..ee65068e5375a533a93038abe550dfab3b816f4f 100644 (file)
@@ -306,6 +306,7 @@ static int controller_remove_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        
        BLI_remlink(&(ob->controllers), cont);
+       unlink_controller(cont);
        free_controller(cont);
        
        WM_event_add_notifier(C, NC_LOGIC, NULL);
@@ -344,12 +345,27 @@ static int controller_add_exec(bContext *C, wmOperator *op)
        Object *ob = ED_object_active_context(C);
        bController *cont;
        int type= RNA_enum_get(op->ptr, "type");
-
+       int bit;
+       
        cont= new_controller(type);
        BLI_addtail(&(ob->controllers), cont);
        make_unique_prop_names(C, cont->name);
+       
+       /* set the controller state mask from the current object state.
+        A controller is always in a single state, so select the lowest bit set
+        from the object state */
+       for (bit=0; bit<OB_MAX_STATES; bit++) {
+               if (ob->state & (1<<bit))
+                       break;
+       }
+       cont->state_mask = (1<<bit);
+       if (cont->state_mask == 0) {
+               /* shouldn't happen, object state is never 0 */
+               cont->state_mask = 1;
+       }
+       
        ob->scaflag |= OB_SHOWCONT;
-
+       
        WM_event_add_notifier(C, NC_LOGIC, NULL);
        
        return OPERATOR_FINISHED;
@@ -390,6 +406,7 @@ static int actuator_remove_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        
        BLI_remlink(&(ob->actuators), act);
+       unlink_actuator(act);
        free_actuator(act);
        
        WM_event_add_notifier(C, NC_LOGIC, NULL);
@@ -432,7 +449,7 @@ static int actuator_add_exec(bContext *C, wmOperator *op)
        act= new_actuator(type);
        BLI_addtail(&(ob->actuators), act);
        make_unique_prop_names(C, act->name);
-       ob->scaflag |= OB_SHOWCONT;
+       ob->scaflag |= OB_SHOWACT;
 
        WM_event_add_notifier(C, NC_LOGIC, NULL);
        
index 54ace5ef8ba4efad35a278e14dec3a7fec449619..5f77e5715100961f5c786a1995ed9949e0621d10 100644 (file)
@@ -3187,21 +3187,22 @@ static void draw_sensor_header(uiLayout *layout, PointerRNA *ptr)
 
 static void draw_sensor_internal_header(uiLayout *layout, PointerRNA *ptr)
 {
-       uiLayout *box, *row;
+       uiLayout *box, *split, *row;
 
        box= uiLayoutBox(layout);
-       row= uiLayoutRow(box, 0);
-
-       if (!RNA_boolean_get(ptr, "expanded"))
-               return;
-
-       row= uiLayoutRow(box, 0);
+       split = uiLayoutSplit(box, 0.45, 0);
+       
+       row= uiLayoutRow(split, 1);
        uiItemR(row, ptr, "pulse_true_level", 0, "", ICON_DOTSUP);
        uiItemR(row, ptr, "pulse_false_level", 0, "", ICON_DOTSDOWN);
-       uiItemR(row, ptr, "frequency", 0, "", 0);
-       uiItemR(row, ptr, "level", 0, "", 0);
-       uiItemR(row, ptr, "tap", 0, "", 0);
-       uiItemR(row, ptr, "invert", 0, "", 0);
+       uiItemR(row, ptr, "frequency", 0, "Freq", 0);
+       
+       row= uiLayoutRow(split, 1);
+       uiItemR(row, ptr, "level", UI_ITEM_R_TOGGLE, NULL, 0);
+       uiItemR(row, ptr, "tap", UI_ITEM_R_TOGGLE, NULL, 0);
+       
+       row= uiLayoutRow(split, 1);
+       uiItemR(row, ptr, "invert", UI_ITEM_R_TOGGLE, "Invert", 0);
 }
 /* sensors in alphabetical order */
 
@@ -3290,10 +3291,21 @@ static void draw_sensor_joystick(uiLayout *layout, PointerRNA *ptr)
 
 static void draw_sensor_keyboard(uiLayout *layout, PointerRNA *ptr)
 {
-       uiItemR(layout, ptr, "key", 0, NULL, 0);
+       uiLayout *row;
+       
+       row = uiLayoutRow(layout, 0);
+       uiItemL(row, "Key:", 0);
+       uiItemR(row, ptr, "key", UI_ITEM_R_EVENT, "", 0);
        uiItemR(layout, ptr, "all_keys", 0, NULL, 0);
-       uiItemR(layout, ptr, "modifier_key", 0, NULL, 0);
-       uiItemR(layout, ptr, "second_modifier_key", 0, NULL, 0);
+       
+       row = uiLayoutRow(layout, 0);
+       uiItemL(row, "First Modifier:", 0);
+       uiItemR(row, ptr, "modifier_key", UI_ITEM_R_EVENT, "", 0);
+       
+       row = uiLayoutRow(layout, 0);
+       uiItemL(row, "Second Modifier:", 0);
+       uiItemR(row, ptr, "second_modifier_key", UI_ITEM_R_EVENT, "", 0);
+       
        uiItemR(layout, ptr, "target", 0, NULL, 0);
        uiItemR(layout, ptr, "log", 0, NULL, 0);
 
@@ -3387,11 +3399,11 @@ void draw_brick_sensor(uiLayout *layout, PointerRNA *ptr)
        
        if (!RNA_boolean_get(ptr, "expanded"))
                return;
+
+       draw_sensor_internal_header(layout, ptr);
        
        box = uiLayoutBox(layout);
 
-       draw_sensor_internal_header(box, ptr);
-       
        switch (RNA_enum_get(ptr, "type")) {
 
                case SENS_ACTUATOR:
@@ -3850,42 +3862,38 @@ void draw_brick_actuator(uiLayout *layout, PointerRNA *ptr)
        }
 }
 
-void logic_buttons(bContext *C, ARegion *ar)
+static void logic_buttons_new(bContext *C, ARegion *ar)
 {
        SpaceLogic *slogic= CTX_wm_space_logic(C);
        Object *ob= CTX_data_active_object(C);
        ID **idar;
-       bSensor *sens;
-       bController *cont;
-       bActuator *act;
+       
+       PointerRNA logic_ptr;
+       
+       uiLayout *layout, *row;
        uiBlock *block;
        uiBut *but;
-       uiLayout *layout, *row;
-       PointerRNA logic_ptr;
-       int a, iact, stbit, offset;
-       int xco, yco, width, ycoo;
-       short count;
        char name[32];
-       /* pin is a bool used for actuator and sensor drawing with states
-        * pin so changing states dosnt hide the logic brick */
-       char pin;
-
+       short a, count;
+       int xco, yco, width;
+       
        if(ob==NULL) return;
-//     uiSetButLock(object_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
-
+       
+       RNA_pointer_create(NULL, &RNA_SpaceLogicEditor, slogic, &logic_ptr);
+       idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
+       
        sprintf(name, "buttonswin %p", ar);
        block= uiBeginBlock(C, ar, name, UI_EMBOSS);
        uiBlockSetHandleFunc(block, do_logic_buts, NULL);
-
-       RNA_pointer_create(NULL, &RNA_SpaceLogicEditor, slogic, &logic_ptr);
        
-       idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
-
        /* clean ACT_LINKED and ACT_VISIBLE of all potentially visible actuators so that 
-          we can determine which is actually linked/visible */
+        we can determine which is actually linked/visible */
        for(a=0; a<count; a++) {
+               bActuator *act;
+               bSensor *sens;
                ob= (Object *)idar[a];
-               act= ob->actuators.first;
+               
+               act = ob->actuators.first;
                while(act) {
                        act->flag &= ~(ACT_LINKED|ACT_VISIBLE);
                        act = act->next;
@@ -3897,14 +3905,10 @@ void logic_buttons(bContext *C, ARegion *ar)
                        sens = sens->next;
                }
        }
-               
-       /* start with the controller because we need to know which one is visible */
-       /* ******************************* */
-       xco= 400; yco= 170; width= 300;
-
-
-       if (G.rt >0) { // new UI code to replace old one
        
+       /* ****************** Controllers ****************** */
+       
+       xco= 420; yco= 170; width= 300;
        layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, U.uistyles.first);
        row = uiLayoutRow(layout, 1);
        
@@ -3914,60 +3918,35 @@ void logic_buttons(bContext *C, ARegion *ar)
        uiItemR(row, &logic_ptr, "controllers_show_active_objects", 0, "Act", 0);
        uiItemR(row, &logic_ptr, "controllers_show_linked_controller", 0, "Link", 0);
 
-
-
-       /* State part - ugly */
-       if(ob->scaflag & OB_SHOWCONT) {
-               unsigned int controller_state_mask = 0; /* store a bitmask for states that are used */
-
-               /* first show the state */
-               uiDefBlockBut(block, object_state_mask_menu, ob, "State", (short)(xco-10), (short)(yco-10), 36, UI_UNIT_Y, "Object state menu: store and retrieve initial state");
-
-               if (!ob->state)
-                       ob->state = 1;
-               for (offset=0; offset<15; offset+=5) {
-                       uiBlockBeginAlign(block);
-                       for (stbit=0; stbit<5; stbit++) {
-                               but = uiDefButBitI(block, controller_state_mask&(1<<(stbit+offset)) ? BUT_TOGDUAL:TOG, 1<<(stbit+offset), stbit+offset, "",     (short)(xco+31+12*stbit+13*offset), yco, 12, 12, (int *)&(ob->state), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+offset)));
-                               uiButSetFunc(but, check_state_mask, but, &(ob->state));
-                       }
-                       for (stbit=0; stbit<5; stbit++) {
-                               but = uiDefButBitI(block, controller_state_mask&(1<<(stbit+offset+15)) ? BUT_TOGDUAL:TOG, 1<<(stbit+offset+15), stbit+offset+15, "",    (short)(xco+31+12*stbit+13*offset), yco-12, 12, 12, (int *)&(ob->state), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+offset+15)));
-                               uiButSetFunc(but, check_state_mask, but, &(ob->state));
-                       }
-               }
+       {
+               PointerRNA settings_ptr;
+               row = uiLayoutRow(layout, 0);
+               RNA_pointer_create(NULL, &RNA_GameObjectSettings, ob, &settings_ptr);
+               uiItemR(row, &logic_ptr, "controllers_show_initial_state", UI_ITEM_R_NO_BG, "", 0);
+               uiTemplateLayers(row, &settings_ptr, "state", &settings_ptr, "used_state", 0);
+               
                uiBlockBeginAlign(block);
-               uiDefButBitS(block, TOG, OB_SETSTBIT, B_SET_STATE_BIT, "All",(short)(xco+226), yco-10, 22, UI_UNIT_Y, &ob->scaflag, 0, 0, 0, 0, "Set all state bits");
-               uiDefButBitS(block, TOG, OB_INITSTBIT, B_INIT_STATE_BIT, "Ini",(short)(xco+248), yco-10, 22, UI_UNIT_Y, &ob->scaflag, 0, 0, 0, 0, "Set the initial state");
-               uiDefButBitS(block, TOG, OB_DEBUGSTATE, 0, "D",(short)(xco+270), yco-10, 15, UI_UNIT_Y, &ob->scaflag, 0, 0, 0, 0, "Print state debug info");
+               uiDefButBitS(block, TOG, OB_SETSTBIT, B_SET_STATE_BIT, "All", 0, 0, UI_UNIT_X, UI_UNIT_Y, &ob->scaflag, 0, 0, 0, 0, "Set all state bits");
+               uiDefButBitS(block, TOG, OB_DEBUGSTATE, 0, "D", 0, 0, UI_UNIT_X, UI_UNIT_Y, &ob->scaflag, 0, 0, 0, 0, "Print state debug info");
                uiBlockEndAlign(block);
-
-               yco-=35;
-       
-               /* display only the controllers that match the current state */
-               offset = 0;
-               for (stbit=0; stbit<32; stbit++) {
-                       if (!(ob->state & (1<<stbit)))
-                               continue;
-                       /* add a separation between controllers of different states */
-                       if (offset) {
-                               offset = 0;
-                               yco -= 6;
-                       }
-
-                       //draw controller
+               
+               if (RNA_boolean_get(&logic_ptr, "controllers_show_initial_state")) {
+                       row = uiLayoutRow(layout, 0);
+                       uiItemL(row, "Initial State:", 0);
+                       uiTemplateLayers(row, &settings_ptr, "initial_state", &settings_ptr, "used_state", 0);
                }
        }
-//                     cont= ob->controllers.first;
-       /* draw individual controllers*/
 
        row = uiLayoutRow(layout, 1);
        uiDefButBitS(block, TOG, OB_SHOWCONT, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide controllers");
        uiItemMenuEnumO(row, "LOGIC_OT_controller_add", "type", "Add Controller", 0);
        
        for(a=0; a<count; a++) {
+               bController *cont;
                PointerRNA ptr;
-               uiLayout *split, *col;
+               uiLayout *split, *subsplit, *col;
+               int iact;
+               
                ob= (Object *)idar[a];
                
                if (!(ob->scavisflag & OB_VIS_CONT) || !(ob->scaflag & OB_SHOWCONT)) continue;
@@ -3976,19 +3955,33 @@ void logic_buttons(bContext *C, ARegion *ar)
                
                for(cont= ob->controllers.first; cont; cont=cont->next) {
                        RNA_pointer_create(&ob->id, &RNA_Controller, cont, &ptr);
-
-//                     if (!(cont->state_mask & (1<<stbit))) 
-//                             continue;
-
+                       
+                       if (!(ob->state & cont->state_mask))
+                               continue;
+                       //if (!(cont->state_mask & (1<<stbit))) 
+                       //      continue;
+                       
                        /* this controller is visible, mark all its actuator */
+                       /* XXX: perhaps move this to a preprocessing stage if possible? */
                        for (iact=0; iact<cont->totlinks; iact++) {
-                               act = cont->links[iact];
+                               bActuator *act = cont->links[iact];
                                if (act)
                                        act->flag |= ACT_VISIBLE;
                        }
                        
-                       split = uiLayoutSplit(layout, 0.95, 0);
-                       col = uiLayoutColumn(split, 1);
+                       /* use two nested splits to align inlinks/links properly */
+                       split = uiLayoutSplit(layout, 0.05, 0);
+                       
+                       /* put inlink button to the left */
+                       col = uiLayoutColumn(split, 0);
+                       uiLayoutSetAlignment(col, UI_LAYOUT_ALIGN_LEFT);
+                       uiDefIconBut(block, INLINK, 0, ICON_INLINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, cont, LINK_CONTROLLER, 0, 0, 0, "");
+                       
+                       //col = uiLayoutColumn(split, 1);
+                       /* nested split for middle and right columns */
+                       subsplit = uiLayoutSplit(split, 0.95, 0);
+                       
+                       col = uiLayoutColumn(subsplit, 1);
                        uiLayoutSetContextPointer(col, "controller", &ptr);
                        
                        /* should make UI template for controller header.. function will do for now */
@@ -3997,17 +3990,199 @@ void logic_buttons(bContext *C, ARegion *ar)
                        /* draw the brick contents */
                        draw_brick_controller(col, &ptr);
                        
+                       
                        /* put link button to the right */
-                       col = uiLayoutColumn(split, 0);
-                       /* use oldskool uiButtons for links for now */
-                       but= uiDefIconBut(block, LINK, 0, ICON_LINK,    (short)(xco+width+UI_UNIT_X), yco, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+                       col = uiLayoutColumn(subsplit, 0);
+                       uiLayoutSetAlignment(col, UI_LAYOUT_ALIGN_LEFT);
+                       but= uiDefIconBut(block, LINK, 0, ICON_LINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
                        uiSetButLink(but, NULL, (void ***)&(cont->links), &cont->totlinks, LINK_CONTROLLER, LINK_ACTUATOR);
                }
        }
        uiBlockLayoutResolve(block, NULL, &yco);        /* stores final height in yco */
+       
+       
+       /* ****************** Sensors ****************** */
+       
+       xco= 10; yco= 170; width= 340;
+       layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, U.uistyles.first);
+       row = uiLayoutRow(layout, 1);
+       
+       uiDefBlockBut(block, sensor_menu, NULL, "Sensors", xco-10, yco, 70, UI_UNIT_Y, "");             /* replace this with uiLayout stuff later */
+       
+       uiItemR(row, &logic_ptr, "sensors_show_selected_objects", 0, "Sel", 0);
+       uiItemR(row, &logic_ptr, "sensors_show_active_objects", 0, "Act", 0);
+       uiItemR(row, &logic_ptr, "sensors_show_linked_controller", 0, "Link", 0);
+       uiItemR(row, &logic_ptr, "sensors_show_active_states", 0, "State", 0);
+       
+       row = uiLayoutRow(layout, 1);
+       uiDefButBitS(block, TOG, OB_SHOWSENS, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide sensors");
+       uiItemMenuEnumO(row, "LOGIC_OT_sensor_add", "type", "Add Sensor", 0);
+       
+       for(a=0; a<count; a++) {
+               bSensor *sens;
+               PointerRNA ptr;
+               
+               ob= (Object *)idar[a];
+               
+               if (!(ob->scavisflag & OB_VIS_SENS) || !(ob->scaflag & OB_SHOWSENS)) continue;
+               
+               uiItemS(layout);
+               
+               for(sens= ob->sensors.first; sens; sens=sens->next) {
+                       RNA_pointer_create(&ob->id, &RNA_Sensor, sens, &ptr);
+                       
+                       if ((slogic->scaflag & BUTS_SENS_STATE) ||
+                               (sens->totlinks == 0) ||                                                                                        /* always display sensor without links so that is can be edited */
+                               (sens->flag & SENS_PIN && slogic->scaflag & BUTS_SENS_STATE) || /* states can hide some sensors, pinned sensors ignore the visible state */
+                               (is_sensor_linked(block, sens))
+                               )
+                       {       // gotta check if the current state is visible or not
+                               uiLayout *split, *col;
+                               
+                               split = uiLayoutSplit(layout, 0.95, 0);
+                               col = uiLayoutColumn(split, 1);
+                               uiLayoutSetContextPointer(col, "sensor", &ptr);
+                               
+                               /* should make UI template for sensor header.. function will do for now */
+                               draw_sensor_header(col, &ptr);
+                               
+                               /* draw the brick contents */
+                               draw_brick_sensor(col, &ptr);
+                               
+                               /* put link button to the right */
+                               col = uiLayoutColumn(split, 0);
+                               /* use oldskool uiButtons for links for now */
+                               but= uiDefIconBut(block, LINK, 0, ICON_LINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+                               uiSetButLink(but, NULL, (void ***)&(sens->links), &sens->totlinks, LINK_SENSOR, LINK_CONTROLLER);
+                       }
+               }
+       }
+       uiBlockLayoutResolve(block, NULL, &yco);        /* stores final height in yco */
+       
+       /* ****************** Actuators ****************** */
+       
+       xco= 800; yco= 170; width= 340;
+       layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, U.uistyles.first);
+       row = uiLayoutRow(layout, 1);
+       
+       uiDefBlockBut(block, sensor_menu, NULL, "Actuators", xco-10, yco, 70, UI_UNIT_Y, "");           /* replace this with uiLayout stuff later */
+       
+       uiItemR(row, &logic_ptr, "actuators_show_selected_objects", 0, "Sel", 0);
+       uiItemR(row, &logic_ptr, "actuators_show_active_objects", 0, "Act", 0);
+       uiItemR(row, &logic_ptr, "actuators_show_linked_controller", 0, "Link", 0);
+       uiItemR(row, &logic_ptr, "actuators_show_active_states", 0, "State", 0);
+       
+       row = uiLayoutRow(layout, 1);
+       uiDefButBitS(block, TOG, OB_SHOWACT, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide actuators");
+       uiItemMenuEnumO(row, "LOGIC_OT_actuator_add", "type", "Add Actuator", 0);
+       
+       for(a=0; a<count; a++) {
+               bActuator *act;
+               PointerRNA ptr;
+               
+               ob= (Object *)idar[a];
+               
+               if (!(ob->scavisflag & OB_VIS_ACT) || !(ob->scaflag & OB_SHOWACT)) continue;
+               
+               uiItemS(layout);
+               
+               for(act= ob->actuators.first; act; act=act->next) {
+                       
+                       RNA_pointer_create(&ob->id, &RNA_Actuator, act, &ptr);
+                       
+                       if ((slogic->scaflag & BUTS_ACT_STATE) ||
+                               !(act->flag & ACT_LINKED) ||            /* always display actuators without links so that is can be edited */
+                               (act->flag & ACT_VISIBLE) ||            /* this actuator has visible connection, display it */
+                               (act->flag & ACT_PIN && slogic->scaflag & BUTS_ACT_STATE)       /* states can hide some sensors, pinned sensors ignore the visible state */
+                               )
+                       {       // gotta check if the current state is visible or not
+                               uiLayout *split, *col;
+                               
+                               split = uiLayoutSplit(layout, 0.05, 0);
+                               
+                               /* put inlink button to the left */
+                               col = uiLayoutColumn(split, 0);
+                               uiDefIconBut(block, INLINK, 0, ICON_INLINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, act, LINK_ACTUATOR, 0, 0, 0, "");
+
+                               col = uiLayoutColumn(split, 1);
+                               uiLayoutSetContextPointer(col, "actuator", &ptr);
+                               
+                               /* should make UI template for actuator header.. function will do for now */
+                               draw_actuator_header(col, &ptr);
+                               
+                               /* draw the brick contents */
+                               draw_brick_actuator(col, &ptr);
+                               
+                       }
+               }
+       }
+       uiBlockLayoutResolve(block, NULL, &yco);        /* stores final height in yco */
+       
+       
+       uiComposeLinks(block);
+       
+       uiEndBlock(C, block);
+       uiDrawBlock(C, block);
+       
+       if(idar) MEM_freeN(idar);
+}
 
+void logic_buttons(bContext *C, ARegion *ar)
+{
+       SpaceLogic *slogic= CTX_wm_space_logic(C);
+       Object *ob= CTX_data_active_object(C);
+       ID **idar;
+       bSensor *sens;
+       bController *cont;
+       bActuator *act;
+       uiBlock *block;
+       uiBut *but;
+       PointerRNA logic_ptr;
+       int a, iact, stbit, offset;
+       int xco, yco, width, ycoo;
+       short count;
+       char name[32];
+       /* pin is a bool used for actuator and sensor drawing with states
+        * pin so changing states dosnt hide the logic brick */
+       char pin;
+
+       if (G.rt != 0) {
+               logic_buttons_new(C, ar);
+               return;
+       }
+       
+       if(ob==NULL) return;
+//     uiSetButLock(object_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
+
+       sprintf(name, "buttonswin %p", ar);
+       block= uiBeginBlock(C, ar, name, UI_EMBOSS);
+       uiBlockSetHandleFunc(block, do_logic_buts, NULL);
+
+       RNA_pointer_create(NULL, &RNA_SpaceLogicEditor, slogic, &logic_ptr);
+       
+       idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
+
+       /* clean ACT_LINKED and ACT_VISIBLE of all potentially visible actuators so that 
+          we can determine which is actually linked/visible */
+       for(a=0; a<count; a++) {
+               ob= (Object *)idar[a];
+               act= ob->actuators.first;
+               while(act) {
+                       act->flag &= ~(ACT_LINKED|ACT_VISIBLE);
+                       act = act->next;
+               }
+               /* same for sensors */
+               sens= ob->sensors.first;
+               while(sens) {
+                       sens->flag &= ~(SENS_VISIBLE);
+                       sens = sens->next;
+               }
+       }
+               
+       /* start with the controller because we need to know which one is visible */
+       /* ******************************* */
+       xco= 400; yco= 170; width= 300;
 
-       } else {        //G.rt == 0 // to be removed ... old code
        uiDefBlockBut(block, controller_menu, NULL, "Controllers", xco-10, yco+35, 100, UI_UNIT_Y, "");
        
        uiBlockBeginAlign(block);
@@ -4144,67 +4319,10 @@ void logic_buttons(bContext *C, ARegion *ar)
                        yco-= 6;
                }
        }
-       } //XXX endif G.rt  == 0 // new UI code to replace old one
 
        /* ******************************* */
        xco= 10; yco= 170; width= 300;
 
-       if (G.rt >0) { //XXX new UI code to replace old one
-       layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, U.uistyles.first);
-       row = uiLayoutRow(layout, 1);
-       
-       uiDefBlockBut(block, sensor_menu, NULL, "Sensors", xco-10, yco, 70, UI_UNIT_Y, "");             /* replace this with uiLayout stuff later */
-       
-       uiItemR(row, &logic_ptr, "sensors_show_selected_objects", 0, "Sel", 0);
-       uiItemR(row, &logic_ptr, "sensors_show_active_objects", 0, "Act", 0);
-       uiItemR(row, &logic_ptr, "sensors_show_linked_controller", 0, "Link", 0);
-       uiItemR(row, &logic_ptr, "sensors_show_active_states", 0, "State", 0);
-       
-       row = uiLayoutRow(layout, 1);
-       uiDefButBitS(block, TOG, OB_SHOWSENS, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide sensors");
-       uiItemMenuEnumO(row, "LOGIC_OT_sensor_add", "type", "Add Sensor", 0);
-       
-       for(a=0; a<count; a++) {
-               PointerRNA ptr;
-
-               ob= (Object *)idar[a];
-               
-               if (!(ob->scavisflag & OB_VIS_SENS) || !(ob->scaflag & OB_SHOWSENS)) continue;
-               
-               uiItemS(layout);
-               
-               for(sens= ob->sensors.first; sens; sens=sens->next) {
-                       RNA_pointer_create(&ob->id, &RNA_Sensor, sens, &ptr);
-                       
-                       if ((slogic->scaflag & BUTS_SENS_STATE) ||
-                                (sens->totlinks == 0) ||                                                                                       /* always display sensor without links so that is can be edited */
-                                (sens->flag & SENS_PIN && slogic->scaflag & BUTS_SENS_STATE) ||        /* states can hide some sensors, pinned sensors ignore the visible state */
-                                (is_sensor_linked(block, sens))
-                               )
-                       {       // gotta check if the current state is visible or not
-                               uiLayout *split, *col;
-                               
-                               split = uiLayoutSplit(layout, 0.95, 0);
-                               col = uiLayoutColumn(split, 1);
-                               uiLayoutSetContextPointer(col, "sensor", &ptr);
-                               
-                               /* should make UI template for sensor header.. function will do for now */
-                               draw_sensor_header(col, &ptr);
-                               
-                               /* draw the brick contents */
-                               draw_brick_sensor(col, &ptr);
-                               
-                               /* put link button to the right */
-                               col = uiLayoutColumn(split, 0);
-                               /* use oldskool uiButtons for links for now */
-                               but= uiDefIconBut(block, LINK, 0, ICON_LINK,    (short)(xco+width+UI_UNIT_X), yco, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
-                               uiSetButLink(but, NULL, (void ***)&(sens->links), &sens->totlinks, LINK_SENSOR, LINK_CONTROLLER);
-                       }
-               }
-       }
-       uiBlockLayoutResolve(block, NULL, &yco);        /* stores final height in yco */
-       } else { //XXX G.rt  == 0 { // to be removed == new UI code to replace old one
-
        uiDefBlockBut(block, sensor_menu, NULL, "Sensors", xco-10, yco+35, 70, UI_UNIT_Y, "");
        
        uiBlockBeginAlign(block);
@@ -4286,71 +4404,8 @@ void logic_buttons(bContext *C, ARegion *ar)
                        yco-= 6;
                }
        }
-
-       } //XXX endif G.rt  == 0 // new UI code to replace old one
-
        /* ******************************* */
        xco= 800; yco= 170; width= 300;
-
-       if (G.rt >0) { //XXX new UI code to replace old one
-       layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, U.uistyles.first);
-       row = uiLayoutRow(layout, 1);
-       
-       uiDefBlockBut(block, sensor_menu, NULL, "Actuators", xco-10, yco, 70, UI_UNIT_Y, "");           /* replace this with uiLayout stuff later */
-       
-       uiItemR(row, &logic_ptr, "actuators_show_selected_objects", 0, "Sel", 0);
-       uiItemR(row, &logic_ptr, "actuators_show_active_objects", 0, "Act", 0);
-       uiItemR(row, &logic_ptr, "actuators_show_linked_controller", 0, "Link", 0);
-       uiItemR(row, &logic_ptr, "actuators_show_active_states", 0, "State", 0);
-       
-       row = uiLayoutRow(layout, 1);
-       uiDefButBitS(block, TOG, OB_SHOWACT, B_REDR, ob->id.name+2,(short)(xco-10), yco, (short)(width-30), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, "Object name, click to show/hide actuators");
-       uiItemMenuEnumO(row, "LOGIC_OT_actuator_add", "type", "Add Actuator", 0);
-       
-       for(a=0; a<count; a++) {
-               PointerRNA ptr;
-
-               ob= (Object *)idar[a];
-               
-               if (!(ob->scavisflag & OB_VIS_ACT) || !(ob->scaflag & OB_SHOWACT)) continue;
-               
-               uiItemS(layout);
-               
-               for(act= ob->actuators.first; act; act=act->next) {
-
-                       RNA_pointer_create(&ob->id, &RNA_Actuator, act, &ptr);
-                       
-                       if ((slogic->scaflag & BUTS_ACT_STATE) ||
-                               !(act->flag & ACT_LINKED) ||            /* always display actuators without links so that is can be edited */
-                               (act->flag & ACT_VISIBLE) ||            /* this actuator has visible connection, display it */
-                               (act->flag & ACT_PIN && slogic->scaflag & BUTS_ACT_STATE)       /* states can hide some sensors, pinned sensors ignore the visible state */
-                               )
-                       {       // gotta check if the current state is visible or not
-                               uiLayout *split, *col;
-                               
-                               split = uiLayoutSplit(layout, 0.95, 0);
-                               col = uiLayoutColumn(split, 1);
-                               uiLayoutSetContextPointer(col, "actuator", &ptr);
-                               
-                               /* should make UI template for actuator header.. function will do for now */
-                               draw_actuator_header(col, &ptr);
-                               
-                               /* draw the brick contents */
-                               draw_brick_actuator(col, &ptr);
-                               
-                               /* put link button to the right */
-                               col = uiLayoutColumn(split, 0);
-                               /* use oldskool uiButtons for links for now */
-
-                               uiDefIconBut(block, INLINK, 0, ICON_INLINK,(short)(xco-19), ycoo, UI_UNIT_X, UI_UNIT_Y, act, LINK_ACTUATOR, 0, 0, 0, "");
-                       }
-               }
-       }
-       uiBlockLayoutResolve(block, NULL, &yco);        /* stores final height in yco */
-
-       } else { //XXX G.rt  == 0 { // to be removed == new UI code to replace old one
-
-               
        uiDefBlockBut(block, actuator_menu, NULL, "Actuators", xco-10, yco+35, 90, UI_UNIT_Y, "");
 
        uiBlockBeginAlign(block);
@@ -4429,8 +4484,6 @@ void logic_buttons(bContext *C, ARegion *ar)
                }
        }
 
-       } //XXX endif G.rt  == 0 // new UI code to replace old one
-
        uiComposeLinks(block);
        
        uiEndBlock(C, block);
index 38aa992a279ec5b434b3aa99cc0238249f3add6f..698492e671529bbde456673c94eebfc6d8a2491b 100644 (file)
@@ -437,6 +437,8 @@ extern Object workob;
 #define OB_RECALC_TIME         4
 #define OB_RECALC                      7
 
+/* controller state */
+#define OB_MAX_STATES          30
 
 /* ob->gameflag */
 #define OB_DYNAMIC             1
index e7ee04b23287d8b8933948fce5c3c02ef95c0156..70419b6a6624753724d2974f2117e2f89b98715a 100644 (file)
@@ -628,6 +628,7 @@ typedef struct SpaceUserPref {
 #define BUTS_ACT_LINK          256
 #define BUTS_SENS_STATE                512
 #define BUTS_ACT_STATE         1024
+#define BUTS_CONT_INIT_STATE   2048
 
 /* FileSelectParams.display */
 enum FileDisplayTypeE {
index 3146555b820b4ddd5b8eee972ee9327554203746..9a67c7fbf1763a89805ba48ee801b84e376c204c 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "DNA_action_types.h"
 #include "DNA_customdata_types.h"
+#include "DNA_controller_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_object_force.h"
@@ -864,19 +865,35 @@ static void rna_GameObjectSettings_state_set(PointerRNA *ptr, const int *values)
        int i, tot= 0;
 
        /* ensure we always have some state selected */
-       for(i=0; i<20; i++)
+       for(i=0; i<OB_MAX_STATES; i++)
                if(values[i])
                        tot++;
        
        if(tot==0)
                return;
 
-       for(i=0; i<20; i++) {
+       for(i=0; i<OB_MAX_STATES; i++) {
                if(values[i]) ob->state |= (1<<i);
                else ob->state &= ~(1<<i);
        }
 }
 
+static void rna_GameObjectSettings_used_state_get(PointerRNA *ptr, int *values)
+{
+       Object *ob= (Object*)ptr->data;
+       bController *cont;
+
+       memset(values, 0, sizeof(int)*OB_MAX_STATES);
+       for (cont=ob->controllers.first; cont; cont=cont->next) {
+               int i;
+
+               for (i=0; i<OB_MAX_STATES; i++) {
+                       if (cont->state_mask & (1<<i))
+                               values[i] = 1;
+               }
+       }
+}
+
 static void rna_Object_active_shape_key_index_range(PointerRNA *ptr, int *min, int *max)
 {
        Object *ob= (Object*)ptr->id.data;
@@ -1235,15 +1252,21 @@ static void rna_def_object_game_settings(BlenderRNA *brna)
 
        /* state */
 
-       prop= RNA_def_property(srna, "state", PROP_BOOLEAN, PROP_NONE);
+       prop= RNA_def_property(srna, "state", PROP_BOOLEAN, PROP_LAYER_MEMBER);
        RNA_def_property_boolean_sdna(prop, NULL, "state", 1);
-       RNA_def_property_array(prop, 30);
+       RNA_def_property_array(prop, OB_MAX_STATES);
        RNA_def_property_ui_text(prop, "State", "State determining which controllers are displayed");
        RNA_def_property_boolean_funcs(prop, NULL, "rna_GameObjectSettings_state_set");
 
+       prop= RNA_def_property(srna, "used_state", PROP_BOOLEAN, PROP_LAYER_MEMBER);
+       RNA_def_property_array(prop, OB_MAX_STATES);
+       RNA_def_property_ui_text(prop, "Used State", "States which are being used by controllers");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_boolean_funcs(prop, "rna_GameObjectSettings_used_state_get", NULL);
+       
        prop= RNA_def_property(srna, "initial_state", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "init_state", 1);
-       RNA_def_property_array(prop, 30);
+       RNA_def_property_array(prop, OB_MAX_STATES);
        RNA_def_property_ui_text(prop, "Initial State", "Initial state when the game starts");
 
        prop= RNA_def_property(srna, "debug_state", PROP_BOOLEAN, PROP_NONE);
index dba175311656aa4d456ddd79091e9a6b5c991345..93eec4cbbdd2a3c15e92aa18c26006f537cf8418 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "rna_internal.h"
 
@@ -232,22 +233,27 @@ static void rna_def_keyboard_sensor(BlenderRNA *brna)
        RNA_def_struct_ui_text(srna, "Keyboard Sensor", "Sensor to detect keyboard events");
        RNA_def_struct_sdna_from(srna, "bKeyboardSensor", "data");
 
+       /*
        prop= RNA_def_property(srna, "key", PROP_INT, PROP_NONE);//XXX need to use another input template
-       RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* need better range or enum check */
+       //RNA_def_property_clear_flag(prop, PROP_EDITABLE); // need better range or enum check
        RNA_def_property_ui_text(prop, "Key", "Input key code");
        RNA_def_property_range(prop, 0, 255);
-
-       prop= RNA_def_property(srna, "modifier_key", PROP_INT, PROP_NONE);
-       RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* need better range or enum check */
-       RNA_def_property_int_sdna(prop, NULL, "qual");
+       */
+       
+       prop= RNA_def_property(srna, "key", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "key");
+       RNA_def_property_enum_items(prop, event_type_items);
+       RNA_def_property_ui_text(prop, "Key",  "");
+       
+       prop= RNA_def_property(srna, "modifier_key", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "qual");
+       RNA_def_property_enum_items(prop, event_type_items);
        RNA_def_property_ui_text(prop, "Modifier Key", "Modifier key code");
-       RNA_def_property_range(prop, 0, 255);
-
-       prop= RNA_def_property(srna, "second_modifier_key", PROP_INT, PROP_NONE);
-       RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* need better range or enum check */
-       RNA_def_property_int_sdna(prop, NULL, "qual2");
+       
+       prop= RNA_def_property(srna, "second_modifier_key", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "qual2");
+       RNA_def_property_enum_items(prop, event_type_items);
        RNA_def_property_ui_text(prop, "Second Modifier Key", "Modifier key code");
-       RNA_def_property_range(prop, 0, 255);
 
        prop= RNA_def_property(srna, "target", PROP_STRING, PROP_NONE);
        RNA_def_property_string_sdna(prop, NULL, "targetName");
index 9778b6a4b12a2aa9b0c3fe630b487785d5c5876a..aa1396889e2e8c2d1cfa67cb813528ddf3eb2b93 100644 (file)
@@ -2148,6 +2148,12 @@ static void rna_def_space_logic(BlenderRNA *brna)
        RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_CONT_LINK);
        RNA_def_property_ui_text(prop, "Show Linked to Controller", "Show linked objects to sensor/actuator");
        RNA_def_property_update(prop, NC_LOGIC, NULL);
+       
+       prop= RNA_def_property(srna, "controllers_show_initial_state", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_CONT_INIT_STATE);
+       RNA_def_property_ui_text(prop, "Show Initial State", "Show the initial controller state for this object");
+       RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
+       RNA_def_property_update(prop, NC_LOGIC, NULL);
 
        /* actuators */
        prop= RNA_def_property(srna, "actuators_show_selected_objects", PROP_BOOLEAN, PROP_NONE);