diff --git a/RootDesk/MyDesk/SlayDeckController.codeblock b/RootDesk/MyDesk/SlayDeckController.codeblock index 090e15a..a43cfe7 100644 --- a/RootDesk/MyDesk/SlayDeckController.codeblock +++ b/RootDesk/MyDesk/SlayDeckController.codeblock @@ -78,6 +78,13 @@ "Attributes": [], "Name": "TweenEventId" }, + { + "Type": "number", + "DefaultValue": "0", + "SyncDirection": 0, + "Attributes": [], + "Name": "CardHoverTweenId" + }, { "Type": "any", "DefaultValue": "nil", @@ -1416,7 +1423,7 @@ "Name": "hover" } ], - "Code": "local prefix = \"\"\nlocal count = 0\nlocal xs = {}\nlocal baseY = 0\nlocal hoverIndex = 0\nlocal push = 110\nif string.find(path, \"/ui/DefaultGroup/CardHand/Card\") == 1 then\n\tprefix = \"/ui/DefaultGroup/CardHand/Card\"\n\tcount = 5\n\txs = { -400, -200, 0, 200, 400 }\n\tbaseY = 0\n\thoverIndex = tonumber(string.match(path, \"Card(%d+)\")) or 0\nelseif string.find(path, \"/ui/DefaultGroup/RewardHud/Reward\") == 1 then\n\tprefix = \"/ui/DefaultGroup/RewardHud/Reward\"\n\tcount = 3\n\txs = { -300, 0, 300 }\n\tbaseY = 0\n\thoverIndex = tonumber(string.match(path, \"Reward(%d+)\")) or 0\nelseif string.find(path, \"/ui/DefaultGroup/ShopHud/Card\") == 1 then\n\tprefix = \"/ui/DefaultGroup/ShopHud/Card\"\n\tcount = 3\n\txs = { -300, 0, 300 }\n\tbaseY = 20\n\thoverIndex = tonumber(string.match(path, \"Card(%d+)\")) or 0\nend\nif count <= 0 then\n\treturn\nend\nlocal items = {}\nfor i = 1, count do\n\tlocal e = _EntityService:GetEntityByPath(prefix .. tostring(i))\n\tif e ~= nil and e.UITransformComponent ~= nil then\n\t\tlocal tr = e.UITransformComponent\n\t\tlocal tx = xs[i]\n\t\tlocal ty = baseY\n\t\tlocal sc = 1\n\t\tif hover == true and hoverIndex > 0 then\n\t\t\tif i == hoverIndex and e.Enable == true then\n\t\t\t\tsc = 1.5\n\t\t\telseif i < hoverIndex then\n\t\t\t\ttx = tx - push\n\t\t\telseif i > hoverIndex then\n\t\t\t\ttx = tx + push\n\t\t\tend\n\t\tend\n\t\ttable.insert(items, { tr = tr, sx = tr.anchoredPosition.x, sy = tr.anchoredPosition.y, ss = tr.UIScale.x, tx = tx, ty = ty, ts = sc })\n\tend\nend\nlocal elapsed = 0\nlocal duration = 0.12\nlocal eventId = 0\neventId = _TimerService:SetTimerRepeat(function()\n\telapsed = elapsed + 1 / 60\n\tlocal t = math.min(elapsed / duration, 1)\n\tlocal eased = _TweenLogic:Ease(0, 1, 1, EaseType.SineEaseOut, t)\n\tfor i = 1, #items do\n\t\tlocal it = items[i]\n\t\tlocal x = it.sx + (it.tx - it.sx) * eased\n\t\tlocal y = it.sy + (it.ty - it.sy) * eased\n\t\tlocal s = it.ss + (it.ts - it.ss) * eased\n\t\tit.tr.anchoredPosition = Vector2(x, y)\n\t\tit.tr.UIScale = Vector3(s, s, 1)\n\tend\n\tif t >= 1 then\n\t\t_TimerService:ClearTimer(eventId)\n\tend\nend, 1 / 60)", + "Code": "local prefix = \"\"\nlocal count = 0\nlocal xs = {}\nlocal baseY = 0\nlocal hoverIndex = 0\nlocal push = 110\nif string.find(path, \"/ui/DefaultGroup/CardHand/Card\") == 1 then\n\tif self.DragSlot ~= nil and self.DragSlot > 0 then\n\t\treturn\n\tend\n\tprefix = \"/ui/DefaultGroup/CardHand/Card\"\n\tcount = 5\n\txs = { -400, -200, 0, 200, 400 }\n\tbaseY = 0\n\thoverIndex = tonumber(string.match(path, \"Card(%d+)\")) or 0\nelseif string.find(path, \"/ui/DefaultGroup/RewardHud/Reward\") == 1 then\n\tprefix = \"/ui/DefaultGroup/RewardHud/Reward\"\n\tcount = 3\n\txs = { -300, 0, 300 }\n\tbaseY = 0\n\thoverIndex = tonumber(string.match(path, \"Reward(%d+)\")) or 0\nelseif string.find(path, \"/ui/DefaultGroup/ShopHud/Card\") == 1 then\n\tprefix = \"/ui/DefaultGroup/ShopHud/Card\"\n\tcount = 3\n\txs = { -300, 0, 300 }\n\tbaseY = 20\n\thoverIndex = tonumber(string.match(path, \"Card(%d+)\")) or 0\nend\nif count <= 0 then\n\treturn\nend\nif self.CardHoverTweenId ~= nil and self.CardHoverTweenId ~= 0 then\n\t_TimerService:ClearTimer(self.CardHoverTweenId)\n\tself.CardHoverTweenId = 0\nend\nlocal items = {}\nfor i = 1, count do\n\tlocal e = _EntityService:GetEntityByPath(prefix .. tostring(i))\n\tif e ~= nil and e.UITransformComponent ~= nil then\n\t\tlocal tr = e.UITransformComponent\n\t\tlocal tx = xs[i]\n\t\tlocal ty = baseY\n\t\tlocal sc = 1\n\t\tif hover == true and hoverIndex > 0 then\n\t\t\tif i == hoverIndex and e.Enable == true then\n\t\t\t\tsc = 1.5\n\t\t\telseif i < hoverIndex then\n\t\t\t\ttx = tx - push\n\t\t\telseif i > hoverIndex then\n\t\t\t\ttx = tx + push\n\t\t\tend\n\t\tend\n\t\ttable.insert(items, { tr = tr, sx = tr.anchoredPosition.x, sy = tr.anchoredPosition.y, ss = tr.UIScale.x, tx = tx, ty = ty, ts = sc })\n\tend\nend\nlocal elapsed = 0\nlocal duration = 0.12\nlocal eventId = 0\neventId = _TimerService:SetTimerRepeat(function()\n\telapsed = elapsed + 1 / 60\n\tlocal t = math.min(elapsed / duration, 1)\n\tlocal eased = _TweenLogic:Ease(0, 1, 1, EaseType.SineEaseOut, t)\n\tfor i = 1, #items do\n\t\tlocal it = items[i]\n\t\tlocal x = it.sx + (it.tx - it.sx) * eased\n\t\tlocal y = it.sy + (it.ty - it.sy) * eased\n\t\tlocal s = it.ss + (it.ts - it.ss) * eased\n\t\tit.tr.anchoredPosition = Vector2(x, y)\n\t\tit.tr.UIScale = Vector3(s, s, 1)\n\tend\n\tif t >= 1 then\n\t\t_TimerService:ClearTimer(eventId)\n\t\tif self.CardHoverTweenId == eventId then\n\t\t\tself.CardHoverTweenId = 0\n\t\tend\n\tend\nend, 1 / 60)\nself.CardHoverTweenId = eventId", "Scope": 2, "ExecSpace": 6, "Attributes": [], @@ -1589,7 +1596,7 @@ "Name": "slot" } ], - "Code": "if self.CombatOver == true or self.FxBusy == true or self.TurnBusy == true then\n\treturn\nend\nif self.Hand == nil or self.Hand[slot] == nil then\n\treturn\nend\nself.DragSlot = slot", + "Code": "if self.CombatOver == true or self.FxBusy == true or self.TurnBusy == true then\n\treturn\nend\nif self.Hand == nil or self.Hand[slot] == nil then\n\treturn\nend\nif self.CardHoverTweenId ~= nil and self.CardHoverTweenId ~= 0 then\n\t_TimerService:ClearTimer(self.CardHoverTweenId)\n\tself.CardHoverTweenId = 0\nend\nlocal cardXs = { -400, -200, 0, 200, 400 }\nfor i = 1, 5 do\n\tlocal e = _EntityService:GetEntityByPath(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(i))\n\tif e ~= nil and e.UITransformComponent ~= nil then\n\t\te.UITransformComponent.UIScale = Vector3(1, 1, 1)\n\t\te.UITransformComponent.anchoredPosition = Vector2(cardXs[i], 0)\n\tend\nend\nself.DragSlot = slot", "Scope": 2, "ExecSpace": 6, "Attributes": [], @@ -1649,7 +1656,7 @@ "Name": "touchPoint" } ], - "Code": "if self.DragSlot ~= slot then\n\treturn\nend\nself.DragSlot = 0\nlocal cardXs = { -400, -200, 0, 200, 400 }\nlocal e = _EntityService:GetEntityByPath(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(slot))\nif e ~= nil and e.UITransformComponent ~= nil then\n\te.UITransformComponent.anchoredPosition = Vector2(cardXs[slot], 0)\nend\nself:ResolveCardDrop(slot, touchPoint)", + "Code": "if self.DragSlot ~= slot then\n\treturn\nend\nself.DragSlot = 0\nlocal cardXs = { -400, -200, 0, 200, 400 }\nlocal e = _EntityService:GetEntityByPath(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(slot))\nif e ~= nil and e.UITransformComponent ~= nil then\n\te.UITransformComponent.anchoredPosition = Vector2(cardXs[slot], 0)\n\te.UITransformComponent.UIScale = Vector3(1, 1, 1)\nend\nself:ResolveCardDrop(slot, touchPoint)", "Scope": 2, "ExecSpace": 6, "Attributes": [], diff --git a/tools/deck/gen-slaydeck.mjs b/tools/deck/gen-slaydeck.mjs index e27c060..a272fa1 100644 --- a/tools/deck/gen-slaydeck.mjs +++ b/tools/deck/gen-slaydeck.mjs @@ -2437,6 +2437,7 @@ function writeCodeblocks() { prop('number', 'MaxEnergy', '3'), prop('number', 'Turn', '0'), prop('number', 'TweenEventId', '0'), + prop('number', 'CardHoverTweenId', '0'), prop('any', 'EndTurnHandler'), prop('any', 'NewGameHandler'), prop('any', 'WarriorSelectHandler'), @@ -3266,6 +3267,9 @@ local baseY = 0 local hoverIndex = 0 local push = 110 if string.find(path, "/ui/DefaultGroup/CardHand/Card") == 1 then + if self.DragSlot ~= nil and self.DragSlot > 0 then + return + end prefix = "/ui/DefaultGroup/CardHand/Card" count = 5 xs = { ${CARD_XS.join(', ')} } @@ -3287,6 +3291,10 @@ end if count <= 0 then return end +if self.CardHoverTweenId ~= nil and self.CardHoverTweenId ~= 0 then + _TimerService:ClearTimer(self.CardHoverTweenId) + self.CardHoverTweenId = 0 +end local items = {} for i = 1, count do local e = _EntityService:GetEntityByPath(prefix .. tostring(i)) @@ -3324,8 +3332,12 @@ eventId = _TimerService:SetTimerRepeat(function() end if t >= 1 then _TimerService:ClearTimer(eventId) + if self.CardHoverTweenId == eventId then + self.CardHoverTweenId = 0 + end end -end, 1 / 60)`, [ +end, 1 / 60) +self.CardHoverTweenId = eventId`, [ { Type: 'string', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'path' }, { Type: 'boolean', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'hover' }, ]), @@ -3466,6 +3478,18 @@ end if self.Hand == nil or self.Hand[slot] == nil then return end +if self.CardHoverTweenId ~= nil and self.CardHoverTweenId ~= 0 then + _TimerService:ClearTimer(self.CardHoverTweenId) + self.CardHoverTweenId = 0 +end +local cardXs = { ${CARD_XS.join(', ')} } +for i = 1, 5 do + local e = _EntityService:GetEntityByPath("/ui/DefaultGroup/CardHand/Card" .. tostring(i)) + if e ~= nil and e.UITransformComponent ~= nil then + e.UITransformComponent.UIScale = Vector3(1, 1, 1) + e.UITransformComponent.anchoredPosition = Vector2(cardXs[i], 0) + end +end self.DragSlot = slot`, [{ Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' }]), method('OnCardDrag', `if self.DragSlot ~= slot then return @@ -3486,6 +3510,7 @@ local cardXs = { ${CARD_XS.join(', ')} } local e = _EntityService:GetEntityByPath("/ui/DefaultGroup/CardHand/Card" .. tostring(slot)) if e ~= nil and e.UITransformComponent ~= nil then e.UITransformComponent.anchoredPosition = Vector2(cardXs[slot], 0) + e.UITransformComponent.UIScale = Vector3(1, 1, 1) end self:ResolveCardDrop(slot, touchPoint)`, [ { Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' },