Exemplo n.º 1
0
    def __init__(self, scenario):
        """
            Sets up the graphics view, the toolbar and the tracker rectangle.
        """
        super().__init__()
        self.setObjectName('minimap-widget')

        layout = QtWidgets.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)

        # the content is a scene
        self.scene = QtWidgets.QGraphicsScene()

        # tracker rectangle that tracks the view of the main map
        self.tracker = QtWidgets.QGraphicsRectItem()
        print(self.tracker.pen().widthF())
        self.tracker.setCursor(QtCore.Qt.PointingHandCursor)
        self.tracker.setZValue(1000)
        self.tracker.hide()
        self.scene.addItem(self.tracker)

        # the view on the scene (no scroll bars)
        self.view = QtWidgets.QGraphicsView(self.scene)
        self.view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        layout.addWidget(self.view)

        # the width and height (fixed width throughout the game)
        self.view.setFixedWidth(self.VIEW_WIDTH)
        view_height = math.floor(0.6 * self.VIEW_WIDTH)
        self.view.setFixedHeight(view_height)

        # tool bar below the mini map
        self.toolbar = QtWidgets.QToolBar()
        self.toolbar.setIconSize(QtCore.QSize(20, 20))

        # action group (only one of them can be checked at each time)
        action_group = QtWidgets.QActionGroup(self.toolbar)
        # political view in the beginning
        action_political = qt_graphics.create_action(tools.load_ui_icon('icon.mini.political.png'),
            'Show political view', action_group, toggle_connection=self.toggled_political, checkable=True)
        self.toolbar.addAction(action_political)
        # geographical view
        self.toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.mini.geographical.png'), 'Show geographical view',
                action_group, toggle_connection=self.toggled_geographical, checkable=True))

        # wrap tool bar into horizontal layout with stretch
        l = QtWidgets.QHBoxLayout()
        l.setContentsMargins(0, 0, 0, 0)
        l.addWidget(self.toolbar)
        l.addStretch()

        # add layout containing tool bar
        layout.addLayout(l)

        # store scenario
        self.scenario = scenario
        self.removable_items = []
Exemplo n.º 2
0
    def __init__(self):
        """
            Create and add all tabs
        """
        super().__init__()

        toolbar = QtWidgets.QToolBar()
        toolbar.setIconSize(QtCore.QSize(32, 32))
        action_group = QtWidgets.QActionGroup(toolbar)

        action_preferences_general = qt_graphics.create_action(tools.load_ui_icon('icon.preferences.general.png'),
            'Show general preferences', action_group, toggle_connection=self._toggled_action_preferences_general, checkable=True)
        toolbar.addAction(action_preferences_general)

        toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.preferences.network.png'), 'Show network preferences',
                action_group, toggle_connection=self._toggled_action_preferences_network, checkable=True))
        toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.preferences.graphics.png'), 'Show graphics preferences',
                action_group, toggle_connection=self._toggled_action_preferences_graphics, checkable=True))
        toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.preferences.music.png'), 'Show music preferences',
                action_group, toggle_connection=self._toggled_action_preferences_music, checkable=True))

        self.stacked_layout = QtWidgets.QStackedLayout()

        layout = QtWidgets.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(toolbar)
        layout.addLayout(self.stacked_layout)

        # empty lists
        self._check_boxes = []
        self._line_edits = []
        self._sliders = []

        # add tabs
        self._layout_widget_preferences_general()
        self._layout_widget_preferences_graphics()
        self._layout_widget_preferences_music()
        self._layout_widget_preferences_network()

        # show general preferences
        action_preferences_general.setChecked(True)
Exemplo n.º 3
0
    def __init__(self):
        """
            Sets up all the input elements of the create new scenario dialog.
        """
        super().__init__()

        self.parameters = {}
        widget_layout = QtWidgets.QVBoxLayout(self)

        # title box
        box = QtWidgets.QGroupBox('Title')
        layout = QtWidgets.QVBoxLayout(box)
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(300)
        edit.setPlaceholderText('Unnamed')
        self.parameters[constants.ScenarioProperties.SCENARIO_TITLE] = edit
        layout.addWidget(edit)
        widget_layout.addWidget(box)

        # map size
        box = QtWidgets.QGroupBox('Map size')
        layout = QtWidgets.QHBoxLayout(box)

        layout.addWidget(QtWidgets.QLabel('Width'))
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(50)
        edit.setValidator(QtGui.QIntValidator(1, 1000))
        edit.setPlaceholderText('100')
        self.parameters[constants.ScenarioProperties.MAP_COLUMNS] = edit
        layout.addWidget(edit)

        layout.addWidget(QtWidgets.QLabel('Height'))
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(50)
        edit.setValidator(QtGui.QIntValidator(1, 1000))
        edit.setPlaceholderText('60')
        self.parameters[constants.ScenarioProperties.MAP_ROWS] = edit
        layout.addWidget(edit)
        layout.addStretch()

        widget_layout.addWidget(box)

        # vertical stretch
        widget_layout.addStretch()

        # add the button
        layout = QtWidgets.QHBoxLayout()
        toolbar = QtWidgets.QToolBar()
        toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.confirm.png'), 'Create new scenario', toolbar,
                self.create_scenario_clicked))
        layout.addStretch()
        layout.addWidget(toolbar)
        widget_layout.addLayout(layout)
Exemplo n.º 4
0
    def create_toolbar(self):
        """
            Setup toolbar at the bottom.
        """
        layout = QtWidgets.QHBoxLayout()

        toolbar = QtWidgets.QToolBar()
        toolbar.setIconSize(QtCore.QSize(20, 20))
        toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.editor.info.terrain.png'), 'Change terrain type', self,
                self.change_terrain))

        layout.addWidget(toolbar)
        layout.addStretch()

        return layout
Exemplo n.º 5
0
    def __init__(self, client):
        """
            Create and setup all the elements.
        """
        super().__init__()

        self.client = client

        # scenario
        self.scenario = None

        self.toolbar = QtWidgets.QToolBar()
        self.toolbar.setIconSize(QtCore.QSize(32, 32))
        self.toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.scenario.new.png'), 'Create new scenario', self,
                self.show_new_scenario_dialog))
        self.toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.scenario.load.png'), 'Load scenario', self,
                self.load_scenario_dialog))
        self.toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.scenario.save.png'), 'Save scenario', self,
                self.save_scenario_dialog))

        self.toolbar.addSeparator()
        self.toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.editor.general.png'), 'Edit base properties', self,
                self.show_general_properties_dialog))
        self.toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.editor.nations.png'), 'Edit nations', self,
                self.show_nations_dialog))
        self.toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.editor.provinces.png'), 'Edit provinces', self,
                self.show_provinces_dialog))

        spacer = QtWidgets.QWidget()
        spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        self.toolbar.addWidget(spacer)

        clock = qt_graphics.ClockLabel()
        self.toolbar.addWidget(clock)

        action_help = QtWidgets.QAction(tools.load_ui_icon('icon.help.png'), 'Show help', self)
        action_help.triggered.connect(client.show_help_browser)  # TODO with partial make reference to specific page
        self.toolbar.addAction(action_help)

        action_quit = QtWidgets.QAction(tools.load_ui_icon('icon.back.startscreen.png'), 'Exit to main menu', self)
        action_quit.triggered.connect(client.switch_to_start_screen)
        # TODO ask if something is changed we should save.. (you might loose progress)
        self.toolbar.addAction(action_quit)

        # info box
        self.info_box = InfoBox(self.scenario)

        # the main map
        self.map = EditorMainMap(self.scenario)
        self.map.tile_at_focus_changed.connect(self.info_box.update_tile_information)

        # the mini map
        self.mini_map = MiniMap(self.scenario)
        self.mini_map.roi_changed.connect(self.map.set_position)

        layout = QtWidgets.QGridLayout(self)
        layout.addWidget(self.toolbar, 0, 0, 1, 2)
        layout.addWidget(self.mini_map, 1, 0)
        layout.addWidget(self.info_box, 2, 0)
        layout.addWidget(self.map, 1, 1, 2, 1)
        layout.setRowStretch(2, 1)  # the info box will take all vertical space left
        layout.setColumnStretch(1, 1)  # the map will take all horizontal space left
Exemplo n.º 6
0
    def _layout_widget_preferences_network(self):
        """
            Create network options widget.
        """
        tab = QtWidgets.QWidget()
        tab_layout = QtWidgets.QVBoxLayout(tab)

        # status label
        self.network_status_label = QtWidgets.QLabel('')
        tab_layout.addWidget(self.network_status_label)

        # remote server groupbox
        l = QtWidgets.QVBoxLayout()
        # remote server address
        l2 = QtWidgets.QHBoxLayout()
        l2.addWidget(QtWidgets.QLabel('Remote IP address'))
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(300)
        l2.addWidget(edit)
        l2.addStretch()
        l.addLayout(l2)
        # actions toolbar
        l2 = QtWidgets.QHBoxLayout()
        toolbar = QtWidgets.QToolBar()
        toolbar.setIconSize(QtCore.QSize(24, 24))
        # connect to remote server
        toolbar.addAction(qt_graphics.create_action(tools.load_ui_icon('icon.preferences.network.png'),
            'Connect/Disconnect to remote server', toolbar, checkable=True))
        l2.addWidget(toolbar)
        l2.addStretch()
        l.addLayout(l2)
        tab_layout.addWidget(qt_graphics.wrap_in_groupbox(l, 'Remote Server'))

        # local server group box
        l = QtWidgets.QVBoxLayout()
        # accepts incoming connections checkbox
        checkbox = QtWidgets.QCheckBox('Accepts incoming connections')
        self._register_check_box(checkbox, constants.Opt.LS_OPEN)
        l.addWidget(checkbox)
        # alias name edit box
        l2 = QtWidgets.QHBoxLayout()
        l2.addWidget(QtWidgets.QLabel('Alias'))
        edit = QtWidgets.QLineEdit()
        edit.setFixedWidth(300)
        l2.addWidget(edit)
        l2.addStretch()
        self._register_line_edit(edit, constants.Opt.LS_NAME)
        l.addLayout(l2)
        # actions toolbar
        l2 = QtWidgets.QHBoxLayout()
        toolbar = QtWidgets.QToolBar()
        toolbar.setIconSize(QtCore.QSize(24, 24))
        # show local server monitor
        toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.preferences.network.png'), 'Show local server monitor',
                toolbar))
        # local server is on/off
        toolbar.addAction(
            qt_graphics.create_action(tools.load_ui_icon('icon.preferences.network.png'), 'Turn local server on/off',
                toolbar, checkable=True))
        l2.addWidget(toolbar)
        l2.addStretch()
        l.addLayout(l2)
        tab_layout.addWidget(qt_graphics.wrap_in_groupbox(l, 'Local Server'))

        # vertical stretch
        tab_layout.addStretch()

        # add tab
        self.tab_network = tab
        self.stacked_layout.addWidget(tab)