mirror of https://github.com/axmolengine/axmol.git
Merge pull request #3537 from samuele3hu/TableView
issue #2764:Add TableView lua binding and releated test sample
This commit is contained in:
commit
80e46dc8c1
|
@ -169,6 +169,7 @@ enum ScriptEventType
|
|||
kAccelerometerEvent,
|
||||
kControlEvent,
|
||||
kCommonEvent,
|
||||
kTableViewEvent,//Now it's only used in LuaBinding
|
||||
};
|
||||
|
||||
struct BasicScriptData
|
||||
|
|
|
@ -992,6 +992,123 @@ local function runEditBoxTest()
|
|||
return newScene
|
||||
end
|
||||
|
||||
|
||||
local TableViewTestLayer = class("TableViewTestLayer")
|
||||
TableViewTestLayer.__index = TableViewTestLayer
|
||||
|
||||
function TableViewTestLayer.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TableViewTestLayer)
|
||||
return target
|
||||
end
|
||||
|
||||
function TableViewTestLayer.scrollViewDidScroll(view)
|
||||
print("scrollViewDidScroll")
|
||||
end
|
||||
|
||||
function TableViewTestLayer.scrollViewDidZoom(view)
|
||||
print("scrollViewDidZoom")
|
||||
end
|
||||
|
||||
function TableViewTestLayer.tableCellTouched(table,cell)
|
||||
print("cell touched at index: " .. cell:getIdx())
|
||||
end
|
||||
|
||||
function TableViewTestLayer.cellSizeForTable(table,idx)
|
||||
return 60,60
|
||||
end
|
||||
|
||||
function TableViewTestLayer.tableCellAtIndex(table, idx)
|
||||
local strValue = string.format("%d",idx)
|
||||
local cell = table:dequeueCell()
|
||||
local label = nil
|
||||
if nil == cell then
|
||||
cell = cc.TableViewCell:new()
|
||||
local sprite = cc.Sprite:create("Images/Icon.png")
|
||||
sprite:setAnchorPoint(cc.p(0,0))
|
||||
sprite:setPosition(cc.p(0, 0))
|
||||
cell:addChild(sprite)
|
||||
|
||||
label = cc.LabelTTF:create(strValue, "Helvetica", 20.0)
|
||||
label:setPosition(cc.p(0,0))
|
||||
label:setAnchorPoint(cc.p(0,0))
|
||||
label:setTag(123)
|
||||
cell:addChild(label)
|
||||
else
|
||||
label = tolua.cast(cell:getChildByTag(123),"LabelTTF")
|
||||
if nil ~= label then
|
||||
label:setString(strValue)
|
||||
end
|
||||
end
|
||||
|
||||
return cell
|
||||
end
|
||||
|
||||
function TableViewTestLayer.numberOfCellsInTableView(table)
|
||||
return 25
|
||||
end
|
||||
|
||||
function TableViewTestLayer:init()
|
||||
|
||||
local winSize = cc.Director:getInstance():getWinSize()
|
||||
|
||||
local tableView = cc.TableView:create(cc.size(600,60))
|
||||
tableView:setDirection(cc.SCROLLVIEW_DIRECTION_HORIZONTAL)
|
||||
tableView:setPosition(cc.p(20, winSize.height / 2 - 150))
|
||||
tableView:setDelegate()
|
||||
self:addChild(tableView)
|
||||
--registerScriptHandler functions must be before the reloadData funtion
|
||||
tableView:registerScriptHandler(TableViewTestLayer.numberOfCellsInTableView,cc.NUMBER_OF_CELLS_IN_TABLEVIEW)
|
||||
tableView:registerScriptHandler(TableViewTestLayer.scrollViewDidScroll,cc.SCROLLVIEW_SCRIPT_SCROLL)
|
||||
tableView:registerScriptHandler(TableViewTestLayer.scrollViewDidZoom,cc.SCROLLVIEW_SCRIPT_ZOOM)
|
||||
tableView:registerScriptHandler(TableViewTestLayer.tableCellTouched,cc.TABLECELL_TOUCHED)
|
||||
tableView:registerScriptHandler(TableViewTestLayer.cellSizeForTable,cc.TABLECELL_SIZE_FOR_INDEX)
|
||||
tableView:registerScriptHandler(TableViewTestLayer.tableCellAtIndex,cc.TABLECELL_SIZE_AT_INDEX)
|
||||
tableView:reloadData()
|
||||
|
||||
tableView = cc.TableView:create(cc.size(60, 350))
|
||||
tableView:setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL)
|
||||
tableView:setPosition(cc.p(winSize.width - 150, winSize.height / 2 - 150))
|
||||
tableView:setDelegate()
|
||||
tableView:setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN)
|
||||
self:addChild(tableView)
|
||||
tableView:registerScriptHandler(TableViewTestLayer.scrollViewDidScroll,cc.SCROLLVIEW_SCRIPT_SCROLL)
|
||||
tableView:registerScriptHandler(TableViewTestLayer.scrollViewDidZoom,cc.SCROLLVIEW_SCRIPT_ZOOM)
|
||||
tableView:registerScriptHandler(TableViewTestLayer.tableCellTouched,cc.TABLECELL_TOUCHED)
|
||||
tableView:registerScriptHandler(TableViewTestLayer.cellSizeForTable,cc.TABLECELL_SIZE_FOR_INDEX)
|
||||
tableView:registerScriptHandler(TableViewTestLayer.tableCellAtIndex,cc.TABLECELL_SIZE_AT_INDEX)
|
||||
tableView:registerScriptHandler(TableViewTestLayer.numberOfCellsInTableView,cc.NUMBER_OF_CELLS_IN_TABLEVIEW)
|
||||
tableView:reloadData()
|
||||
|
||||
-- Back Menu
|
||||
local pToMainMenu = cc.Menu:create()
|
||||
CreateExtensionsBasicLayerMenu(pToMainMenu)
|
||||
pToMainMenu:setPosition(cc.p(0, 0))
|
||||
self:addChild(pToMainMenu,10)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function TableViewTestLayer.create()
|
||||
local layer = TableViewTestLayer.extend(cc.Layer:create())
|
||||
if nil ~= layer then
|
||||
layer:init()
|
||||
end
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
local function runTableViewTest()
|
||||
local newScene = cc.Scene:create()
|
||||
local newLayer = TableViewTestLayer.create()
|
||||
newScene:addChild(newLayer)
|
||||
return newScene
|
||||
end
|
||||
|
||||
local function runScrollViewTest()
|
||||
local newScene = cc.Scene:create()
|
||||
local newLayer = cc.Layer:create()
|
||||
|
@ -1116,7 +1233,6 @@ local function ExtensionsMainLayer()
|
|||
item:setPosition(s.width / 2, s.height - i * LINE_SPACE)
|
||||
menu:addChild(item, kItemTagBasic + i)
|
||||
if ((i == ExtensionTestEnum.TEST_WEBSOCKET + 1) and (false == bSupportWebSocket))
|
||||
or ( i == ExtensionTestEnum.TEST_TABLEVIEW + 1)
|
||||
or ((i == ExtensionTestEnum.TEST_EDITBOX + 1) and (false == bSupportEdit)) then
|
||||
item:setEnabled(false)
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
--Send Text
|
||||
local function onMenuSendTextClicked()
|
||||
if nil ~= wsSendText then
|
||||
if kStateOpen == wsSendText:getReadyState() then
|
||||
if cc.WEBSOCKET_STATE_OPEN == wsSendText:getReadyState() then
|
||||
sendTextStatus:setString("Send Text WS is waiting...")
|
||||
wsSendText:sendString("Hello WebSocket中文, I'm a text message.")
|
||||
else
|
||||
|
@ -45,7 +45,7 @@
|
|||
--Send Binary
|
||||
local function onMenuSendBinaryClicked()
|
||||
if nil ~= wsSendBinary then
|
||||
if kStateOpen == wsSendBinary:getReadyState() then
|
||||
if cc.WEBSOCKET_STATE_OPEN == wsSendBinary:getReadyState() then
|
||||
sendBinaryStatus:setString("Send Binary WS is waiting...")
|
||||
wsSendBinary:sendString("Hello WebSocket中文--,\0 I'm\0 a\0 binary\0 message\0.")
|
||||
else
|
||||
|
@ -156,24 +156,24 @@
|
|||
end
|
||||
|
||||
if nil ~= wsSendText then
|
||||
wsSendText:registerScriptHandler(wsSendTextOpen,kWebSocketScriptHandlerOpen)
|
||||
wsSendText:registerScriptHandler(wsSendTextMessage,kWebSocketScriptHandlerMessage)
|
||||
wsSendText:registerScriptHandler(wsSendTextClose,kWebSocketScriptHandlerClose)
|
||||
wsSendText:registerScriptHandler(wsSendTextError,kWebSocketScriptHandlerError)
|
||||
wsSendText:registerScriptHandler(wsSendTextOpen,cc.WEBSOCKET_OPEN)
|
||||
wsSendText:registerScriptHandler(wsSendTextMessage,cc.WEBSOCKET_MESSAGE)
|
||||
wsSendText:registerScriptHandler(wsSendTextClose,cc.WEBSOCKET_CLOSE)
|
||||
wsSendText:registerScriptHandler(wsSendTextError,cc.WEBSOCKET_ERROR)
|
||||
end
|
||||
|
||||
if nil ~= wsSendBinary then
|
||||
wsSendBinary:registerScriptHandler(wsSendBinaryOpen,kWebSocketScriptHandlerOpen)
|
||||
wsSendBinary:registerScriptHandler(wsSendBinaryMessage,kWebSocketScriptHandlerMessage)
|
||||
wsSendBinary:registerScriptHandler(wsSendBinaryClose,kWebSocketScriptHandlerClose)
|
||||
wsSendBinary:registerScriptHandler(wsSendBinaryError,kWebSocketScriptHandlerError)
|
||||
wsSendBinary:registerScriptHandler(wsSendBinaryOpen,cc.WEBSOCKET_OPEN)
|
||||
wsSendBinary:registerScriptHandler(wsSendBinaryMessage,cc.WEBSOCKET_MESSAGE)
|
||||
wsSendBinary:registerScriptHandler(wsSendBinaryClose,cc.WEBSOCKET_CLOSE)
|
||||
wsSendBinary:registerScriptHandler(wsSendBinaryError,cc.WEBSOCKET_ERROR)
|
||||
end
|
||||
|
||||
if nil ~= wsError then
|
||||
wsError:registerScriptHandler(wsErrorOpen,kWebSocketScriptHandlerOpen)
|
||||
wsError:registerScriptHandler(wsErrorMessage,kWebSocketScriptHandlerMessage)
|
||||
wsError:registerScriptHandler(wsErrorClose,kWebSocketScriptHandlerClose)
|
||||
wsError:registerScriptHandler(wsErrorError,kWebSocketScriptHandlerError)
|
||||
wsError:registerScriptHandler(wsErrorOpen,cc.WEBSOCKET_OPEN)
|
||||
wsError:registerScriptHandler(wsErrorMessage,cc.WEBSOCKET_MESSAGE)
|
||||
wsError:registerScriptHandler(wsErrorClose,cc.WEBSOCKET_CLOSE)
|
||||
wsError:registerScriptHandler(wsErrorError,cc.WEBSOCKET_ERROR)
|
||||
end
|
||||
|
||||
local function OnExit(strEventName)
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
function clone(object)
|
||||
local lookup_table = {}
|
||||
local function _copy(object)
|
||||
if type(object) ~= "table" then
|
||||
return object
|
||||
elseif lookup_table[object] then
|
||||
return lookup_table[object]
|
||||
end
|
||||
local new_table = {}
|
||||
lookup_table[object] = new_table
|
||||
for key, value in pairs(object) do
|
||||
new_table[_copy(key)] = _copy(value)
|
||||
end
|
||||
return setmetatable(new_table, getmetatable(object))
|
||||
end
|
||||
return _copy(object)
|
||||
end
|
||||
|
||||
--Create an class.
|
||||
function class(classname, super)
|
||||
|
|
|
@ -30,4 +30,5 @@
|
|||
android:smallScreens="true"
|
||||
android:anyDensity="true"
|
||||
android:normalScreens="true"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
</manifest>
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "LuaScriptHandlerMgr.h"
|
||||
#include "GUI/CCControlExtension/CCControl.h"
|
||||
#include "LuaOpengl.h"
|
||||
#include "lua_cocos2dx_extension_manual.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -246,6 +247,11 @@ int LuaEngine::sendEvent(ScriptEvent* evt)
|
|||
return handlerControlEvent(evt->data);
|
||||
}
|
||||
break;
|
||||
case kTableViewEvent:
|
||||
{
|
||||
return handleTableViewEvent(evt->data);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -455,7 +461,7 @@ int LuaEngine::handleCommonEvent(void* data)
|
|||
}
|
||||
else
|
||||
{
|
||||
_stack->pushObject(commonInfo->eventSource, "CCObject");
|
||||
_stack->pushObject(commonInfo->eventSource, "Object");
|
||||
}
|
||||
}
|
||||
int ret = _stack->executeFunctionByHandler(commonInfo->handler, commonInfo->eventSource ? 2 : 1);
|
||||
|
@ -571,6 +577,51 @@ int LuaEngine::handleTouchesEvent(void* data)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::handleTableViewEvent(void* data)
|
||||
{
|
||||
if (nullptr == data)
|
||||
return 0;
|
||||
|
||||
BasicScriptData* eventData = static_cast<BasicScriptData*>(data);
|
||||
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
||||
return 0;
|
||||
|
||||
LuaTableViewEventData* tableViewEventData = static_cast<LuaTableViewEventData*>(eventData->value);
|
||||
if (tableViewEventData->eventType < ScriptHandlerMgr::kScrollViewScrollHandler || tableViewEventData->eventType > ScriptHandlerMgr::kNumberOfCellsInTableView )
|
||||
return 0;
|
||||
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, tableViewEventData->eventType);
|
||||
|
||||
if (0 == handler)
|
||||
return 0;
|
||||
|
||||
int ret = 0;
|
||||
switch (tableViewEventData->eventType)
|
||||
{
|
||||
case ScriptHandlerMgr::kScrollViewScrollHandler:
|
||||
case ScriptHandlerMgr::kScrollViewZoomHandler:
|
||||
{
|
||||
_stack->pushObject(static_cast<Object*>(eventData->nativeObject), "TableView");
|
||||
ret = _stack->executeFunctionByHandler(handler, 1);
|
||||
}
|
||||
break;
|
||||
case ScriptHandlerMgr::kTableCellTouched:
|
||||
case ScriptHandlerMgr::kTableCellHighlight:
|
||||
case ScriptHandlerMgr::kTableCellUnhighlight:
|
||||
case ScriptHandlerMgr::kTableCellWillRecycle:
|
||||
{
|
||||
_stack->pushObject(static_cast<Object*>(eventData->nativeObject), "TableView");
|
||||
_stack->pushObject(static_cast<Object*>(tableViewEventData->value), "TableViewCell");
|
||||
ret = _stack->executeFunctionByHandler(handler, 2);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LuaEngine::handlerControlEvent(void* data)
|
||||
{
|
||||
if ( NULL == data )
|
||||
|
@ -653,4 +704,71 @@ void LuaEngine::extendGLNode(lua_State* lua_S)
|
|||
lua_rawset(lua_S,-3);
|
||||
}
|
||||
}
|
||||
|
||||
int LuaEngine::sendEventReturnArray(ScriptEvent* message,int numResults,Array& resultArray)
|
||||
{
|
||||
if (nullptr == message || numResults <= 0)
|
||||
return 0;
|
||||
|
||||
switch (message->type)
|
||||
{
|
||||
case kTableViewEvent:
|
||||
return handleTableViewEventReturnArray(message->data,numResults,resultArray);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngine::handleTableViewEventReturnArray(void* data,int numResults,Array& resultArray)
|
||||
{
|
||||
if (nullptr == data || numResults <= 0)
|
||||
return 0;
|
||||
|
||||
if (nullptr == data)
|
||||
return 0;
|
||||
|
||||
BasicScriptData* eventData = static_cast<BasicScriptData*>(data);
|
||||
if (nullptr == eventData->nativeObject || nullptr == eventData->value)
|
||||
return 0;
|
||||
|
||||
LuaTableViewEventData* tableViewEventData = static_cast<LuaTableViewEventData*>(eventData->value);
|
||||
if (tableViewEventData->eventType < ScriptHandlerMgr::kScrollViewScrollHandler || tableViewEventData->eventType > ScriptHandlerMgr::kNumberOfCellsInTableView )
|
||||
return 0;
|
||||
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, tableViewEventData->eventType);
|
||||
|
||||
if (0 == handler)
|
||||
return 0;
|
||||
|
||||
int ret = 0;
|
||||
switch (tableViewEventData->eventType)
|
||||
{
|
||||
case ScriptHandlerMgr::kTableCellSizeForIndex:
|
||||
{
|
||||
_stack->pushObject(static_cast<Object*>(eventData->nativeObject), "TableView");
|
||||
_stack->pushInt(*((int*)tableViewEventData->value));
|
||||
ret = _stack->executeFunctionReturnArray(handler, 2, 2, resultArray);
|
||||
}
|
||||
break;
|
||||
case ScriptHandlerMgr::kTableCellAtIndex:
|
||||
{
|
||||
_stack->pushObject(static_cast<Object*>(eventData->nativeObject), "TableView");
|
||||
_stack->pushInt(*((int*)tableViewEventData->value));
|
||||
ret = _stack->executeFunctionReturnArray(handler, 2, 1, resultArray);
|
||||
}
|
||||
break;
|
||||
case ScriptHandlerMgr::kNumberOfCellsInTableView:
|
||||
{
|
||||
_stack->pushObject(static_cast<Object*>(eventData->nativeObject), "TableView");
|
||||
ret = _stack->executeFunctionReturnArray(handler, 1, 1, resultArray);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
NS_CC_END
|
||||
|
|
|
@ -120,6 +120,7 @@ public:
|
|||
virtual bool handleAssert(const char *msg);
|
||||
|
||||
virtual int sendEvent(ScriptEvent* message);
|
||||
virtual int sendEventReturnArray(ScriptEvent* message,int numResults,Array& resultArray);
|
||||
void extendLuaObject();
|
||||
private:
|
||||
LuaEngine(void)
|
||||
|
@ -138,6 +139,8 @@ private:
|
|||
int handleTouchEvent(void* data);
|
||||
int handleTouchesEvent(void* data);
|
||||
int handlerControlEvent(void* data);
|
||||
int handleTableViewEvent(void* data);
|
||||
int handleTableViewEventReturnArray(void* data,int numResults,Array& resultArray);
|
||||
void extendWebsocket(lua_State* lua_S);
|
||||
void extendGLNode(lua_State* lua_S);
|
||||
private:
|
||||
|
|
|
@ -456,4 +456,89 @@ int LuaStack::reallocateScriptHandler(int nHandler)
|
|||
|
||||
}
|
||||
|
||||
int LuaStack::executeFunctionReturnArray(int handler,int numArgs,int numResults,Array& resultArray)
|
||||
{
|
||||
if (pushFunctionByHandler(handler)) /* L: ... arg1 arg2 ... func */
|
||||
{
|
||||
if (numArgs > 0)
|
||||
{
|
||||
lua_insert(_state, -(numArgs + 1)); /* L: ... func arg1 arg2 ... */
|
||||
int functionIndex = -(numArgs + 1);
|
||||
if (!lua_isfunction(_state, functionIndex))
|
||||
{
|
||||
CCLOG("value at stack [%d] is not function", functionIndex);
|
||||
lua_pop(_state, numArgs + 1); // remove function and arguments
|
||||
return 0;
|
||||
}
|
||||
|
||||
int traceback = 0;
|
||||
lua_getglobal(_state, "__G__TRACKBACK__"); /* L: ... func arg1 arg2 ... G */
|
||||
if (!lua_isfunction(_state, -1))
|
||||
{
|
||||
lua_pop(_state, 1); /* L: ... func arg1 arg2 ... */
|
||||
}
|
||||
else
|
||||
{
|
||||
lua_insert(_state, functionIndex - 1); /* L: ... G func arg1 arg2 ... */
|
||||
traceback = functionIndex - 1;
|
||||
}
|
||||
|
||||
int error = 0;
|
||||
++_callFromLua;
|
||||
error = lua_pcall(_state, numArgs, numResults, traceback); /* L: ... [G] ret1 ret2 ... retResults*/
|
||||
--_callFromLua;
|
||||
if (error)
|
||||
{
|
||||
if (traceback == 0)
|
||||
{
|
||||
CCLOG("[LUA ERROR] %s", lua_tostring(_state, - 1)); /* L: ... error */
|
||||
lua_pop(_state, 1); // remove error message from stack
|
||||
}
|
||||
else /* L: ... G error */
|
||||
{
|
||||
lua_pop(_state, 2); // remove __G__TRACKBACK__ and error message from stack
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get return value,don't pass LUA_MULTRET to numResults,
|
||||
if (numResults <= 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0 ; i < numResults; i++)
|
||||
{
|
||||
if (lua_type(_state, -1) == LUA_TBOOLEAN) {
|
||||
|
||||
bool value = lua_toboolean(_state, -1);
|
||||
resultArray.addObject(Bool::create(value)) ;
|
||||
|
||||
}else if (lua_type(_state, -1) == LUA_TNUMBER) {
|
||||
|
||||
double value = lua_tonumber(_state, -1);
|
||||
resultArray.addObject(Double::create(value));
|
||||
|
||||
}else if (lua_type(_state, -1) == LUA_TSTRING) {
|
||||
|
||||
const char* value = lua_tostring(_state, -1);
|
||||
resultArray.addObject(String::create(value));
|
||||
|
||||
}else{
|
||||
|
||||
resultArray.addObject(static_cast<Object*>(tolua_tousertype(_state, -1, NULL)));
|
||||
}
|
||||
// remove return value from stack
|
||||
lua_pop(_state, 1); /* L: ... [G] ret1 ret2 ... ret*/
|
||||
}
|
||||
/* L: ... [G]*/
|
||||
|
||||
if (traceback)
|
||||
{
|
||||
lua_pop(_state, 1); // remove __G__TRACKBACK__ from stack /* L: ... */
|
||||
}
|
||||
}
|
||||
}
|
||||
lua_settop(_state, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -113,6 +113,7 @@ public:
|
|||
virtual int executeFunction(int numArgs);
|
||||
|
||||
virtual int executeFunctionByHandler(int nHandler, int numArgs);
|
||||
virtual int executeFunctionReturnArray(int handler,int numArgs,int numResults,Array& resultArray);
|
||||
|
||||
virtual bool handleAssert(const char *msg);
|
||||
|
||||
|
|
|
@ -702,30 +702,6 @@ TOLUA_API int tolua_script_handler_mgr_open(lua_State* tolua_S)
|
|||
tolua_endmodule(tolua_S);
|
||||
tolua_cclass(tolua_S,"ScriptHandlerMgr","ScriptHandlerMgr","",NULL);
|
||||
tolua_beginmodule(tolua_S, "ScriptHandlerMgr");
|
||||
tolua_constant(tolua_S,"kNormalHandler",ScriptHandlerMgr::kNodeHandler);
|
||||
tolua_constant(tolua_S,"kMenuClickHandler",ScriptHandlerMgr::kMenuClickHandler);
|
||||
tolua_constant(tolua_S,"kNotificationHandler",ScriptHandlerMgr::kNotificationHandler);
|
||||
tolua_constant(tolua_S,"kCallFuncHandler",ScriptHandlerMgr::kCallFuncHandler);
|
||||
tolua_constant(tolua_S,"kScheduleHandler",ScriptHandlerMgr::kScheduleHandler);
|
||||
tolua_constant(tolua_S,"kTouchesHandler",ScriptHandlerMgr::kTouchesHandler);
|
||||
tolua_constant(tolua_S,"kKeypadHandler",ScriptHandlerMgr::kKeypadHandler);
|
||||
tolua_constant(tolua_S,"kAccelerometerHandler",ScriptHandlerMgr::kAccelerometerHandler);
|
||||
tolua_constant(tolua_S,"kControlTouchDownHandler",ScriptHandlerMgr::kControlTouchDownHandler);
|
||||
tolua_constant(tolua_S,"kControlTouchDragInsideHandler",ScriptHandlerMgr::kControlTouchDragInsideHandler);
|
||||
tolua_constant(tolua_S,"kControlTouchDragOutsideHandler",ScriptHandlerMgr::kControlTouchDragOutsideHandler);
|
||||
tolua_constant(tolua_S,"kControlTouchDragEnterHandler",ScriptHandlerMgr::kControlTouchDragEnterHandler);
|
||||
tolua_constant(tolua_S,"kControlTouchDragExitHandler",ScriptHandlerMgr::kControlTouchDragExitHandler);
|
||||
tolua_constant(tolua_S,"kControlTouchUpInsideHandler",ScriptHandlerMgr::kControlTouchUpInsideHandler);
|
||||
tolua_constant(tolua_S,"kControlTouchUpOutsideHandler",ScriptHandlerMgr::kControlTouchUpOutsideHandler);
|
||||
tolua_constant(tolua_S,"kControlTouchCancelHandler",ScriptHandlerMgr::kControlTouchCancelHandler);
|
||||
tolua_constant(tolua_S,"kControlValueChangedHandler",ScriptHandlerMgr::kControlValueChangedHandler);
|
||||
tolua_constant(tolua_S,"kWebSocketScriptHandlerOpen",ScriptHandlerMgr::kWebSocketScriptHandlerOpen);
|
||||
tolua_constant(tolua_S,"kWebSocketScriptHandlerMessage",ScriptHandlerMgr::kWebSocketScriptHandlerMessage);
|
||||
tolua_constant(tolua_S,"kWebSocketScriptHandlerClose",ScriptHandlerMgr::kWebSocketScriptHandlerClose);
|
||||
tolua_constant(tolua_S,"kWebSocketScriptHandlerError",ScriptHandlerMgr::kWebSocketScriptHandlerError);
|
||||
tolua_constant(tolua_S,"kGLNodeDrawHandler",ScriptHandlerMgr::kGLNodeDrawHandler);
|
||||
tolua_constant(tolua_S,"kScrollViewScrollHandler",ScriptHandlerMgr::kScrollViewScrollHandler);
|
||||
tolua_constant(tolua_S,"kScrollViewZoomHandler",ScriptHandlerMgr::kScrollViewZoomHandler);
|
||||
tolua_function(tolua_S, "getInstance", tolua_Cocos2d_ScriptHandlerMgr_getInstance00);
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_endmodule(tolua_S);
|
||||
|
|
|
@ -72,34 +72,42 @@ public:
|
|||
|
||||
enum HandlerEventType
|
||||
{
|
||||
kNodeHandler = 0,
|
||||
kMenuClickHandler,
|
||||
kNotificationHandler,
|
||||
kCallFuncHandler,
|
||||
kScheduleHandler,
|
||||
kTouchesHandler,
|
||||
kKeypadHandler,
|
||||
kAccelerometerHandler,
|
||||
|
||||
kControlTouchDownHandler,
|
||||
kControlTouchDragInsideHandler,
|
||||
kControlTouchDragOutsideHandler,
|
||||
kControlTouchDragEnterHandler,
|
||||
kControlTouchDragExitHandler,
|
||||
kControlTouchUpInsideHandler,
|
||||
kControlTouchUpOutsideHandler,
|
||||
kControlTouchCancelHandler,
|
||||
kControlValueChangedHandler,
|
||||
|
||||
kWebSocketScriptHandlerOpen,
|
||||
kWebSocketScriptHandlerMessage,
|
||||
kWebSocketScriptHandlerClose,
|
||||
kWebSocketScriptHandlerError,
|
||||
kNodeHandler = 0,
|
||||
kMenuClickHandler,
|
||||
kNotificationHandler,
|
||||
kCallFuncHandler,
|
||||
kScheduleHandler,
|
||||
kTouchesHandler,
|
||||
kKeypadHandler,
|
||||
kAccelerometerHandler,
|
||||
|
||||
kGLNodeDrawHandler,
|
||||
kControlTouchDownHandler,
|
||||
kControlTouchDragInsideHandler,
|
||||
kControlTouchDragOutsideHandler,
|
||||
kControlTouchDragEnterHandler,
|
||||
kControlTouchDragExitHandler,
|
||||
kControlTouchUpInsideHandler,
|
||||
kControlTouchUpOutsideHandler,
|
||||
kControlTouchCancelHandler,
|
||||
kControlValueChangedHandler,
|
||||
|
||||
kWebSocketScriptHandlerOpen,
|
||||
kWebSocketScriptHandlerMessage,
|
||||
kWebSocketScriptHandlerClose,
|
||||
kWebSocketScriptHandlerError,
|
||||
|
||||
kGLNodeDrawHandler,
|
||||
|
||||
kScrollViewScrollHandler,
|
||||
kScrollViewZoomHandler,
|
||||
|
||||
kScrollViewScrollHandler,
|
||||
kScrollViewZoomHandler,
|
||||
kTableCellTouched,
|
||||
kTableCellHighlight,
|
||||
kTableCellUnhighlight,
|
||||
kTableCellWillRecycle,
|
||||
kTableCellSizeForIndex,
|
||||
kTableCellAtIndex,
|
||||
kNumberOfCellsInTableView,
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -352,15 +352,6 @@ TOLUA_API int tolua_web_socket_open(lua_State* tolua_S){
|
|||
tolua_reg_Web_Socket_type(tolua_S);
|
||||
tolua_module(tolua_S,NULL,0);
|
||||
tolua_beginmodule(tolua_S,NULL);
|
||||
tolua_constant(tolua_S,"kStateConnecting",(int)WebSocket::State::CONNECTING);
|
||||
tolua_constant(tolua_S,"kStateOpen",(int)WebSocket::State::OPEN);
|
||||
tolua_constant(tolua_S,"kStateClosing",(int)WebSocket::State::CLOSING);
|
||||
tolua_constant(tolua_S,"kStateClosed",(int)WebSocket::State::CLOSED);
|
||||
tolua_constant(tolua_S,"kWebSocketScriptHandlerOpen",LuaWebSocket::kWebSocketScriptHandlerOpen);
|
||||
tolua_constant(tolua_S,"kWebSocketScriptHandlerMessage",LuaWebSocket::kWebSocketScriptHandlerMessage);
|
||||
tolua_constant(tolua_S,"kWebSocketScriptHandlerClose",LuaWebSocket::kWebSocketScriptHandlerClose);
|
||||
tolua_constant(tolua_S,"kWebSocketScriptHandlerError",LuaWebSocket::kWebSocketScriptHandlerError);
|
||||
|
||||
#ifdef __cplusplus
|
||||
tolua_cclass(tolua_S,"WebSocket","WebSocket","",tolua_collect_WebSocket);
|
||||
#else
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
{
|
||||
CommonScriptData data(handler,"");
|
||||
ScriptEvent event(kCommonEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
LuaEngine::getInstance()->sendEvent(&event);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public:
|
|||
{
|
||||
CommonScriptData data(handler,"");
|
||||
ScriptEvent event(kCommonEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
LuaEngine::getInstance()->sendEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -853,6 +853,482 @@ static void extendCCBAnimationManager(lua_State* tolua_S)
|
|||
}
|
||||
}
|
||||
|
||||
#define KEY_TABLEVIEW_DATA_SOURCE "TableViewDataSource"
|
||||
#define KEY_TABLEVIEW_DELEGATE "TableViewDelegate"
|
||||
|
||||
class LUA_TableViewDelegate:public Object, public TableViewDelegate
|
||||
{
|
||||
public:
|
||||
LUA_TableViewDelegate(){}
|
||||
|
||||
virtual ~LUA_TableViewDelegate(){}
|
||||
|
||||
|
||||
virtual void scrollViewDidScroll(ScrollView* view)
|
||||
{
|
||||
if (nullptr != view)
|
||||
{
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)view, ScriptHandlerMgr::kScrollViewScrollHandler);
|
||||
if (0 != handler)
|
||||
{
|
||||
LuaTableViewEventData eventData(ScriptHandlerMgr::kScrollViewScrollHandler);
|
||||
BasicScriptData data(view,&eventData);
|
||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
||||
LuaEngine::getInstance()->sendEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void scrollViewDidZoom(ScrollView* view)
|
||||
{
|
||||
if (nullptr != view)
|
||||
{
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)view, ScriptHandlerMgr::kScrollViewZoomHandler);
|
||||
if (0 != handler)
|
||||
{
|
||||
LuaTableViewEventData eventData(ScriptHandlerMgr::kScrollViewZoomHandler);
|
||||
BasicScriptData data(view,&eventData);
|
||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
||||
LuaEngine::getInstance()->sendEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void tableCellTouched(TableView* table, TableViewCell* cell)
|
||||
{
|
||||
if (nullptr != table && nullptr != cell)
|
||||
{
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::kTableCellTouched);
|
||||
if (0 != handler)
|
||||
{
|
||||
LuaTableViewEventData eventData(ScriptHandlerMgr::kTableCellTouched,cell);
|
||||
BasicScriptData data(table,&eventData);
|
||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
||||
LuaEngine::getInstance()->sendEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void tableCellHighlight(TableView* table, TableViewCell* cell)
|
||||
{
|
||||
if (nullptr != table && nullptr != cell)
|
||||
{
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::kTableCellHighlight);
|
||||
if (0 != handler)
|
||||
{
|
||||
LuaTableViewEventData eventData(ScriptHandlerMgr::kTableCellHighlight,cell);
|
||||
BasicScriptData data(table,&eventData);
|
||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
||||
LuaEngine::getInstance()->sendEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void tableCellUnhighlight(TableView* table, TableViewCell* cell)
|
||||
{
|
||||
if (nullptr != table && nullptr != cell)
|
||||
{
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::kTableCellUnhighlight);
|
||||
if (0 != handler)
|
||||
{
|
||||
LuaTableViewEventData eventData(ScriptHandlerMgr::kTableCellUnhighlight,cell);
|
||||
BasicScriptData data(table,&eventData);
|
||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
||||
LuaEngine::getInstance()->sendEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void tableCellWillRecycle(TableView* table, TableViewCell* cell)
|
||||
{
|
||||
if (nullptr != table && nullptr != cell)
|
||||
{
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::kTableCellWillRecycle);
|
||||
if (0 != handler)
|
||||
{
|
||||
LuaTableViewEventData eventData(ScriptHandlerMgr::kTableCellWillRecycle,cell);
|
||||
BasicScriptData data(table,&eventData);
|
||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
||||
LuaEngine::getInstance()->sendEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static int lua_cocos2dx_TableView_setDelegate(lua_State* L)
|
||||
{
|
||||
if (nullptr == L)
|
||||
return 0;
|
||||
|
||||
int argc = 0;
|
||||
TableView* self = nullptr;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
if (!tolua_isusertype(L,1,"TableView",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
self = (TableView*) tolua_tousertype(L,1,0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (nullptr == self)
|
||||
{
|
||||
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_TableView_setDelegate'\n", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(L) - 1;
|
||||
|
||||
if (0 == argc)
|
||||
{
|
||||
LUA_TableViewDelegate* delegate = new LUA_TableViewDelegate();
|
||||
if (nullptr == delegate)
|
||||
return 0;
|
||||
|
||||
Dictionary* userDict = static_cast<Dictionary*>(self->getUserObject());
|
||||
if (nullptr == userDict)
|
||||
{
|
||||
userDict = new Dictionary();
|
||||
if (NULL == userDict)
|
||||
return 0;
|
||||
|
||||
self->setUserObject(userDict);
|
||||
userDict->release();
|
||||
}
|
||||
|
||||
userDict->setObject(delegate, KEY_TABLEVIEW_DELEGATE);
|
||||
self->setDelegate(delegate);
|
||||
delegate->release();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
CCLOG("'setDelegate' function of TableView wrong number of arguments: %d, was expecting %d\n", argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(L,"#ferror in function 'setDelegate'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
class LUA_TableViewDataSource:public Object,public TableViewDataSource
|
||||
{
|
||||
public:
|
||||
LUA_TableViewDataSource(){}
|
||||
virtual ~LUA_TableViewDataSource(){}
|
||||
|
||||
virtual Size tableCellSizeForIndex(TableView *table, unsigned int idx)
|
||||
{
|
||||
if (nullptr != table )
|
||||
{
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::kTableCellSizeForIndex);
|
||||
if (0 != handler)
|
||||
{
|
||||
Array resultArray;
|
||||
resultArray.initWithCapacity(1);
|
||||
LuaTableViewEventData eventData(ScriptHandlerMgr::kTableCellSizeForIndex,&idx);
|
||||
BasicScriptData data(table,&eventData);
|
||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
||||
LuaEngine::getInstance()->sendEventReturnArray(&event, 2, resultArray);
|
||||
CCASSERT(resultArray.count() == 2, "tableCellSizeForIndex Array count error");
|
||||
Double* width = dynamic_cast<Double*>(resultArray.getObjectAtIndex(0));
|
||||
Double* height = dynamic_cast<Double*>(resultArray.getObjectAtIndex(1));
|
||||
if (nullptr != width && nullptr != height)
|
||||
{
|
||||
return Size((float)width->getValue(), (float)height->getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Size::ZERO;
|
||||
}
|
||||
|
||||
virtual TableViewCell* tableCellAtIndex(TableView *table, unsigned int idx)
|
||||
{
|
||||
if (nullptr != table )
|
||||
{
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::kTableCellAtIndex);
|
||||
if (0 != handler)
|
||||
{
|
||||
Array resultArray;
|
||||
resultArray.initWithCapacity(1);
|
||||
LuaTableViewEventData eventData(ScriptHandlerMgr::kTableCellAtIndex,&idx);
|
||||
BasicScriptData data(table,&eventData);
|
||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
||||
LuaEngine::getInstance()->sendEventReturnArray(&event, 1, resultArray);
|
||||
TableViewCell* viewCell = nullptr;
|
||||
if (resultArray.count() > 0)
|
||||
{
|
||||
viewCell = dynamic_cast<TableViewCell*>(resultArray.getObjectAtIndex(0));
|
||||
}
|
||||
|
||||
return viewCell;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual unsigned int numberOfCellsInTableView(TableView *table)
|
||||
{
|
||||
if (nullptr != table )
|
||||
{
|
||||
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::kNumberOfCellsInTableView);
|
||||
if (0 != handler)
|
||||
{
|
||||
Array resultArray;
|
||||
resultArray.initWithCapacity(1);
|
||||
LuaTableViewEventData eventData(ScriptHandlerMgr::kNumberOfCellsInTableView);
|
||||
BasicScriptData data(table,&eventData);
|
||||
ScriptEvent event(kTableViewEvent,(void*)&data);
|
||||
LuaEngine::getInstance()->sendEventReturnArray(&event, 1, resultArray);
|
||||
Double* numbers = dynamic_cast<Double*>(resultArray.getObjectAtIndex(0));
|
||||
if (NULL != numbers)
|
||||
{
|
||||
return (int)numbers->getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
static int lua_cocos2dx_TableView_setDataSource(lua_State* L)
|
||||
{
|
||||
if (nullptr == L)
|
||||
return 0;
|
||||
|
||||
int argc = 0;
|
||||
TableView* self = nullptr;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
if (!tolua_isusertype(L,1,"TableView",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
self = (TableView*) tolua_tousertype(L,1,0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (nullptr == self)
|
||||
{
|
||||
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_TableView_setDataSource'\n", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(L) - 1;
|
||||
|
||||
if (0 == argc)
|
||||
{
|
||||
LUA_TableViewDataSource* dataSource = new LUA_TableViewDataSource();
|
||||
if (nullptr == dataSource)
|
||||
return 0;
|
||||
|
||||
Dictionary* userDict = static_cast<Dictionary*>(self->getUserObject());
|
||||
if (nullptr == userDict)
|
||||
{
|
||||
userDict = new Dictionary();
|
||||
if (NULL == userDict)
|
||||
return 0;
|
||||
|
||||
self->setUserObject(userDict);
|
||||
userDict->release();
|
||||
}
|
||||
|
||||
userDict->setObject(dataSource, KEY_TABLEVIEW_DATA_SOURCE);
|
||||
|
||||
self->setDataSource(dataSource);
|
||||
|
||||
dataSource->release();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
CCLOG("'setDataSource' function of TableView wrong number of arguments: %d, was expecting %d\n", argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(L,"#ferror in function 'setDataSource'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int lua_cocos2dx_TableView_create(lua_State* L)
|
||||
{
|
||||
if (nullptr == L)
|
||||
return 0;
|
||||
|
||||
int argc = 0;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
if (!tolua_isusertable(L,1,"TableView",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(L) - 1;
|
||||
|
||||
if (2 == argc || 1 == argc)
|
||||
{
|
||||
LUA_TableViewDataSource* dataSource = new LUA_TableViewDataSource();
|
||||
Size size;
|
||||
ok &= luaval_to_size(L, 2, &size);
|
||||
|
||||
TableView* ret = nullptr;
|
||||
|
||||
if (1 == argc)
|
||||
{
|
||||
ret = TableView::create(dataSource, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertype(L,3,"Node",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
Node* node = static_cast<Node*>(tolua_tousertype(L, 2, nullptr));
|
||||
ret = TableView::create(dataSource, size, node);
|
||||
}
|
||||
|
||||
if (nullptr == ret)
|
||||
return 0;
|
||||
|
||||
ret->reloadData();
|
||||
|
||||
Dictionary* userDict = new Dictionary();
|
||||
userDict->setObject(dataSource, KEY_TABLEVIEW_DATA_SOURCE);
|
||||
ret->setUserObject(userDict);
|
||||
userDict->release();
|
||||
|
||||
dataSource->release();
|
||||
|
||||
|
||||
int nID = (int)ret->_ID;
|
||||
int* pLuaID = &ret->_luaID;
|
||||
toluafix_pushusertype_ccobject(L, nID, pLuaID, (void*)ret,"TableView");
|
||||
|
||||
return 1;
|
||||
}
|
||||
CCLOG("'create' function of TableView wrong number of arguments: %d, was expecting %d\n", argc, 1);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(L,"#ferror in function 'create'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int lua_cocos2d_TableView_registerScriptHandler(lua_State* L)
|
||||
{
|
||||
if (NULL == L)
|
||||
return 0;
|
||||
|
||||
int argc = 0;
|
||||
TableView* self = nullptr;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
if (!tolua_isusertype(L,1,"TableView",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
self = static_cast<TableView*>(tolua_tousertype(L,1,0));
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (nullptr == self) {
|
||||
tolua_error(L,"invalid 'self' in function 'tolua_cocos2d_TableView_registerScriptHandler'\n", NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
argc = lua_gettop(L) - 1;
|
||||
if (2 == argc)
|
||||
{
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err) ||
|
||||
!tolua_isnumber(L, 3, 0, &tolua_err) )
|
||||
{
|
||||
goto tolua_lerror;
|
||||
}
|
||||
#endif
|
||||
LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0));
|
||||
ScriptHandlerMgr::HandlerEventType handlerType = (ScriptHandlerMgr::HandlerEventType) ((int)tolua_tonumber(L,3,0) + ScriptHandlerMgr::kScrollViewScrollHandler);
|
||||
|
||||
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, handlerType);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CCLOG("'registerScriptHandler' function of TableView has wrong number of arguments: %d, was expecting %d\n", argc, 2);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(L,"#ferror in function 'registerScriptHandler'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int lua_cocos2d_TableView_unregisterScriptHandler(lua_State* L)
|
||||
{
|
||||
if (NULL == L)
|
||||
return 0;
|
||||
|
||||
int argc = 0;
|
||||
TableView* self = nullptr;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
if (!tolua_isusertype(L,1,"TableView",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
self = static_cast<TableView*>(tolua_tousertype(L,1,0));
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (nullptr == self) {
|
||||
tolua_error(L,"invalid 'self' in function 'lua_cocos2d_TableView_unregisterScriptHandler'\n", NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(L) - 1;
|
||||
|
||||
if (1 == argc)
|
||||
{
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isnumber(L, 2, 0, &tolua_err))
|
||||
goto tolua_lerror;
|
||||
#endif
|
||||
ScriptHandlerMgr::HandlerEventType handlerType = (ScriptHandlerMgr::HandlerEventType) ((int)tolua_tonumber(L,2,0) + ScriptHandlerMgr::kScrollViewScrollHandler);
|
||||
ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)self, handlerType);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CCLOG("'unregisterScriptHandler' function of TableView has wrong number of arguments: %d, was expecting %d\n", argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(L,"#ferror in function 'unregisterScriptHandler'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void extendTableView(lua_State* L)
|
||||
{
|
||||
lua_pushstring(L, "TableView");
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
if (lua_istable(L,-1))
|
||||
{
|
||||
tolua_function(L, "setDelegate", lua_cocos2dx_TableView_setDelegate);
|
||||
tolua_function(L, "setDataSource", lua_cocos2dx_TableView_setDataSource);
|
||||
tolua_function(L, "create", lua_cocos2dx_TableView_create);
|
||||
tolua_function(L, "registerScriptHandler", lua_cocos2d_TableView_registerScriptHandler);
|
||||
tolua_function(L, "unregisterScriptHandler", lua_cocos2d_TableView_unregisterScriptHandler);
|
||||
}
|
||||
}
|
||||
|
||||
int register_all_cocos2dx_extension_manual(lua_State* tolua_S)
|
||||
{
|
||||
extendScrollView(tolua_S);
|
||||
|
@ -860,5 +1336,6 @@ int register_all_cocos2dx_extension_manual(lua_State* tolua_S)
|
|||
extendEditBox(tolua_S);
|
||||
extendCCBReader(tolua_S);
|
||||
extendCCBAnimationManager(tolua_S);
|
||||
extendTableView(tolua_S);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -12,4 +12,16 @@ extern "C" {
|
|||
TOLUA_API int register_all_cocos2dx_extension_manual(lua_State* tolua_S);
|
||||
TOLUA_API int register_cocos2dx_extension_CCBProxy(lua_State* tolua_S);
|
||||
|
||||
struct LuaTableViewEventData
|
||||
{
|
||||
int eventType;
|
||||
void* value;
|
||||
|
||||
// Constructor
|
||||
LuaTableViewEventData(int _eventType,void* _value = nullptr)
|
||||
: eventType(_eventType),value(_value)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif // #ifndef COCOS2DX_SCRIPT_LUA_COCOS2DX_SUPPORT_LUA_COCOS2DX_EXTENSION_MANUAL_H
|
||||
|
|
|
@ -186,6 +186,13 @@ cc.PLATFORM_OS_TIZEN = 9
|
|||
|
||||
cc.SCROLLVIEW_SCRIPT_SCROLL = 0
|
||||
cc.SCROLLVIEW_SCRIPT_ZOOM = 1
|
||||
cc.TABLECELL_TOUCHED = 2
|
||||
cc.TABLECELL_HIGH_LIGHT = 3
|
||||
cc.TABLECELL_UNHIGH_LIGHT = 4
|
||||
cc.TABLECELL_WILL_RECYCLE = 5
|
||||
cc.TABLECELL_SIZE_FOR_INDEX = 6
|
||||
cc.TABLECELL_SIZE_AT_INDEX = 7
|
||||
cc.NUMBER_OF_CELLS_IN_TABLEVIEW = 8
|
||||
|
||||
cc.SCROLLVIEW_DIRECTION_NONE = -1
|
||||
cc.SCROLLVIEW_DIRECTION_HORIZONTAL = 0
|
||||
|
@ -253,3 +260,15 @@ cc.CONTROL_STEPPER_PART_MINUS = 0
|
|||
cc.CONTROL_STEPPER_PART_PLUS = 1
|
||||
cc.CONTROL_STEPPER_PART_NONE = 2
|
||||
|
||||
cc.TABLEVIEW_FILL_TOPDOWN = 0
|
||||
cc.TABLEVIEW_FILL_BOTTOMUP = 1
|
||||
|
||||
cc.WEBSOCKET_OPEN = 0
|
||||
cc.WEBSOCKET_MESSAGE = 1
|
||||
cc.WEBSOCKET_CLOSE = 2
|
||||
cc.WEBSOCKET_ERROR = 3
|
||||
|
||||
cc.WEBSOCKET_STATE_CONNECTING = 0
|
||||
cc.WEBSOCKET_STATE_OPEN = 1
|
||||
cc.WEBSOCKET_STATE_CLOSING = 2
|
||||
cc.WEBSOCKET_STATE_CLOSED = 3
|
||||
|
|
|
@ -385,3 +385,13 @@ _G.CCControlStateNormal = cc.CONTROL_STATE_NORMAL
|
|||
_G.CCControlStateHighlighted = cc.CONTROL_STATE_HIGH_LIGHTED
|
||||
_G.CCControlStateDisabled = cc.CONTROL_STATE_DISABLED
|
||||
_G.CCControlStateSelected = cc.CONTROL_STATE_SELECTED
|
||||
|
||||
_G.kWebSocketScriptHandlerOpen = cc.WEBSOCKET_OPEN
|
||||
_G.kWebSocketScriptHandlerMessage = cc.WEBSOCKET_MESSAGE
|
||||
_G.kWebSocketScriptHandlerClose = cc.WEBSOCKET_CLOSE
|
||||
_G.kWebSocketScriptHandlerError = cc.WEBSOCKET_ERROR
|
||||
|
||||
_G.kStateConnecting = cc.WEBSOCKET_STATE_CONNECTING
|
||||
_G.kStateOpen = cc.WEBSOCKET_STATE_OPEN
|
||||
_G.kStateClosing = cc.WEBSOCKET_STATE_CLOSING
|
||||
_G.kStateClosed = cc.WEBSOCKET_STATE_CLOSED
|
||||
|
|
Loading…
Reference in New Issue