diff --git a/eos/db/__init__.py b/eos/db/__init__.py index 113e3f09d..09a092c81 100755 --- a/eos/db/__init__.py +++ b/eos/db/__init__.py @@ -66,7 +66,7 @@ from eos.db.saveddata.queries import getUser, getCharacter, getFit, getFitsWithS getCharacterList, getPrice, getDamagePatternList, getDamagePattern, \ getFitList, getFleetList, getFleet, save, remove, commit, add, \ getCharactersForUser, getMiscData, getSquadsIDsWithFitID, getWing, \ - getSquad + getSquad, getBoosterFits #If using in memory saveddata, you'll want to reflect it so the data structure is good. if config.saveddata_connectionstring == "sqlite:///:memory:": diff --git a/eos/db/migration.py b/eos/db/migration.py index 9dafb52ac..1da35e129 100755 --- a/eos/db/migration.py +++ b/eos/db/migration.py @@ -3,7 +3,7 @@ import sqlalchemy def update(saveddata_engine): checkPriceFailures(saveddata_engine) checkApiDefaultChar(saveddata_engine) - + checkFitBooster(saveddata_engine) def checkPriceFailures(saveddata_engine): # Check if we have 'failed' column @@ -39,3 +39,22 @@ def checkApiDefaultChar(saveddata_engine): except sqlalchemy.exc.DatabaseError: saveddata_engine.execute("ALTER TABLE characters ADD COLUMN defaultChar INTEGER;") saveddata_engine.execute("ALTER TABLE characters ADD COLUMN chars VARCHAR;") + +def checkFitBooster(saveddata_engine): + try: + saveddata_engine.execute("SELECT * FROM fits LIMIT 1") + # If table doesn't exist, it means we're doing everything from scratch + # and sqlalchemy will process everything as needed + except sqlalchemy.exc.DatabaseError: + pass + # If not, we're running on top of existing DB + else: + # Check that we have columns + try: + saveddata_engine.execute("SELECT booster FROM fits LIMIT 1") + # If we don't, create them + # This is ugly as hell, but we can't use proper migrate packages as it + # will require us to rebuild skeletons, including mac + except sqlalchemy.exc.DatabaseError: + saveddata_engine.execute("ALTER TABLE fits ADD COLUMN booster BOOLEAN;") + saveddata_engine.execute("UPDATE fits SET booster = 0;") diff --git a/eos/db/saveddata/fit.py b/eos/db/saveddata/fit.py index fdf9f07f0..25516b7b6 100755 --- a/eos/db/saveddata/fit.py +++ b/eos/db/saveddata/fit.py @@ -17,7 +17,7 @@ # along with eos. If not, see . #=============================================================================== -from sqlalchemy import Table, Column, Integer, ForeignKey, String +from sqlalchemy import Table, Column, Integer, ForeignKey, String, Boolean from sqlalchemy.orm import relation, mapper from sqlalchemy.sql import and_ @@ -36,7 +36,8 @@ fits_table = Table("fits", saveddata_meta, Column("name", String, nullable = False), Column("timestamp", Integer, nullable = False), Column("characterID", ForeignKey("characters.ID"), nullable = True), - Column("damagePatternID", ForeignKey("damagePatterns.ID"), nullable=True)) + Column("damagePatternID", ForeignKey("damagePatterns.ID"), nullable=True), + Column("booster", Boolean, nullable = False, index = True, default = 0)) projectedFits_table = Table("projectedFits", saveddata_meta, Column("sourceID", ForeignKey("fits.ID"), primary_key = True), diff --git a/eos/db/saveddata/queries.py b/eos/db/saveddata/queries.py index 13a88a852..01c2888ce 100755 --- a/eos/db/saveddata/queries.py +++ b/eos/db/saveddata/queries.py @@ -248,6 +248,24 @@ def getFitsWithShip(shipID, ownerID=None, where=None, eager=None): raise TypeError("ShipID must be integer") return fits +def getBoosterFits(ownerID=None, where=None, eager=None): + """ + Get all the fits that are flagged as a boosting ship + If no user is passed, do this for all users. + """ + + if ownerID is not None and not isinstance(ownerID, int): + raise TypeError("OwnerID must be integer") + filter = Fit.booster == 1 + if ownerID is not None: + filter = and_(filter, Fit.ownerID == ownerID) + + filter = processWhere(filter, where) + eager = processEager(eager) + with sd_lock: + fits = saveddata_session.query(Fit).options(*eager).filter(filter).all() + return fits + def countFitsWithShip(shipID, ownerID=None, where=None, eager=None): """ Get all the fits using a certain ship. diff --git a/gui/gangView.py b/gui/gangView.py index 88080a56f..41d7fd429 100644 --- a/gui/gangView.py +++ b/gui/gangView.py @@ -37,19 +37,35 @@ class GangView ( ScrolledPanel ): self.draggedFitID = None + help = '''Set fit as booster to display in dropdown, or drag fitting from\nship browser to this window, or right click fit and select booster role.''' + helpSizer = wx.BoxSizer( wx.HORIZONTAL ) + self.helpText = wx.StaticText( self, wx.ID_ANY, help, wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE ) + helpSizer.Add( self.helpText, 1, wx.ALL, 5 ) + self.FitDNDPopupMenu = wx.Menu() self.options = ["Fleet booster", "Wing booster", "Squad booster"] - for option in self.options: + self.fleet = {} + for id, option in enumerate(self.options): item = self.FitDNDPopupMenu.Append(-1, option) - self.Bind(wx.EVT_MENU, self.OnPopupItemSelected, item) + # We bind it to the mainFrame because it may be called from either this class or from FitItem via shipBrowser + self.mainFrame.Bind(wx.EVT_MENU, self.OnPopupItemSelected, item) + + # set content for each commander + self.fleet[id] = {} + self.fleet[id]['stLabel'] = wx.StaticText( self, wx.ID_ANY, self.options[id]+':', wx.DefaultPosition, wx.DefaultSize, 0 ) + self.fleet[id]['stText'] = wx.StaticText( self, wx.ID_ANY, 'None', wx.DefaultPosition, wx.DefaultSize, 0 ) + self.fleet[id]['chFit'] = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, [] ) + self.fleet[id]['chChar'] = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, [] ) + self.fleet[id]['fitSizer'] = wx.BoxSizer( wx.VERTICAL ) contentFGSizer = wx.FlexGridSizer( 5, 3, 0, 0 ) contentFGSizer.AddGrowableCol( 1 ) contentFGSizer.SetFlexibleDirection( wx.BOTH ) contentFGSizer.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED ) + ### Header self.oneonePlaceholder = wx.StaticText( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) self.oneonePlaceholder.Wrap( -1 ) contentFGSizer.Add( self.oneonePlaceholder, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 ) @@ -73,82 +89,43 @@ class GangView ( ScrolledPanel ): self.m_staticline4 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) contentFGSizer.Add( self.m_staticline4, 0, wx.EXPAND, 5 ) - self.stFleet = wx.StaticText( self, wx.ID_ANY, u"Fleet booster:", wx.DefaultPosition, wx.DefaultSize, 0 ) - self.stFleet.Wrap( -1 ) - self.stFleet.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 92, False, wx.EmptyString ) ) + ### Content + for id in self.fleet: + # set various properties + self.fleet[id]['stLabel'].Wrap( -1 ) + self.fleet[id]['stLabel'].SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 92, False, wx.EmptyString ) ) + self.fleet[id]['stText'].Wrap( -1 ) - contentFGSizer.Add( self.stFleet, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + # bind text and choice events + self.fleet[id]['stText'].Bind(wx.EVT_LEFT_DCLICK, self.RemoveBooster) + self.fleet[id]['stText'].Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow) + self.fleet[id]['stText'].Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow) + self.fleet[id]['stText'].SetToolTip(wx.ToolTip("Double click to remove booster")) + self.fleet[id]['chChar'].Bind(wx.EVT_CHOICE, self.CharChanged) + self.fleet[id]['chFit'].Bind(wx.EVT_CHOICE, self.OnFitChoiceSelected) - self.stFleetFit = wx.StaticText( self, wx.ID_ANY, u"None", wx.DefaultPosition, wx.DefaultSize, 0 ) - self.stFleetFit.Wrap( -1 ) - contentFGSizer.Add( self.stFleetFit, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + # add fit text and choice to the fit sizer + self.fleet[id]['fitSizer'].Add( self.fleet[id]['stText'], 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + self.fleet[id]['fitSizer'].Add( self.fleet[id]['chFit'], 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, 1 ) - chFleetCharChoices = [] - self.chFleetChar = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, chFleetCharChoices, 0 ) - self.chFleetChar.SetSelection( 0 ) - - contentFGSizer.Add( self.chFleetChar, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5 ) - - self.stWing = wx.StaticText( self, wx.ID_ANY, u"Wing booster:", wx.DefaultPosition, wx.DefaultSize, 0 ) - self.stWing.Wrap( -1 ) - self.stWing.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 92, False, wx.EmptyString ) ) - contentFGSizer.Add( self.stWing, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) - - self.stWingFit = wx.StaticText( self, wx.ID_ANY, u"None", wx.DefaultPosition, wx.DefaultSize, 0 ) - self.stWingFit.Wrap( -1 ) - contentFGSizer.Add( self.stWingFit, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) - - chWingCharChoices = [] - self.chWingChar = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, chWingCharChoices, 0 ) - self.chWingChar.SetSelection( 0 ) - - contentFGSizer.Add( self.chWingChar, 0, wx.ALL| wx.ALIGN_CENTER_VERTICAL, 5 ) - - self.stSquad = wx.StaticText( self, wx.ID_ANY, u"Squad booster:", wx.DefaultPosition, wx.DefaultSize, 0 ) - self.stSquad.Wrap( -1 ) - self.stSquad.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 92, False, wx.EmptyString ) ) - contentFGSizer.Add( self.stSquad, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) - - self.stSquadFit = wx.StaticText( self, wx.ID_ANY, u"None", wx.DefaultPosition, wx.DefaultSize, 0 ) - self.stSquadFit.Wrap( -1 ) - contentFGSizer.Add( self.stSquadFit, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) - - chSquadCharChoices = [] - self.chSquadChar = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, chSquadCharChoices, 0 ) - self.chSquadChar.SetSelection( 0 ) - - contentFGSizer.Add( self.chSquadChar, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5 ) + # add everything to the content sizer + contentFGSizer.Add( self.fleet[id]['stLabel'], 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) + contentFGSizer.Add( self.fleet[id]['fitSizer'], 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, 5 ) + contentFGSizer.Add( self.fleet[id]['chChar'], 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 ) mainSizer.Add( contentFGSizer, 1, wx.EXPAND, 0 ) - - self.stBoosters = [] - self.stBoosters.append(self.stFleetFit) - self.stBoosters.append(self.stWingFit) - self.stBoosters.append(self.stSquadFit) - - - self.chCharacters = [] - self.chCharacters.append(self.chFleetChar) - self.chCharacters.append(self.chWingChar) - self.chCharacters.append(self.chSquadChar) + mainSizer.Add( helpSizer, 0, wx.EXPAND, 0 ) self.SetSizer( mainSizer ) self.SetAutoLayout(True) self.SetupScrolling() - self.Disable() self.mainFrame.Bind(GE.CHAR_LIST_UPDATED, self.RefreshCharacterList) self.mainFrame.Bind(GE.FIT_CHANGED, self.fitSelected) self.mainFrame.Bind(gui.shipBrowser.EVT_FIT_RENAMED, self.fitRenamed) + self.mainFrame.Bind(gui.shipBrowser.BOOSTER_LIST_UPDATED, self.RefreshBoosterFits) - for stBooster in self.stBoosters: - stBooster.Bind(wx.EVT_LEFT_DCLICK, self.RemoveBooster) - stBooster.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow) - stBooster.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow) - stBooster.SetToolTip(wx.ToolTip("Double click to remove booster")) - - for chCharacter in self.chCharacters: - chCharacter.Bind(wx.EVT_CHOICE, self.CharChanged) + self.RefreshBoosterFits() self.RefreshCharacterList() def OnEnterWindow(self, event): @@ -161,16 +138,13 @@ class GangView ( ScrolledPanel ): obj.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) event.Skip() - def CharChanged(self, event): + ''' Change booster character ''' chBooster = event.GetEventObject() + type = -1 - if chBooster == self.chFleetChar: - type = 0 - if chBooster == self.chWingChar: - type = 1 - if chBooster == self.chSquadChar: - type = 2 + for id in self.fleet: + if chBooster == self.fleet[id]['chChar']: type = id if type == -1: event.Skip() @@ -227,12 +201,8 @@ class GangView ( ScrolledPanel ): location = event.GetEventObject() - if location == self.stFleetFit: - type = 0 - if location == self.stWingFit: - type = 1 - if location == self.stSquadFit: - type = 2 + for id in self.fleet: + if location == self.fleet[id]['stText']: type = id sFit = service.Fit.getInstance() boostee = sFit.getFit(activeFitID) @@ -240,12 +210,15 @@ class GangView ( ScrolledPanel ): fleetSrv = service.Fleet.getInstance() - if type == 0: - fleetSrv.setLinearFleetCom(boostee, booster) - elif type == 1: - fleetSrv.setLinearWingCom(boostee, booster) - elif type == 2: - fleetSrv.setLinearSquadCom(boostee, booster) + if type == 0: fleetSrv.setLinearFleetCom(boostee, booster) + if type == 1: fleetSrv.setLinearWingCom(boostee, booster) + if type == 2: fleetSrv.setLinearSquadCom(boostee, booster) + + # Hide stText and, default fit selection, and enable it + location.Hide() + choice = self.fleet[type]['chFit'] + choice.SetSelection(0) + choice.Show() sFit.recalc(boostee, withBoosters=True) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=activeFitID)) @@ -260,70 +233,49 @@ class GangView ( ScrolledPanel ): self.fitSelected(ev) def fitSelected(self, event): + ''' Fires when active fit is selected and when booster is saved to fit. Update the UI to reflect changes ''' fleetSrv = service.Fleet.getInstance() activeFitID = self.mainFrame.getActiveFit() cFit = service.Fit.getInstance() fit = cFit.getFit(event.fitID or activeFitID) + commanders = (None, None, None) if activeFitID: commanders = fleetSrv.loadLinearFleet(fit) - if commanders is None: - fleetCom, wingCom, squadCom = (None, None, None) - else: - fleetCom, wingCom, squadCom = commanders - if fleetCom: - fleetComName = fleetCom.ship.item.name + ": " + fleetCom.name - fleetComCharName = fleetCom.character.name if fleetCom.character is not None else "All 0" - else: - fleetComName = "None" - fleetComCharName = "All 0" + for id in self.fleet: + # try...except here as we're trying 2 different criteria and want to fall back on the same code + try: + commander = commanders[id] - if wingCom: - wingComName = wingCom.ship.item.name + ": " + wingCom.name - wingComCharName = wingCom.character.name if wingCom.character is not None else "All 0" - else: - wingComName = "None" - wingComCharName = "All 0" + if not activeFitID or commander is None: + raise Exception() - if squadCom: - squadComName = squadCom.ship.item.name + ": " + squadCom.name - squadComCharName = squadCom.character.name if squadCom.character is not None else "All 0" - else: - squadComName = "None" - squadComCharName = "All 0" + self.fleet[id]['stText'].SetLabel(commander.ship.item.name + ": " + commander.name) + self.fleet[id]['chChar'].SetStringSelection(commander.character.name if commander.character is not None else "All 0") + self.fleet[id]['chChar'].Enable() + self.fleet[id]['chFit'].Hide() + self.fleet[id]['stText'].Show() + except: + #set defaults, disable char selection, and enable fit selection + self.fleet[id]['stText'].SetLabel("None") + self.fleet[id]['chChar'].SetStringSelection("All 0") + self.fleet[id]['chChar'].Disable() + self.fleet[id]['chFit'].SetSelection(0) + self.fleet[id]['chFit'].Show() + self.fleet[id]['stText'].Hide() - self.UpdateFleetFitsUI( fleetComName, wingComName, squadComName, fleetComCharName, wingComCharName, squadComCharName ) + if activeFitID: self.Enable() - else: - fleetComName = "None" - fleetComCharName = "All 0" - wingComName = "None" - wingComCharName = "All 0" - squadComName = "None" - squadComCharName = "All 0" - - self.UpdateFleetFitsUI( fleetComName, wingComName, squadComName, fleetComCharName, wingComCharName, squadComCharName ) self.Disable() - def UpdateFleetFitsUI(self, fleet, wing, squad, fleetChar, wingChar, squadChar): - self.stFleetFit.SetLabel(fleet) - self.stWingFit.SetLabel(wing) - self.stSquadFit.SetLabel(squad) - - self.chFleetChar.SetStringSelection(fleetChar) - self.chWingChar.SetStringSelection(wingChar) - self.chSquadChar.SetStringSelection(squadChar) - - self.Layout() self.SendSizeEvent() - - def AddCommander(self, fitID, type = None): + ''' Adds booster to a fit, then recalculates active fit ''' if type is None: return @@ -336,20 +288,48 @@ class GangView ( ScrolledPanel ): fleetSrv = service.Fleet.getInstance() - if type == 0: - fleetSrv.setLinearFleetCom(boostee, booster) - elif type == 1: - fleetSrv.setLinearWingCom(boostee, booster) - elif type == 2: - fleetSrv.setLinearSquadCom(boostee, booster) + if type == 0: fleetSrv.setLinearFleetCom(boostee, booster) + if type == 1: fleetSrv.setLinearWingCom(boostee, booster) + if type == 2: fleetSrv.setLinearSquadCom(boostee, booster) + sFit.recalc(boostee, withBoosters=True) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=activeFitID)) + def RefreshBoosterFits(self, event = None): + sFit = service.Fit.getInstance() + sMarket = service.Market.getInstance() + fitList = sFit.getBoosterFits() + + for id in self.fleet: + choice = self.fleet[id]['chFit'] + chCurrSelection = choice.GetSelection() + chCurrData = -1 + if chCurrSelection != -1: + chCurrData = choice.GetClientData(chCurrSelection) + chCurrSelString = choice.GetString(chCurrSelection) + choice.Clear() + currSelFound = False + choice.Append("None", -1) + for fit in fitList: + id,name,type = fit + ship = sMarket.getItem(type) + choice.Append(ship.name+': '+name, id) + if chCurrData == id: + currSelFound = True + + if chCurrSelection == -1: + choice.SetSelection(0) + else: + if currSelFound: + choice.SetStringSelection(chCurrSelString) + else: + choice.SetSelection(0) + def RefreshCharacterList(self, event = None): cChar = service.Character.getInstance() charList = cChar.getCharacterList() - - for choice in self.chCharacters: + for id in self.fleet: + choice = self.fleet[id]['chChar'] chCurrSelection = choice.GetSelection() chCurrData = -1 if chCurrSelection != -1: @@ -372,6 +352,7 @@ class GangView ( ScrolledPanel ): choice.SetSelection(1) def handleDrag(self, type, fitID): + ''' Handle dragging of fit to fleet interface ''' #Those are drags coming from pyfa sources, NOT builtin wx drags self.draggedFitID = None if type == "fit": @@ -384,20 +365,37 @@ class GangView ( ScrolledPanel ): self.PopupMenu(self.FitDNDPopupMenu, pos) -# sFit.project(activeFit,draggedFit) -# wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=activeFit)) def OnPopupItemSelected(self, event): - item = self.FitDNDPopupMenu.FindItemById(event.GetId()) - text = item.GetText() - booster = self.options.index(text) + ''' Fired when booster popup item is selected ''' + # Get menu selection ID via self.options + menuItem = self.FitDNDPopupMenu.FindItemById(event.GetId()) + type = self.options.index(menuItem.GetText()) + if self.draggedFitID: sFit = service.Fit.getInstance() draggedFit = sFit.getFit(self.draggedFitID) -# self.stBoosters[booster].SetLabel(draggedFit.name) -# self.Layout() - - self.AddCommander(draggedFit.ID, booster) + self.AddCommander(draggedFit.ID, type) self.mainFrame.additionsPane.select("Fleet") + def OnFitChoiceSelected(self, event): + ''' Fired when booster choice is selected ''' + sFit = service.Fit.getInstance() + + # set type via choice box used + chFit = event.GetEventObject() + fitID = chFit.GetClientData(chFit.GetSelection()) + + type = -1 + for id in self.fleet: + if chFit == self.fleet[id]['chFit']: type = id + + if type == -1 or fitID == -1: + event.Skip() + return + + fit = sFit.getFit(fitID) + + self.AddCommander(fit.ID, type) + self.mainFrame.additionsPane.select("Fleet") \ No newline at end of file diff --git a/gui/shipBrowser.py b/gui/shipBrowser.py index d51fac100..453607a69 100644 --- a/gui/shipBrowser.py +++ b/gui/shipBrowser.py @@ -23,6 +23,8 @@ FitRenamed, EVT_FIT_RENAMED = wx.lib.newevent.NewEvent() FitSelected, EVT_FIT_SELECTED = wx.lib.newevent.NewEvent() FitRemoved, EVT_FIT_REMOVED = wx.lib.newevent.NewEvent() +BoosterListUpdated, BOOSTER_LIST_UPDATED = wx.lib.newevent.NewEvent() + Stage1Selected, EVT_SB_STAGE1_SEL = wx.lib.newevent.NewEvent() Stage2Selected, EVT_SB_STAGE2_SEL = wx.lib.newevent.NewEvent() Stage3Selected, EVT_SB_STAGE3_SEL = wx.lib.newevent.NewEvent() @@ -806,8 +808,8 @@ class ShipBrowser(wx.Panel): self._stage3ShipName = shipName self._stage3Data = shipID - for ID, name, timestamp in fitList: - self.lpane.AddWidget(FitItem(self.lpane, ID, (shipName, name, timestamp),shipID)) + for ID, name, booster, timestamp in fitList: + self.lpane.AddWidget(FitItem(self.lpane, ID, (shipName, name, booster, timestamp),shipID)) self.lpane.RefreshList() self.lpane.Thaw() @@ -843,8 +845,8 @@ class ShipBrowser(wx.Panel): for ship in ships: self.lpane.AddWidget(ShipItem(self.lpane, ship.ID, (ship.name, len(sFit.getFitsWithShip(ship.ID))), ship.race)) - for ID, name, shipID, shipName,timestamp in fitList: - self.lpane.AddWidget(FitItem(self.lpane, ID, (shipName, name,timestamp), shipID)) + for ID, name, shipID, shipName, booster, timestamp in fitList: + self.lpane.AddWidget(FitItem(self.lpane, ID, (shipName, name, booster, timestamp), shipID)) if len(ships) == 0 and len(fitList) == 0 : self.lpane.AddWidget(PFStaticText(self.lpane, label = "No matching results.")) self.lpane.RefreshList(doFocus = False) @@ -1314,7 +1316,7 @@ class PFBitmapFrame(wx.Frame): class FitItem(SFItem.SFBrowserItem): - def __init__(self, parent, fitID=None, shipFittingInfo=("Test", "cnc's avatar", 0 ), shipID = None, itemData=None, + def __init__(self, parent, fitID=None, shipFittingInfo=("Test", "cnc's avatar", 0, 0 ), shipID = None, itemData=None, id=wx.ID_ANY, pos=wx.DefaultPosition, size=(0, 40), style=0): @@ -1341,6 +1343,9 @@ class FitItem(SFItem.SFBrowserItem): self.deleted = False + # @todo: replace all getActiveFit() in class with this variable and test + self.activeFit = self.mainFrame.getActiveFit() + if shipID: self.shipBmp = bitmapLoader.getBitmap(str(shipID),"ships") @@ -1348,12 +1353,26 @@ class FitItem(SFItem.SFBrowserItem): self.shipBmp = bitmapLoader.getBitmap("ship_no_image_big","icons") self.shipFittingInfo = shipFittingInfo - self.shipName, self.fitName, self.timestamp = shipFittingInfo + self.shipName, self.fitName, self.fitBooster, self.timestamp = shipFittingInfo - self.copyBmp = bitmapLoader.getBitmap("fit_add_small", "icons") - self.renameBmp = bitmapLoader.getBitmap("fit_rename_small", "icons") - self.deleteBmp = bitmapLoader.getBitmap("fit_delete_small","icons") - self.acceptBmp = bitmapLoader.getBitmap("faccept_small", "icons") + # access these by index based on toggle for booster fit + + self.fitMenu = wx.Menu() + self.toggleItem = self.fitMenu.Append(-1, "Booster Fit", kind=wx.ITEM_CHECK) + self.fitMenu.Check(self.toggleItem.GetId(), self.fitBooster) + self.Bind(wx.EVT_MENU, self.OnPopupItemSelected, self.toggleItem) + + if self.activeFit: + # If there is an active fit, get menu for setting individual boosters + self.fitMenu.AppendSeparator() + boosterMenu = self.mainFrame.additionsPane.gangPage.FitDNDPopupMenu + self.fitMenu.AppendMenu(wx.ID_ANY, 'Set Booster', boosterMenu) + + self.boosterBmp = bitmapLoader.getBitmap("fleet_fc_small", "icons") + self.copyBmp = bitmapLoader.getBitmap("fit_add_small", "icons") + self.renameBmp = bitmapLoader.getBitmap("fit_rename_small", "icons") + self.deleteBmp = bitmapLoader.getBitmap("fit_delete_small","icons") + self.acceptBmp = bitmapLoader.getBitmap("faccept_small", "icons") self.shipEffBk = bitmapLoader.getBitmap("fshipbk_big","icons") @@ -1380,6 +1399,7 @@ class FitItem(SFItem.SFBrowserItem): self.SetDraggable() + self.boosterBtn = self.toolbar.AddButton(self.boosterBmp,"Booster", show=self.fitBooster) self.toolbar.AddButton(self.copyBmp,"Copy", self.copyBtnCB) self.renameBtn = self.toolbar.AddButton(self.renameBmp,"Rename", self.renameBtnCB) self.toolbar.AddButton(self.deleteBmp, "Delete", self.deleteBtnCB) @@ -1424,15 +1444,30 @@ class FitItem(SFItem.SFBrowserItem): self.Bind(wx.EVT_RIGHT_UP, self.OnContextMenu) + def OnPopupItemSelected(self, event): + ''' Fires when fit menu item is selected ''' + # currently only have one menu option (toggle booster) + sFit = service.Fit.getInstance() + sFit.toggleBoostFit(self.fitID) + self.fitBooster = not self.fitBooster + self.boosterBtn.Show(self.fitBooster) + self.fitMenu.Check(self.toggleItem.GetId(), self.fitBooster) + wx.PostEvent(self.mainFrame, BoosterListUpdated()) + event.Skip() + def OnContextMenu(self, event): - self.mainFrame.additionsPane.gangPage.handleDrag("fit", self.fitID) + ''' Handles context menu for fit. Dragging is handled by MouseLeftUp() ''' + pos = wx.GetMousePosition() + pos = self.ScreenToClient(pos) + # Even though we may not select a booster, automatically set this so that the fleet pane knows which fit we're applying + self.mainFrame.additionsPane.gangPage.draggedFitID = self.fitID + self.PopupMenu(self.fitMenu, pos) event.Skip() def GetType(self): return 3 - def OnTimer(self, event): if self.selTimerID == event.GetId(): @@ -1663,7 +1698,7 @@ class FitItem(SFItem.SFBrowserItem): mdc.DrawBitmap(self.shipBmp, self.shipBmpx, self.shipBmpy, 0) - shipName, fittings, timestamp = self.shipFittingInfo + shipName, fittings, booster, timestamp = self.shipFittingInfo mdc.SetFont(self.fontNormal) diff --git a/service/fit.py b/service/fit.py index fe4754eee..546333897 100644 --- a/service/fit.py +++ b/service/fit.py @@ -79,6 +79,7 @@ class Fit(object): def __init__(self): self.pattern = DamagePattern.getInstance().getDamagePattern("Uniform") self.character = Character.getInstance().all5() + self.booster = False self.dirtyFitIDs = set() serviceFittingDefaultOptions = {"useGlobalCharacter": False, "useGlobalDamagePattern": False, "defaultCharacter": self.character.ID, "useGlobalForceReload": False} @@ -95,10 +96,20 @@ class Fit(object): return names def getFitsWithShip(self, id): + ''' Lists fits of shipID, used with shipBrowser ''' fits = eos.db.getFitsWithShip(id) names = [] for fit in fits: - names.append((fit.ID, fit.name, fit.timestamp)) + names.append((fit.ID, fit.name, fit.booster, fit.timestamp)) + + return names + + def getBoosterFits(self): + ''' Lists fits flagged as booster ''' + fits = eos.db.getBoosterFits() + names = [] + for fit in fits: + names.append((fit.ID, fit.name, fit.shipID)) return names @@ -125,10 +136,16 @@ class Fit(object): fit.name = name if name is not None else "New %s" % fit.ship.item.name fit.damagePattern = self.pattern fit.character = self.character + fit.booster = self.booster eos.db.save(fit) self.recalc(fit) return fit.ID + def toggleBoostFit(self, fitID): + fit = eos.db.getFit(fitID) + fit.booster = not fit.booster + eos.db.commit() + def renameFit(self, fitID, newName): fit = eos.db.getFit(fitID) fit.name = newName @@ -203,7 +220,7 @@ class Fit(object): results = eos.db.searchFits(name) fits = [] for fit in results: - fits.append((fit.ID, fit.name, fit.ship.item.ID, fit.ship.item.name, fit.timestamp)) + fits.append((fit.ID, fit.name, fit.ship.item.ID, fit.ship.item.name, fit.booster, fit.timestamp)) return fits def addImplant(self, fitID, itemID):