Пример #1
0
    def load_rules(self):
        """

        """
        # read rules
        rule_file = c.extend(c.Scenario_Ruleset_Folder, self._properties['rules'])
        self._properties['rules'] = u.read_as_yaml(rule_file)
Пример #2
0
    def load_rules(self):
        """

        """
        # read rules
        rule_file = c.extend(c.Scenario_Ruleset_Folder,
                             self._properties['rules'])
        self._properties['rules'] = u.read_as_yaml(rule_file)
Пример #3
0
    def __init__(self, client):
        super().__init__()

        self.setAttribute(QtCore.Qt.WA_StyledBackground)
        self.setProperty('background', 'black')

        layout = qt_graphics.RelativeLayout(self)

        start_image = QtGui.QPixmap(constants.extend(constants.GRAPHICS_UI_FOLDER, 'start.background.jpg'))
        start_image_item = QtWidgets.QGraphicsPixmapItem(start_image)
        start_image_item.setZValue(1)

        scene = QtWidgets.QGraphicsScene(self)
        scene.addItem(start_image_item)

        view = QtWidgets.QGraphicsView(scene)
        view.resize(start_image.size())
        view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        view.setSceneRect(0, 0, start_image.width(), start_image.height())
        view.layout_constraint = qt_graphics.RelativeLayoutConstraint().center_horizontal().center_vertical()
        layout.addWidget(view)

        subtitle = QtWidgets.QLabel('')
        subtitle.layout_constraint = qt_graphics.RelativeLayoutConstraint((0.5, -0.5, 0),
            (0.5, -0.5, start_image.height() / 2 + 20))
        layout.addWidget(subtitle)

        actions = {'exit': client.quit, 'help': client.show_help_browser, 'lobby': client.show_game_lobby_dialog,
            'editor': client.switch_to_editor_screen, 'options': client.show_preferences_dialog}

        image_map_file = constants.extend(constants.GRAPHICS_UI_FOLDER, 'start.overlay.info')
        image_map = utils.read_as_yaml(image_map_file)

        # security check, they have to be the same
        if actions.keys() != image_map.keys():
            raise RuntimeError('Start screen hot map info file ({}) corrupt.'.format(image_map_file))

        for k, v in image_map.items():
            # add action from our predefined action dictionary
            pixmap = QtGui.QPixmap(constants.extend(constants.GRAPHICS_UI_FOLDER, v['overlay']))
            mapitem = MapItem(view, pixmap, label=subtitle, description=v['label'])
            mapitem.item.setZValue(3)
            offset = v['offset']
            mapitem.item.setOffset(QtCore.QPointF(offset[0], offset[1]))
            mapitem.item.signaller.clicked.connect(actions[k])

            frame_path = QtGui.QPainterPath()
            frame_path.addRect(mapitem.item.boundingRect())
            frame_item = scene.addPath(frame_path, StartScreen.frame_pen)
            frame_item.setZValue(4)
            scene.addItem(mapitem.item)

        version_label = QtWidgets.QLabel(
            '<font color=#ffffff>{}</font>'.format(tools.get_option(constants.Opt.VERSION)))
        version_label.layout_constraint = qt_graphics.RelativeLayoutConstraint().east(20).south(20)
        layout.addWidget(version_label)
Пример #4
0
def load_soundtrack_playlist():
    """
        Loads the play list of the soundtracks and replaces the file name with the full path, then returns the list.

        A playlist is a list where each entry is a list of two strings: filepath, title
    """
    playlist = u.read_as_yaml(c.Soundtrack_Playlist)
    # add the soundtrack folder to each file name
    for entry in playlist:
        entry[0] = c.extend(c.Soundtrack_Folder, entry[0])
    return playlist
Пример #5
0
def load_soundtrack_playlist():
    """
        Loads the play list of the soundtracks and replaces the file name with the full path, then returns the list.

        A playlist is a list where each entry is a list of two strings: filepath, title
    """
    playlist = u.read_as_yaml(c.Soundtrack_Playlist)
    # add the soundtrack folder to each file name
    for entry in playlist:
        entry[0] = c.extend(c.Soundtrack_Folder, entry[0])
    return playlist
Пример #6
0
def load_soundtrack_playlist():
    """
        Loads the play list of the soundtracks and replaces the file name with the full path.

        A playlist is a list where each entry is a list of two strings: filepath, title
    """
    global soundtrack_playlist

    # create playlist
    soundtrack_playlist = QtMultimedia.QMediaPlaylist()
    soundtrack_playlist.setPlaybackMode(QtMultimedia.QMediaPlaylist.Loop)

    # read information file
    data = utils.read_as_yaml(constants.SOUNDTRACK_INFO_FILE)

    # add the soundtrack folder to each file name
    for entry in data:
        file = constants.extend(constants.SOUNDTRACK_FOLDER, entry[0])
        url = tools.local_url(file)
        media = QtMultimedia.QMediaContent(url)
        soundtrack_playlist.addMedia(media)
Пример #7
0
    def load(self, file_name):
        """
            Load/deserialize all internal variables from a zipped archive via YAML.
        """

        # so we can do that also during game play, we reset
        self.reset()

        reader = utils.ZipArchiveReader(file_name)

        self._properties = reader.read_as_yaml(SCENARIO_FILE_PROPERTIES)
        self._maps = reader.read_as_yaml(SCENARIO_FILE_MAPS)
        self._provinces = reader.read_as_yaml(SCENARIO_FILE_PROVINCES)
        # TODO check all ids are smaller then len()

        self._nations = reader.read_as_yaml(SCENARIO_FILE_NATIONS)
        # TODO check all ids are smaller then len()

        # read rule file
        # TODO how to specify which rules file apply
        rule_file = constants.extend(constants.SCENARIO_RULESET_FOLDER, self._properties['rules'])
        self._rules = utils.read_as_yaml(rule_file)
Пример #8
0
def load_options(file_name):
    """
        Load options from a JSON file and apply some conversions like changing the main window bounding rectangle
        from list to QtCore.QRect.
    """
    global options
    options = read_as_yaml(file_name)

    # delete entries that are not in Constants.Options
    for key in list(options.keys()):
        if key not in c.Options:
            del options[key]

    # copy values that are in Constants.Options but not here
    for key in c.Options:
        if key not in options:
            options[key] = c.Options[key].default

    # main window bounding rectangle, convert from list to QRect
    rect = get_option(c.O.MW_BOUNDS)
    if rect is not None:
        set_option(c.O.MW_BOUNDS, QtCore.QRect(*rect))
Пример #9
0
def load_options(file_name):
    """
        Load options from a JSON file and apply some conversions like changing the main window bounding rectangle
        from list to QtCore.QRect.
    """
    global options
    options = read_as_yaml(file_name)

    # delete entries that are not in Constants.Options
    for key in list(options.keys()):
        if key not in constants.Options:
            del options[key]

    # copy values that are in Constants.Options but not here
    for key in constants.Options:
        if key not in options:
            options[key] = constants.Options[key].default

    # main window bounding rectangle, convert from list to QRect
    rect = get_option(constants.Opt.MAINWINDOW_BOUNDS)
    if rect is not None:
        set_option(constants.Opt.MAINWINDOW_BOUNDS, QtCore.QRect(*rect))
Пример #10
0
    def __init__(self, client):
        super().__init__()

        self.setAttribute(QtCore.Qt.WA_StyledBackground)
        self.setProperty('background', 'texture')

        layout = g.RelativeLayout(self)

        start_image = QtGui.QPixmap(c.extend(c.Graphics_UI_Folder, 'start.background.jpg'))
        start_image_item = QtGui.QGraphicsPixmapItem(start_image)
        start_image_item.setZValue(1)

        scene = QtGui.QGraphicsScene(self)
        scene.addItem(start_image_item)

        view = QtGui.QGraphicsView(scene)
        view.resize(start_image.size())
        view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        view.setSceneRect(0, 0, start_image.width(), start_image.height())
        view.layout_constraint = g.RelativeLayoutConstraint().center_horizontal().center_vertical()
        layout.addWidget(view)

        subtitle = QtGui.QLabel('')
        subtitle.layout_constraint = g.RelativeLayoutConstraint((0.5, -0.5, 0),
                                                                (0.5, -0.5, start_image.height() / 2 + 20))
        layout.addWidget(subtitle)

        actions = {
            'exit': client.quit,
            'help': client.show_help_browser,
            'lobby': client.show_game_lobby_dialog,
            'editor': client.switch_to_editor_screen,
            'options': client.show_options_dialog
        }

        image_map_file = c.extend(c.Graphics_UI_Folder, 'start.overlay.info')
        image_map = u.read_as_yaml(image_map_file)

        # security check, they have to be the same
        if actions.keys() != image_map.keys():
            raise RuntimeError('Start screen hot map info file ({}) corrupt.'.format(image_map_file))

        for k, v in image_map.items():
            # add action from our predefined action dictionary
            pixmap = QtGui.QPixmap(c.extend(c.Graphics_UI_Folder, v['overlay']))
            mapitem = MapItem(view, pixmap, label=subtitle, description=v['label'])
            mapitem.item.setZValue(3)
            offset = v['offset']
            mapitem.item.setOffset(QtCore.QPointF(offset[0], offset[1]))
            mapitem.item.clicked.connect(actions[k])

            frame_path = QtGui.QPainterPath()
            frame_path.addRect(mapitem.item.boundingRect())
            frame_item = scene.addPath(frame_path, StartScreen.frame_pen)
            frame_item.setZValue(4)
            scene.addItem(mapitem.item)

        version_label = QtGui.QLabel('<font color=#ffffff>{}</font>'.format(t.get_option(c.O.VERSION)))
        version_label.layout_constraint = g.RelativeLayoutConstraint().east(20).south(20)
        layout.addWidget(version_label)