Logic Editor UI work

* 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)
This commit is contained in:
2010-05-05 00:12:31 +00:00
parent c3cd8175c1
commit 96aa9f7002
7 changed files with 372 additions and 264 deletions

View 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);

View 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,6 +3862,271 @@ void draw_brick_actuator(uiLayout *layout, PointerRNA *ptr)
}
}
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;
PointerRNA logic_ptr;
uiLayout *layout, *row;
uiBlock *block;
uiBut *but;
char name[32];
short a, count;
int xco, yco, width;
if(ob==NULL) return;
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);
/* 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++) {
bActuator *act;
bSensor *sens;
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;
}
}
/* ****************** 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);
uiDefBlockBut(block, controller_menu, NULL, "Controllers", xco-10, yco, 70, UI_UNIT_Y, ""); /* replace this with uiLayout stuff later */
uiItemR(row, &logic_ptr, "controllers_show_selected_objects", 0, "Sel", 0);
uiItemR(row, &logic_ptr, "controllers_show_active_objects", 0, "Act", 0);
uiItemR(row, &logic_ptr, "controllers_show_linked_controller", 0, "Link", 0);
{
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", 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);
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);
}
}
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, *subsplit, *col;
int iact;
ob= (Object *)idar[a];
if (!(ob->scavisflag & OB_VIS_CONT) || !(ob->scaflag & OB_SHOWCONT)) continue;
uiItemS(layout);
for(cont= ob->controllers.first; cont; cont=cont->next) {
RNA_pointer_create(&ob->id, &RNA_Controller, cont, &ptr);
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++) {
bActuator *act = cont->links[iact];
if (act)
act->flag |= ACT_VISIBLE;
}
/* 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 */
draw_controller_header(col, &ptr);
/* draw the brick contents */
draw_brick_controller(col, &ptr);
/* put link button to the right */
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);
@@ -3860,7 +4137,6 @@ void logic_buttons(bContext *C, ARegion *ar)
bActuator *act;
uiBlock *block;
uiBut *but;
uiLayout *layout, *row;
PointerRNA logic_ptr;
int a, iact, stbit, offset;
int xco, yco, width, ycoo;
@@ -3870,6 +4146,11 @@ void logic_buttons(bContext *C, ARegion *ar)
* 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);
@@ -3902,112 +4183,6 @@ void logic_buttons(bContext *C, ARegion *ar)
/* ******************************* */
xco= 400; yco= 170; width= 300;
if (G.rt >0) { // 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, controller_menu, NULL, "Controllers", xco-10, yco, 70, UI_UNIT_Y, ""); /* replace this with uiLayout stuff later */
uiItemR(row, &logic_ptr, "controllers_show_selected_objects", 0, "Sel", 0);
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));
}
}
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");
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
}
}
// 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++) {
PointerRNA ptr;
uiLayout *split, *col;
ob= (Object *)idar[a];
if (!(ob->scavisflag & OB_VIS_CONT) || !(ob->scaflag & OB_SHOWCONT)) continue;
uiItemS(layout);
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;
/* this controller is visible, mark all its actuator */
for (iact=0; iact<cont->totlinks; iact++) {
act = cont->links[iact];
if (act)
act->flag |= ACT_VISIBLE;
}
split = uiLayoutSplit(layout, 0.95, 0);
col = uiLayoutColumn(split, 1);
uiLayoutSetContextPointer(col, "controller", &ptr);
/* should make UI template for controller header.. function will do for now */
draw_controller_header(col, &ptr);
/* 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, "");
uiSetButLink(but, NULL, (void ***)&(cont->links), &cont->totlinks, LINK_CONTROLLER, LINK_ACTUATOR);
}
}
uiBlockLayoutResolve(block, NULL, &yco); /* stores final height in yco */
} 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);

View 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

View 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 {

View 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);

View 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");

View 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);