Refactoring of code, along with general housekeeping. Also, character menu is now disabled with no fit selected.
This commit is contained in:
234
gui/gangView.py
234
gui/gangView.py
@@ -41,24 +41,30 @@ class GangView ( ScrolledPanel ):
|
||||
|
||||
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)
|
||||
# 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 )
|
||||
|
||||
fleetFitsSizer = wx.BoxSizer( wx.VERTICAL )
|
||||
wingFitsSizer = wx.BoxSizer( wx.VERTICAL )
|
||||
squadFitsSizer = wx.BoxSizer( wx.VERTICAL )
|
||||
|
||||
self.stFits = wx.StaticText( self, wx.ID_ANY, u"Fits", wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
self.stFits.Wrap( -1 )
|
||||
self.stFits.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 92, False, wx.EmptyString ) )
|
||||
@@ -78,114 +84,41 @@ 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 )
|
||||
self.stFleetFit.Hide()
|
||||
# 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, 1 )
|
||||
|
||||
cFleetFitChoices = []
|
||||
self.cFleetFit = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, cFleetFitChoices, 0 )
|
||||
|
||||
fleetFitsSizer.Add( self.stFleetFit, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
|
||||
fleetFitsSizer.Add( self.cFleetFit, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 1 )
|
||||
contentFGSizer.Add( fleetFitsSizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
|
||||
|
||||
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 )
|
||||
self.stWingFit.Hide()
|
||||
|
||||
cWingFitChoices = []
|
||||
self.cWingFit = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, cWingFitChoices, 0 )
|
||||
|
||||
wingFitsSizer.Add( self.stWingFit, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
|
||||
wingFitsSizer.Add( self.cWingFit, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 1 )
|
||||
contentFGSizer.Add( wingFitsSizer, 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 )
|
||||
self.stSquadFit.Hide()
|
||||
|
||||
cSquadFitChoices = []
|
||||
self.cSquadFit = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, cSquadFitChoices, 0 )
|
||||
|
||||
squadFitsSizer.Add( self.stSquadFit, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
|
||||
squadFitsSizer.Add( self.cSquadFit, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 1 )
|
||||
contentFGSizer.Add( squadFitsSizer, 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'], 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 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)
|
||||
|
||||
self.chFits = []
|
||||
self.chFits.append(self.cFleetFit)
|
||||
self.chFits.append(self.cWingFit)
|
||||
self.chFits.append(self.cSquadFit)
|
||||
|
||||
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)
|
||||
|
||||
for chFits in self.chFits:
|
||||
chFits.Bind(wx.EVT_CHOICE, self.OnFitChoiceSelected)
|
||||
|
||||
self.RefreshBoosterFits()
|
||||
self.RefreshCharacterList()
|
||||
|
||||
@@ -204,9 +137,8 @@ class GangView ( ScrolledPanel ):
|
||||
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()
|
||||
@@ -263,9 +195,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)
|
||||
@@ -277,8 +208,10 @@ class GangView ( ScrolledPanel ):
|
||||
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.chFits[type]
|
||||
choice = self.fleet[type]['chFit']
|
||||
choice.SetSelection(0)
|
||||
choice.Show()
|
||||
|
||||
sFit.recalc(boostee, withBoosters=True)
|
||||
@@ -294,68 +227,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:
|
||||
self.stFleetFit.SetLabel(fleetCom.ship.item.name + ": " + fleetCom.name)
|
||||
self.chFleetChar.SetStringSelection(fleetCom.character.name if fleetCom.character is not None else "All 0")
|
||||
self.cFleetFit.Hide()
|
||||
self.stFleetFit.Show()
|
||||
else:
|
||||
self.stFleetFit.SetLabel("None")
|
||||
self.chFleetChar.SetStringSelection("All 0")
|
||||
self.stFleetFit.Hide()
|
||||
self.cFleetFit.Show()
|
||||
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:
|
||||
self.stWingFit.SetLabel(wingCom.ship.item.name + ": " + wingCom.name)
|
||||
self.chWingChar.SetStringSelection(wingCom.character.name if wingCom.character is not None else "All 0")
|
||||
self.cWingFit.Hide()
|
||||
self.stWingFit.Show()
|
||||
else:
|
||||
self.stWingFit.SetLabel("None")
|
||||
self.chWingChar.SetStringSelection("All 0")
|
||||
self.stWingFit.Hide()
|
||||
self.cWingFit.Show()
|
||||
if not activeFitID or commander is None:
|
||||
raise Exception()
|
||||
|
||||
if squadCom:
|
||||
self.stSquadFit.SetLabel(squadCom.ship.item.name + ": " + squadCom.name)
|
||||
self.chSquadChar.SetStringSelection(squadCom.character.name if squadCom.character is not None else "All 0")
|
||||
self.cSquadFit.Hide()
|
||||
self.stSquadFit.Show()
|
||||
else:
|
||||
self.stSquadFit.SetLabel("None")
|
||||
self.chSquadChar.SetStringSelection("All 0")
|
||||
self.stSquadFit.Hide()
|
||||
self.cSquadFit.Show()
|
||||
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()
|
||||
|
||||
if activeFitID:
|
||||
self.Enable()
|
||||
|
||||
else:
|
||||
self.stFleetFit.SetLabel("None")
|
||||
self.chFleetChar.SetStringSelection("All 0")
|
||||
self.stWingFit.SetLabel("None")
|
||||
self.chWingChar.SetStringSelection("All 0")
|
||||
self.stSquadFit.SetLabel("None")
|
||||
self.chSquadChar.SetStringSelection("All 0")
|
||||
|
||||
self.Disable()
|
||||
|
||||
self.Layout()
|
||||
self.SendSizeEvent()
|
||||
|
||||
def AddCommander(self, fitID, type = None):
|
||||
''' Adds booster to a fit, then recalculates active fit '''
|
||||
if type is None:
|
||||
return
|
||||
|
||||
@@ -380,7 +294,8 @@ class GangView ( ScrolledPanel ):
|
||||
sMarket = service.Market.getInstance()
|
||||
fitList = sFit.getBoosterFits()
|
||||
|
||||
for choice in self.chFits:
|
||||
for id in self.fleet:
|
||||
choice = self.fleet[id]['chFit']
|
||||
chCurrSelection = choice.GetSelection()
|
||||
chCurrData = -1
|
||||
if chCurrSelection != -1:
|
||||
@@ -388,26 +303,27 @@ class GangView ( ScrolledPanel ):
|
||||
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(str(id)+': '+ship.name+' - '+name, id)
|
||||
choice.Append(ship.name+': '+name, id)
|
||||
if chCurrData == id:
|
||||
currSelFound = True
|
||||
|
||||
if chCurrSelection == -1:
|
||||
choice.SetSelection(1)
|
||||
choice.SetSelection(0)
|
||||
else:
|
||||
if currSelFound:
|
||||
choice.SetStringSelection(chCurrSelString)
|
||||
else:
|
||||
choice.SetSelection(1)
|
||||
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:
|
||||
@@ -464,18 +380,16 @@ class GangView ( ScrolledPanel ):
|
||||
|
||||
# set type via choice box used
|
||||
chFit = event.GetEventObject()
|
||||
|
||||
fitID = chFit.GetClientData(chFit.GetSelection())
|
||||
type = -1
|
||||
if chFit == self.cFleetFit: type = 0
|
||||
if chFit == self.cWingFit: type = 1
|
||||
if chFit == self.cSquadFit: type = 2
|
||||
for id in self.fleet:
|
||||
if chFit == self.fleet[id]['chFit']: type = id
|
||||
|
||||
if type == -1:
|
||||
if type == -1 or fitID == -1:
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
id = chFit.GetClientData(chFit.GetSelection())
|
||||
fit = sFit.getFit(id)
|
||||
fit = sFit.getFit(fitID)
|
||||
|
||||
self.AddCommander(fit.ID, type)
|
||||
self.mainFrame.additionsPane.select("Fleet")
|
||||
Reference in New Issue
Block a user