| 701 | } |
| 702 | |
| 703 | void ControlGenerator::fillAgentControl(GameState &state, sp<Graphic> baseControl, |
| 704 | const AgentInfo &info) |
| 705 | { |
| 706 | if (!singleton.initialised) |
| 707 | { |
| 708 | singleton.init(state); |
| 709 | } |
| 710 | |
| 711 | baseControl->Controls.clear(); |
| 712 | if (!info.agent) |
| 713 | { |
| 714 | baseControl->setImage(nullptr); |
| 715 | return; |
| 716 | } |
| 717 | baseControl->setImage(singleton.battleSelect[(int)info.selected]); |
| 718 | baseControl->setData(info.agent); |
| 719 | |
| 720 | auto unitIcon = baseControl->createChild<Graphic>(info.agent->getPortrait().icon); |
| 721 | unitIcon->AutoSize = true; |
| 722 | unitIcon->Location = {2, 1}; |
| 723 | unitIcon->ToolTipText = info.agent->name; |
| 724 | |
| 725 | if (info.useRank) |
| 726 | { |
| 727 | auto rankIcon = baseControl->createChild<Graphic>(singleton.unitRanks[(int)info.rank]); |
| 728 | rankIcon->AutoSize = true; |
| 729 | rankIcon->Location = {0, 0}; |
| 730 | } |
| 731 | if (info.healthProportion > 0.0f) |
| 732 | { |
| 733 | // FIXME: Put these somewhere slightly less magic? |
| 734 | Vec2<int> healthBarOffset = {27, 2}; |
| 735 | Vec2<int> healthBarSize = {3, 20}; |
| 736 | |
| 737 | auto healthImg = info.shield ? singleton.shieldImage : singleton.healthImage; |
| 738 | auto healthGraphic = baseControl->createChild<Graphic>(healthImg); |
| 739 | // This is a bit annoying as the health bar starts at the bottom, but the coord origin is |
| 740 | // top-left, so fix that up a bit |
| 741 | int healthBarHeight = (int)((float)healthBarSize.y * info.healthProportion); |
| 742 | healthBarOffset.y = healthBarOffset.y + (healthBarSize.y - healthBarHeight); |
| 743 | healthBarSize.y = healthBarHeight; |
| 744 | healthGraphic->Location = healthBarOffset; |
| 745 | healthGraphic->Size = healthBarSize; |
| 746 | healthGraphic->ImagePosition = FillMethod::Stretch; |
| 747 | } |
| 748 | if (info.stunProportion > 0.0f) |
| 749 | { |
| 750 | // FIXME: Put these somewhere slightly less magic? |
| 751 | Vec2<int> healthBarOffset = {27, 2}; |
| 752 | Vec2<int> healthBarSize = {3, 20}; |
| 753 | |
| 754 | auto healthImg = singleton.stunImage; |
| 755 | auto healthGraphic = baseControl->createChild<Graphic>(healthImg); |
| 756 | // This is a bit annoying as the health bar starts at the bottom, but the coord origin is |
| 757 | // top-left, so fix that up a bit |
| 758 | int healthBarHeight = (int)((float)healthBarSize.y * info.stunProportion); |
| 759 | healthBarOffset.y = healthBarOffset.y + (healthBarSize.y - healthBarHeight); |
| 760 | healthBarSize.y = healthBarHeight; |