1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
| Class MainWindow
' Instanciation des DataTables qui serviront de base aux DataViews
Dim JobsList As New DataSet.JobsListDataTable
Dim WeaponsList As New DataSet.WeaponDataTable
' Création des BindingCollectionView (supportant INotifyCollectionChanged et CustomFilter) qui serviront d'ItemsSource aux Comboboxs.
' Note: Ne pouvant pas directement utiliser GetDefaultView(Datatable) pour contruire les BindingCollectionView,
' il faut initialiser au préalable chaque BindingCollectionView avec son propre DataView, de façon à ce que les differentes vues soient filtrées indépendamment.
Dim MainJobBindingList As BindingListCollectionView = CType(CollectionViewSource.GetDefaultView(New DataView(JobsList)), BindingListCollectionView)
Dim SubJobBindingList As BindingListCollectionView = CType(CollectionViewSource.GetDefaultView(New DataView(JobsList)), BindingListCollectionView)
Dim MainWeapon1BindingList As BindingListCollectionView = CType(CollectionViewSource.GetDefaultView(New DataView(WeaponsList)), BindingListCollectionView)
Dim SubWeapon1BindingList As BindingListCollectionView = CType(CollectionViewSource.GetDefaultView(New DataView(WeaponsList)), BindingListCollectionView)
Dim MainWeapon2BindingList As BindingListCollectionView = CType(CollectionViewSource.GetDefaultView(New DataView(WeaponsList)), BindingListCollectionView)
Dim SubWeapon2BindingList As BindingListCollectionView = CType(CollectionViewSource.GetDefaultView(New DataView(WeaponsList)), BindingListCollectionView)
' Variable empêchant l'appel intempestif de la routine "UpdateCBXItemsSources"
Private IsReady As Boolean = False
Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles MyBase.Loaded
'Chargez les données dans la table JobsList.
Dim DataSetJobsListTableAdapter As WpfApplication1.DataSetTableAdapters.JobsListTableAdapter = New WpfApplication1.DataSetTableAdapters.JobsListTableAdapter()
DataSetJobsListTableAdapter.Fill(JobsList)
'Chargez les données dans la table Weapon.
Dim DataSetWeaponTableAdapter As WpfApplication1.DataSetTableAdapters.WeaponTableAdapter = New WpfApplication1.DataSetTableAdapters.WeaponTableAdapter()
DataSetWeaponTableAdapter.Fill(WeaponsList)
' Construction de la colonne "Description" pour chacune des DataTables Equipements
' Chaque enregistrement de cette colonne est une String concaténant chaque champ de la DataTable avec la valeur correspondante (non vide),
' et servira de contenu dynamique pour une infobulle sur chaque ComboBoxItem.
BuildDescriptions() ' Hors-topic ici
' Affectation des Bindings correspondants à chaque ComboBox, chacune ayant sa propre vue pour permettre un filtrage indépendant.
MainJob.DataContext = MainJobBindingList
SubJob.DataContext = SubJobBindingList
SubJob.SelectedValue = ""
MainWeapon1.DataContext = MainWeapon1BindingList
SubWeapon1.DataContext = SubWeapon1BindingList
MainWeapon2.DataContext = MainWeapon2BindingList
SubWeapon2.DataContext = SubWeapon2BindingList
IsReady = True
End Sub
Private Sub UpdateCBXItemsSources(ByVal sender As Object, ByVal e As RoutedEventArgs)
If IsReady Then
IsReady = False
Dim RowFilter As String = "( [Equippable Jobs] LIKE '*" & MainJob.SelectedValue &
"*' OR [Equippable Jobs] = 'ALL' )" &
" AND Level <= '" & MainLevel.Text & "'"
Dim MainWeapon1Type As String = "Hand-to-Hand"
Dim SubWeapon1Type As String = ""
Dim MainWeapon2Type As String = "Hand-to-Hand"
Dim SubWeapon2Type As String = ""
Dim Ranged1Type As String = ""
Dim Ranged2Type As String = ""
Dim FightStyle1 As String = "Hand-to-Hand"
Dim FightStyle2 As String = "Hand-to-Hand"
If Not IsNothing(MainWeapon1.SelectedValue) Then
MainWeapon1Type = WeaponsList.FindByNames(MainWeapon1.SelectedValue).Type
FightStyle1 = SkillsList.FindBySkills(MainWeapon1Type).Style
End If
If Not IsNothing(SubWeapon1.SelectedValue) Then : SubWeapon1Type = WeaponsList.FindByNames(SubWeapon1.SelectedValue).Type
End If
If Not IsNothing(MainWeapon2.SelectedValue) Then
MainWeapon2Type = WeaponsList.FindByNames(MainWeapon2.SelectedValue).Type
FightStyle2 = SkillsList.FindBySkills(MainWeapon2Type).Style
End If
If Not IsNothing(SubWeapon2.SelectedValue) Then : SubWeapon2Type = WeaponsList.FindByNames(SubWeapon2.SelectedValue).Type
End If
If Not IsNothing(RangedWeapon1.SelectedValue) Then : Ranged1Type = RangedList.FindByNames(RangedWeapon1.SelectedValue).Type
End If
If Not IsNothing(RangedWeapon2.SelectedValue) Then : Ranged2Type = RangedList.FindByNames(RangedWeapon2.SelectedValue).Type
End If
Select Case sender.Name
Case "MainJob", "MainLevel"
If IsNumeric(MainLevel.Text) And MainLevel.Text.Length = 2 Then
If CUInt(MainLevel.Text) > MaxMainLevel Then ' Verifier si MainLevel <= 90
MainLevel.Text = MaxMainLevel.ToString
End If
If CUInt(SubLevel.Text) > Math.Floor(CUInt(MainLevel.Text) / 2) Then ' Verifier si SubLevel <= MainLevel/2
SubLevel.Text = Math.Floor(CUInt(MainLevel.Text) / 2).ToString
End If
ElseIf Not IsNumeric(MainLevel.Text) OrElse CUInt(MainLevel.Text) < 0 Then : MainLevel.Text = "01"
ElseIf Not MainLevel.IsFocused AndAlso MainLevel.Text.Length <= 1 Then
MainLevel.Text = "0" & MainLevel.Text
End If
' Filtrer : SubJob, toutes les cbx equipements
SubJobBindingList.CustomFilter = "Jobs <>'" & MainJob.SelectedValue & "'"
MainWeapon1BindingList.CustomFilter = RowFilter & " AND Type <> 'Grips' AND Type <> 'Shield'" &
" AND NOT( Names = '" & Replace(SubWeapon1.SelectedValue, "'", "''") & "' AND Rare = 'True' )"
MainWeapon2BindingList.CustomFilter = RowFilter & " AND Type <> 'Grips' AND Type <> 'Shield'" &
" AND NOT( Names = '" & Replace(SubWeapon2.SelectedValue, "'", "''") & "' AND Rare = 'True' )"
SubWeapon1BindingList.CustomFilter = RowFilter &
" AND Type <> 'Hand-to-Hand' AND Type <> 'Great Axe' AND Type <> 'Great Katana' AND Type <> 'Great Sword' AND Type <> 'Polearm' AND Type <> 'Scythe' AND Type <> 'Staff'" &
" AND " & IIf(FightStyle1 = "Hand-to-Hand", "Names = ''", IIf(FightStyle1 = "1Handed", "Type <> 'Grips'", IIf(FightStyle1 = "2Handed", "Type <> 'Shield' AND Type <> 'Axe' AND Type <> 'Club' AND Type <> 'Dagger' AND Type <> 'Katana' AND Type <> 'Sword'", "Type <>''"))) &
" AND NOT( Names = '" & Replace(MainWeapon1.SelectedValue, "'", "''") & "' AND Rare = 'True' )"
SubWeapon2BindingList.CustomFilter = RowFilter &
" AND Type <> 'Hand-to-Hand' AND Type <> 'Great Axe' AND Type <> 'Great Katana' AND Type <> 'Great Sword' AND Type <> 'Polearm' AND Type <> 'Scythe' AND Type <> 'Staff'" &
" AND " & IIf(FightStyle2 = "Hand-to-Hand", "Names = ''", IIf(FightStyle2 = "1Handed", "Type <> 'Grips'", IIf(FightStyle2 = "2Handed", "Type <> 'Shield' AND Type <> 'Axe' AND Type <> 'Club' AND Type <> 'Dagger' AND Type <> 'Katana' AND Type <> 'Sword'", "Type <>''"))) &
" AND NOT( Names = '" & Replace(MainWeapon2.SelectedValue, "'", "''") & "' AND Rare = 'True' )"
Case "SubJob", "SubLevel"
If IsNumeric(SubLevel.Text) AndAlso SubLevel.Text.Length = 2 AndAlso CUInt(SubLevel.Text) > Math.Floor(CUInt(MainLevel.Text) / 2) Then ' Verifier si SubLevel <= MainLevel/2
SubLevel.Text = Math.Floor(CUInt(MainLevel.Text) / 2).ToString
ElseIf IsNothing(SubJob.SelectedValue) OrElse Not IsNumeric(SubLevel.Text) OrElse CUInt(SubLevel.Text) < 0 OrElse SubJob.SelectedValue = "" Then : SubLevel.Text = "00"
ElseIf Not SubLevel.IsFocused AndAlso SubLevel.Text.Length <= 1 Then
SubLevel.Text = "0" & SubLevel.Text
End If
' Filtrer : MainJob, et JobAbilities1 & 2
MainJobBindingList.CustomFilter = "Jobs <>'" & SubJob.SelectedValue & "'"
Case "MainWeapon1"
' Filtrer : SubWeapon1
SubWeapon1BindingList.CustomFilter = RowFilter &
" AND Type <> 'Hand-to-Hand' AND Type <> 'Great Axe' AND Type <> 'Great Katana' AND Type <> 'Great Sword' AND Type <> 'Polearm' AND Type <> 'Scythe' AND Type <> 'Staff'" &
" AND " & IIf(FightStyle1 = "Hand-to-Hand", "Names = ''", IIf(FightStyle1 = "1Handed", "Type <> 'Grips'", IIf(FightStyle1 = "2Handed", "Type <> 'Shield' AND Type <> 'Axe' AND Type <> 'Club' AND Type <> 'Dagger' AND Type <> 'Katana' AND Type <> 'Sword'", "Type <>''"))) &
" AND NOT( Names = '" & Replace(MainWeapon1.SelectedValue, "'", "''") & "' AND Rare = 'True' )"
Case "MainWeapon2"
' Filtrer : SubWeapon2
SubWeapon2BindingList.CustomFilter = RowFilter &
" AND Type <> 'Hand-to-Hand' AND Type <> 'Great Axe' AND Type <> 'Great Katana' AND Type <> 'Great Sword' AND Type <> 'Polearm' AND Type <> 'Scythe' AND Type <> 'Staff'" &
" AND " & IIf(FightStyle2 = "Hand-to-Hand", "Names = ''", IIf(FightStyle2 = "1Handed", "Type <> 'Grips'", IIf(FightStyle2 = "2Handed", "Type <> 'Shield' AND Type <> 'Axe' AND Type <> 'Club' AND Type <> 'Dagger' AND Type <> 'Katana' AND Type <> 'Sword'", "Type <>''"))) &
" AND NOT( Names = '" & Replace(MainWeapon2.SelectedValue, "'", "''") & "' AND Rare = 'True' )"
Case "SubWeapon1"
' Filtrer : MainWeapon1
MainWeapon1BindingList.CustomFilter = RowFilter & " AND Type <> 'Grips' AND Type <> 'Shield'" &
" AND NOT( Names = '" & Replace(SubWeapon1.SelectedValue, "'", "''") & "' AND Rare = 'True' )"
Case "SubWeapon2"
' Filtrer : MainWeapon2
MainWeapon2BindingList.CustomFilter = RowFilter & " AND Type <> 'Grips' AND Type <> 'Shield'" &
" AND NOT( Names = '" & Replace(SubWeapon2.SelectedValue, "'", "''") & "' AND Rare = 'True' )"
Case Else
End Select
IsReady = True
End If
End Sub
' Petite fonction pour calcul intermédiaire pour certaines expressions de filtrage.
Function CalculSkill(ByVal Skill As String) As Integer
If Skill = "" Or Skill = "Grips" Or Skill = "Shield" Then : Return 0
End If
Dim SkillRank = StatSkillGrades.FindByStatsSkills(Skill).Item(MainJob.SelectedValue)
If IsDBNull(SkillRank) Then
If SubJob.SelectedValue <> "" Then
SkillRank = StatSkillGrades.FindByStatsSkills(Skill).Item(SubJob.SelectedValue)
If IsDBNull(SkillRank) Then : Return 0
End If
Else : Return 0
End If
End If
Return SkillCaps.FindByLevel(CShort(MainLevel.Text)).Item(SkillRank)
End Function
End Class |
Partager