Exemple #1
0
    def __init__(self, tile_data, view, window=None):
        super(TerrainMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.tile_data = tile_data
        self.window = window

        self.view = view

        self.alpha_slider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.alpha_slider.setRange(0, 255)
        self.alpha_slider.setValue(192)
        self.grid.addWidget(QtGui.QLabel("Transparency"), 0, 0)
        self.grid.addWidget(self.alpha_slider, 0, 1)

        self.list = SignalList(self)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True
        self.list.setIconSize(QtCore.QSize(32, 32))

        # Ingest terrain_data
        for color, terrain in Data.terrain_data.items():
            tid, name = terrain
            pixmap = QtGui.QPixmap(32, 32)
            pixmap.fill(QtGui.QColor(color[0], color[1], color[2]))

            item = QtGui.QListWidgetItem(tid + ': ' + name)
            item.setIcon(QtGui.QIcon(pixmap))
            self.list.addItem(item)

        self.grid.addWidget(self.list, 1, 0, 1, 2)

        self.mouse_down = False
        self.undo_stack = []
    def __init__(self, unit_data, view, window):
        super(UnitMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.window = window
        self.view = view

        self.create_mode_view_box()

        self.list = SignalList(self, del_func=self.remove_unit)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True
        self.list.setIconSize(QtCore.QSize(32, 32))
        self.delegate = ItemDelegate(unit_data)
        self.list.setItemDelegate(self.delegate)

        self.load(unit_data)
        self.list.currentItemChanged.connect(self.center_on_unit)
        self.list.itemDoubleClicked.connect(self.modify_unit)
        # delete_key = QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Delete), self.list)
        # self.connect(delete_key, QtCore.SIGNAL('activated()'), self.remove_unit)

        self.load_unit_button = QtGui.QPushButton('Load Unit')
        self.load_unit_button.clicked.connect(self.load_unit)
        self.create_unit_button = QtGui.QPushButton('Create Unit')
        self.create_unit_button.clicked.connect(self.create_unit)
        self.remove_unit_button = QtGui.QPushButton('Remove Unit')
        self.remove_unit_button.clicked.connect(self.remove_unit)

        self.grid.addWidget(self.list, 2, 0)
        self.grid.addWidget(self.load_unit_button, 3, 0)
        self.grid.addWidget(self.create_unit_button, 4, 0)
        self.grid.addWidget(self.remove_unit_button, 5, 0)

        self.last_touched_generic = None
Exemple #3
0
    def __init__(self, unit_data, view, window=None):
        super(FactionMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.window = window
        self.view = view

        self.load_player_characters = QtGui.QCheckBox(
            'Load saved player characters?')
        self.load_player_characters.stateChanged.connect(
            self.set_load_player_characters)

        self.list = SignalList(self, del_func=self.remove_faction)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True
        self.list.setIconSize(QtCore.QSize(32, 32))

        self.unit_data = unit_data
        self.load(unit_data)

        self.list.itemDoubleClicked.connect(self.modify_faction)

        self.add_faction_button = QtGui.QPushButton('Add Faction')
        self.add_faction_button.clicked.connect(self.add_faction)
        self.remove_faction_button = QtGui.QPushButton('Remove Faction')
        self.remove_faction_button.clicked.connect(self.remove_faction)

        self.grid.addWidget(self.load_player_characters, 0, 0)
        self.grid.addWidget(self.list, 1, 0)
        self.grid.addWidget(self.add_faction_button, 2, 0)
        self.grid.addWidget(self.remove_faction_button, 3, 0)
Exemple #4
0
    def __init__(self, unit_data, view, window=None):
        super(TriggerMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.window = window
        self.view = view

        self.list = SignalList(self, del_func=self.remove_trigger)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True

        self.unit_data = unit_data
        self.load(unit_data)

        self.arrow = None

        self.add_trigger_button = QtGui.QPushButton('Add Trigger')
        self.add_trigger_button.clicked.connect(self.add_trigger)
        self.remove_trigger_button = QtGui.QPushButton('Remove Trigger')
        self.remove_trigger_button.clicked.connect(self.remove_trigger)

        self.grid.addWidget(self.list, 0, 0)
        self.grid.addWidget(self.add_trigger_button, 1, 0)
        self.grid.addWidget(self.remove_trigger_button, 2, 0)
Exemple #5
0
    def __init__(self, terrain_data, view, window=None):
        super(TerrainMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.window = window

        self.view = view

        self.list = SignalList(self)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True
        self.list.setIconSize(QtCore.QSize(32, 32))

        # Ingest terrain_data
        for color, terrain in Data.terrain_data.iteritems():
            tid, name = terrain
            pixmap = QtGui.QPixmap(32, 32)
            pixmap.fill(QtGui.QColor(color[0], color[1], color[2]))

            item = QtGui.QListWidgetItem(tid + ': ' + name)
            item.setIcon(QtGui.QIcon(pixmap))
            self.list.addItem(item)

        self.grid.addWidget(self.list, 0, 0)
Exemple #6
0
class TerrainMenu(QtGui.QWidget):
    def __init__(self, terrain_data, view, window=None):
        super(TerrainMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.window = window

        self.view = view

        self.list = SignalList(self)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True
        self.list.setIconSize(QtCore.QSize(32, 32))

        # Ingest terrain_data
        for color, terrain in Data.terrain_data.iteritems():
            tid, name = terrain
            pixmap = QtGui.QPixmap(32, 32)
            pixmap.fill(QtGui.QColor(color[0], color[1], color[2]))

            item = QtGui.QListWidgetItem(tid + ': ' + name)
            item.setIcon(QtGui.QIcon(pixmap))
            self.list.addItem(item)

        self.grid.addWidget(self.list, 0, 0)

    def get_current_color(self):
        color = Data.terrain_data.keys()[self.list.currentRow()]
        print(color)
        return color

    def set_current_color(self, color):
        idx = Data.terrain_data.keys().index(color)
        self.list.setCurrentRow(idx)

    def get_info(self, color):
        return Data.terrain_data[color]

    def get_info_str(self, color):
        tid, name = Data.terrain_data[color]
        return str(tid) + " - " + str(name)
Exemple #7
0
    def __init__(self, view, window=None):
        super(TileInfoMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.window = window

        self.view = view

        self.list = SignalList(self)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True
        self.list.setIconSize(QtCore.QSize(32, 32))

        # Ingest Data
        self.info = sorted(kinds.values(), key=lambda x: x.num)
        for info in self.info:
            image = Engine.transform_scale(info.image, (32, 32))
            pixmap = EditorUtilities.create_pixmap(image)

            item = QtGui.QListWidgetItem(info.name)
            item.setIcon(QtGui.QIcon(pixmap))
            self.list.addItem(item)

        self.grid.addWidget(self.list, 0, 0)
Exemple #8
0
class TriggerMenu(QtGui.QWidget):
    def __init__(self, unit_data, view, window=None):
        super(TriggerMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.window = window
        self.view = view

        self.list = SignalList(self, del_func=self.remove_trigger)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True

        self.unit_data = unit_data
        self.load(unit_data)

        self.arrow = None

        self.add_trigger_button = QtGui.QPushButton('Add Trigger')
        self.add_trigger_button.clicked.connect(self.add_trigger)
        self.remove_trigger_button = QtGui.QPushButton('Remove Trigger')
        self.remove_trigger_button.clicked.connect(self.remove_trigger)

        self.grid.addWidget(self.list, 0, 0)
        self.grid.addWidget(self.add_trigger_button, 1, 0)
        self.grid.addWidget(self.remove_trigger_button, 2, 0)

    def add_trigger(self):
        trigger, ok = QtGui.QInputDialog.getText(
            self, "New Trigger", 'Enter name of new move trigger:')
        if ok:
            item = QtGui.QListWidgetItem(trigger)
            self.list.addItem(item)
            self.unit_data.add_trigger(trigger)
            self.list.scrollToBottom()
            self.list.setCurrentItem(item)

    def remove_trigger(self):
        idx = self.list.currentRow()
        self.list.takeItem(idx)
        self.unit_data.remove_trigger(idx)

    def get_current_trigger(self):
        if self.unit_data.triggers:
            return self.unit_data.get_trigger(self.list.currentRow())
        return None

    def get_current_trigger_name(self):
        if self.unit_data.triggers:
            return self.unit_data.get_trigger_name(self.list.currentRow())

    def get_current_arrow(self):
        return self.arrow

    def set_current_arrow(self, unit, pos):
        self.arrow = unit, pos

    def clear_current_arrow(self):
        self.arrow = None

    def load(self, unit_data):
        self.clear()
        self.unit_data = unit_data
        # Ingest Data
        for trigger_name in self.unit_data.triggers:
            item = QtGui.QListWidgetItem(trigger_name)
            self.list.addItem(item)

    def clear(self):
        self.list.clear()
        self.clear_current_arrow()
Exemple #9
0
class TerrainMenu(QtGui.QWidget):
    def __init__(self, tile_data, view, window=None):
        super(TerrainMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.tile_data = tile_data
        self.window = window

        self.view = view

        self.alpha_slider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.alpha_slider.setRange(0, 255)
        self.alpha_slider.setValue(192)
        self.grid.addWidget(QtGui.QLabel("Transparency"), 0, 0)
        self.grid.addWidget(self.alpha_slider, 0, 1)

        self.list = SignalList(self)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True
        self.list.setIconSize(QtCore.QSize(32, 32))

        # Ingest terrain_data
        for color, terrain in Data.terrain_data.items():
            tid, name = terrain
            pixmap = QtGui.QPixmap(32, 32)
            pixmap.fill(QtGui.QColor(color[0], color[1], color[2]))

            item = QtGui.QListWidgetItem(tid + ': ' + name)
            item.setIcon(QtGui.QIcon(pixmap))
            self.list.addItem(item)

        self.grid.addWidget(self.list, 1, 0, 1, 2)

        self.mouse_down = False
        self.undo_stack = []

    def get_current_color(self):
        color = list(Data.terrain_data.keys())[self.list.currentRow()]
        return color

    def set_current_color(self, color):
        idx = list(Data.terrain_data.keys()).index(color)
        self.list.setCurrentRow(idx)

    def get_info(self, color):
        return Data.terrain_data[color]

    def get_info_str(self, color):
        tid, name = Data.terrain_data[color]
        return str(tid) + " - " + str(name)

    def get_alpha(self):
        return int(self.alpha_slider.value())

    def undo(self):
        if not self.undo_stack:
            return
        last_actions = self.undo_stack.pop()
        for action in last_actions:
            pos, old_color, new_color = action
            self.tile_data.tiles[pos] = old_color
        self.window.update_view()

    def paint(self, pos):
        if not self.mouse_down:  # First pick
            self.undo_stack.append([])
        self.mouse_down = True
        old_color = self.tile_data.tiles[pos]
        new_color = self.get_current_color()
        self.tile_data.tiles[pos] = new_color
        if old_color != new_color:  # Required since updating view each frame is EXPENSIVE!
            self.undo_stack[-1].append((pos, old_color, new_color))
            self.window.update_view()

    def mouse_release(self):
        self.mouse_down = False
class UnitMenu(QtGui.QWidget):
    def __init__(self, unit_data, view, window):
        super(UnitMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.window = window
        self.view = view

        self.create_mode_view_box()

        self.list = SignalList(self, del_func=self.remove_unit)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True
        self.list.setIconSize(QtCore.QSize(32, 32))
        self.delegate = ItemDelegate(unit_data)
        self.list.setItemDelegate(self.delegate)

        self.load(unit_data)
        self.list.currentItemChanged.connect(self.center_on_unit)
        self.list.itemDoubleClicked.connect(self.modify_unit)
        # delete_key = QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Delete), self.list)
        # self.connect(delete_key, QtCore.SIGNAL('activated()'), self.remove_unit)

        self.load_unit_button = QtGui.QPushButton('Load Unit')
        self.load_unit_button.clicked.connect(self.load_unit)
        self.create_unit_button = QtGui.QPushButton('Create Unit')
        self.create_unit_button.clicked.connect(self.create_unit)
        self.remove_unit_button = QtGui.QPushButton('Remove Unit')
        self.remove_unit_button.clicked.connect(self.remove_unit)

        self.grid.addWidget(self.list, 2, 0)
        self.grid.addWidget(self.load_unit_button, 3, 0)
        self.grid.addWidget(self.create_unit_button, 4, 0)
        self.grid.addWidget(self.remove_unit_button, 5, 0)

        self.last_touched_generic = None

    # def trigger(self):
    #     self.view.tool = 'Units'

    def create_mode_view_box(self):
        self.mode_view_label = QtGui.QLabel("Current Mode:")
        names = [mode['name'] for mode in GC.DIFFICULTYDATA.values()]
        self.mode_view_combobox = QtGui.QComboBox()
        for name in names:
            self.mode_view_combobox.addItem(name)

        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.mode_view_label)
        hbox.addWidget(self.mode_view_combobox)
        self.grid.addLayout(hbox, 0, 0)

    def current_mode_view(self):
        return str(self.mode_view_combobox.currentText())

    def get_current_item(self):
        return self.list.item(self.list.currentRow())

    def get_current_unit(self):
        if self.unit_data.units:
            return self.unit_data.units[self.list.currentRow()]
        else:
            return None

    def get_item_from_unit(self, unit):
        return self.list.item(self.unit_data.units.index(unit))

    def set_current_idx(self, idx):
        self.list.setCurrentRow(idx)

    def center_on_unit(self, item, prev):
        idx = self.list.row(item)
        # idx = int(idx)
        unit = self.unit_data.units[idx]
        if unit.position:
            current_mode = str(self.mode_view_combobox.currentText())
            if current_mode not in unit.mode:
                EditorUtilities.setComboBox(self.mode_view_combobox,
                                            unit.mode[0])
            self.view.center_on_pos(unit.position)

    def load(self, unit_data):
        self.clear()
        self.unit_data = unit_data
        # Ingest Data
        for unit in self.unit_data.units:
            self.list.addItem(self.create_item(unit))

    def clear(self):
        self.list.clear()

    def create_item(self, unit):
        if unit.generic:
            item = QtGui.QListWidgetItem(
                str(unit.klass) + ': L' + str(unit.level))
        else:
            item = QtGui.QListWidgetItem(unit.name)
        klass = Data.class_data.get(unit.klass)
        if klass:
            item.setIcon(
                EditorUtilities.create_icon(
                    klass.get_image(unit.team, unit.gender)))
        if not unit.position:
            item.setTextColor(QtGui.QColor("red"))
        return item

    def load_unit(self):
        loaded_unit, ok = UnitDialogs.LoadUnitDialog.getUnit(
            self, "Load Unit", "Select unit:")
        if ok:
            self.unit_data.add_unit(loaded_unit)
            self.add_unit(loaded_unit)
            self.window.update_view()

    def create_unit(self):
        if self.unit_data.factions:
            unit = self.get_current_unit()
            if unit and not unit.generic:
                unit = self.last_touched_generic
            created_unit, ok = UnitDialogs.CreateUnitDialog.getUnit(
                self, "Create Unit", "Enter values for unit:", unit)
            if ok:
                self.unit_data.add_unit(created_unit)
                self.add_unit(created_unit)
                self.last_touched_generic = created_unit
                self.window.update_view()
        else:
            # Show pop-up
            QtGui.QMessageBox.critical(
                self, "No Faction!",
                "Must create at least one faction to create a generic unit!")

    def remove_unit(self):
        unit_idx = self.list.currentRow()
        self.list.takeItem(unit_idx)
        self.unit_data.remove_unit_from_idx(unit_idx)
        self.window.update_view()

    def modify_unit(self, item):
        idx = self.list.row(item)
        unit = self.unit_data.units[idx]
        if unit.generic:
            modified_unit, ok = UnitDialogs.CreateUnitDialog.getUnit(
                self, "Create Unit", "Enter values for unit:", unit)
        else:
            modified_unit, ok = UnitDialogs.LoadUnitDialog.getUnit(
                self, "Load Unit", "Select unit:", unit)
        if ok:
            modified_unit.position = unit.position
            # Replace unit
            self.list.takeItem(idx)
            self.list.insertItem(idx, self.create_item(modified_unit))
            self.unit_data.replace_unit(idx, modified_unit)
            if modified_unit.generic:
                self.last_touched_generic = modified_unit
            self.window.update_view()

    def add_unit(self, unit):
        self.list.addItem(self.create_item(unit))
        self.list.setCurrentRow(self.list.count() - 1)

    def tick(self, current_time):
        if GC.PASSIVESPRITECOUNTER.update(current_time):
            for idx, unit in enumerate(self.unit_data.units):
                if unit.klass in Data.class_data:
                    klass = Data.class_data[unit.klass]
                else:
                    klass = Data.class_data['Citizen']
                klass_image = klass.get_image(unit.team, unit.gender)
                self.list.item(idx).setIcon(
                    EditorUtilities.create_icon(klass_image))
                unit.klass_image = klass_image
Exemple #11
0
class FactionMenu(QtGui.QWidget):
    def __init__(self, unit_data, view, window=None):
        super(FactionMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.window = window
        self.view = view

        self.load_player_characters = QtGui.QCheckBox(
            'Load saved player characters?')
        self.load_player_characters.stateChanged.connect(
            self.set_load_player_characters)

        self.list = SignalList(self, del_func=self.remove_faction)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True
        self.list.setIconSize(QtCore.QSize(32, 32))

        self.unit_data = unit_data
        self.load(unit_data)

        self.list.itemDoubleClicked.connect(self.modify_faction)

        self.add_faction_button = QtGui.QPushButton('Add Faction')
        self.add_faction_button.clicked.connect(self.add_faction)
        self.remove_faction_button = QtGui.QPushButton('Remove Faction')
        self.remove_faction_button.clicked.connect(self.remove_faction)

        self.grid.addWidget(self.load_player_characters, 0, 0)
        self.grid.addWidget(self.list, 1, 0)
        self.grid.addWidget(self.add_faction_button, 2, 0)
        self.grid.addWidget(self.remove_faction_button, 3, 0)

    def create_item(self, faction):
        item = QtGui.QListWidgetItem(faction.faction_id)

        image = GC.UNITDICT.get(faction.faction_icon + 'Emblem')
        if image:
            image = image.convert_alpha()
            item.setIcon(EditorUtilities.create_icon(image))

        return item

    def add_faction(self):
        faction_obj, ok = FactionDialog.getFaction(
            self, "Factions", "Enter New Faction Values:")
        if ok:
            self.list.addItem(self.create_item(faction_obj))
            self.unit_data.factions[faction_obj.faction_id] = faction_obj

    def modify_faction(self, item):
        faction_obj, ok = FactionDialog.getFaction(self, "Factions",
                                                   "Modify Faction Values:",
                                                   self.get_current_faction())
        if ok:
            cur_row = self.list.currentRow()
            self.list.takeItem(cur_row)
            self.list.insertItem(cur_row, self.create_item(faction_obj))
            self.unit_data.factions[faction_obj.faction_id] = faction_obj

    def remove_faction(self):
        idx = self.list.currentRow()
        self.list.takeItem(idx)
        del self.unit_data.factions[self.unit_data.factions.key()[idx]]

    def set_load_player_characters(self, state):
        self.unit_data.load_player_characters = bool(state)

    def get_current_faction(self):
        return list(self.unit_data.factions.values())[self.list.currentRow()]

    def load(self, unit_data):
        self.clear()
        self.unit_data = unit_data
        # Ingest Data
        for faction in self.unit_data.factions.values():
            self.list.addItem(self.create_item(faction))
        self.load_player_characters.setChecked(
            self.unit_data.load_player_characters)

    def clear(self):
        self.list.clear()
        self.load_player_characters.setChecked(False)
Exemple #12
0
class TileInfoMenu(QtGui.QWidget):
    def __init__(self, view, window=None):
        super(TileInfoMenu, self).__init__(window)
        self.grid = QtGui.QGridLayout()
        self.setLayout(self.grid)
        self.window = window

        self.view = view

        self.list = SignalList(self)
        self.list.setMinimumSize(128, 320)
        self.list.uniformItemSizes = True
        self.list.setIconSize(QtCore.QSize(32, 32))

        # Ingest Data
        self.info = sorted(kinds.values(), key=lambda x: x.num)
        for info in self.info:
            image = Engine.transform_scale(info.image, (32, 32))
            pixmap = EditorUtilities.create_pixmap(image)

            item = QtGui.QListWidgetItem(info.name)
            item.setIcon(QtGui.QIcon(pixmap))
            self.list.addItem(item)

        self.grid.addWidget(self.list, 0, 0)

    # def trigger(self):
    #     self.view.tool = 'Tile Info'

    def start_dialog(self, tile_info_at_pos):
        kind = self.info[self.list.currentRow()].kind
        if kind == 'Status':
            current_statuses = tile_info_at_pos.get(
                'Status') if tile_info_at_pos else None
            current_statuses = current_statuses.split(
                ',') if current_statuses else None
            statuses, ok = ComboDialog.getItems(self, "Tile Status Effects",
                                                "Select Status:",
                                                Data.skill_data,
                                                current_statuses)
            if ok:
                return ','.join(statuses)
            else:
                return None
        elif kind == 'Item':
            current_shop = tile_info_at_pos.get(
                'Shop') if tile_info_at_pos else None
            current_shop = current_shop.split(',') if current_shop else None
            items, ok = ComboDialog.getItems(self, "Shop Items",
                                             "Select Items:", Data.item_data,
                                             current_shop)
            if ok:
                return ','.join(items)
            else:
                return None
        elif kind == 'string':
            text, ok = QtGui.QInputDialog.getText(self,
                                                  self.get_current_name(),
                                                  'Enter ID to use:')
            if ok:
                return text
            else:
                return None
        elif kind == 'int':
            text, ok = QtGui.QInputDialog.getInt(self, self.get_current_name(),
                                                 'Set Starting HP:', 10, 0)
            if ok:
                return text
            else:
                return None
        else:  # None
            return '0'

    def get_current_name(self):
        return self.info[self.list.currentRow()].name