载入中...
搜索中...
未找到
CardTypes.cpp
浏览该文件的文档.
1#include "card/CardTypes.h"
2#include <glm/vec2.hpp>
3
5
6#include "graphics/Font.h"
7#include "graphics/Graphics.h"
8
9#include <algorithm>
10#include <cmath>
11#include <random>
12
13namespace eve::card {
14
15const char *cardStateName(CardState state) {
16 switch (state) {
17 case CardState::Deck: return "deck";
18 case CardState::Hand: return "hand";
19 case CardState::Hovered: return "hovered";
20 case CardState::Dragging: return "dragging";
21 case CardState::Returning: return "returning";
22 case CardState::Played: return "played";
23 case CardState::Discarded: return "discarded";
24 case CardState::Disabled: return "disabled";
25 }
26 return "unknown";
27}
28
29// ---------------------------------------------------------------------------
30// 工具
31// ---------------------------------------------------------------------------
32
33namespace {
34
35struct RenderTransform {
36 float cx = 0.f;
37 float cy = 0.f;
38 float degrees = 0.f;
39 bool active = false;
40};
41
42RenderTransform gRenderTransform;
43
44glm::vec2 transformedCenter(float x, float y, float w, float h) {
45 glm::vec2 center{x + w * 0.5f, y + h * 0.5f};
46 if (!gRenderTransform.active || std::abs(gRenderTransform.degrees) < 0.001f) return center;
47 const float rad = gRenderTransform.degrees * 3.14159265358979323846f / 180.f;
48 const float c = std::cos(rad);
49 const float s = std::sin(rad);
50 const float dx = center.x - gRenderTransform.cx;
51 const float dy = center.y - gRenderTransform.cy;
52 return {gRenderTransform.cx + dx * c - dy * s, gRenderTransform.cy + dx * s + dy * c};
53}
54
55float clampf(float v, float lo, float hi) { return v < lo ? lo : (v > hi ? hi : v); }
56float lerpf(float a, float b, float t) { return a + (b - a) * t; }
57
58// 帧率无关的插值系数:k 是 60fps 下的每帧系数,换算到实际 dt。
59float frameRateK(float k, float dt) {
60 if (dt <= 0.f) return k;
61 const float u = 1.f - k;
62 const float n = dt * 60.f;
63 const int whole = static_cast<int>(n);
64 const float frac = n - static_cast<float>(whole);
65 float r = 1.f;
66 for (int i = 0; i < whole; ++i) r *= u;
67 r *= (1.f + frac * (u - 1.f));
68 return 1.f - r;
69}
70
71constexpr float kPi = 3.14159265358979323846f;
72} // namespace
73
74CardFlipPose evaluateCardFlip(float flipProgress, float liftPeak) {
76 pose.progress = clampf(flipProgress, 0.f, 1.f);
77 pose.angleRadians = pose.progress * kPi;
78 pose.angleDegrees = pose.progress * 180.f;
79 pose.lift = std::sin(pose.angleRadians) * liftPeak;
80 pose.axisScale = std::fabs(std::cos(pose.angleRadians));
81 pose.showingFront = pose.progress < 0.5f;
82 return pose;
83}
84
85void advanceCardFlip(float &flip, float targetFaceDown, float speed, float dt) {
86 const float target = clampf(targetFaceDown, 0.f, 1.f);
87 const float k = frameRateK(clampf(speed, 0.f, 1.f), dt);
88 flip = lerpf(flip, target, k);
89 if (std::fabs(flip - target) < 0.0005f) flip = target;
90}
91
92bool resolveCardWantFaceUp(bool cardFaceUp, bool handFaceDown, bool handPeek) {
93 if (handFaceDown) return handPeek;
94 return cardFaceUp;
95}
96
97namespace {
98
99void drawSolid(graphics::Graphics *gfx, float x, float y, float w, float h, float angle,
100 const glm::vec4 &color) {
101 if (!gRenderTransform.active || std::abs(angle) < 0.001f)
102 gfx->drawSolidRect(x, y, w, h, color);
103 else {
104 const glm::vec2 center = transformedCenter(x, y, w, h);
106 }
107}
108
109void drawTexture(graphics::Graphics *gfx, graphics::Texture *texture, float x, float y, float w, float h,
110 float angle, const glm::vec4 &color) {
111 if (!gRenderTransform.active || std::abs(angle) < 0.001f) {
112 gfx->drawTexturedRect(texture, x, y, w, h, color);
113 } else {
114 const glm::vec2 center = transformedCenter(x, y, w, h);
115 gfx->drawTexturedRectShaderUVRotated(texture, nullptr, center.x, center.y, w, h,
116 angle, 0.f, 0.f, 1.f, 1.f, color);
117 }
118}
119
120void drawGem(graphics::Graphics *gfx, float x, float y, float size, float angle,
121 const glm::vec3 &rgb, float a) {
122 drawSolid(gfx, x, y, size, size, angle, glm::vec4(0.15f, 0.13f, 0.10f, a));
123 const float p = size * 0.20f;
124 drawSolid(gfx, x + p, y + p, size - p * 2.f, size - p * 2.f, angle, glm::vec4(rgb, a));
125}
126
127} // namespace
128
129// ---------------------------------------------------------------------------
130// CardData
131// ---------------------------------------------------------------------------
132
134 CardData *c = CardData::create();
135 c->identity();
136 c->stats();
137 c->attributes();
138 c->effects();
139 c->visual();
140 c->layout();
141 c->state();
142 c->definitionBinding();
143 return c;
144}
145
146bool CardData::hit(float px, float py) {
147 const auto *L = layout().operator->();
148 if (L->w <= 0.f || L->h <= 0.f) return false;
149 const float cw = L->w * L->scale;
150 const float ch = L->h * L->scale;
151 return px >= L->x - cw * 0.5f && px <= L->x + cw * 0.5f && py >= L->y - ch * 0.5f &&
152 py <= L->y + ch * 0.5f;
153}
154
155std::string CardData::describe() {
156 const auto *I = identity().operator->();
157 auto projected = CardAttributeAdapter::project(*this);
158 if (!projected) projected.ignore("card description retained legacy projection after attribute failure");
159 const auto *S = stats().operator->();
160 if (I->kind == "spell") return I->name + "(法术 · 费用 " + std::to_string(S->cost) + ")";
161 return I->name + "(" + std::to_string(S->attack) + "/" + std::to_string(S->health) + " · 费用 " +
162 std::to_string(S->cost) + ")";
163}
164
165// ---------------------------------------------------------------------------
166// Deck
167// ---------------------------------------------------------------------------
168
170 Deck *d = Deck::create();
171 d->membership();
172 return d;
173}
174
176 auto &cards = membership()->cards;
177 if (cards.empty()) return nullptr;
178 CardData *top = cards.back();
179 cards.pop_back();
180 return top;
181}
182
184 auto &cards = membership()->cards;
185 return cards.empty() ? nullptr : cards.back();
186}
187
189 auto &cards = membership()->cards;
190 if (index < 0 || static_cast<size_t>(index) >= cards.size()) return nullptr;
191 return cards[static_cast<size_t>(index)];
192}
193
195 static thread_local std::mt19937 rng(std::random_device{}());
196 std::shuffle(membership()->cards.begin(), membership()->cards.end(), rng);
197}
198
199// ---------------------------------------------------------------------------
200// Zone
201// ---------------------------------------------------------------------------
202
204 Zone *z = Zone::create();
205 z->rect();
206 z->filter();
207 return z;
208}
209
210bool Zone::contains(float px, float py) {
211 const auto *R = rect().operator->();
212 return px >= R->x && px <= R->x + R->w && py >= R->y && py <= R->y + R->h;
213}
214
216 const auto *R = rect().operator->();
217 if (!R->enabled || !card) return false;
218 const auto &kinds = filter()->acceptKinds;
219 if (kinds.empty()) return true;
220 const std::string &kind = card->identity()->kind;
221 for (const auto &k : kinds)
222 if (k == kind) return true;
223 return false;
224}
225
226void Zone::render(graphics::Graphics *gfx, bool showLabel) {
227 auto *R = rect().operator->();
228 gfx->drawSolidRect(R->x, R->y, R->w, R->h, glm::vec4(R->color, R->alpha));
229 if (showLabel && gfx->getFont() && !R->label.empty()) {
230 const glm::vec4 tint(clampf(R->color.r * 0.9f + 0.3f, 0.f, 1.f),
231 clampf(R->color.g * 0.9f + 0.3f, 0.f, 1.f),
232 clampf(R->color.b * 0.9f + 0.3f, 0.f, 1.f), 1.f);
233 printCentered(gfx, R->label, R->x + R->w * 0.5f, R->y + R->h * 0.5f, 0.9f, tint);
234 }
235}
236
237// ---------------------------------------------------------------------------
238// 渲染辅助
239// ---------------------------------------------------------------------------
240
241void printCentered(graphics::Graphics *gfx, const std::string &text, float cx, float cy, float scale,
242 const glm::vec4 &color) {
243 auto *font = gfx->getFont();
244 if (!font) return;
245 const float tw = font->getWidth(text) * scale;
246 const float th = font->getHeight() * scale;
247 // drawText 的 y 是行顶;视觉中心按现有卡牌布局略作补偿。
248 gfx->drawText(font, text, cx - tw * 0.5f, cy - th * 0.35f, color, scale);
249}
250
251void renderCardBack(graphics::Graphics *gfx, float x, float y, float w, float h, float angle, float a) {
252 const RenderTransform previous = gRenderTransform;
253 gRenderTransform = {x + w * 0.5f, y + h * 0.5f, angle, true};
254 // 2D solids keep the first fragment at equal depth, so inner details go first.
255 if (gfx->getFont())
256 printCentered(gfx, "?", x + w * 0.5f, y + h * 0.5f, 1.2f * (w / 110.f),
257 glm::vec4(0.9f, 0.85f, 0.95f, a));
258 const float i2 = w * 0.10f;
259 drawSolid(gfx, x + i2, y + i2, w - i2 * 2.f, h - i2 * 2.f, angle,
260 glm::vec4(0.11f, 0.08f, 0.22f, a));
261 const float i1 = w * 0.05f;
262 drawSolid(gfx, x + i1, y + i1, w - i1 * 2.f, h - i1 * 2.f, angle,
263 glm::vec4(0.30f, 0.17f, 0.45f, a));
264 drawSolid(gfx, x, y, w, h, angle, glm::vec4(0.06f, 0.06f, 0.10f, a));
265 gRenderTransform = previous;
266}
267
268void renderCard(graphics::Graphics *gfx, const CardData &cardRef, const LayoutConfig &cfg, bool back) {
269 CardData &card = const_cast<CardData &>(cardRef);
270 auto projected = CardAttributeAdapter::project(card);
271 if (!projected) {
272 projected.ignore("card renderer skipped an invalid attribute projection");
273 return;
274 }
275 const auto *L = card.layout().operator->();
276 const auto *V = card.visual().operator->();
277 const auto *I = card.identity().operator->();
278 const auto *S = card.stats().operator->();
279
280 const CardFlipPose pose = evaluateCardFlip(V->flip, cfg.flipLift);
281 const bool showBack = back || !pose.showingFront;
282 const float baseW = L->w * L->scale;
283 const float baseH = L->h * L->scale;
284 const float w = (cfg.flipAxis == 0) ? baseW * pose.axisScale : baseW;
285 const float h = (cfg.flipAxis == 1) ? baseH * pose.axisScale : baseH;
286 const float cx = L->x;
287 const float cy = L->y - pose.lift;
288 const float x = cx - w * 0.5f;
289 const float y = cy - h * 0.5f;
290 const float a = L->alpha;
291
292 const RenderTransform previous = gRenderTransform;
293 gRenderTransform = {cx, cy, L->angle, true};
294
295 if (showBack) {
296 renderCardBack(gfx, x, y, w, h, L->angle, a);
297 gRenderTransform = previous;
298 return;
299 }
300
301 // 外框
302 drawSolid(gfx, x, y, w, h, L->angle, glm::vec4(0.07f, 0.07f, 0.09f, a));
303 const float inset = w * 0.035f;
304 const float ix = x + inset;
305 const float iy = y + inset;
306 const float iw = w - inset * 2.f;
307 const float ih = h - inset * 2.f;
308
309 // 卡面底色
310 drawSolid(gfx, ix, iy, iw, ih, L->angle, glm::vec4(V->tint, a));
311
312 // 头部色带
313 const float headerH = ih * 0.16f;
314 drawSolid(gfx, ix, iy, iw, headerH, L->angle,
315 glm::vec4(V->tint.r * 0.82f, V->tint.g * 0.82f, V->tint.b * 0.82f, a));
316
317 // 卡图区域
318 const float artY = iy + headerH;
319 const float artH = ih * 0.34f;
320 if (V->texture) {
321 drawTexture(gfx, V->texture, ix + 2.f, artY + 2.f, iw - 4.f, artH - 4.f, L->angle,
322 glm::vec4(1.f, 1.f, 1.f, a));
323 } else {
324 drawSolid(gfx, ix + 2.f, artY + 2.f, iw - 4.f, artH - 4.f, L->angle,
325 glm::vec4(V->tint.r * 0.55f, V->tint.g * 0.55f, V->tint.b * 0.55f, a));
326 }
327
328 // 描述文字区
329 const float bodyY = artY + artH;
330 const float bodyH = iy + ih - bodyY;
331 drawSolid(gfx, ix, bodyY, iw, bodyH, L->angle, glm::vec4(0.96f, 0.94f, 0.90f, a));
332 drawSolid(gfx, ix + iw * 0.12f, bodyY + bodyH * 0.5f - 1.f, iw * 0.76f, 2.f, L->angle,
333 glm::vec4(0.45f, 0.42f, 0.38f, a));
334
335 // 数值宝石
336 const float gem = w * 0.13f;
337 drawGem(gfx, x + inset, iy, gem, L->angle, glm::vec3(1.00f, 0.78f, 0.25f), a); // 费用(金)
338 if (I->kind != "spell") {
339 drawGem(gfx, x + inset, iy + ih - gem, gem, L->angle, glm::vec3(0.92f, 0.38f, 0.22f), a); // 攻击(橙)
340 drawGem(gfx, x + iw - inset - gem, iy + ih - gem, gem, L->angle, glm::vec3(0.30f, 0.78f, 0.42f), a); // 生命(绿)
341 }
342
343 // 文字(可选:需 gfx 已 setFont)
344 auto *font = gfx->getFont();
345 if (font) {
346 const float ts = 1.f * (w / 110.f);
347 printCentered(gfx, std::to_string(S->cost), x + inset + gem * 0.5f, iy + gem * 0.55f, ts,
348 glm::vec4(0.12f, 0.08f, 0.05f, a));
349 if (I->kind != "spell") {
350 printCentered(gfx, std::to_string(S->attack), x + inset + gem * 0.5f, iy + ih - gem * 0.45f,
351 ts, glm::vec4(0.10f, 0.05f, 0.05f, a));
352 printCentered(gfx, std::to_string(S->health), x + iw - inset - gem * 0.5f,
353 iy + ih - gem * 0.45f, ts, glm::vec4(0.05f, 0.10f, 0.05f, a));
354 }
355 printCentered(gfx, I->name, x + w * 0.5f, iy + headerH * 0.5f, ts * 0.8f,
356 glm::vec4(0.10f, 0.08f, 0.06f, a));
357 }
358 gRenderTransform = previous;
359}
360
361// ---------------------------------------------------------------------------
362// Hand
363// ---------------------------------------------------------------------------
364
366 Hand *h = Hand::create();
367 h->meta();
368 h->membership();
369 h->drag();
370 return h;
371}
372
374 membership()->cards.push_back(c);
375 if (c) {
376 auto *md = meta().operator->();
377 c->state()->phase = c->visual()->disabled ? CardState::Disabled : CardState::Hand;
378 c->layout()->w = md->config ? md->config->cardW : 110.f;
379 c->layout()->h = md->config ? md->config->cardH : 150.f;
380 c->layout()->scale = 0.01f; // 从 0 生长出牌动画
381 c->layout()->alpha = (c->visual()->disabled && md->config) ? md->config->disabledAlpha : 1.f;
382 // Deal into a face-down hand starts already down — animate only later reveals.
383 if (md->faceDown && !md->peek)
384 c->visual()->flip = 1.f;
385 else if (!md->faceDown && c->visual()->faceUp)
386 c->visual()->flip = 0.f;
387 }
388}
389
391 auto &cards = membership()->cards;
392 for (size_t i = 0; i < cards.size(); ++i) {
393 if (cards[i] == c) {
394 cards.erase(cards.begin() + static_cast<ptrdiff_t>(i));
395 return true;
396 }
397 }
398 return false;
399}
400
402 membership()->cards.clear();
403 auto *d = drag().operator->();
404 d->card = nullptr;
405 d->press = nullptr;
406}
407
409 auto &cards = membership()->cards;
410 if (index < 0 || static_cast<size_t>(index) >= cards.size()) return nullptr;
411 return cards[static_cast<size_t>(index)];
412}
413
414CardData *Hand::find(const std::string &id) {
415 for (auto *c : membership()->cards)
416 if (c && c->identity()->id == id) return c;
417 return nullptr;
418}
419
420CardData *Hand::pick(float px, float py) {
421 auto &cards = membership()->cards;
422 for (auto it = cards.rbegin(); it != cards.rend(); ++it) {
423 if (*it && (*it)->hit(px, py)) return *it;
424 }
425 return nullptr;
426}
427
428void Hand::slotTransform(int i, int n, float &ox, float &oy, float &angle) {
429 const LayoutConfig cfg = meta()->config ? *meta()->config : LayoutConfig();
430 const float totalW = static_cast<float>(n) * cfg.cardW + static_cast<float>(n - 1) * cfg.spacing;
431 const float left = cfg.handX - totalW * 0.5f;
432 ox = left + static_cast<float>(i) * (cfg.cardW + cfg.spacing) + cfg.cardW * 0.5f;
433 const float t = (n > 1) ? static_cast<float>(i) / static_cast<float>(n - 1) : 0.5f;
434 const float d = 2.f * t - 1.f;
435 oy = cfg.handY - cfg.arcHeight * (d * d);
436 angle = cfg.rotationAngle * d;
437}
438
439void Hand::update(float dt, float mx, float my, bool down, const std::vector<Zone *> &zones,
440 std::vector<CardEvent> &out) {
441 auto *md = meta().operator->();
442 auto *d = drag().operator->();
443 auto &cards = membership()->cards;
444 const LayoutConfig cfg = md->config ? *md->config : LayoutConfig();
445 const int n = static_cast<int>(cards.size());
446
447 // 1) 布局 + 悬浮
448 for (int i = 0; i < n; ++i) {
449 CardData *card = cards[static_cast<size_t>(i)];
450 if (!card || card == d->card) continue;
451
452 float sx = 0.f, sy = 0.f, sa = 0.f;
453 slotTransform(i, n, sx, sy, sa);
454
455 bool hover = false;
456 if (d->card == nullptr) hover = (card == pick(mx, my));
457 auto *st = card->state().operator->();
458 auto *vis = card->visual().operator->();
459 auto *lay = card->layout().operator->();
460 st->hovered = hover;
461 if (vis->disabled) st->phase = CardState::Disabled;
462 else if (st->dragging) st->phase = CardState::Dragging;
463 else if (hover) st->phase = CardState::Hovered;
464 else if (st->phase != CardState::Returning) st->phase = CardState::Hand;
465
466 float targetScale = 1.f;
467 float targetY = sy;
468 float targetAngle = sa;
469 if (hover) {
470 targetY = sy - cfg.hoverLift;
471 targetScale = cfg.hoverScale;
472 if (cfg.hoverRotation) targetAngle = 0.f;
473 }
474 float k = frameRateK(hover ? cfg.hoverSpeed : cfg.motionSpeed, dt);
475 lay->x = lerpf(lay->x, sx, k);
476 lay->y = lerpf(lay->y, targetY, k);
477 lay->scale = lerpf(lay->scale, targetScale, k);
478 lay->angle = lerpf(lay->angle, targetAngle, k);
479 lay->alpha = lerpf(lay->alpha, vis->disabled ? cfg.disabledAlpha : 1.f, k);
480 const float targetFlip = resolveCardWantFaceUp(vis->faceUp, md->faceDown, md->peek) ? 0.f : 1.f;
481 advanceCardFlip(vis->flip, targetFlip, cfg.flipSpeed, dt);
482 }
483
484 // 2) 拖拽状态机
485 const bool press = down && !d->wasDown;
486 const bool release = !down && d->wasDown;
487 d->wasDown = down;
488
489 if (press && md->interactive) {
490 d->press = pick(mx, my);
491 if (d->press && d->press->visual()->disabled) d->press = nullptr;
492 d->pressX = mx;
493 d->pressY = my;
494 }
495
496 if (down && d->press && !d->card) {
497 const float dx = mx - d->pressX;
498 const float dy = my - d->pressY;
499 if (dx * dx + dy * dy > cfg.dragThreshold) {
500 d->card = d->press;
501 d->card->state()->dragging = true;
502 d->card->state()->phase = CardState::Dragging;
503 d->ox = mx - d->card->layout()->x;
504 d->oy = my - d->card->layout()->y;
505 }
506 }
507
508 if (d->card && down) {
509 auto *lay = d->card->layout().operator->();
510 auto *vis = d->card->visual().operator->();
511 lay->x = mx - d->ox;
512 lay->y = my - d->oy;
513 lay->scale = cfg.hoverScale;
514 lay->angle = 0.f;
515 lay->alpha = 1.f;
516 const float targetFlip = resolveCardWantFaceUp(vis->faceUp, md->faceDown, md->peek) ? 0.f : 1.f;
517 advanceCardFlip(vis->flip, targetFlip, cfg.flipSpeed, dt);
518 }
519
520 if (release) {
521 if (d->card) {
522 d->card->state()->dragging = false;
523 d->card->state()->phase = CardState::Returning;
524 CardData *dropped = d->card;
525 d->card = nullptr; // 归位;若已从手牌移除则自然消失
526 for (Zone *z : zones) {
527 if (z && z->contains(mx, my)) {
528 const std::string cardId = dropped ? dropped->identity()->id : "";
529 if (z->accepts(dropped)) {
530 out.push_back(CardEvent{"drop", md->owner, z->rect()->id, cardId, ""});
531 } else {
532 out.push_back(CardEvent{"dropRejected", md->owner, z->rect()->id, cardId,
533 "kind_not_allowed"});
534 }
535 break;
536 }
537 }
538 } else if (d->press) {
539 out.push_back(CardEvent{"click", md->owner, "", d->press->identity()->id, ""});
540 }
541 d->press = nullptr;
542 }
543}
544
546 auto *md = meta().operator->();
547 const LayoutConfig cfg = md->config ? *md->config : LayoutConfig();
548 // Flip progress owns face visibility; do not force an instant back face here.
549 const CardData *dragCard = drag()->card;
550 for (auto *c : membership()->cards) {
551 if (c && c != dragCard) renderCard(gfx, *c, cfg, false);
552 }
553 if (dragCard) renderCard(gfx, *dragCard, cfg, false);
554}
555
556} // namespace eve::card
double z
double y
double x
LogicalId target
bool & active
float w
Definition AnimClip.cpp:738
eve::EntitySpatialPose pose
const std::string & s
Selective canonical attributes for card combat values.
float cx
Definition CardTypes.cpp:36
float cy
Definition CardTypes.cpp:37
float degrees
Definition CardTypes.cpp:38
glm::vec4 p[6]
std::string layout
std::uint32_t dropped
glm::vec4 tint
uint32_t i1
Definition Grass.cpp:61
uint32_t i2
Definition Grass.cpp:61
float u
Definition Grass.cpp:233
glm::vec3 n
Definition Grass.cpp:63
double r
float v
HexVec3 left
std::int32_t c
int h
std::vector< Colorf > px
std::array< float, 3 > scale
std::string id
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
glm::dvec2 center
glm::dvec3 dx
double dt
std::shared_ptr< const OceanSprayFrame > previous
Texture * texture
float d
float t
std::vector< EquipmentStat > stats
std::string filter
std::string text
ScriptStructure out
std::string kind
float dy
Definition Shadow.cpp:151
float size
Definition TreeMesh.cpp:158
uint32_t index
double oy
double ox
uint64_t identity
static eve::Result< void > project(CardData &card)
Project canonical values into the legacy integer Stats fields.
单张卡牌:ECS 实体,数据拆成 Identity / Stats / Visual / Layout / State。
Definition CardTypes.h:106
static CardData * createCard()
创建并触摸全部组件。
bool hit(float px, float py)
以当前中心 + 缩放判断点是否命中。
std::string describe()
卡牌描述字符串(调试用)。
牌库(栈顶在末尾)。
Definition CardTypes.h:207
CardData * get(int index)
CardData * peek()
查看栈顶卡牌(不弹出)。
void shuffle()
洗牌。
CardData * draw()
弹出栈顶卡牌(末尾);空牌库返回 nullptr。
static Deck * createDeck()
创建并触摸 Membership。
手牌:扇形布局 + 悬浮 + 拖拽 + 落区判定 + 渲染。
Definition CardTypes.h:292
void slotTransform(int i, int n, float &ox, float &oy, float &angle)
第 i 张(共 n 张)的扇形目标位置(牌中心)。
void release() override
Entity.
Definition CardTypes.h:298
CardData * get(int index)
static Hand * createHand()
创建并触摸全部组件。
bool removeCard(CardData *c)
CardData * pick(float px, float py)
命中检测:返回 (px,py) 处最上层卡牌。
void addCard(CardData *c)
手牌增删与查询。
void render(graphics::Graphics *gfx)
绘制整手牌。
void update(float dt, float mx, float my, bool down, const std::vector< Zone * > &zones, std::vector< CardEvent > &out)
每帧推进:布局 + 悬浮 + 拖拽状态机,产出事件到 out。
CardData * find(const std::string &id)
落牌区(手牌区 / 出牌区 / 弃牌区),用于拖放命中判定。
Definition CardTypes.h:242
void render(graphics::Graphics *gfx, bool showLabel)
绘制落牌区。
static Zone * createZone()
创建并触摸组件。
bool accepts(CardData *card)
该区域是否接受这张卡。
bool contains(float px, float py)
点是否落在区域内。
float getWidth(const std::string &text) const
Pixel width of text (UTF-8), including kerning; delegates to FontData.
Definition Font.cpp:176
virtual void drawSolidRect(float x, float y, float w, float h, float r, float g, float b, float a=1.f)
RGBA-float overload matching the script-facing drawSolidRect name.
virtual void drawText(Font *font, const std::string &text, float x, float y, const Color &color=Color(1.f, 1.f, 1.f, 1.f), float scale=1.f)
Draw UTF-8 text with an explicitly supplied GPU font.
virtual void drawSolidRectRotated(float cx, float cy, float w, float h, float degrees, const Color &color, BlendMode blend=BlendMode::Alpha)=0
Rotated solid quad degrees clockwise (screen Y-down) around (cx, cy).
Font * getFont() const
Returns the font.
Definition Graphics.h:1697
SQInteger top
Definition Snapshot.cpp:115
constexpr float lerpf(float a, float b, float t) noexcept
Lerpf.
Definition AnimMath.h:40
constexpr float clampf(float v, float lo, float hi) noexcept
Clampf.
Definition AnimMath.h:34
void renderCardBack(graphics::Graphics *gfx, float x, float y, float w, float h, float angle, float a)
绘制牌背。
void advanceCardFlip(float &flip, float targetFaceDown, float speed, float dt)
Advance animated flip toward a face-down target with frame-rate-normalized speed.
Definition CardTypes.cpp:85
bool resolveCardWantFaceUp(bool cardFaceUp, bool handFaceDown, bool handPeek)
Resolve whether a card should read as face-up under hand faceDown/peek rules.
Definition CardTypes.cpp:92
const char * cardStateName(CardState state)
状态枚举的字符串名(用于脚本/调试)。
Definition CardTypes.cpp:15
CardState
单张卡牌的运行时状态。
Definition CardTypes.h:31
CardFlipPose evaluateCardFlip(float flipProgress, float liftPeak)
Evaluate face-down progress into an adapter-facing flip pose.
Definition CardTypes.cpp:74
void printCentered(graphics::Graphics *gfx, const std::string &text, float cx, float cy, float scale, const glm::vec4 &color)
渲染辅助(也供 Zone / Deck 复用)。
void renderCard(graphics::Graphics *gfx, const CardData &cardRef, const LayoutConfig &cfg, bool back)
绘制单张卡牌(正面或牌背;back 强制牌背,忽略 flip)。
一次交互事件。
Definition CardTypes.h:279
Evaluated flip pose for external 2D/3D adapters (graphics-independent).
Definition CardTypes.h:355
UiCard 风格的布局配置(脚本可实时修改,对应 UiCard 的 Configs 面板)。
Definition CardTypes.h:46
float cardW
卡牌宽/高(像素)。
Definition CardTypes.h:48
bool hoverRotation
悬浮时是否恢复为水平。
Definition CardTypes.h:60
float arcHeight
扇形弧度(两端上翘高度)。
Definition CardTypes.h:56
float flipLift
Peak lift (logical pixels) at the edge-on midpoint of a flip.
Definition CardTypes.h:73
float disabledAlpha
禁用牌透明度。
Definition CardTypes.h:80
float handX
手牌扇形中心 X / 基准高度 Y。
Definition CardTypes.h:53
float motionSpeed
通用归位运动速度。
Definition CardTypes.h:66
float flipSpeed
Face flip lerp speed (same 60fps-normalized units as motionSpeed). Drives the animated 0....
Definition CardTypes.h:71
int flipAxis
Flip hinge: 0 = vertical (width foreshortens / rotate about local up), 1 = horizontal (height foresho...
Definition CardTypes.h:78
float spacing
手牌水平间距。
Definition CardTypes.h:51
float hoverScale
悬浮缩放/上移像素/运动速度。
Definition CardTypes.h:62
float rotationAngle
手牌两端最大旋转角(度)。
Definition CardTypes.h:58
float dragThreshold
拖拽触发距离(像素)。
Definition CardTypes.h:87
glm::vec4 color