wip: initial work on issue #406

This commit is contained in:
Ignacio Muñoz Fernandez 2020-11-25 00:42:51 +01:00 committed by Dan Albert
parent 4a1809d56e
commit 6e153c6451
5 changed files with 163 additions and 56 deletions

View File

@ -34,6 +34,7 @@ def run_ui(game: Optional[Game] = None) -> None:
# init the theme and load the stylesheet based on the theme index
liberation_theme.init()
with open("./resources/stylesheets/"+liberation_theme.get_theme_css_file()) as stylesheet:
logging.info('Loading stylesheet: %s', liberation_theme.get_theme_css_file())
app.setStyleSheet(stylesheet.read())
# Inject custom payload in pydcs framework

View File

@ -0,0 +1,140 @@
import datetime
from PySide2.QtWidgets import QLabel, QHBoxLayout, QGroupBox, QVBoxLayout, QFrame, QSizePolicy, QStyle, QPushButton
from game.weather import Conditions, TimeOfDay
import qt_ui.uiconstants as CONST
class QTimeTurnWidget(QGroupBox):
"""
UI Component to display current turn and time info
"""
def __init__(self):
super(QTimeTurnWidget, self).__init__("Turn")
self.setStyleSheet('padding: 0px; margin-left: 5px; margin-right: 0px; margin-top: 1ex; margin-bottom: 5px; border-right: 0px')
self.icons = {
TimeOfDay.Dawn: CONST.ICONS["Dawn"],
TimeOfDay.Day: CONST.ICONS["Day"],
TimeOfDay.Dusk: CONST.ICONS["Dusk"],
TimeOfDay.Night: CONST.ICONS["Night"],
}
# self.setProperty('style', 'conditions__widget--turn')
self.layout = QHBoxLayout()
self.setLayout(self.layout)
self.daytime_icon = QLabel()
self.daytime_icon.setPixmap(self.icons[TimeOfDay.Dawn])
self.layout.addWidget(self.daytime_icon)
self.time_column = QVBoxLayout()
self.layout.addLayout(self.time_column)
self.date_display = QLabel()
self.time_column.addWidget(self.date_display)
self.time_display = QLabel()
self.time_column.addWidget(self.time_display)
def setCurrentTurn(self, turn: int, conditions: Conditions) -> None:
"""Sets the turn information display.
:arg turn Current turn number.
:arg conditions Current time and weather conditions.
"""
self.daytime_icon.setPixmap(self.icons[conditions.time_of_day])
self.date_display.setText(conditions.start_time.strftime("%d %b %Y"))
self.time_display.setText(
conditions.start_time.strftime("%H:%M:%S Local"))
self.setTitle("Turn " + str(turn + 1))
class QWeatherWidget(QGroupBox):
"""
UI Component to display current weather forecast
"""
def __init__(self):
super(QWeatherWidget, self).__init__("")
self.setProperty('style', 'QWeatherWidget')
self.icons = {
TimeOfDay.Dawn: CONST.ICONS["Dawn"],
TimeOfDay.Day: CONST.ICONS["Day"],
TimeOfDay.Dusk: CONST.ICONS["Dusk"],
TimeOfDay.Night: CONST.ICONS["Night"],
}
self.layout = QHBoxLayout()
self.setLayout(self.layout)
self.weather_icon = QLabel()
self.weather_icon.setPixmap(self.icons[TimeOfDay.Dawn])
self.layout.addWidget(self.weather_icon)
self.forecast = QLabel('')
self.layout.addWidget(self.forecast)
self.details = QPushButton("Weather")
self.details.setProperty("style", "btn-primary")
self.details.setDisabled(True)
self.details.clicked.connect(self.openDetailWindow)
self.layout.addWidget(self.details)
def openDetailWindow(self):
pass
def setCurrentConditions(self, conditions: Conditions) -> None:
"""Sets the turn information display.
:arg conditions Current time and weather conditions.
"""
self.conditions = conditions
self.updateIcon()
self.updateText()
pass
def updateIcon(self):
"""
Updates the Forecast Icon based on turn conditions
"""
pass
def updateText(self):
"""
Updates the Forecast Text based on turn conditions
"""
pass
def updateDetailsBtn(self):
if not self.conditions:
self.details.setEnable(False)
else:
self.details.setEnable(True)
class QConditionsWidget(QFrame):
def __init__(self):
super(QConditionsWidget, self).__init__()
self.layout = QHBoxLayout()
self.layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(self.layout)
self.setProperty('style', 'QConditionsWidget')
self.time_turn_widget = QTimeTurnWidget()
self.layout.addWidget(self.time_turn_widget)
self.weather_widget = QWeatherWidget()
self.layout.addWidget(self.weather_widget)
def setCurrentTurn(self, turn: int, conditions: Conditions) -> None:
self.time_turn_widget.setCurrentTurn(turn, conditions)
self.weather_widget.setCurrentConditions(conditions)

View File

@ -16,13 +16,13 @@ from gen.flights.traveltime import TotEstimator
from qt_ui.models import GameModel
from qt_ui.widgets.QBudgetBox import QBudgetBox
from qt_ui.widgets.QFactionsInfos import QFactionsInfos
from qt_ui.widgets.QTurnCounter import QTurnCounter
from qt_ui.widgets.clientslots import MaxPlayerCount
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
from qt_ui.windows.QWaitingForMissionResultWindow import \
QWaitingForMissionResultWindow
from qt_ui.windows.settings.QSettingsWindow import QSettingsWindow
from qt_ui.windows.stats.QStatsWindow import QStatsWindow
from qt_ui.widgets.QConditionsWidget import QConditionsWidget
class QTopPanel(QFrame):
@ -39,9 +39,8 @@ class QTopPanel(QFrame):
def game(self) -> Optional[Game]:
return self.game_model.game
def init_ui(self):
self.turnCounter = QTurnCounter()
def init_ui(self):
self.conditionsWidget = QConditionsWidget()
self.budgetBox = QBudgetBox(self.game)
self.passTurnButton = QPushButton("Pass Turn")
@ -85,21 +84,23 @@ class QTopPanel(QFrame):
self.proceedBox.setLayout(self.proceedBoxLayout)
self.layout = QHBoxLayout()
self.layout.addWidget(self.factionsInfos)
self.layout.addWidget(self.turnCounter)
self.layout.addWidget(self.conditionsWidget)
self.layout.addWidget(self.budgetBox)
self.layout.addWidget(self.buttonBox)
self.layout.addStretch(1)
self.layout.addWidget(self.proceedBox)
self.layout.setContentsMargins(0,0,0,0)
self.setLayout(self.layout)
def setGame(self, game: Optional[Game]):
if game is None:
return
self.turnCounter.setCurrentTurn(game.turn, game.conditions)
self.conditionsWidget.setCurrentTurn(game.turn, game.conditions)
self.budgetBox.setGame(game)
self.factionsInfos.setGame(game)

View File

@ -1,50 +0,0 @@
import datetime
from PySide2.QtWidgets import QLabel, QHBoxLayout, QGroupBox, QVBoxLayout
from game.weather import Conditions, TimeOfDay
import qt_ui.uiconstants as CONST
class QTurnCounter(QGroupBox):
"""
UI Component to display current turn and time info
"""
def __init__(self):
super(QTurnCounter, self).__init__("Turn")
self.icons = {
TimeOfDay.Dawn: CONST.ICONS["Dawn"],
TimeOfDay.Day: CONST.ICONS["Day"],
TimeOfDay.Dusk: CONST.ICONS["Dusk"],
TimeOfDay.Night: CONST.ICONS["Night"],
}
self.layout = QHBoxLayout()
self.setLayout(self.layout)
self.daytime_icon = QLabel()
self.daytime_icon.setPixmap(self.icons[TimeOfDay.Dawn])
self.layout.addWidget(self.daytime_icon)
self.time_column = QVBoxLayout()
self.layout.addLayout(self.time_column)
self.date_display = QLabel()
self.time_column.addWidget(self.date_display)
self.time_display = QLabel()
self.time_column.addWidget(self.time_display)
def setCurrentTurn(self, turn: int, conditions: Conditions) -> None:
"""Sets the turn information display.
:arg turn Current turn number.
:arg conditions Current time and weather conditions.
"""
self.daytime_icon.setPixmap(self.icons[conditions.time_of_day])
self.date_display.setText(conditions.start_time.strftime("%d %b %Y"))
self.time_display.setText(
conditions.start_time.strftime("%H:%M:%S Local"))
self.setTitle("Turn " + str(turn + 1))

View File

@ -506,4 +506,19 @@ QWidget[style="baseMenuHeader"]{
QLabel[style="small"]{
font-size: 8px;
}
QFrame[style="QConditionsWidget"] {
margin: 0px;
border: 0px;
padding: 0px;
background: transparent;
}
QGroupBox[style="QWeatherWidget"] {
padding: 0px;
margin-left: 0px;
margin-right: 5px;
margin-top: 1ex;
margin-bottom: 5px;
}