Briefing has start function and departure airbase selection

This commit is contained in:
Khopa 2019-07-07 13:57:04 +02:00
parent 0b87e192ce
commit 817a3a5e15

View File

@ -2,9 +2,11 @@ import os
from PySide2.QtGui import QWindow
from PySide2.QtWidgets import QHBoxLayout, QLabel, QWidget, QDialog, QVBoxLayout, QGridLayout, QGroupBox, QCheckBox, \
QSpinBox, QPushButton
QSpinBox, QPushButton, QMessageBox, QComboBox
from pip._internal.utils import typing
from game.game import AWACS_BUDGET_COST, PinpointStrike, db, Event
from game.game import AWACS_BUDGET_COST, PinpointStrike, db, Event, FrontlineAttackEvent, FrontlinePatrolEvent, Task, \
UnitType
from userdata.persistency import base_path
import qt_ui.uiconstants as CONST
@ -19,6 +21,7 @@ class QBriefingWindow(QDialog):
self.setWindowIcon(CONST.EVENT_ICONS[self.gameEvent.__class__])
self.setModal(True)
self.base = self.gameEvent.from_cp.base
self.game = self.gameEvent.game
self.scramble_entries = {k: {} for k in self.gameEvent.tasks}
self.initUi()
@ -29,6 +32,19 @@ class QBriefingWindow(QDialog):
self.scramble_box = QGroupBox("Units")
self.gridLayout = QGridLayout()
self.scramble_box.setLayout(self.gridLayout)
self.depart_box = QGroupBox("Departure")
self.depart_layout = QHBoxLayout()
self.depart_box.setLayout(self.depart_layout)
self.depart_from_label = QLabel("Depart from : ")
self.depart_from = QComboBox()
for cp in [b for b in self.game.theater.controlpoints if b.captured]:
self.depart_from.addItem(str(cp.name))
self.depart_layout.addWidget(self.depart_from_label)
self.depart_layout.addWidget(self.depart_from)
row = 0
def header(text, row):
@ -92,11 +108,13 @@ class QBriefingWindow(QDialog):
self.action_layout = QHBoxLayout()
self.commit_button = QPushButton("Commit")
self.back_button = QPushButton("Commit")
self.commit_button.clicked.connect(self.start)
self.action_layout.addWidget(self.commit_button)
self.action_layout.addWidget(self.back_button)
self.support_box = self.initSupportBox()
self.layout.addWidget(QLabel("<h2>{} on {}</h2>".format(self.gameEvent, self.gameEvent.to_cp.name)))
self.layout.addWidget(self.depart_box)
self.layout.addWidget(self.scramble_box)
self.layout.addWidget(self.support_box)
self.layout.addWidget(QLabel("<b>Ready?</b>"))
@ -149,4 +167,91 @@ class QBriefingWindow(QDialog):
pass
def debriefing_directory_location(self) -> str:
return os.path.join(base_path(), "liberation_debriefings")
return os.path.join(base_path(), "liberation_debriefings")
def start(self):
if self.awacs_checkbox.isChecked() == 1:
self.gameEvent.is_awacs_enabled = True
self.game.awacs_expense_commit()
else:
self.gameEvent.is_awacs_enabled = False
ca_slot_entry_value = self.ca_slot_entry.value()
try:
ca_slots = int(ca_slot_entry_value and ca_slot_entry_value or "0")
except:
ca_slots = 0
self.gameEvent.ca_slots = ca_slots
flights = {k: {} for k in self.gameEvent.tasks} # type: db.TaskForceDict
units_scramble_counts = {} # type: typing.Dict[typing.Type[UnitType], int]
tasks_scramble_counts = {} # type: typing.Dict[typing.Type[Task], int]
tasks_clients_counts = {} # type: typing.Dict[typing.Type[Task], int]
def dampen_count(unit_type, count: int) -> int:
nonlocal units_scramble_counts
total_count = self.base.total_units_of_type(unit_type)
total_scrambled = units_scramble_counts.get(unit_type, 0)
dampened_value = count if count + total_scrambled < total_count else total_count - total_scrambled
units_scramble_counts[unit_type] = units_scramble_counts.get(unit_type, 0) + dampened_value
return dampened_value
for task_type, dict in self.scramble_entries.items():
for unit_type, (count_entry, clients_entry) in dict.items():
try:
count = int(count_entry.value())
except:
count = 0
try:
clients_count = int(clients_entry and clients_entry.value() or 0)
except:
clients_count = 0
dampened_count = dampen_count(unit_type, count)
tasks_clients_counts[task_type] = tasks_clients_counts.get(task_type, 0) + clients_count
tasks_scramble_counts[task_type] = tasks_scramble_counts.get(task_type, 0) + dampened_count
flights[task_type][unit_type] = dampened_count, clients_count
for task in self.gameEvent.ai_banned_tasks:
if tasks_clients_counts.get(task, 0) == 0 and tasks_scramble_counts.get(task, 0) > 0:
self.showErrorMessage("Need at least one player in flight {}".format(self.gameEvent.flight_name(task)))
return
for task in self.gameEvent.player_banned_tasks:
if tasks_clients_counts.get(task, 0) != 0:
self.showErrorMessage("Players are not allowed on flight {}".format(self.gameEvent.flight_name(task)))
return
if self.game.is_player_attack(self.gameEvent):
if isinstance(self.gameEvent, FrontlineAttackEvent) or isinstance(self.gameEvent, FrontlinePatrolEvent):
if self.gameEvent.from_cp.base.total_armor == 0:
self.showErrorMessage("No ground vehicles available to attack!")
return
self.gameEvent.player_attacking(flights)
else:
if isinstance(self.gameEvent, FrontlineAttackEvent) or isinstance(self.gameEvent, FrontlinePatrolEvent):
if self.gameEvent.to_cp.base.total_armor == 0:
self.showErrorMessage("No ground vehicles available to defend!")
return
self.gameEvent.player_defending(flights)
self.gameEvent.departure_cp = self.gameEvent.from_cp
self.game.initiate_event(self.gameEvent)
# EventResultsMenu(self.window, self.parent, self.game, self.gameEvent).display()
def showErrorMessage(self, text):
about = QMessageBox()
about.setWindowTitle("Error")
about.setIcon(QMessageBox.Icon.Critical)
about.setText(text)
about.exec_()