예제 #1
0
bool
CKLBUpdateZip::initScript(CLuaState& lua)
{
	// bool res = true;

	int argc = lua.numArgs();

	// 引数チェック
	if(argc < ARG_ZIPREQUIRE || argc > ARG_ZIPNUM) {
		return false;
	}

	const char * callbackUnzip		= (argc >= ARG_ZIPUNZIP_CALLBACK)   ? lua.getString(ARG_ZIPUNZIP_CALLBACK)  : NULL;
	const char * callbackFinish		= (argc >= ARG_ZIPFINISH_CALLBACK)  ? lua.getString(ARG_ZIPFINISH_CALLBACK) : NULL;
	const char * callbackError		= (argc >= ARG_ZIPERROR_CALLBACK)   ? lua.getString(ARG_ZIPERROR_CALLBACK)  : NULL;
	
	const char * tmp_name			= lua.getString(ARG_ZIPTMPNAME);
	m_tmpPath						= CKLBUtility::copyString(tmp_name);

	// Load "Update" info if any
	if (lockExist()) {
		m_eStep = S_INIT_UNZIP;

		m_zipEntry			= 0;
		m_callbackZIP		= CKLBUtility::copyString(callbackUnzip);
		m_callbackFinish	= CKLBUtility::copyString(callbackFinish);
		m_callbackError		= callbackError ? CKLBUtility::copyString(callbackError) : NULL;

		return regist(NULL, P_NORMAL);
	} else {
		return false;
	}
}
예제 #2
0
int
CKLBGenericTask::commandScript(CLuaState& lua)
{
    int argc = lua.numArgs();
    if(argc < 2) {
        lua.retBoolean(false);
        return 1;
    }
    int cmd = lua.getInt(2);
    int ret = 1;

    switch(cmd)
    {
    default:
    {
        lua.retBoolean(false);
        ret = 1;
    }
    break;
    case GENERIC_STOP_EXECUTE:
    {
        KLBDELETEA(m_luaFuncExec);
        m_luaFuncExec = NULL;
        lua.retBoolean(true);
        ret = 1;
    }
    break;
    }
    return ret;
}
예제 #3
0
int
CKLBLifeCtrlTask::commandScript(CLuaState& lua)
{
	int argc = lua.numArgs();
	if(argc < 2) {
		lua.retBoolean(false);
		return 1;
	}
	int cmd = lua.getInt(2);
	int ret = 1;

	switch(cmd)
	{
	default:
		{
			lua.retBoolean(false);
			ret = 1;
		}
		break;
	case LIFECTRL_ADD_CHILD:
		{
			if(argc != 3) {
				lua.retBoolean(false);
				ret = 1;
				break;
			}
			CKLBTask * pTask = (CKLBTask *)lua.getPointer(3);
			child(pTask);	// 自身の子として登録
		}
		break;
	}
	return ret;
}
예제 #4
0
int
CKLBUITouchPad::commandScript(CLuaState& lua)
{
	int argc = lua.numArgs();
	if(argc < 2) {
		lua.retBool(false);
		return 1;
	}

	int cmd = lua.getInt(2);
	int ret = 1;
	switch(cmd)
	{
	default:
		{
			lua.retBool(false);
			ret = 1;
		}
		break;
	case UI_TOUCHPAD_SET_GROUP:
		{
			bool result = false;
			if(argc == 3) {
				const char * group_name = lua.getString(3);
				result = setGroup(group_name);
			}
			lua.retBoolean(result);
			ret = 1;
		}
		break;
	case UI_TOUCHPAD_LOCK:
		{
			bool result = false;
			if(argc == 3) {
				bool lock_mode = lua.getBool(3);
				lock(lock_mode);
				result = true;
			}
			lua.retBoolean(true);
			ret = 1;
		}
		break;
	case UI_TOUCHPAD_GET_ALL:
		{
			bool result = false;
			if(argc == 3) {
				setGetAll(lua.getBool(3));
				result = true;
			}
			lua.retBoolean(result);
			ret = 1;
		}
		break;
	}
	return ret;
}
예제 #5
0
bool
CKLBUIButton::initScript(CLuaState& lua)
{
	int argc = lua.numArgs();
	if(argc < ARG_REQUIRE || argc > ARG_NUMS) return false;

	const char * funcname = lua.getString(ARG_CALLBACK);

	return init(NULL, funcname);
}
예제 #6
0
bool
CKLBUIControl::initScript(CLuaState& lua)
{
	int argc = lua.numArgs();
	if(argc != 2) return false;

	const char * onClick = lua.getString(1);
	const char * onDrag  = lua.getString(2);

	return init(NULL, onClick, onDrag);
}
예제 #7
0
bool
CKLBUISimpleItem::initUI(CLuaState& lua)
{
	int argc = lua.numArgs();
    if(argc < ARG_REQUIRE || argc > ARG_NUMS) { return false; }

	float x = lua.getFloat(ARG_X);
	float y = lua.getFloat(ARG_Y);

	return initCore(lua.getInt(ARG_ORDER),x,y,lua.getString(ARG_ASSET));
} 
예제 #8
0
bool
CKLBUITouchPad::initScript(CLuaState& lua)
{
	int argc = lua.numArgs();
    if(argc < ARG_REQUIRE || argc > ARG_NUMS) { return false; }

	const char * funcname = lua.getString(ARG_CALLBACK);
	bool modal = (argc >= ARG_MODAL) ? lua.getBool(ARG_MODAL) : false;

	return init(NULL, funcname, modal);
}
예제 #9
0
bool
CKLBPauseCtrl::initScript(CLuaState& lua)
{
	int argc = lua.numArgs();
	if(argc != 2) {
		return false;
	}
	const char * pause  = (lua.isNil(1)) ? NULL : lua.getString(1);
	const char * resume = (lua.isNil(2)) ? NULL : lua.getString(2);
	
	return init(NULL, pause, resume);
}
예제 #10
0
bool
CKLBUIScore::initUI(CLuaState& lua)
{
	int argc = lua.numArgs();

	// 引数の数が合わない場合
    if(argc < ARG_REQUIRE || argc > ARG_NUMS) { return false; }

	float   x            = lua.getFloat(ARG_X);
	float   y            = lua.getFloat(ARG_Y);
	u32     order        = lua.getInt(ARG_ORDER);
	s32     order_offset = lua.getInt(ARG_ODOFF);
	float   stepX        = lua.getFloat(ARG_STEP_X);
	float   stepY        = lua.getFloat(ARG_STEP_Y);
	int     column       = lua.getInt(ARG_COLS);
	bool    fillzero     = lua.getBool(ARG_FILLZERO);
	bool    anim_flag    = lua.getBool(ARG_ANIM);
	int     align        = (argc >= ARG_ALIGN)     ? lua.getInt(ARG_ALIGN)      : ALIGN_RIGHT;
	bool    countclip    = (argc >= ARG_COUNTCLIP) ? lua.getBool(ARG_COUNTCLIP) : false;

	const char * tex_list[10];
	lua.retValue(ARG_TEXTBL);	// 対象となる配列をスタックトップに積む
	lua.retNil();				// nil をスタックトップに積む
	int tex_cnt = 0;
	while(lua.tableNext()) {
		lua.retValue(-2);
		int idx = lua.getInt(-1) - 1;			// Lua配列の添え字は1からなので、-1する。
		const char * str = lua.getString(-1);

		// 与えられた配列のindexに整数以外が使われているときや、
		// 範囲を超えたものがある場合はエラー扱いとする。
		klb_assert((idx >= 0 && idx <= 9), "BAD INDEX [%s] in texture array.", str);
		if(idx < 0 || idx > 9) {	// 数値以外のインデックスが指定されていたり、範囲を超えている場合
			return false;
		}
		const char * texname = lua.getString(-2);	// テクスチャ名称が格納されている。
		tex_list[idx] = texname;
		tex_cnt++;
		lua.pop(2);
	}
	lua.pop(1);
	// テクスチャの数が足りなければエラーとする。
	if(tex_cnt != 10) {
		klb_assert(tex_cnt == 10, "%s(%d): The number of textures is insufficient. ", lua.getScriptName(), lua.getNumLine()); 
		return false;
	}

	return initCore(order, order_offset, x, y, tex_list, stepX, stepY, column, fillzero, anim_flag, align, countclip);
}
예제 #11
0
bool
CKLBGenericTask::initScript(CLuaState &lua)
{
    int argc = lua.numArgs();
    if(argc < ARGS_REQUIRE || argc > ARGS_MAX) {
        return false;
    }

    const char * name_exec = lua.getString(ARGS_EXEC);
    const char * name_die  = lua.getString(ARGS_DIE);
    const char * arr_index = lua.getString(ARGS_ARRAY);
    CKLBTask::TASK_PHASE phase = (CKLBTask::TASK_PHASE)((argc >= ARGS_PHASE) ? lua.getInt(ARGS_PHASE) : P_NORMAL);
    CKLBTask * pParent = (argc >= ARGS_PARENT) ? (CKLBTask *)lua.getPointer(ARGS_PARENT) : NULL;

    return init(pParent, phase, name_exec, name_die, arr_index);
}
예제 #12
0
bool
CKLBUIMultiImgItem::initUI(CLuaState& lua)
{
	int argc = lua.numArgs();
	if(argc < ARG_REQUIRE || argc > ARG_NUMS) return false;

	float x     = lua.getFloat(ARG_X);
	float y     = lua.getFloat(ARG_Y);
	u32 order   = lua.getInt(ARG_ORDER);
	u32 idxImg  = (argc >= ARG_INDEX) ? lua.getInt(ARG_INDEX) : 0;
	
	// asset list を取得
	lua.retValue(ARG_ASSET_LIST);

	// 要素の数を数える
	int max = 0;
	lua.retNil();

	// Read indexes and count entries.
	while(lua.tableNext()) {
		lua.retValue(-2);
		int idx = lua.getInt(-1);
		if(max < idx) max = idx;
		lua.pop(2);
	}

	IMGITEM* items = KLBNEWA(IMGITEM, max);

    if(!items) { return false; }

	// Reset all handle to NULL
	for(int idx = 0; idx < max; idx++) {
		items[idx].handle = 0;
		items[idx].sprite = NULL;
	}

	m_order = order; // Needed for getImgList
    if(!getImgList(lua,items,max)) { return false; }
	return initCore(order, x,y,idxImg,items,max);
}
예제 #13
0
bool
CKLBUpdate::initScript(CLuaState& lua)
{
	// bool res = true;

	int argc = lua.numArgs();

	// 引数チェック
	if(argc < ARG_REQUIRE || argc > ARG_NUM) {
		return false;
	}

	const char * callbackDownload	= (argc >= ARG_DOWNLOAD_CALLBACK)	? lua.getString(ARG_DOWNLOAD_CALLBACK)	: NULL;
	const char * callbackUnzip		= (argc >= ARG_UNZIP_CALLBACK)		? lua.getString(ARG_UNZIP_CALLBACK)		: NULL;
	const char * callbackFinish		= (argc >= ARG_FINISH_CALLBACK)		? lua.getString(ARG_FINISH_CALLBACK)	: NULL;
	const char * callbackError		= (argc >= ARG_ERROR_CALLBACK)		? lua.getString(ARG_ERROR_CALLBACK)		: NULL;
	
	const char * zip_url;
	const char * zip_size;
	const char * tmp_name;
	zip_url				= lua.getString(ARG_ZIPURL);
	zip_size			= lua.getString(ARG_ZIPSIZE);	// サイズは狂いがあると困るのでstringで受ける
	tmp_name			= lua.getString(ARG_TMPNAME);

	m_tmpPath			= CKLBUtility::copyString(tmp_name);
	m_zipURL			= CKLBUtility::copyString(zip_url);
	m_zipSize			= CKLBUtility::stringNum64(zip_size);

	m_eStep	= S_INIT_DL;
	// Start from scratch and download
	m_dlSize			= -1;
	m_zipEntry			= 0;
	m_callbackDL		= CKLBUtility::copyString(callbackDownload);
	m_callbackZIP		= CKLBUtility::copyString(callbackUnzip);
	m_callbackFinish	= CKLBUtility::copyString(callbackFinish);
	m_callbackError		= callbackError ? CKLBUtility::copyString(callbackError) : NULL;

	return regist(NULL, P_NORMAL);
}
예제 #14
0
int
CKLBUIControl::commandScript(CLuaState& lua)
{
	int argc = lua.numArgs();
	if(argc < 2) {
		lua.retBoolean(false);
		return 1;
	}
	int ret = 1;
	int cmd = lua.getInt(2);
	switch(cmd)
	{
	default:
		{
			ret = 1;
			lua.retBoolean(false);
		}
		break;
	case UI_CONTROL_ON_PINCH:
		{
			ret = 1;
			if(argc != 3) {
				lua.retBoolean(false);
				break;
			}
			const char * onPinch = lua.getString(3);
			if(!onPinch) {
				lua.retBoolean(false);
				break;
			}
			m_onPinch = CKLBUtility::copyString(onPinch);
			if(!onPinch) {
				lua.retBoolean(false);
				break;
			}
			lua.retBoolean(true);
		}
		break;
    case UI_CONTROL_ON_DBLCLICK:
		{
			ret = 1;
			if(argc != 3) {
				lua.retBoolean(false);
				break;
			}
			const char * onDblClick = lua.getString(3);
			if(!onDblClick) {
				lua.retBoolean(false);
				break;
			}
			setOnDblClick(onDblClick);
			if(!onDblClick) {
				lua.retBoolean(false);
				break;
			}
			lua.retBoolean(true);
		}
        break;
	case UI_CONTROL_ON_LONGTAP:
		{
			ret = 1;
			if(argc != 3) {
				lua.retBoolean(false);
				break;
			}
			const char * onLongTap = lua.getString(3);
			setOnLongTap(onLongTap);
			if(!onLongTap) {
				lua.retBoolean(false);
				break;
			}
			lua.retBoolean(true);
		}
		break;
	case UI_CONTROL_ON_RAWEVENT:
		{
			ret = 1;
			if(argc != 3) {
				lua.retBoolean(false);
				break;
			}
			const char * onRawEvent = lua.getString(3);
			setOnEventRaw(onRawEvent);
			if(!onRawEvent) {
				lua.retBoolean(false);
				break;
			}
			lua.retBoolean(true);
		}
		break;
	case UI_CONTROL_SET_GROUP:
		{
			bool result = false;
			if(argc == 3) {
				const char * group_name = lua.getString(3);
				ret = setGroup(group_name);
			}
			lua.retBoolean(result);
			ret = 1;
		}
		break;
		/*
	case UI_CONTROL_LOCK:
		{
			bool result = false;
			if(argc == 3) {
				bool lock_mode = lua.getBool(3);
				lock(lock_mode);
				result = true;
			}
			lua.retBoolean(result);
			ret = 1;
		}
		break;
		*/
	case UI_CONTROL_SET_MASK:
		{
			bool result = false;
			if(argc == 3) {
				u16 mask = lua.getInt(3);
				m_callbackMask = mask;
				result = true;
			}
			lua.retBoolean(result);
			ret = 1;
		}
		break;
	case UI_CONTROL_GET_ALL:
		{
			bool result = false;
			if(argc == 3) {
				setGetAll(lua.getBool(3));
				result = true;
			}
			lua.retBoolean(result);
			ret = 1;
		}
		break;
	}
	return ret;
}