viewcontroller.py (10511B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\eveclientqatools\sofpreviewer\sofselection\viewcontroller.py 2 from __future__ import print_function 3 from __future__ import absolute_import 4 from eveclientqatools.sofpreviewer.sofselection.view import SofSelectionView 5 from shipskins.static import SkinMaterialStorage 6 from sofDnaLibrary.query import GetDnaStringsMatchingQuery 7 from .viewmodel import SofSelectionViewModel 8 from eveclientqatools.sofpreviewer import viewhelper as ViewHelper 9 import fsdBuiltData.common.graphicMaterialSets as graphicMaterialSets 10 from .constraints import Constraints 11 12 class SofSelectionViewController(object): 13 14 def __init__(self, model, parentController, parentView): 15 self.parentController = parentController 16 self.parentView = parentView 17 self.model = model 18 self.viewModel = SofSelectionViewModel(self.model) 19 self.view = None 20 self.constraints = None 21 self.currentFaction = None 22 23 def ShowUI(self, parentContainer): 24 self.view = SofSelectionView(self) 25 self.view.Setup(parentContainer, self.viewModel) 26 self.constraints = Constraints(self.view) 27 self.UpdateIcon() 28 return self.view 29 30 def ConstrainDnaSelection(self): 31 raceQuery = '.*' 32 factionQuery = '.*' 33 hullQuery = '.*' 34 if self.constraints.faction: 35 factionQuery = self.view.factionCombo.GetKey() 36 if self.constraints.hull: 37 hullQuery = self.view.hullCombos[0].GetKey() 38 if self.constraints.race: 39 raceQuery = self.view.raceCombo.GetKey() 40 if self.constraints.pattern and self.viewModel.currentPattern != 'None': 41 self.viewModel.currentHulls[0] = ViewHelper.TrySettingComboOptions(self.view.hullCombos[0], self.model.patternToHulls[self.viewModel.currentPattern], self.viewModel.currentHulls[0]) 42 if self.constraints.HasNoConstraints(): 43 self.RestoreDefaultCurrentValues() 44 else: 45 self.ConstrainDnaWithConstrains(factionQuery, hullQuery, raceQuery) 46 self.parentController.UpdatePreviewShip() 47 48 def ConstrainDnaWithConstrains(self, factionQuery, hullQuery, raceQuery): 49 dnaList = GetDnaStringsMatchingQuery(hullQuery, factionQuery, raceQuery) 50 selectableRaces = [] 51 selectableFactions = [] 52 selectableHulls = [] 53 self.FilterSelectables(dnaList, selectableFactions, selectableHulls, selectableRaces) 54 if not self.constraints.pattern: 55 selectablePatterns = [ patternName for patternName, hulls in self.model.patternToHulls.iteritems() for hullName in selectableHulls if hullName in hulls ] 56 selectablePatterns = list(set(selectablePatterns)) 57 selectablePatterns.insert(0, 'None') 58 self.viewModel.currentPattern = ViewHelper.TrySettingComboOptions(self.view.patternCombo, selectablePatterns, self.viewModel.currentPattern) 59 elif self.viewModel.currentPattern != 'None': 60 selectableHullsBasedOfPattern = set(self.model.patternToHulls[self.viewModel.currentPattern]) 61 selectableHulls = list(set(selectableHulls).intersection(selectableHullsBasedOfPattern)) 62 if not self.constraints.hull: 63 self.viewModel.currentHulls[0] = ViewHelper.TrySettingComboOptions(self.view.hullCombos[0], selectableHulls, self.viewModel.currentHulls[0]) 64 self.ShowMultiHullComboBoxes(self.viewModel.currentHulls[0]) 65 if not self.constraints.faction: 66 self.currentFaction = ViewHelper.TrySettingComboOptions(self.view.factionCombo, selectableFactions, self.GetDefaultFactionForHull()) 67 if not self.constraints.race: 68 self.viewModel.currentRace = ViewHelper.TrySettingComboOptions(self.view.raceCombo, selectableRaces, self.viewModel.currentRace) 69 if not self.constraints.pattern and self.constraints.hull: 70 availablePatterns = [ pattern for pattern, hulls in self.model.patternToHulls.iteritems() if self.viewModel.currentHulls[0] in hulls ] 71 availablePatterns.insert(0, 'None') 72 self.viewModel.currentPattern = ViewHelper.TrySettingComboOptions(self.view.patternCombo, availablePatterns, self.viewModel.currentPattern) 73 74 def FilterSelectables(self, dnaList, selectableFactions, selectableHulls, selectableRaces): 75 for dna in dnaList: 76 dnaElements = dna.split(':') 77 hull = dnaElements[0] 78 faction = dnaElements[1] 79 race = dnaElements[2] 80 if faction not in selectableFactions: 81 selectableFactions.append(faction) 82 if race not in selectableRaces: 83 selectableRaces.append(race) 84 if hull not in selectableHulls: 85 selectableHulls.append(hull) 86 87 def RestoreDefaultCurrentValues(self): 88 self.currentFaction = ViewHelper.TrySettingComboOptions(self.view.factionCombo, self.model.sofFactions, self.GetDefaultFactionForHull()) 89 self.viewModel.currentRace = ViewHelper.TrySettingComboOptions(self.view.raceCombo, self.model.sofRaces, self.viewModel.currentRace) 90 self.viewModel.currentHulls[0] = ViewHelper.TrySettingComboOptions(self.view.hullCombos[0], self.model.sofHulls, self.viewModel.currentHulls[0]) 91 self.viewModel.currentPattern = ViewHelper.TrySettingComboOptions(self.view.patternCombo, self.model.sofPatterns, self.viewModel.currentPattern) 92 93 def ShowMultiHullComboBoxes(self, hull): 94 isMultiHull = self.model.IsMultiHull(hull) 95 self.view.multiHullContainer.display = isMultiHull 96 if isMultiHull: 97 baseHullName = self.model.GetMultiHullBaseName(hull) 98 for i in xrange(1, self.model.const.MAX_MULTI_HULLS): 99 availableHulls = [ hull for hull, specification, variation in sorted(self.model.multihulls[baseHullName], key=lambda x: x[2]) if specification == i + 1 ] 100 ViewHelper.TrySettingComboOptions(self.view.hullCombos[i], availableHulls, self.viewModel.currentPattern) 101 self.viewModel.currentHulls[i] = availableHulls[0] 102 103 else: 104 for i in xrange(1, self.model.const.MAX_MULTI_HULLS): 105 self.viewModel.currentHulls[i] = None 106 107 def GetCurrentHull(self): 108 currentHull = self.viewModel.currentHulls[0] 109 if self.model.IsMultiHull(currentHull): 110 currentHull += ';' + ';'.join((hull for hull in self.viewModel.currentHulls[1:] if hull is not None)) 111 return currentHull 112 113 def GetDefaultFactionForHull(self): 114 if self.viewModel.currentHulls[0].endswith('t2'): 115 return self.model._GetDefaultFactionForT2Hull(self.viewModel.currentHulls[0]) 116 else: 117 return self.model._GetDefaultFactionForT1Hull(self.viewModel.currentHulls[0]) 118 119 def UpdateIcon(self): 120 path = None 121 id = self.parentController.GetCurrentMaterialSetID() 122 for mid, m in SkinMaterialStorage().iteritems(): 123 if m.materialSetID == id: 124 path = 'res:/UI/Texture/classes/skins/icons/%s.png' % mid 125 break 126 127 self.view.skinUnavailableLabel.display = path is None 128 if path is None: 129 path = 'res:/UI/Texture/notavailable.dds' 130 self.view.previewImage.texture.resPath = path 131 132 def FilterMaterialSet(self, filterByRace, materialSets, availableMaterialSets): 133 for materialSetID, materialSet in materialSets.iteritems(): 134 if filterByRace: 135 raceHint = graphicMaterialSets.GetSofRaceHint(materialSet) 136 if raceHint and raceHint == self.view.raceCombo.GetKey(): 137 availableMaterialSets.append((materialSetID, materialSet.description)) 138 else: 139 availableMaterialSets.append((materialSetID, materialSet.description)) 140 141 @property 142 def currentPattern(self): 143 return self.viewModel.currentPattern 144 145 def OnPatternComboChange(self, comboBox, pattern, value): 146 self.viewModel.currentPattern = pattern 147 if self.constraints.pattern: 148 self.ConstrainDnaSelection() 149 self.parentController.UpdatePreviewShip() 150 151 def OnMaterialSetIDChange(self, materialSet): 152 faction = graphicMaterialSets.GetSofFactionName(materialSet) 153 if not faction: 154 dna = self.model.GetDnaFromPlayerShip() 155 if dna.split(':')[0] == self.GetCurrentHull(): 156 faction = dna.split(':')[1] 157 if faction: 158 try: 159 self.view.factionCombo.SelectItemByLabel(faction) 160 except RuntimeError: 161 if materialSet is not None: 162 print("Removing constraints because '%s' is not in the constrained faction list" % materialSet.sofFactionName) 163 self.constraints.SetAll(False) 164 self.ConstrainDnaSelection() 165 166 self.view.factionCombo.SelectItemByLabel(faction) 167 self.OnFactionComboChange(self.view.factionCombo, faction, None) 168 sofPatternName = graphicMaterialSets.GetSofPatternName(materialSet, 'None') 169 idx = ViewHelper.GetComboListIndex(self.model.sofPatterns, sofPatternName) 170 self.view.patternCombo.SelectItemByValue(idx) 171 self.OnPatternComboChange(self.view.patternCombo, sofPatternName, idx) 172 173 def OnRaceComboChange(self, comboBox, race, value): 174 self.viewModel.currentRace = race 175 if self.constraints.race: 176 self.ConstrainDnaSelection() 177 if self.parentController.isMaterialSetFilteredByRace: 178 self.parentController.FilterMaterialSet(self.viewModel.currentRace) 179 self.parentController.UpdatePreviewShip() 180 181 def OnConstraintChanged(self, checkbox): 182 self.ConstrainDnaSelection() 183 184 def OnFactionComboChange(self, comboBox, faction, value): 185 self.viewModel.currentFaction = faction 186 if self.constraints.faction: 187 self.ConstrainDnaSelection() 188 self.parentController.UpdatePreviewShip() 189 190 def OnHullComboChange(self, comboBox, hull, value): 191 self.viewModel.currentHulls[0] = hull 192 self.ShowMultiHullComboBoxes(hull) 193 if self.constraints.hull: 194 self.ConstrainDnaSelection() 195 self.parentController.UpdatePreviewShip() 196 197 def OnSpecificationChanges(self, comboBox, hull, value): 198 specification = self.model.GetMultiHullSpecification(hull) 199 self.viewModel.currentHulls[specification - 1] = hull 200 self.parentController.UpdatePreviewShip()