From f9e7bc3603e6a09f65a10761cb5a3acd5098b661 Mon Sep 17 00:00:00 2001 From: gahusb Date: Mon, 15 Jun 2026 00:29:48 +0900 Subject: [PATCH] fix(cards): support large hand drag positions --- RootDesk/MyDesk/SlayDeckController.codeblock | 33 +++++++++++++++++--- tools/deck/gen-slaydeck.mjs | 30 ++++++++++++------ 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/RootDesk/MyDesk/SlayDeckController.codeblock b/RootDesk/MyDesk/SlayDeckController.codeblock index a966842..b867e66 100644 --- a/RootDesk/MyDesk/SlayDeckController.codeblock +++ b/RootDesk/MyDesk/SlayDeckController.codeblock @@ -1645,7 +1645,7 @@ "Name": "animate" } ], - "Code": "local drawnSlots = {}\nfor i = 1, amount do\n\tif #self.DrawPile <= 0 then\n\t\tself:RecycleDiscardIntoDraw()\n\tend\n\tif #self.DrawPile <= 0 then\n\t\tbreak\n\tend\n\tlocal cardId = table.remove(self.DrawPile)\n\tif #self.Hand >= 10 then\n\t\ttable.insert(self.DiscardPile, cardId)\n\t\tself:TriggerSly(cardId)\n\telse\n\t\ttable.insert(self.Hand, cardId)\n\t\tif #self.Hand <= 5 then\n\t\t\ttable.insert(drawnSlots, #self.Hand)\n\t\tend\n\tend\nend\nself:RenderPiles()\nif animate == true and #drawnSlots > 0 then\n\tself:RenderHand(false)\n\tlocal drawStart = Vector2(-590, 8)\n\tfor i = 1, #drawnSlots do\n\t\tlocal slot = drawnSlots[i]\n\t\tself:AnimateCardFrom(slot, drawStart, Vector2((slot - 3) * 200, 0), 0.08 + i * 0.045)\n\tend\nend", + "Code": "local drawnSlots = {}\nfor i = 1, amount do\n\tif #self.DrawPile <= 0 then\n\t\tself:RecycleDiscardIntoDraw()\n\tend\n\tif #self.DrawPile <= 0 then\n\t\tbreak\n\tend\n\tlocal cardId = table.remove(self.DrawPile)\n\tif #self.Hand >= 10 then\n\t\ttable.insert(self.DiscardPile, cardId)\n\t\tself:TriggerSly(cardId)\n\telse\n\t\ttable.insert(self.Hand, cardId)\n\t\tif #self.Hand <= 5 then\n\t\t\ttable.insert(drawnSlots, #self.Hand)\n\t\tend\n\tend\nend\nself:RenderPiles()\nif animate == true and #drawnSlots > 0 then\n\tself:RenderHand(false)\n\tlocal drawStart = Vector2(-590, 8)\n\tfor i = 1, #drawnSlots do\n\t\tlocal slot = drawnSlots[i]\n\t\tself:AnimateCardFrom(slot, drawStart, Vector2(self:GetHandSlotX(slot), 0), 0.08 + i * 0.045)\n\tend\nend", "Scope": 2, "ExecSpace": 6, "Attributes": [], @@ -1930,6 +1930,29 @@ "Attributes": [], "Name": "ApplyAllDeckCardVisual" }, + { + "Return": { + "Type": "number", + "DefaultValue": null, + "SyncDirection": 0, + "Attributes": [], + "Name": null + }, + "Arguments": [ + { + "Type": "number", + "DefaultValue": null, + "SyncDirection": 0, + "Attributes": [], + "Name": "slot" + } + ], + "Code": "local n = 0\nif self.Hand ~= nil then\n\tn = #self.Hand\nend\nif n <= 0 then\n\treturn 0\nend\nlocal spacing = 175\nif n > 8 then spacing = math.floor(1400 / n) end\nlocal startX = -((n - 1) * spacing) / 2\nreturn startX + (slot - 1) * spacing", + "Scope": 2, + "ExecSpace": 6, + "Attributes": [], + "Name": "GetHandSlotX" + }, { "Return": { "Type": "void", @@ -1947,7 +1970,7 @@ "Name": "animate" } ], - "Code": "local n = #self.Hand\nlocal spacing = 175\nif n > 8 then spacing = math.floor(1400 / n) end\nlocal startX = -((n - 1) * spacing) / 2\nlocal drawStart = Vector2(-590, 8)\nfor i = 1, 10 do\n\tlocal cardEntity = _EntityService:GetEntityByPath(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(i))\n\tif cardEntity ~= nil then\n\t\tlocal cardId = self.Hand[i]\n\t\tif cardId == nil then\n\t\t\tcardEntity.Enable = false\n\t\telse\n\t\t\tcardEntity.Enable = true\n\t\t\tif cardEntity.UITransformComponent ~= nil then cardEntity.UITransformComponent.UIScale = Vector3(1, 1, 1) end\n\t\t\tself:ApplyCardVisual(i, cardId)\n\t\t\tlocal tx = startX + (i - 1) * spacing\n\t\t\tif animate == true then\n\t\t\t\tself:AnimateCardFrom(i, drawStart, Vector2(tx, 0), 0.16 + i * 0.03)\n\t\t\telse\n\t\t\t\tif cardEntity.UITransformComponent ~= nil then cardEntity.UITransformComponent.anchoredPosition = Vector2(tx, 0) end\n\t\t\tend\n\t\tend\n\tend\nend\nself:RenderPiles()", + "Code": "local n = #self.Hand\nlocal spacing = 175\nif n > 8 then spacing = math.floor(1400 / n) end\nlocal startX = -((n - 1) * spacing) / 2\nlocal drawStart = Vector2(-590, 8)\nfor i = 1, 10 do\n\tlocal cardEntity = _EntityService:GetEntityByPath(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(i))\n\tif cardEntity ~= nil then\n\t\tlocal cardId = self.Hand[i]\n\t\tif cardId == nil then\n\t\t\tcardEntity.Enable = false\n\t\telse\n\t\t\tcardEntity.Enable = true\n\t\t\tif cardEntity.UITransformComponent ~= nil then cardEntity.UITransformComponent.UIScale = Vector3(1, 1, 1) end\n\t\t\tself:ApplyCardVisual(i, cardId)\n\t\t\tlocal tx = self:GetHandSlotX(i)\n\t\t\tif animate == true then\n\t\t\t\tself:AnimateCardFrom(i, drawStart, Vector2(tx, 0), 0.16 + i * 0.03)\n\t\t\telse\n\t\t\t\tif cardEntity.UITransformComponent ~= nil then cardEntity.UITransformComponent.anchoredPosition = Vector2(tx, 0) end\n\t\t\tend\n\t\tend\n\tend\nend\nself:RenderPiles()", "Scope": 2, "ExecSpace": 6, "Attributes": [], @@ -2007,7 +2030,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\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", + "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 = 0\n\tif self.Hand ~= nil then count = #self.Hand end\n\tfor i = 1, count do\n\t\txs[i] = self:GetHandSlotX(i)\n\tend\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": [], @@ -2384,7 +2407,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\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", + "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\nfor i = 1, 10 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(self:GetHandSlotX(i), 0)\n\tend\nend\nself.DragSlot = slot", "Scope": 2, "ExecSpace": 6, "Attributes": [], @@ -2444,7 +2467,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)\n\te.UITransformComponent.UIScale = Vector3(1, 1, 1)\nend\nself:ResolveCardDrop(slot, touchPoint)", + "Code": "if self.DragSlot ~= slot then\n\treturn\nend\nself.DragSlot = 0\nlocal e = _EntityService:GetEntityByPath(\"/ui/DefaultGroup/CardHand/Card\" .. tostring(slot))\nif e ~= nil and e.UITransformComponent ~= nil then\n\te.UITransformComponent.anchoredPosition = Vector2(self:GetHandSlotX(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 f8d2092..f54f370 100644 --- a/tools/deck/gen-slaydeck.mjs +++ b/tools/deck/gen-slaydeck.mjs @@ -3734,7 +3734,7 @@ if animate == true and #drawnSlots > 0 then \tlocal drawStart = Vector2(-590, 8) \tfor i = 1, #drawnSlots do \t\tlocal slot = drawnSlots[i] -\t\tself:AnimateCardFrom(slot, drawStart, Vector2((slot - 3) * 200, 0), 0.08 + i * 0.045) +\t\tself:AnimateCardFrom(slot, drawStart, Vector2(self:GetHandSlotX(slot), 0), 0.08 + i * 0.045) \tend end`, [ { Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'amount' }, @@ -3976,6 +3976,17 @@ end`), { Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' }, { Type: 'string', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'cardId' }, ]), + method('GetHandSlotX', `local n = 0 +if self.Hand ~= nil then + n = #self.Hand +end +if n <= 0 then + return 0 +end +local spacing = 175 +if n > 8 then spacing = math.floor(1400 / n) end +local startX = -((n - 1) * spacing) / 2 +return startX + (slot - 1) * spacing`, [{ Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' }], 0, 'number'), method('RenderHand', `local n = #self.Hand local spacing = 175 if n > 8 then spacing = math.floor(1400 / n) end @@ -3991,7 +4002,7 @@ for i = 1, 10 do \t\t\tcardEntity.Enable = true \t\t\tif cardEntity.UITransformComponent ~= nil then cardEntity.UITransformComponent.UIScale = Vector3(1, 1, 1) end \t\t\tself:ApplyCardVisual(i, cardId) -\t\t\tlocal tx = startX + (i - 1) * spacing +\t\t\tlocal tx = self:GetHandSlotX(i) \t\t\tif animate == true then \t\t\t\tself:AnimateCardFrom(i, drawStart, Vector2(tx, 0), 0.16 + i * 0.03) \t\t\telse @@ -4048,8 +4059,11 @@ if string.find(path, "/ui/DefaultGroup/CardHand/Card") == 1 then return end prefix = "/ui/DefaultGroup/CardHand/Card" - count = 5 - xs = { ${CARD_XS.join(', ')} } + count = 0 + if self.Hand ~= nil then count = #self.Hand end + for i = 1, count do + xs[i] = self:GetHandSlotX(i) + end baseY = 0 hoverIndex = tonumber(string.match(path, "Card(%d+)")) or 0 elseif string.find(path, "/ui/DefaultGroup/RewardHud/Reward") == 1 then @@ -4365,12 +4379,11 @@ 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 +for i = 1, 10 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) + e.UITransformComponent.anchoredPosition = Vector2(self:GetHandSlotX(i), 0) end end self.DragSlot = slot`, [{ Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' }]), @@ -4389,10 +4402,9 @@ end`, [ return end self.DragSlot = 0 -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.anchoredPosition = Vector2(self:GetHandSlotX(slot), 0) e.UITransformComponent.UIScale = Vector3(1, 1, 1) end self:ResolveCardDrop(slot, touchPoint)`, [