示例#1
0
 def addModule(self, x, y, itemID):
     """Add a module from the market browser (from dragging it)"""
     fitID = self.mainFrame.getActiveFit()
     item = Market.getInstance().getItem(itemID)
     fit = Fit.getInstance().getFit(fitID)
     dstRow, _ = self.HitTest((x, y))
     if dstRow == -1 or dstRow in self.blanks:
         dstMod = None
     else:
         try:
             dstMod = self.mods[dstRow]
         except IndexError:
             dstMod = None
         if not isinstance(dstMod, Module):
             dstMod = None
         if dstMod not in fit.modules:
             dstMod = None
     dstPos = fit.modules.index(dstMod) if dstMod is not None else None
     mstate = wx.GetMouseState()
     # If we dropping on a module, try to replace, or add if replacement fails
     if item.isModule and dstMod is not None and not dstMod.isEmpty:
         positions = getSimilarModPositions(fit.modules, dstMod) if mstate.GetModifiers() == wx.MOD_ALT else [dstPos]
         command = cmd.GuiReplaceLocalModuleCommand(fitID=fitID, itemID=itemID, positions=positions)
         if not self.mainFrame.command.Submit(command):
             if mstate.GetModifiers() == wx.MOD_ALT:
                 self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID))
             else:
                 self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID))
     elif item.isModule:
         if mstate.GetModifiers() == wx.MOD_ALT:
             self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID))
         elif dstPos is not None:
             self.mainFrame.command.Submit(cmd.GuiReplaceLocalModuleCommand(fitID=fitID, itemID=itemID, positions=[dstPos]))
         else:
             self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID))
     elif item.isSubsystem:
         self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID))
     elif item.isCharge:
         failoverToAll = False
         positionsAll = list(range(len(fit.modules)))
         if dstMod is None or dstMod.isEmpty:
             positions = positionsAll
         elif mstate.GetModifiers() == wx.MOD_ALT:
             positions = getSimilarModPositions(fit.modules, dstMod)
             failoverToAll = True
         else:
             positions = [fit.modules.index(dstMod)]
         if len(positions) > 0:
             command = cmd.GuiChangeLocalModuleChargesCommand(fitID=fitID, positions=positions, chargeItemID=itemID)
             if not self.mainFrame.command.Submit(command) and failoverToAll:
                 self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleChargesCommand(
                     fitID=fitID, positions=positionsAll, chargeItemID=itemID))
示例#2
0
    def handleAmmoSwitch(self, event):
        charge = self.chargeIds.get(event.Id, False)
        if charge is False:
            event.Skip()
            return

        fitID = self.mainFrame.getActiveFit()
        sFit = Fit.getInstance()
        switchAll = sFit.serviceFittingOptions[
            'ammoChangeAll'] is not wx.GetMouseState().CmdDown()
        # Switch in selection or all modules, depending on ctrl key state and settings
        if switchAll:
            fit = sFit.getFit(fitID)
            selectedModule = self.modules[0]
            if self.context == 'fittingModule':
                self.mainFrame.command.Submit(
                    cmd.GuiChangeLocalModuleChargesCommand(
                        fitID=fitID,
                        modules=[
                            m for m in fit.modules if m.itemID is not None
                            and m.itemID == selectedModule.itemID
                        ],
                        chargeItemID=charge.ID
                        if charge is not None else None))
            elif self.context == 'projectedModule':
                self.mainFrame.command.Submit(
                    cmd.GuiChangeProjectedModuleChargesCommand(
                        fitID=fitID,
                        modules=[
                            m for m in fit.projectedModules
                            if m.itemID is not None
                            and m.itemID == selectedModule.itemID
                        ],
                        chargeItemID=charge.ID
                        if charge is not None else None))
        else:
            if self.context == 'fittingModule':
                self.mainFrame.command.Submit(
                    cmd.GuiChangeLocalModuleChargesCommand(
                        fitID=fitID,
                        modules=self.modules,
                        chargeItemID=charge.ID
                        if charge is not None else None))
            elif self.context == 'projectedModule':
                self.mainFrame.command.Submit(
                    cmd.GuiChangeProjectedModuleChargesCommand(
                        fitID=fitID,
                        modules=self.modules,
                        chargeItemID=charge.ID
                        if charge is not None else None))
示例#3
0
    def appendItem(self, event):
        """
        Adds items that are double clicks from the market browser. We handle both modules and ammo
        """
        if not self:
            event.Skip()
            return
        if self.parent.IsActive(self):
            itemID = event.itemID
            fitID = self.activeFitID
            if fitID is not None:
                item = Market.getInstance().getItem(itemID, eager='group.category')
                if item is None or not (item.isModule or item.isSubsystem):
                    event.Skip()
                    return
                if item.isCharge:
                    # If we've selected ammo, then apply to the selected module(s)
                    modules = []
                    sel = self.GetFirstSelected()
                    while sel != -1 and sel not in self.blanks:
                        mod = self.mods[self.GetItemData(sel)]
                        if isinstance(mod, Module) and not mod.isEmpty:
                            modules.append(self.mods[self.GetItemData(sel)])
                        sel = self.GetNextSelected(sel)

                    if len(modules) > 0:
                        self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleChargesCommand(fitID, modules, itemID))
                else:
                    self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID, itemID))

        event.Skip()
示例#4
0
    def appendItem(self, event):
        """
        Adds items that are double clicks from the market browser. We handle both modules and ammo
        """
        if not self:
            event.Skip()
            return
        if self.parent.IsActive(self):
            itemID = event.itemID
            fitID = self.activeFitID
            if fitID is not None:
                item = Market.getInstance().getItem(itemID,
                                                    eager='group.category')
                if item is None:
                    event.Skip()
                    return
                batchOp = wx.GetMouseState().altDown and getattr(
                    event, 'allowBatch', None) is not False
                # If we've selected ammo, then apply to the selected module(s)
                if item.isCharge:
                    positions = []
                    fit = Fit.getInstance().getFit(fitID)
                    if batchOp:
                        for position, mod in enumerate(fit.modules):
                            if isinstance(mod, Module) and not mod.isEmpty:
                                positions.append(position)
                    else:
                        sel = self.GetFirstSelected()
                        while sel != -1 and sel not in self.blanks:
                            try:
                                mod = self.mods[self.GetItemData(sel)]
                            except IndexError:
                                sel = self.GetNextSelected(sel)
                                continue
                            if isinstance(
                                    mod, Module
                            ) and not mod.isEmpty and mod in fit.modules:
                                positions.append(fit.modules.index(mod))
                            sel = self.GetNextSelected(sel)

                    if len(positions) > 0:
                        self.mainFrame.command.Submit(
                            cmd.GuiChangeLocalModuleChargesCommand(
                                fitID=fitID,
                                positions=positions,
                                chargeItemID=itemID))
                elif (item.isModule and not batchOp) or item.isSubsystem:
                    self.mainFrame.command.Submit(
                        cmd.GuiAddLocalModuleCommand(fitID=fitID,
                                                     itemID=itemID))
                elif item.isModule and batchOp:
                    self.mainFrame.command.Submit(
                        cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID,
                                                              itemID=itemID))

        event.Skip()
示例#5
0
    def activate(self, fullContext, selection, i):

        srcContext = fullContext[0]
        sFit = Fit.getInstance()
        fitID = self.mainFrame.getActiveFit()
        fit = sFit.getFit(fitID)

        if srcContext == "fittingModule":
            self.mainFrame.command.Submit(
                cmd.GuiRemoveLocalModuleCommand(fitID=fitID,
                                                modules=[
                                                    module
                                                    for module in selection
                                                    if module is not None
                                                ]))
        elif srcContext == "fittingCharge":
            self.mainFrame.command.Submit(
                cmd.GuiChangeLocalModuleChargesCommand(fitID=fitID,
                                                       modules=selection,
                                                       chargeItemID=None))
        elif srcContext == "droneItem":
            self.mainFrame.command.Submit(
                cmd.GuiRemoveLocalDroneCommand(fitID=fitID,
                                               position=fit.drones.index(
                                                   selection[0]),
                                               amount=math.inf))
        elif srcContext == "fighterItem":
            self.mainFrame.command.Submit(
                cmd.GuiRemoveLocalFighterCommand(fitID=fitID,
                                                 position=fit.fighters.index(
                                                     selection[0])))
        elif srcContext == "implantItem":
            self.mainFrame.command.Submit(
                cmd.GuiRemoveImplantCommand(fitID=fitID,
                                            position=fit.implants.index(
                                                selection[0])))
        elif srcContext == "boosterItem":
            self.mainFrame.command.Submit(
                cmd.GuiRemoveBoosterCommand(fitID=fitID,
                                            position=fit.boosters.index(
                                                selection[0])))
        elif srcContext == "cargoItem":
            self.mainFrame.command.Submit(
                cmd.GuiRemoveCargoCommand(fitID=fitID,
                                          itemID=selection[0].itemID))
        elif srcContext == "projectedFit":
            self.mainFrame.command.Submit(
                cmd.GuiRemoveProjectedFitCommand(
                    fitID=fitID, projectedFitID=selection[0].ID))
        elif srcContext == "projectedModule":
            self.mainFrame.command.Submit(
                cmd.GuiRemoveProjectedModuleCommand(
                    fitID=fitID,
                    position=fit.projectedModules.index(selection[0])))
        elif srcContext == "projectedDrone":
            self.mainFrame.command.Submit(
                cmd.GuiRemoveProjectedDroneCommand(fitID=fitID,
                                                   itemID=selection[0].itemID,
                                                   amount=math.inf))
        elif srcContext == "projectedFighter":
            self.mainFrame.command.Submit(
                cmd.GuiRemoveProjectedFighterCommand(
                    fitID=fitID,
                    position=fit.projectedFighters.index(selection[0])))
        elif srcContext == "commandFit":
            self.mainFrame.command.Submit(
                cmd.GuiRemoveCommandFitCommand(fitID=fitID,
                                               commandFitID=selection[0].ID))