Fix carrier option not taking effect this turn.

This really shouldn't need to happen but I don't feel like rewriting the
culling code right now. There's no reason for these to be persisted to
the Game at all, we should be generating these once they're needed.
This commit is contained in:
Dan Albert 2021-10-21 20:05:07 -07:00
parent 626740366b
commit 6dae5b98d5
8 changed files with 72 additions and 16 deletions

View File

@ -17,12 +17,19 @@ def boolean_option(
invert: bool = False,
detail: Optional[str] = None,
tooltip: Optional[str] = None,
causes_expensive_game_update: bool = False,
**kwargs: Any,
) -> bool:
return field(
metadata={
SETTING_DESCRIPTION_KEY: BooleanOption(
page, section, text, detail, tooltip, invert
page,
section,
text,
detail,
tooltip,
causes_expensive_game_update,
invert,
)
},
default=default,

View File

@ -26,7 +26,15 @@ def bounded_float_option(
return field(
metadata={
SETTING_DESCRIPTION_KEY: BoundedFloatOption(
page, section, text, detail, tooltip, min, max, divisor
page,
section,
text,
detail,
tooltip,
causes_expensive_game_update=False,
min=min,
max=max,
divisor=divisor,
)
},
default=default,

View File

@ -24,7 +24,14 @@ def bounded_int_option(
return field(
metadata={
SETTING_DESCRIPTION_KEY: BoundedIntOption(
page, section, text, detail, tooltip, min, max
page,
section,
text,
detail,
tooltip,
causes_expensive_game_update=False,
min=min,
max=max,
)
},
default=default,

View File

@ -37,7 +37,8 @@ def choices_option(
text,
detail,
tooltip,
dict(choices),
causes_expensive_game_update=False,
choices=dict(choices),
)
},
default=default,

View File

@ -25,7 +25,14 @@ def minutes_option(
return field(
metadata={
SETTING_DESCRIPTION_KEY: MinutesOption(
page, section, text, detail, tooltip, min, max
page,
section,
text,
detail,
tooltip,
causes_expensive_game_update=False,
min=min,
max=max,
)
},
default=default,

View File

@ -12,3 +12,4 @@ class OptionDescription:
text: str
detail: Optional[str]
tooltip: Optional[str]
causes_expensive_game_update: bool

View File

@ -410,6 +410,7 @@ class Settings:
page=MISSION_GENERATOR_PAGE,
section=PERFORMANCE_SECTION,
default=True,
causes_expensive_game_update=True,
)
# Cheating. Not using auto settings because the same page also has buttons which do

View File

@ -82,9 +82,16 @@ class CheatSettingsBox(QGroupBox):
class AutoSettingsLayout(QGridLayout):
def __init__(self, page: str, section: str, settings: Settings) -> None:
def __init__(
self,
page: str,
section: str,
settings: Settings,
write_full_settings: Callable[[], None],
) -> None:
super().__init__()
self.settings = settings
self.write_full_settings = write_full_settings
for row, (name, description) in enumerate(Settings.fields(page, section)):
self.add_label(row, description)
@ -116,6 +123,8 @@ class AutoSettingsLayout(QGridLayout):
if description.invert:
value = not value
self.settings.__dict__[name] = value
if description.causes_expensive_game_update:
self.write_full_settings()
checkbox = QCheckBox()
value = self.settings.__dict__[name]
@ -184,24 +193,42 @@ class AutoSettingsLayout(QGridLayout):
class AutoSettingsGroup(QGroupBox):
def __init__(self, page: str, section: str, settings: Settings) -> None:
def __init__(
self,
page: str,
section: str,
settings: Settings,
write_full_settings: Callable[[], None],
) -> None:
super().__init__(section)
self.setLayout(AutoSettingsLayout(page, section, settings))
self.setLayout(AutoSettingsLayout(page, section, settings, write_full_settings))
class AutoSettingsPageLayout(QVBoxLayout):
def __init__(self, page: str, settings: Settings) -> None:
def __init__(
self,
page: str,
settings: Settings,
write_full_settings: Callable[[], None],
) -> None:
super().__init__()
self.setAlignment(Qt.AlignTop)
for section in Settings.sections(page):
self.addWidget(AutoSettingsGroup(page, section, settings))
self.addWidget(
AutoSettingsGroup(page, section, settings, write_full_settings)
)
class AutoSettingsPage(QWidget):
def __init__(self, page: str, settings: Settings) -> None:
def __init__(
self,
page: str,
settings: Settings,
write_full_settings: Callable[[], None],
) -> None:
super().__init__()
self.setLayout(AutoSettingsPageLayout(page, settings))
self.setLayout(AutoSettingsPageLayout(page, settings, write_full_settings))
class QSettingsWindow(QDialog):
@ -214,7 +241,7 @@ class QSettingsWindow(QDialog):
self.pages: dict[str, AutoSettingsPage] = {}
for page in Settings.pages():
self.pages[page] = AutoSettingsPage(page, game.settings)
self.pages[page] = AutoSettingsPage(page, game.settings, self.applySettings)
self.setModal(True)
self.setWindowTitle("Settings")
@ -284,9 +311,6 @@ class QSettingsWindow(QDialog):
self.setLayout(self.layout)
def init(self):
raise RuntimeError
def initCheatLayout(self):
self.cheatPage = QWidget()