| 2730 | } |
| 2731 | |
| 2732 | void BattleView::orderSelect(StateRef<BattleUnit> u, bool inverse, bool additive) |
| 2733 | { |
| 2734 | auto pos = |
| 2735 | std::find(battle.battleViewSelectedUnits.begin(), battle.battleViewSelectedUnits.end(), u); |
| 2736 | if (inverse) |
| 2737 | { |
| 2738 | // Unit in selection => remove |
| 2739 | if (pos != battle.battleViewSelectedUnits.end()) |
| 2740 | { |
| 2741 | battle.battleViewSelectedUnits.erase(pos); |
| 2742 | } |
| 2743 | } |
| 2744 | else |
| 2745 | { |
| 2746 | // Unit not selected |
| 2747 | if (pos == battle.battleViewSelectedUnits.end()) |
| 2748 | { |
| 2749 | if (additive) |
| 2750 | { |
| 2751 | // Unit not in selection, and not full => add unit to selection |
| 2752 | if (battle.battleViewSelectedUnits.size() < 6) |
| 2753 | { |
| 2754 | battle.battleViewSelectedUnits.push_front(u); |
| 2755 | updateSquadIndex(u); |
| 2756 | } |
| 2757 | } |
| 2758 | else |
| 2759 | { |
| 2760 | // Unit not in selection => replace selection with unit |
| 2761 | battle.battleViewSelectedUnits.clear(); |
| 2762 | battle.battleViewSelectedUnits.push_back(u); |
| 2763 | updateSquadIndex(u); |
| 2764 | } |
| 2765 | } |
| 2766 | // Unit is selected |
| 2767 | else |
| 2768 | { |
| 2769 | // Unit in selection and additive => move unit to front |
| 2770 | if (additive) |
| 2771 | { |
| 2772 | battle.battleViewSelectedUnits.erase(pos); |
| 2773 | battle.battleViewSelectedUnits.push_front(u); |
| 2774 | updateSquadIndex(u); |
| 2775 | } |
| 2776 | // If not additive and in selection - select only this unit |
| 2777 | else if (battle.battleViewSelectedUnits.size() > 1) |
| 2778 | { |
| 2779 | battle.battleViewSelectedUnits.clear(); |
| 2780 | battle.battleViewSelectedUnits.push_front(u); |
| 2781 | updateSquadIndex(u); |
| 2782 | } |
| 2783 | // If not in additive mode and clicked on selected unit - deselect |
| 2784 | else |
| 2785 | { |
| 2786 | battle.battleViewSelectedUnits.clear(); |
| 2787 | } |
| 2788 | } |
| 2789 | } |