4242import org .terasology .rendering .nui .UIWidget ;
4343import org .terasology .rendering .nui .WidgetUtil ;
4444import org .terasology .rendering .nui .databinding .BindHelper ;
45- import org .terasology .rendering .nui .databinding .DefaultBinding ;
4645import org .terasology .rendering .nui .databinding .IntToStringBinding ;
4746import org .terasology .rendering .nui .databinding .ReadOnlyBinding ;
4847import org .terasology .rendering .nui .itemRendering .StringTextRenderer ;
@@ -86,9 +85,10 @@ public class JoinGameScreen extends CoreScreenLayer {
8685 private UIList <ServerInfo > visibleList ;
8786
8887 private List <ServerInfo > listedServers = new ArrayList <>();
89- private List <ServerInfo > customServers = new ArrayList <>();
9088
91- private boolean updateComplete = false ;
89+ private Predicate <ServerInfo > activeServersOnly = server -> server .isActive ();
90+
91+ private boolean updateComplete ;
9292
9393 @ Override
9494 public void initialise () {
@@ -99,12 +99,14 @@ public void initialise() {
9999
100100 UIList <ServerInfo > customServerList = find ("customServerList" , UIList .class );
101101 if (customServerList != null ) {
102- configureServerList (customServerList , customServers );
102+ customServerList .setList (config .getNetwork ().getServerInfos ());
103+ configureServerList (customServerList );
103104 }
104105
105106 UIList <ServerInfo > onlineServerList = find ("onlineServerList" , UIList .class );
106107 if (onlineServerList != null ) {
107- configureServerList (onlineServerList , listedServers );
108+ onlineServerList .setList (listedServers );
109+ configureServerList (onlineServerList );
108110 }
109111
110112 ActivateEventListener activateCustom = e -> {
@@ -154,13 +156,8 @@ public void update(float delta) {
154156 updateComplete = true ;
155157 }
156158
157- Predicate <ServerInfo > onlyActive = server -> server .isActive ();
158-
159- customServers .clear ();
160- customServers .addAll (Collections2 .filter (config .getNetwork ().getServers (), onlyActive ));
161-
162159 listedServers .clear ();
163- listedServers .addAll (Collections2 .filter (downloader .getServers (), onlyActive ));
160+ listedServers .addAll (Collections2 .filter (downloader .getServers (), activeServersOnly ));
164161 }
165162 }
166163
@@ -200,9 +197,8 @@ public JoinStatus call() throws InterruptedException {
200197
201198 }
202199
203- private void configureServerList (final UIList <ServerInfo > serverList , List < ServerInfo > servers ) {
200+ private void configureServerList (final UIList <ServerInfo > serverList ) {
204201
205- serverList .bindList (new DefaultBinding <List <ServerInfo >>(servers ));
206202 serverList .subscribe (new ItemActivateEventListener <ServerInfo >() {
207203 @ Override
208204 public void onItemActivated (UIWidget widget , ServerInfo item ) {
@@ -314,17 +310,29 @@ public void onActivated(UIWidget button) {
314310
315311 private void bindCustomButtons () {
316312
313+ UIList <?> customServerList = find ("customServerList" , UIList .class );
314+ ReadOnlyBinding <Boolean > localSelectedServerOnly = new ReadOnlyBinding <Boolean >() {
315+ @ Override
316+ public Boolean get () {
317+ return customServerList .getSelection () != null ;
318+ }
319+ };
320+
317321 UIButton add = find ("add" , UIButton .class );
318322 if (add != null ) {
319323 add .subscribe (button -> {
320324 AddServerPopup popup = getManager ().pushScreen (AddServerPopup .ASSET_URI , AddServerPopup .class );
321325 // select the entry if added successfully
322- popup .onSuccess (item -> visibleList .setSelection (item ));
326+ popup .onSuccess (item -> {
327+ config .getNetwork ().addServerInfo (item );
328+ visibleList .setSelection (item );
329+ });
323330 });
324331 }
325332
326333 UIButton edit = find ("edit" , UIButton .class );
327334 if (edit != null ) {
335+ edit .bindEnabled (localSelectedServerOnly );
328336 edit .subscribe (button -> {
329337 AddServerPopup popup = getManager ().pushScreen (AddServerPopup .ASSET_URI , AddServerPopup .class );
330338 ServerInfo info = visibleList .getSelection ();
@@ -337,10 +345,11 @@ private void bindCustomButtons() {
337345
338346 UIButton removeButton = find ("remove" , UIButton .class );
339347 if (removeButton != null ) {
348+ removeButton .bindEnabled (localSelectedServerOnly );
340349 removeButton .subscribe (button -> {
341350 ServerInfo info = visibleList .getSelection ();
342351 if (info != null ) {
343- config .getNetwork ().remove (info );
352+ config .getNetwork ().removeServerInfo (info );
344353 extInfo .remove (info );
345354 visibleList .setSelection (null );
346355 }
0 commit comments