Esempio n. 1
0
void
CKLBLuaLibMatrix::setVector(CLuaState& lua, VECTOR * vec)
{
	lua.tableNew();		// ベクトル用のテーブル
	for(int n = 0; n < 4; n++) {
		lua.retInt(n + 1); lua.retDouble(vec->v[n]); lua.tableSet();
	}
}
Esempio n. 2
0
void
CKLBLuaLibMatrix::getVector(CLuaState& lua, VECTOR * vec)
{
	// Luaスタックトップにはvectorテーブルが積んである
	for(int n = 0; n < 4; n++) {
		lua.retInt(n + 1); lua.tableGet(); vec->v[n] = lua.getFloat(-1); lua.pop(1);
	}
}
Esempio n. 3
0
void
CKLBLuaLibMatrix::getMatrix(CLuaState& lua, MATRIX * ret)
{
	// 最上位には対象の配列が積んである
	for(int idx = 0; idx < 16; idx++) {
		lua.retInt(idx + 1);			// Luaテーブル上のindexを積む
		lua.tableGet();					// 対応する値を取得する
		float val = lua.getFloat(-1);
		ret->m[idx] = val;
		lua.pop(1);
	}
}
Esempio n. 4
0
void
CKLBLuaLibMatrix::setMatrix(CLuaState& lua, MATRIX * mat)
{
	// 最上位に対象の配列を作る
	lua.tableNew();
	for(int idx = 0; idx < 16; idx++) {
		// key として index 値を積む
		lua.retInt(idx + 1);
		// 値を積む
		lua.retDouble(mat->m[idx]);
		// 値を設定する
		lua.tableSet();
	}
}
Esempio n. 5
0
void
CKLBLuaLibMatrix::setVectorArray(CLuaState& lua, VECTOR * vec, int nums)
{
	lua.tableNew();		// ベクトル配列用のテーブル

	for(int idx = 0; idx < nums; idx++) {
		lua.retInt(idx + 1);	// ベクトル配列中のindexを指定する

		// ベクトルの値をスタック上に積む
		setVector(lua, &vec[idx]);

		// この時点で、ベクトル配列のindexと、ベクトルがスタックに積まれている
		lua.tableSet();	// ベクトル配列にベクトルを設定する
	}
	// 一通りの設定が終わり、ベクトル配列テーブルがスタック上に積まれた状態になる。
}
Esempio n. 6
0
bool
CKLBFormIF::updateUIContainer(CLuaState& lua, int argc, int base, int subcmd, CKLBNode * pNode, int& ret, void * item, int index)
{
	CKLBUIContainer * pCont = (CKLBUIContainer *)pNode;
	bool result = true;
	switch(subcmd)
	{
	default:
		{
			result = updateUIElement(lua, argc, base, subcmd, pNode, ret, item, index);
		}
		break;
	case FORM_CONT_VIEWOFFSET:
		{
			if(argc != base + 2) {
				result = false;
				break;
			}
			s32 offX = lua.getInt(base + 1);
			s32 offY = lua.getInt(base + 2);
			pCont->setViewOffsetX(offX);
			pCont->setViewOffsetY(offY);
		}
		break;
	case FORM_CONT_GET_RADIO_VALUE:
		{
			if(argc != base) {
				result = false;
				break;
			}
			u32 value = pCont->getRadioValue();
			lua.retInt(value);
			ret = 1;
		}
		break;
	}
	return result;
}
Esempio n. 7
0
bool
CKLBFormIF::updateStandardNode(CLuaState& lua, int argc, int base, int subcmd, CKLBNode * pNode, int& ret, void * /*item*/, int index)
{
	bool result = true;
	switch(subcmd)
	{
	default:
		{
			result = false;
		}
		break;
	case FORM_NODE_POINTER:
		{
			if(argc != base) {
				lua.retNil();
				ret = 1;
				break;
			}
			lua.retPointer(pNode);
			ret = 1;
		}
		break;

	case FORM_NODE_RECURSIVE:
		{
			if(argc != base + 1) {
				result = false;
				break;
			}
			const char * funcname = lua.getString(base + 1);	// コールバック名の取得
			result = nodeRecursive(lua, funcname, pNode, index);
		}
		break;

	case FORM_NODE_TRANS:
		{
			if(argc != (base + 2)) {
				result = false;
				break;
			}
			float x = lua.getFloat(base + 1);
			float y = lua.getFloat(base + 2);

			CKLBUITask* pTask = pNode->getUITask();
			if (pTask) {
				// Change next frame or current frame.
				if(pTask->isNewScriptModel()) {
					pTask->setX(x);
					pTask->setY(y);
				} else {
					int idxX = pTask->findProperty("x");
					int idxY = idxX + 1;
					pTask->setNum(idxX, x);
					pTask->setNum(idxY, y);
				}
				// Trick: we modify directly the node AND change the property.
				// If another property is modified later, it will force the value to be used. 
				// ==> Do not execute pTask->setInnerUpdate();
			}
			// But changes also RIGHT AWAY
			pNode->setTranslate(x, y);
		}
		break;
	case FORM_NODE_SCALE:
		{
			if(argc != base + 2) {
				result = false;
				break;
			}
			float scaleX = lua.getFloat(base + 1);
			float scaleY = lua.getFloat(base + 2);

			CKLBUITask* pTask = pNode->getUITask();
			if (pTask) {
				if(pTask->isNewScriptModel()) {
					pTask->setScaleX(scaleX);
					pTask->setScaleY(scaleY);
				} else {
					int idxX = pTask->findProperty("scaleX");
					int idxY = idxX + 1;
					pTask->setNum(idxX, scaleX);
					pTask->setNum(idxY, scaleY);
				}
				// Trick: we modify directly the node AND change the property.
				// If another property is modified later, it will force the value to be used. 
				// ==> Do not execute pTask->setInnerUpdate();
			}
			pNode->setScale(scaleX, scaleY);
		}
		break;
	case FORM_NODE_ROT:
		{
			if(argc != base + 1) {
				result = false;
				break;
			}
			float rot = lua.getFloat(base + 1);

			CKLBUITask* pTask = pNode->getUITask();
			if (pTask) {
				if(pTask->isNewScriptModel()) {
					pTask->setRotation(rot);
				} else {
					int idxRot = pTask->findProperty("rot");
					pTask->setNum(idxRot, rot);
				}
				pTask->setInnerUpdate();
				// Trick: we modify directly the node AND change the property.
				// If another property is modified later, it will force the value to be used. 
				// ==> Do not execute pTask->setInnerUpdate();
			}
			pNode->setRotation(rot);
		}
		break;
	case FORM_NODE_COLOR:
		{
			if(argc != base + 2) {
				result = false;
				break;
			}

			u32 alpha = lua.getInt(base + 1);
			u32 rgb   = lua.getInt(base + 2);

			CKLBUITask* pTask = pNode->getUITask();
			if (pTask) {
				if(pTask->isNewScriptModel()) {
					pTask->setAlpha(alpha);
					pTask->setArgb(rgb);
				} else {
					int idxcol = pTask->findProperty("alpha");	// Color just after !
					pTask->setInt(idxcol, alpha);
					pTask->setInt(idxcol+1, rgb);
				}
				pTask->setInnerUpdate();
			}

			SColorVector color;
			color.m_type = 0;

			for(int i = 0; i < 3; i++) {
				int col = 0xff & (rgb >> (16 - 8 * i));
				color.m_vector[i] = col / 255.0f;
			}
			color.m_vector[3] = (alpha & 0xff) / 255.0f;
			pNode->setColorMatrix(color);
		}
		break;
	case FORM_NODE_VISIBLE:
		{
			if(argc != base + 1) {
				result = false;
				break;
			}
			bool visible = lua.getBool(base + 1);

			CKLBUITask* pTask = pNode->getUITask();
			if (pTask) {
				pTask->setVisible(visible);
			} else {
				pNode->setVisible(visible);
			}
		}
		break;
	case FORM_NODE_ORDER:
		{
			if(argc != base + 1) {
				result = false;
				break;
			}
			int order = lua.getInt(base + 1);
			CKLBUITask* pTask = pNode->getUITask();
			if (pTask) {
				if(pTask->isNewScriptModel()) {
					pTask->setOrder(order);
					pTask->setInnerUpdate();
				} else {
					int idx_order = pTask->findProperty("order");
					if (idx_order >= 0) {
						pTask->setInt(idx_order, order);
						pTask->setInnerUpdate();
					}
				}
			}
			pNode->setPriority(order);
			pNode->markUpMatrix();
		}
		break;
	case FORM_NODE_GET_ORDER:
		{
			if(argc != base) {
				result = false;
				break;
			}
			int order;
			CKLBUITask* pTask = pNode->getUITask();
			if (pTask) {
				if(pTask->isNewScriptModel()) {
					order = pTask->getOrder();
				} else {
					int idx_order = pTask->findProperty("order");
					if (idx_order >= 0) {
						order = pTask->getInt(idx_order);
					} else {
						order = 0;
					}
				}
			} else {
				order = pNode->getPriority();
			}
			lua.retInt(order);
			ret = 1;
		}
		break;

	case FORM_NODE_TASK:
		{
			if(argc != base) {
				result = false;
				break;
			}
			CKLBUITask * pTask = pNode->getUITask();
			if(!pTask) {
				lua.retNil();
			} else {
				lua.retPointer(pTask);
			}
			ret = 1;
		}
		break;
	}
	return result;
}
Esempio n. 8
0
int
CKLBUIScore::commandUI(CLuaState& lua, int argc, int cmd)
{
	int ret = 0;
	switch(cmd)
	{
	case UI_SCORE_RESET:
		setValue(0);
		m_bScoreUpdate = true;
		break;
	case UI_SCORE_SET:
		{
			if(argc != 3) {
				lua.retNil();
				ret = 1;
				break;
			}
			int value = lua.getInt(3);
			if(m_bCountClip && value >= m_maxvalue) value = m_maxvalue - 1;
			setValue(value);
		}
		break;
	case UI_SCORE_SETFLOAT:
		{
			if(argc != 4) {
				lua.retNil();
				ret = 1;
				break;
			}
			float value = lua.getFloat(3);
			int pos = lua.getInt(4);
			if(m_bCountClip && value >= m_maxvalue) value = m_maxvalue - 1;
			setValueFloat(value, pos);
		}
		break;
	case UI_SCORE_SETDOT:
		{
			if(argc != 5) {
				lua.retNil();
				ret = 1;
				break;
			}

			setDot(lua.getString(3), lua.getInt(4), lua.getInt(5));
		}
		break;
	case UI_SCORE_GET:
		{	
			int value = getValue();
			lua.retInt(value);
			ret = 1;
		}
		break;
	case UI_SCORE_ENTERANIM:
		{
			if(argc != 8) {
				lua.retBoolean(false);
				ret = 1;
				break;
			}
			s32  mspt       = lua.getInt(3);
			s32  tshift     = lua.getInt(4);
			bool onlychg    = lua.getBool(5);
			int  type       = lua.getInt(6);
			u32  affected   = lua.getInt(7);
			float mat[8];
			klb_assert(type > 0, "UI_Score: UI_SCORE_ENTERANIM type == 0");

			// 配列を読む
			lua.retValue(8);
			lua.retNil();
			while(lua.tableNext()) {
				lua.retValue(-2);
				int idx = lua.getInt(-1) - 1;
				klb_assert((idx >= 0 && idx < 8), "%s(%d): bad array index. UI_SCORE_ENTERANIM", lua.getScriptName(), lua.getNumLine());
				mat[idx] = lua.getFloat(-2);
				lua.pop(2);
			}
			lua.pop(1);

			klb_assert(type != 0, "Custom animation is not authorized (type 0)");
			m_pScoreNode->setEnterAnimation(mspt, tshift, onlychg, type, affected, mat);
		}
		break;
	case UI_SCORE_EXITANIM:
		{
			if(argc != 8) {
				lua.retBoolean(false);
				ret = 1;
				break;
			}
			s32  mspt       = lua.getInt(3);
			s32  tshift     = lua.getInt(4);
			bool onlychg    = lua.getBool(5);
			int  type       = lua.getInt(6);
			u32  affected   = lua.getInt(7);
			float mat[4];
			klb_assert(type > 0, "UI_Score: UI_SCORE_ENTERANIM type == 0");

			// 配列を読む
			lua.retValue(8);
			lua.retNil();
			while(lua.tableNext()) {
				lua.retValue(-2);
				int idx = lua.getInt(-1) - 1;
				mat[idx] = lua.getFloat(-2);
				lua.pop(2);
			}
			lua.pop(1);

			klb_assert(type != 0, "Custom animation is not authorized (type 0)");
			m_pScoreNode->setExitAnimation(mspt, tshift, onlychg, type, affected, mat);
		}
		break;
	case UI_SCORE_ALIGN:
		{
			bool bResult = false;
			if(argc == 3) {
				int align = lua.getInt(3);
				setAlign(align);
				bResult = true;
			}
			lua.retBool(bResult);
			ret = 1;
		}
		break;
	}
	return ret;
}