feat(combat-feel): 카드 드래그 타겟팅 (UITouchReceive·ResolveCardDrop)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -419,6 +419,12 @@ function upsertUi() {
|
|||||||
if (!card.componentNames.includes('MOD.Core.ButtonComponent')) {
|
if (!card.componentNames.includes('MOD.Core.ButtonComponent')) {
|
||||||
card.componentNames += ',MOD.Core.ButtonComponent';
|
card.componentNames += ',MOD.Core.ButtonComponent';
|
||||||
}
|
}
|
||||||
|
if (!comps.some((c) => c['@type'] === 'MOD.Core.UITouchReceiveComponent')) {
|
||||||
|
comps.push({ '@type': 'MOD.Core.UITouchReceiveComponent', Enable: true });
|
||||||
|
}
|
||||||
|
if (!card.componentNames.includes('MOD.Core.UITouchReceiveComponent')) {
|
||||||
|
card.componentNames += ',MOD.Core.UITouchReceiveComponent';
|
||||||
|
}
|
||||||
card.jsonString.enable = true;
|
card.jsonString.enable = true;
|
||||||
card.jsonString.visible = true;
|
card.jsonString.visible = true;
|
||||||
|
|
||||||
@@ -1831,6 +1837,9 @@ function writeCodeblocks() {
|
|||||||
prop('any', 'RelicPool'),
|
prop('any', 'RelicPool'),
|
||||||
prop('string', 'ShopRelic', '""'),
|
prop('string', 'ShopRelic', '""'),
|
||||||
prop('boolean', 'ShopRelicBought', 'false'),
|
prop('boolean', 'ShopRelicBought', 'false'),
|
||||||
|
prop('number', 'DragSlot', '0'),
|
||||||
|
prop('boolean', 'FxBusy', 'false'),
|
||||||
|
prop('boolean', 'TurnBusy', 'false'),
|
||||||
], [
|
], [
|
||||||
method('OnBeginPlay', `self:ShowMainMenu()`),
|
method('OnBeginPlay', `self:ShowMainMenu()`),
|
||||||
method('HideGameHud', `self:SetEntityEnabled("/ui/DefaultGroup/Button_Attack", false)
|
method('HideGameHud', `self:SetEntityEnabled("/ui/DefaultGroup/Button_Attack", false)
|
||||||
@@ -2070,8 +2079,10 @@ if allDeckClose ~= nil and allDeckClose.ButtonComponent ~= nil then
|
|||||||
end
|
end
|
||||||
for i = 1, 5 do
|
for i = 1, 5 do
|
||||||
local cardEntity = _EntityService:GetEntityByPath("/ui/DefaultGroup/CardHand/Card" .. tostring(i))
|
local cardEntity = _EntityService:GetEntityByPath("/ui/DefaultGroup/CardHand/Card" .. tostring(i))
|
||||||
if cardEntity ~= nil and cardEntity.ButtonComponent ~= nil then
|
if cardEntity ~= nil and cardEntity.UITouchReceiveComponent ~= nil then
|
||||||
cardEntity:ConnectEvent(ButtonClickEvent, function() self:PlayCard(i) end)
|
cardEntity:ConnectEvent(UITouchBeginDragEvent, function(ev) self:OnCardDragBegin(i) end)
|
||||||
|
cardEntity:ConnectEvent(UITouchDragEvent, function(ev) self:OnCardDrag(i, ev.TouchPoint) end)
|
||||||
|
cardEntity:ConnectEvent(UITouchEndDragEvent, function(ev) self:OnCardDragEnd(i, ev.TouchPoint) end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i = 1, 3 do
|
for i = 1, 3 do
|
||||||
@@ -2382,6 +2393,78 @@ self:RenderHand(false)
|
|||||||
self:RenderPiles()
|
self:RenderPiles()
|
||||||
self:RenderCombat()
|
self:RenderCombat()
|
||||||
self:CheckCombatEnd()`, [{ Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' }]),
|
self:CheckCombatEnd()`, [{ Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' }]),
|
||||||
|
method('OnCardDragBegin', `if self.CombatOver == true or self.FxBusy == true or self.TurnBusy == true then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if self.Hand == nil or self.Hand[slot] == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
self.DragSlot = slot`, [{ Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' }]),
|
||||||
|
method('OnCardDrag', `if self.DragSlot ~= slot then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local e = _EntityService:GetEntityByPath("/ui/DefaultGroup/CardHand/Card" .. tostring(slot))
|
||||||
|
if e ~= nil and e.UITransformComponent ~= nil then
|
||||||
|
local ui = _UILogic:ScreenToUIPosition(touchPoint)
|
||||||
|
e.UITransformComponent.anchoredPosition = Vector2(ui.x, ui.y + 360)
|
||||||
|
end`, [
|
||||||
|
{ Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' },
|
||||||
|
{ Type: 'any', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'touchPoint' },
|
||||||
|
]),
|
||||||
|
method('OnCardDragEnd', `if self.DragSlot ~= slot then
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
self:ResolveCardDrop(slot, touchPoint)`, [
|
||||||
|
{ Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' },
|
||||||
|
{ Type: 'any', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'touchPoint' },
|
||||||
|
]),
|
||||||
|
method('ResolveCardDrop', `if self.CombatOver == true or self.FxBusy == true or self.TurnBusy == true then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local cardId = self.Hand[slot]
|
||||||
|
if cardId == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local c = self.Cards[cardId]
|
||||||
|
if c == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if c.kind == "Attack" then
|
||||||
|
local best = 0
|
||||||
|
local bestDist = 200
|
||||||
|
for i = 1, #self.Monsters do
|
||||||
|
local m = self.Monsters[i]
|
||||||
|
if m.alive == true and m.entity ~= nil and isvalid(m.entity) and m.entity.TransformComponent ~= nil then
|
||||||
|
local wp = m.entity.TransformComponent.WorldPosition
|
||||||
|
local sp = _UILogic:WorldToScreenPosition(Vector2(wp.x, wp.y + 0.7))
|
||||||
|
local dx = sp.x - touchPoint.x
|
||||||
|
local dy = sp.y - touchPoint.y
|
||||||
|
local d = math.sqrt(dx * dx + dy * dy)
|
||||||
|
if d < bestDist then
|
||||||
|
bestDist = d
|
||||||
|
best = i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if best > 0 then
|
||||||
|
self.TargetIndex = best
|
||||||
|
self:PlayCard(slot)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local ui = _UILogic:ScreenToUIPosition(touchPoint)
|
||||||
|
if ui.y > -180 then
|
||||||
|
self:PlayCard(slot)
|
||||||
|
end
|
||||||
|
end`, [
|
||||||
|
{ Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' },
|
||||||
|
{ Type: 'any', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'touchPoint' },
|
||||||
|
]),
|
||||||
method('Toast', `log(message)`, [{ Type: 'string', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'message' }]),
|
method('Toast', `log(message)`, [{ Type: 'string', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'message' }]),
|
||||||
method('DealDamageToTarget', `local m = self.Monsters[self.TargetIndex]
|
method('DealDamageToTarget', `local m = self.Monsters[self.TargetIndex]
|
||||||
if m == nil or m.alive ~= true then
|
if m == nil or m.alive ~= true then
|
||||||
|
|||||||
Reference in New Issue
Block a user