@@ -24,6 +24,8 @@ import org.openbase.planetsudo.net.PlanetSudoClient
24
24
import org.openbase.planetsudo.net.PlanetSudoClient.Companion.instance
25
25
import org.openbase.planetsudo.view.MainGUI
26
26
import org.openbase.planetsudo.view.level.LevelDisplayPanel
27
+ import org.openbase.planetsudo.view.util.getItems
28
+ import org.openbase.planetsudo.view.util.getSelection
27
29
import org.slf4j.Logger
28
30
import org.slf4j.LoggerFactory
29
31
import java.awt.Color
@@ -62,19 +64,25 @@ class ConfigurationPanel : JPanel() {
62
64
updateTeamList()
63
65
64
66
// setup default team
65
- setDefaultTeamButton!! .foreground = Color .BLACK
66
- setDefaultTeamButton!! .isEnabled = true
67
- defaultTeamComboBox!! .isEnabled = true
68
- syncButton!! .isEnabled = false
67
+ enableDefaultTeamSelection()
68
+
69
69
try {
70
- val loadDefaultTeam = loadDefaultTeam()
71
- setDefaultTeam(loadDefaultTeam)
70
+ loadDefaultTeam()?.let {
71
+ setDefaultTeam(it)
72
+ }
72
73
} catch (ex: CouldNotPerformException ) {
73
74
ExceptionPrinter .printHistory(CouldNotPerformException (" Could not load default team!" , ex), logger)
74
75
}
75
76
}
76
77
77
- fun updateTeamList () {
78
+ fun enableDefaultTeamSelection () {
79
+ setDefaultTeamButton!! .foreground = Color .BLACK
80
+ setDefaultTeamButton!! .isEnabled = true
81
+ defaultTeamComboBox!! .isEnabled = true
82
+ syncButton!! .isEnabled = false
83
+ }
84
+
85
+ fun updateTeamList (selectTeam : TeamData ? = null) {
78
86
try {
79
87
teamAComboBox!! .isEnabled = false
80
88
teamBComboBox!! .isEnabled = false
@@ -97,25 +105,24 @@ class ConfigurationPanel : JPanel() {
97
105
98
106
// restore selection
99
107
if (teamAComboBox!! .itemCount > 0 ) {
100
- if (teamAComboBox !! .model.size > stateProperties.getProperty( PROPERTY_SELECTED_TEAM_A , " 0 " ).toInt()) {
101
- teamAComboBox!! .selectedIndex = stateProperties.getProperty( PROPERTY_SELECTED_TEAM_A , " 0 " ).toInt ()
102
- } else {
103
- teamAComboBox !! .selectedIndex = 0
104
- stateProperties.setProperty( PROPERTY_SELECTED_TEAM_A , " 0 " )
105
- }
108
+ (selectTeam
109
+ ? : teamAComboBox!! .getItems ()
110
+ .filterNotNull()
111
+ .find { it.name == stateProperties.getProperty( PROPERTY_SELECTED_TEAM_A , " " ) })
112
+ ?. also {teamAComboBox !! .selectedItem = it }
113
+ ? : run {teamAComboBox !! .selectedIndex = 0 }
106
114
}
107
115
108
116
if (teamBComboBox!! .itemCount > 0 ) {
109
- if (teamBComboBox!! .model.size > stateProperties.getProperty(PROPERTY_SELECTED_TEAM_B , " 0" ).toInt()) {
110
- teamBComboBox!! .selectedIndex = stateProperties.getProperty(PROPERTY_SELECTED_TEAM_B , " 0" ).toInt()
111
- } else {
112
- teamBComboBox!! .selectedIndex = 0
113
- stateProperties.setProperty(PROPERTY_SELECTED_TEAM_B , " 0" )
114
- }
117
+ teamBComboBox!! .getItems()
118
+ .filterNotNull()
119
+ .find { it.name == stateProperties.getProperty(PROPERTY_SELECTED_TEAM_B , " " ) }
120
+ ?.also {teamBComboBox!! .selectedItem = it }
121
+ ? : run {teamBComboBox!! .selectedIndex = 0 }
115
122
}
116
123
117
124
teamAComboBox!! .isEnabled = true
118
- teamBComboBox!! .setEnabled( true )
125
+ teamBComboBox!! .isEnabled = true
119
126
} catch (ex: CouldNotPerformException ) {
120
127
logger.warn(" Could not load teams!" , ex)
121
128
}
@@ -135,10 +142,10 @@ class ConfigurationPanel : JPanel() {
135
142
teamsPanel = JPanel ()
136
143
versusLabel = JLabel ()
137
144
teamAPanel = JPanel ()
138
- teamAComboBox = JComboBox <TeamData >()
145
+ teamAComboBox = JComboBox <TeamData ? >()
139
146
teamALabel = JLabel ()
140
147
teamBPanel = JPanel ()
141
- teamBComboBox = JComboBox <TeamData >()
148
+ teamBComboBox = JComboBox <TeamData ? >()
142
149
teamBLabel = JLabel ()
143
150
levelChooserPanel = JPanel ()
144
151
levelChooserComboBox = JComboBox <String >()
@@ -675,7 +682,9 @@ class ConfigurationPanel : JPanel() {
675
682
selectedItem?.let { selectedItem ->
676
683
gameManager.addTeam(selectedItem as TeamData , GameManager .TeamType .A )
677
684
if (isEnabled) {
678
- stateProperties.setProperty(PROPERTY_SELECTED_TEAM_A , selectedIndex.toString())
685
+ getSelection()?.name?.let {
686
+ stateProperties.setProperty(PROPERTY_SELECTED_TEAM_A , it )
687
+ }
679
688
}
680
689
}
681
690
}
@@ -686,7 +695,9 @@ class ConfigurationPanel : JPanel() {
686
695
selectedItem?.let {selectedItem ->
687
696
gameManager.addTeam(selectedItem as TeamData , GameManager .TeamType .B )
688
697
if (isEnabled) {
689
- stateProperties.setProperty(PROPERTY_SELECTED_TEAM_B , selectedIndex.toString())
698
+ getSelection()?.name?.let {
699
+ stateProperties.setProperty(PROPERTY_SELECTED_TEAM_B , it )
700
+ }
690
701
}
691
702
}
692
703
}
@@ -695,14 +706,21 @@ class ConfigurationPanel : JPanel() {
695
706
private fun defaultTeamComboBoxActionPerformed () { // GEN-FIRST:event_defaultTeamComboBoxActionPerformed
696
707
} // GEN-LAST:event_defaultTeamComboBoxActionPerformed
697
708
698
- private fun setDefaultTeam (defaultTeamData : TeamData ? ) {
709
+ fun setDefaultTeamCandidate (teamData : TeamData ) = teamData
710
+ .takeIf { defaultTeamComboBox!! .isEnabled }
711
+ ?.also {
712
+ saveDefaultTeam(it)
713
+ setDefaultTeam(it)
714
+ }
715
+
716
+ private fun setDefaultTeam (defaultTeamData : TeamData ) {
699
717
setDefaultTeamButton!! .foreground = Color .BLACK
700
718
setDefaultTeamButton!! .isEnabled = false
701
719
defaultTeamComboBox!! .isEnabled = false
702
720
syncButton!! .isEnabled = true
703
721
try {
704
722
for (i in 0 until defaultTeamComboBox!! .model.size) {
705
- if ((defaultTeamComboBox!! .model.getElementAt(i) as TeamData ).name == defaultTeamData!! .name) {
723
+ if ((defaultTeamComboBox!! .model.getElementAt(i) as TeamData ).name == defaultTeamData.name) {
706
724
defaultTeamComboBox!! .selectedItem = defaultTeamComboBox!! .model.getElementAt(i)
707
725
break
708
726
}
@@ -750,8 +768,8 @@ class ConfigurationPanel : JPanel() {
750
768
private var logoLabel: JLabel ? = null
751
769
private var setDefaultTeamButton: JButton ? = null
752
770
private var syncButton: JButton ? = null
753
- private var teamAComboBox: JComboBox <TeamData >? = null
754
- private var teamBComboBox: JComboBox <TeamData >? = null
771
+ private var teamAComboBox: JComboBox <TeamData ? >? = null
772
+ private var teamBComboBox: JComboBox <TeamData ? >? = null
755
773
private var randomLevelButton: JButton ? = null // End of variables declaration//GEN-END:variables
756
774
757
775
/* *
0 commit comments