示例#1
0
void cxActionReadAttr(cxReaderAttrInfo *info)
{
    cxAction this = info->object;
    //
    cxActionSetStepHide(this, cxXMLReadBoolAttr(info, "cxAction.stepHide", this->stepHide));
    //delay
    cxActionSetDelay(this, cxXMLReadFloatAttr(info, "cxAction.delay", this->delay));
    //time
    cxActionSetDuration(this, cxXMLReadFloatAttr(info, "cxAction.time", this->duration));
    //init time
    cxActionSetDurationInit(this, cxXMLReadFloatAttr(info, "cxAction.initTime", this->durationInit));
    //curve
    cxConstChars scurve = cxXMLAttr(info->reader, "cxAction.curve");
    cxCurveItem curve = cxCurveGet(scurve);
    if(curve != NULL){
        CX_METHOD_OVERRIDE(this->Curve, curve->func);
    }
    //
    cxActionSetSplit(this, cxXMLReadIntAttr(info, "cxAction.split", this->split));
    //
    cxActionSetSpeed(this, cxXMLReadFloatAttr(info, "cxAction.speed", this->speed));
    //actionId
    cxActionSetId(this, cxXMLReadIntAttr(info, "cxAction.id", this->actionId));
    //forever
    if(cxXMLReadBoolAttr(info, "cxAction.forever", false)){
        CX_METHOD_OVERRIDE(this->Exit, cxActionForever);
    }
    //assist
    this->assist = cxXMLReadAssist4fAttr(info, "cxAction.assist", this->assist);
    //event
    cxXMLAppendEvent(info, this, cxAction, onStart);
    cxXMLAppendEvent(info, this, cxAction, onStop);
    cxXMLAppendEvent(info, this, cxAction, onSplit);
    cxXMLAppendEvent(info, this, cxAction, onStep);
}
示例#2
0
static cxInt cxEventAction(lua_State *L)
{
    CX_LUA_DEF_THIS(cxObject);
    cxAny view = NULL;
    cxConstChars src = NULL;
    cxConstChars viewId = NULL;
    cxBool cache = false;
    cxConstChars curve = NULL;
    cxFloat delay = 0;
    if(!lua_istable(L, 2)){
        luaL_error(L, "args error");
        return 0;
    }
    //
    lua_getfield(L, 2, "delay");
    if(lua_isnumber(L, -1)){
        delay = lua_tonumber(L, -1);
    }
    lua_pop(L,1);
    //
    lua_getfield(L, 2, "src");
    if(lua_isstring(L, -1)){
        src = lua_tostring(L, -1);
    }
    lua_pop(L, 1);
    CX_RETURN(src == NULL, 0);
    //
    lua_getfield(L, 2, "curve");
    if(lua_isstring(L, -1)){
        curve = lua_tostring(L, -1);
    }
    lua_pop(L, 1);
    //
    lua_getfield(L, 2, "view");
    if(lua_isstring(L, -1)){
        viewId = lua_tostring(L, -1);
    }else if(lua_isuserdata(L, -1)){
        view = CX_LUA_GET_PTR(-1);
    }
    lua_pop(L, 1);
    //
    lua_getfield(L, 2, "cache");
    if(lua_isboolean(L, -1)){
        cache = lua_toboolean(L, -1);
    }
    lua_pop(L, 1);
    //get view by id and cxBase
    if(view != NULL){
        viewId = NULL;
    }else if(this->cxBase == cxBaseTypeAction){
        view = cxActionView(this);
    }else if(this->cxBase == cxBaseTypeView){
        view = this;
    }else{
        luaL_error(L,"base view and action can use this event");
        return 0;
    }
    CX_ASSERT(view != NULL, "this event's sender must base cxAction and cxView");
    if(viewId != NULL){
        view = cxViewRootGet(view, viewId);
        CX_RETURN(view == NULL, 0);
    }
    //get action
    cxAny action = NULL;
    cxBool fromcache =  false;
    if(cache){
        action = cxViewGetCache(view, src);
        fromcache = (action != NULL);
    }
    if(action == NULL){
        action = cxActionRootGet(src);
    }
    CX_RETURN(action == NULL, 0);
    if(!fromcache && cache){
        cxViewSetCache(view, src, action);
    }
    if(fromcache){
        cxActionReset(action);
    }
    //set action corve
    cxCurveItem curveitem = cxCurveGet(curve);
    if(curveitem != NULL){
        cxActionSetCurve(action, curveitem->func);
    }
    //delay
    if(delay > 0){
        cxActionSetDelay(action, delay);
    }
    cxViewAppendAction(view, action);
    return 0;
}