Example #1
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)
Example #2
0
    def __init__(self):
        """
            All the necessary initializations. Is shown at the end.
        """
        super().__init__()
        # set geometry
        self.setGeometry(t.get_option(c.O.MW_BOUNDS))
        # set icon
        self.setWindowIcon(t.load_ui_icon('icon.ico'))
        # set title
        self.setWindowTitle('Imperialism Remake')

        # just a layout but nothing else
        self.layout = QtGui.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.content = None

        # show in full screen, maximized or normal
        if t.get_option(c.O.FULLSCREEN):
            self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
            self.showFullScreen()
        elif t.get_option(c.O.MW_MAXIMIZED):
            self.showMaximized()
        else:
            self.show()

        # loading animation
        # TODO animation right and start, stop in client
        self.animation = QtGui.QMovie(c.extend(c.Graphics_UI_Folder, 'loading.gif'))
        # self.animation.start()
        self.loading_label = QtGui.QLabel(self, f=QtCore.Qt.FramelessWindowHint | QtCore.Qt.Window)
        self.loading_label.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.loading_label.setMovie(self.animation)
Example #3
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)
Example #4
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)
Example #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
Example #6
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
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
0
    def redraw_map(self):
        """
            When a scenario is loaded new we need to draw the whole map new.
        """
        self.scene.clear()

        columns = self.scenario[k.MAP_COLUMNS]
        rows = self.scenario[k.MAP_ROWS]

        width = (columns + 0.5) * self.TILE_SIZE
        height = rows * self.TILE_SIZE
        self.scene.setSceneRect(0, 0, width, height)

        # TODO should load only once and cache (universal cache)
        # load all textures
        brushes = {}
        brushes[0] = QtGui.QBrush(QtGui.QColor(64, 64, 255))
        brushes[1] = QtGui.QBrush(QtGui.QColor(64, 255, 64))
        brushes[2] = QtGui.QBrush(QtGui.QColor(64, 255, 64))
        brushes[3] = QtGui.QBrush(QtGui.QColor(64, 255, 64))
        brushes[4] = QtGui.QBrush(QtGui.QColor(222, 222, 222))
        brushes[5] = QtGui.QBrush(QtGui.QColor(0, 128, 0))
        brushes[6] = QtGui.QBrush(QtGui.QColor(222, 222, 0))

        # fill the ground layer with ocean
        item = self.scene.addRect(0, 0, width, height, brush=brushes[0], pen=g.TRANSPARENT_PEN)
        item.setZValue(0)

        # fill plains, hills, mountains, tundra, swamp, desert with texture

        # go through each position
        paths = {}
        for t in range(1, 7):
            paths[t] = QtGui.QPainterPath()
        for column in range(0, columns):
            for row in range(0, rows):
                t = self.scenario.terrain_at(column, row)
                if t != 0:
                    # not for sea
                    sx, sy = self.scenario.scene_position(column, row)
                    paths[t].addRect(sx * self.TILE_SIZE, sy * self.TILE_SIZE, self.TILE_SIZE, self.TILE_SIZE)
        for t in paths:
            path = paths[t]
            path = path.simplified()
            item = self.scene.addPath(path, brush=brushes[t], pen=g.TRANSPARENT_PEN)
            item.setZValue(1)

        # fill the half tiles which are not part of the map
        brush = QtGui.QBrush(QtCore.Qt.darkGray)
        for row in range(0, rows):
            if row % 2 == 0:
                item = self.scene.addRect(columns * self.TILE_SIZE, row * self.TILE_SIZE, self.TILE_SIZE / 2,
                                          self.TILE_SIZE, pen=g.TRANSPARENT_PEN)
            else:
                item = self.scene.addRect(0, row * self.TILE_SIZE, self.TILE_SIZE / 2, self.TILE_SIZE,
                                          pen=g.TRANSPARENT_PEN)
            item.setBrush(brush)
            item.setZValue(1)

        # draw rivers
        river_pen = QtGui.QPen(QtGui.QColor(64, 64, 255))
        river_pen.setWidth(5)
        # TODO get rivers via a method (generator)
        for river in self.scenario._properties['rivers']:
            tiles = river['tiles']
            path = QtGui.QPainterPath()
            for tile in tiles:
                sx, sy = self.scenario.scene_position(tile[0], tile[1])
                x = (sx + 0.5) * self.TILE_SIZE
                y = (sy + 0.5) * self.TILE_SIZE
                if tile == tiles[0]:
                    path.moveTo(x, y)
                else:
                    path.lineTo(x, y)
            item = self.scene.addPath(path, pen=river_pen)
            item.setZValue(2)

        # draw province and nation borders
        # TODO the whole border drawing is a crude approximiation, implement it the right way
        province_border_pen = QtGui.QPen(QtGui.QColor(QtCore.Qt.black))
        province_border_pen.setWidth(2)
        nation_border_pen = QtGui.QPen()
        nation_border_pen.setWidth(4)
        for nation in self.scenario.all_nations():
            # get nation color
            color = self.scenario.get_nation_property(nation, 'color')
            nation_color = QtGui.QColor()
            nation_color.setNamedColor(color)
            # get all provinces
            provinces = self.scenario.get_provinces_of_nation(nation)
            nation_path = QtGui.QPainterPath()
            # get all tiles
            for province in provinces:
                province_path = QtGui.QPainterPath()
                tiles = self.scenario.get_province_property(province, 'tiles')
                for column, row in tiles:
                    sx, sy = self.scenario.scene_position(column, row)
                    province_path.addRect(sx * self.TILE_SIZE, sy * self.TILE_SIZE, self.TILE_SIZE, self.TILE_SIZE)
                province_path = province_path.simplified()
                item = self.scene.addPath(province_path, pen=province_border_pen)
                item.setZValue(4)
                nation_path.addPath(province_path)
            nation_path = nation_path.simplified()
            nation_border_pen.setColor(nation_color)
            item = self.scene.addPath(nation_path, pen=nation_border_pen)
            item.setZValue(5)

        # draw towns and names
        city_pixmap = QtGui.QPixmap(c.extend(c.Graphics_Map_Folder, 'city.png'))
        for nation in self.scenario.all_nations():
            # get all provinces of this nation
            provinces = self.scenario.get_provinces_of_nation(nation)
            for province in provinces:
                column, row = self.scenario.get_province_property(province, 'town_location')
                sx, sy = self.scenario.scene_position(column, row)
                # center city image on center of tile
                x = (sx + 0.5) * self.TILE_SIZE - city_pixmap.width() / 2
                y = (sy + 0.5) * self.TILE_SIZE - city_pixmap.height() / 2
                item = self.scene.addPixmap(city_pixmap)
                item.setOffset(x, y)
                item.setZValue(6)
                # display province name below
                province_name = self.scenario.get_province_property(province, 'name')
                item = self.scene.addSimpleText(province_name)
                item.setPen(g.TRANSPARENT_PEN)
                item.setBrush(QtGui.QBrush(QtCore.Qt.darkRed))
                x = (sx + 0.5) * self.TILE_SIZE - item.boundingRect().width() / 2
                y = (sy + 1) * self.TILE_SIZE - item.boundingRect().height()
                item.setPos(x, y)
                item.setZValue(6)
                # display rounded rectangle below province name
                bx = 8
                by = 4
                background = QtCore.QRectF(x - bx, y - by, item.boundingRect().width() + 2 * bx,
                                           item.boundingRect().height() + 2 * by)
                path = QtGui.QPainterPath()
                path.addRoundRect(background, 50, 50)
                item = self.scene.addPath(path, pen=g.TRANSPARENT_PEN,
                                          brush=QtGui.QBrush(QtGui.QColor(128, 128, 255, 64)))
                item.setZValue(5)

        # draw the grid and the coordinates
        for column in range(0, columns):
            for row in range(0, rows):
                sx, sy = self.scenario.scene_position(column, row)
                # item = self.scene.addRect(sx * self.tile_size, sy * self.tile_size,  self.tile_size,  self.tile_size)
                # item.setZValue(1000)
                text = '({},{})'.format(column, row)
                item = QtGui.QGraphicsSimpleTextItem(text)
                item.setBrush(QtGui.QBrush(QtCore.Qt.black))
                item.setPos((sx + 0.5) * self.TILE_SIZE - item.boundingRect().width() / 2, sy * self.TILE_SIZE)
                item.setZValue(1001)
                self.scene.addItem(item)
Example #11
0
"""
    Calculates the countour of nation maps
"""

from PySide import QtGui

from base import constants as c
from server.scenario import *

# load scenario

scenario = Scenario()
scenario.load(c.extend(c.Core_Scenario_Folder, 'Europe1814.scenario'))

# nation map
columns = scenario[MAP_COLUMNS]
rows = scenario[MAP_ROWS]
map = [0] * (columns * rows)
for nation in scenario.all_nations():
    provinces = scenario.get_provinces_of_nation(nation)
    for province in provinces:
        tiles = scenario.get_province_property(province, 'tiles')
        for column, row in tiles:
            map[row * columns + column] = nation

# get outlines
for nation in scenario.all_nations():
    visited = [False] * (columns * rows)
    for i in range(0, columns * rows):
        column = i % columns
        row = i // columns
Example #12
0
def load_ui_icon(name):
    """
        Load an icon from a base icon path.
    """
    file_name = c.extend(c.Graphics_UI_Folder, name)
    return QtGui.QIcon(file_name)
Example #13
0
def load_ui_icon(name):
    """
        Loads an icon from a base icon path.
    """
    file_name = constants.extend(constants.GRAPHICS_UI_FOLDER, name)
    return QtGui.QIcon(file_name)
"""
    Calculates the countour of nation maps
"""

from PyQt5 import QtGui

from base import constants as c
from server.scenario import *

# load scenario

scenario = Scenario()
scenario.load(c.extend(c.CORE_SCENARIO_FOLDER, 'Europe1814.scenario'))

# nation map
columns = scenario[MAP_COLUMNS]
rows = scenario[MAP_ROWS]
map = [0] * (columns * rows)
for nation in scenario.all_nations():
    provinces = scenario.get_provinces_of_nation(nation)
    for province in provinces:
        tiles = scenario.get_province_property(province, 'tiles')
        for column, row in tiles:
            map[row * columns + column] = nation

# get outlines
for nation in scenario.all_nations():
    visited = [False] * (columns * rows)
    for i in range(0, columns * rows):
        column = i % columns
        row = i // columns