ItemManager.lua
2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
cc.exports.ItemManager=class("ItemManager")
ItemManager.lock_pok = false;
local queuePopList = {};
local isPopping = false;
local runningScene = nil;
local lastPopTime = 0;
local function showPopItem()
if not isPopping then
if #queuePopList > 0 then
isPopping = true;
local obj = queuePopList[1];
table.remove(queuePopList,1);
local PopItem = cc.CSLoader:createNode("ui/PopItem.csb");
local rect = PopItem:getBoundingBox();
PopItem:setPosition(cc.p(display.width/2-rect.width/2,display.height/2-rect.height/2));
local icon = PopItem:getChildByName("icon");
icon:loadTexture("res/iconsmall/"..obj.id..".png");
local item_amount = PopItem:getChildByName("item_amount");
local itemInfo = ItemInfo.getItemInfo(obj.id);
item_amount:setString(itemInfo.name.."* "..obj.num);
runningScene:addChild(PopItem,dialog.ZORDER_POP+1);
local function fadeOutBack()
PopItem:removeSelf();
if not isPopping then
showPopItem();
end
end
local fadeOut = cc.FadeOut:create(1);
local moveBy = cc.MoveBy:create(1, cc.p(0, 200));
PopItem:runAction(moveBy);
PopItem:runAction(cc.Sequence:create(fadeOut,cc.CallFunc:create(fadeOutBack)));
local function nextPopFun()
isPopping = false;
showPopItem();
end
runningScene:runAction(cc.Sequence:create(cc.DelayTime:create(0.3),cc.CallFunc:create(nextPopFun)));
end
end
end
function ItemManager.addPopItem(ID,num)
if ID == 100004 or ItemManager.lock_pok then
return;
end
local obj = {id=ID,num=num};
if runningScene ~= cc.Director:getInstance():getRunningScene() then
queuePopList = {};
runningScene = cc.Director:getInstance():getRunningScene();
end
queuePopList[#queuePopList+1] = obj;
if ID == 100001 then
ccs.ArmatureDataManager:getInstance():addArmatureFileInfo(string.format("res/effects/%s/%s.ExportJson","gold","gold"))
local effect = ccs.Armature:create("gold");
effect:getAnimation():play("gold");
runningScene:addChild(effect,dialog.ZORDER_POP);
effect:setPosition(cc.p(display.width/2,display.height/2));
effect:getAnimation():setMovementEventCallFunc(function(arm, eventType, movmentID)
if (eventType == ccs.MovementEventType.complete or eventType == ccs.MovementEventType.loopComplete) then
arm:removeSelf();
end
end)
end
showPopItem();
end
return ItemManager