mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Allow shift/ctrl click to buy/sell multiple units.
Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1221
This commit is contained in:
parent
7e3cebb96d
commit
08d32ffc77
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from PySide2.QtCore import Qt
|
||||
from PySide2.QtWidgets import (
|
||||
QGroupBox,
|
||||
QHBoxLayout,
|
||||
@ -10,6 +10,7 @@ from PySide2.QtWidgets import (
|
||||
QSizePolicy,
|
||||
QSpacerItem,
|
||||
QGridLayout,
|
||||
QApplication,
|
||||
)
|
||||
|
||||
from game.dcs.unittype import UnitType
|
||||
@ -18,6 +19,12 @@ from game.unitdelivery import PendingUnitDeliveries
|
||||
from qt_ui.models import GameModel
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
from qt_ui.windows.QUnitInfoWindow import QUnitInfoWindow
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class RecruitType(Enum):
|
||||
BUY = 0
|
||||
SELL = 1
|
||||
|
||||
|
||||
class PurchaseGroup(QGroupBox):
|
||||
@ -41,7 +48,9 @@ class PurchaseGroup(QGroupBox):
|
||||
QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
||||
)
|
||||
|
||||
self.sell_button.clicked.connect(lambda: self.recruiter.sell(self.unit_type))
|
||||
self.sell_button.clicked.connect(
|
||||
lambda: self.recruiter.recruit_handler(RecruitType.SELL, self.unit_type)
|
||||
)
|
||||
|
||||
self.amount_bought = QLabel()
|
||||
self.amount_bought.setSizePolicy(
|
||||
@ -54,7 +63,9 @@ class PurchaseGroup(QGroupBox):
|
||||
self.buy_button.setMinimumSize(16, 16)
|
||||
self.buy_button.setMaximumSize(16, 16)
|
||||
|
||||
self.buy_button.clicked.connect(lambda: self.recruiter.buy(self.unit_type))
|
||||
self.buy_button.clicked.connect(
|
||||
lambda: self.recruiter.recruit_handler(RecruitType.BUY, self.unit_type)
|
||||
)
|
||||
self.buy_button.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
|
||||
|
||||
layout.addWidget(self.sell_button)
|
||||
@ -162,17 +173,39 @@ class QRecruitBehaviour:
|
||||
def update_available_budget(self) -> None:
|
||||
GameUpdateSignal.get_instance().updateBudget(self.game_model.game)
|
||||
|
||||
def buy(self, unit_type: UnitType) -> None:
|
||||
def recruit_handler(self, recruit_type: RecruitType, unit_type: UnitType) -> None:
|
||||
# Lookup if Keyboard Modifiers were pressed
|
||||
# Shift = 10 times
|
||||
# CTRL = 5 Times
|
||||
modifiers = QApplication.keyboardModifiers()
|
||||
if modifiers == Qt.ShiftModifier:
|
||||
amount = 10
|
||||
elif modifiers == Qt.ControlModifier:
|
||||
amount = 5
|
||||
else:
|
||||
amount = 1
|
||||
|
||||
for i in range(amount):
|
||||
if recruit_type == RecruitType.SELL:
|
||||
if not self.sell(unit_type):
|
||||
return
|
||||
elif recruit_type == RecruitType.BUY:
|
||||
if not self.buy(unit_type):
|
||||
return
|
||||
|
||||
def buy(self, unit_type: UnitType) -> bool:
|
||||
|
||||
if not self.enable_purchase(unit_type):
|
||||
logging.error(f"Purchase of {unit_type} not allowed at {self.cp.name}")
|
||||
return
|
||||
return False
|
||||
|
||||
self.pending_deliveries.order({unit_type: 1})
|
||||
self.budget -= unit_type.price
|
||||
self.update_purchase_controls()
|
||||
self.update_available_budget()
|
||||
return True
|
||||
|
||||
def sell(self, unit_type: UnitType) -> None:
|
||||
def sell(self, unit_type: UnitType) -> bool:
|
||||
if self.pending_deliveries.available_next_turn(unit_type) > 0:
|
||||
self.budget += unit_type.price
|
||||
self.pending_deliveries.sell({unit_type: 1})
|
||||
@ -180,6 +213,7 @@ class QRecruitBehaviour:
|
||||
del self.pending_deliveries.units[unit_type]
|
||||
self.update_purchase_controls()
|
||||
self.update_available_budget()
|
||||
return True
|
||||
|
||||
def update_purchase_controls(self) -> None:
|
||||
for group in self.purchase_groups.values():
|
||||
|
||||
@ -89,7 +89,7 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
||||
return False
|
||||
return True
|
||||
|
||||
def buy(self, unit_type: AircraftType) -> None:
|
||||
def buy(self, unit_type: AircraftType) -> bool:
|
||||
if self.maximum_units > 0:
|
||||
if self.cp.unclaimed_parking(self.game_model.game) <= 0:
|
||||
logging.debug(f"No space for additional aircraft at {self.cp}.")
|
||||
@ -100,7 +100,7 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
||||
"another plane.",
|
||||
QMessageBox.Ok,
|
||||
)
|
||||
return
|
||||
return False
|
||||
# If we change our mind about selling, we want the aircraft to be put
|
||||
# back in the inventory immediately.
|
||||
elif self.pending_deliveries.units.get(unit_type, 0) < 0:
|
||||
@ -110,8 +110,9 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
||||
|
||||
super().buy(unit_type)
|
||||
self.hangar_status.update_label()
|
||||
return True
|
||||
|
||||
def sell(self, unit_type: AircraftType) -> None:
|
||||
def sell(self, unit_type: AircraftType) -> bool:
|
||||
# Don't need to remove aircraft from the inventory if we're canceling
|
||||
# orders.
|
||||
if self.pending_deliveries.units.get(unit_type, 0) <= 0:
|
||||
@ -128,10 +129,12 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
||||
"assigned to a mission?",
|
||||
QMessageBox.Ok,
|
||||
)
|
||||
return
|
||||
return False
|
||||
super().sell(unit_type)
|
||||
self.hangar_status.update_label()
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class QHangarStatus(QHBoxLayout):
|
||||
def __init__(self, game_model: GameModel, control_point: ControlPoint) -> None:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user