Fix type errors with Flight.start_type in the UI.

Also reorders the enum so that iteration shows the order we want in the
UI by default.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1672
This commit is contained in:
Dan Albert 2021-10-23 12:18:48 -07:00
parent b728fcc2d6
commit 14769c0350
4 changed files with 16 additions and 13 deletions

View File

@ -9,7 +9,7 @@ class StartType(Enum):
IN_FLIGHT. IN_FLIGHT.
""" """
IN_FLIGHT = "In Flight"
RUNWAY = "Runway"
COLD = "Cold" COLD = "Cold"
WARM = "Warm" WARM = "Warm"
RUNWAY = "Runway"
IN_FLIGHT = "In Flight"

View File

@ -56,6 +56,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from game.ato.starttype import StartType
from game.commander.tasks.compound.nextaction import PlanNextAction from game.commander.tasks.compound.nextaction import PlanNextAction
from game.commander.tasks.theatercommandertask import TheaterCommanderTask from game.commander.tasks.theatercommandertask import TheaterCommanderTask
from game.commander.theaterstate import TheaterState from game.commander.theaterstate import TheaterState
@ -70,7 +71,7 @@ class TheaterCommander(Planner[TheaterState, TheaterCommanderTask]):
def __init__(self, game: Game, player: bool) -> None: def __init__(self, game: Game, player: bool) -> None:
super().__init__( super().__init__(
PlanNextAction( PlanNextAction(
aircraft_cold_start=game.settings.default_start_type == "Cold" aircraft_cold_start=game.settings.default_start_type is StartType.COLD
) )
) )
self.game = game self.game = game

View File

@ -14,6 +14,7 @@ from PySide2.QtWidgets import (
from dcs.unittype import FlyingType from dcs.unittype import FlyingType
from game import Game from game import Game
from game.ato.starttype import StartType
from game.squadrons.squadron import Squadron from game.squadrons.squadron import Squadron
from game.theater import ControlPoint, OffMapSpawn from game.theater import ControlPoint, OffMapSpawn
from game.ato.package import Package from game.ato.package import Package
@ -98,8 +99,9 @@ class QFlightCreator(QDialog):
# we restore the previous choice. # we restore the previous choice.
self.restore_start_type: Optional[str] = None self.restore_start_type: Optional[str] = None
self.start_type = QComboBox() self.start_type = QComboBox()
self.start_type.addItems(["Cold", "Warm", "Runway", "In Flight"]) for start_type in StartType:
self.start_type.setCurrentText(self.game.settings.default_start_type) self.start_type.addItem(start_type.value, start_type)
self.start_type.setCurrentText(self.game.settings.default_start_type.value)
layout.addLayout( layout.addLayout(
QLabeledWidget( QLabeledWidget(
"Start type:", "Start type:",
@ -178,7 +180,7 @@ class QFlightCreator(QDialog):
# the roster is passed explicitly. Needs a refactor. # the roster is passed explicitly. Needs a refactor.
roster.max_size, roster.max_size,
task, task,
self.start_type.currentText(), self.start_type.currentData(),
divert, divert,
custom_name=self.custom_name_text, custom_name=self.custom_name_text,
roster=roster, roster=roster,
@ -197,10 +199,10 @@ class QFlightCreator(QDialog):
def on_departure_changed(self, departure: ControlPoint) -> None: def on_departure_changed(self, departure: ControlPoint) -> None:
if isinstance(departure, OffMapSpawn): if isinstance(departure, OffMapSpawn):
previous_type = self.start_type.currentText() previous_type = self.start_type.currentData()
if previous_type != "In Flight": if previous_type != StartType.IN_FLIGHT:
self.restore_start_type = previous_type self.restore_start_type = previous_type
self.start_type.setCurrentText("In Flight") self.start_type.setCurrentText(StartType.IN_FLIGHT.value)
self.start_type.setEnabled(False) self.start_type.setEnabled(False)
else: else:
self.start_type.setEnabled(True) self.start_type.setEnabled(True)

View File

@ -7,6 +7,7 @@ from PySide2.QtWidgets import (
) )
from game.ato.flight import Flight from game.ato.flight import Flight
from game.ato.starttype import StartType
from qt_ui.models import PackageModel from qt_ui.models import PackageModel
@ -21,10 +22,9 @@ class QFlightStartType(QGroupBox):
self.start_type_label = QLabel("Start type:") self.start_type_label = QLabel("Start type:")
self.start_type = QComboBox() self.start_type = QComboBox()
for i, st in enumerate([b for b in ["Cold", "Warm", "Runway", "In Flight"]]): for start_type in StartType:
self.start_type.addItem(st, st) self.start_type.addItem(start_type.value, start_type)
if flight.start_type == st: self.start_type.setCurrentText(flight.start_type.value)
self.start_type.setCurrentIndex(i)
self.start_type.currentTextChanged.connect(self._on_start_type_selected) self.start_type.currentTextChanged.connect(self._on_start_type_selected)
self.main_row.addWidget(self.start_type_label) self.main_row.addWidget(self.start_type_label)