2424import org .destinationsol .ui .nui .NUIManager ;
2525import org .destinationsol .ui .nui .NUIScreenLayer ;
2626import org .destinationsol .ui .nui .widgets .KeyActivatedButton ;
27+ import org .json .JSONObject ;
28+ import org .slf4j .Logger ;
29+ import org .slf4j .LoggerFactory ;
2730import org .terasology .gestalt .assets .ResourceUrn ;
2831import org .terasology .nui .Canvas ;
32+ import org .terasology .nui .UITextureRegion ;
2933import org .terasology .nui .backends .libgdx .GDXInputUtil ;
3034import org .terasology .nui .widgets .UIButton ;
35+ import org .terasology .nui .widgets .UIImage ;
3136
3237import javax .inject .Inject ;
3338import java .util .ArrayList ;
3439import java .util .List ;
3540
3641public class NewShipScreen extends NUIScreenLayer {
37-
42+ private static final Logger logger = LoggerFactory . getLogger ( NewShipScreen . class );
3843 private final SolApplication solApplication ;
3944 private int numberOfSystems = SystemsBuilder .DEFAULT_SYSTEM_COUNT ;
4045 private int playerSpawnConfigIndex = 0 ;
4146 private List <String > playerSpawnConfigNames = new ArrayList <>();
47+ private List <UITextureRegion > playerSpawnConfigTextures = new ArrayList <>();
4248
4349 @ Inject
4450 public NewShipScreen (SolApplication solApplication ) {
@@ -59,14 +65,29 @@ public void initialise() {
5965 });
6066
6167 for (ResourceUrn configUrn : Assets .getAssetHelper ().listAssets (Json .class , "playerSpawnConfig" )) {
62- playerSpawnConfigNames .addAll (Validator .getValidatedJSON (configUrn .toString (), "engine:schemaPlayerSpawnConfig" ).keySet ());
68+ JSONObject playerSpawnConfigs = Validator .getValidatedJSON (configUrn .toString (), "engine:schemaPlayerSpawnConfig" );
69+ playerSpawnConfigNames .addAll (playerSpawnConfigs .keySet ());
70+ for (String spawnConfigName : playerSpawnConfigs .keySet ()) {
71+ JSONObject playerSpawnConfig = playerSpawnConfigs .getJSONObject (spawnConfigName );
72+ try {
73+ playerSpawnConfigTextures .add (Assets .getDSTexture (playerSpawnConfig .getString ("hull" )).getUiTexture ());
74+ } catch (RuntimeException e ) {
75+ logger .error ("Failed to load ship texture!" , e );
76+ // Null values will not render any texture.
77+ playerSpawnConfigTextures .add (null );
78+ }
79+ }
6380 }
6481
82+ UIImage shipPreviewImage = find ("shipPreviewImage" , UIImage .class );
83+ shipPreviewImage .setImage (playerSpawnConfigTextures .get (playerSpawnConfigIndex ));
84+
6585 UIButton startingShipButton = find ("startingShipButton" , UIButton .class );
6686 startingShipButton .setText ("Starting Ship: " + playerSpawnConfigNames .get (playerSpawnConfigIndex ));
6787 startingShipButton .subscribe (button -> {
6888 playerSpawnConfigIndex = (playerSpawnConfigIndex + 1 ) % playerSpawnConfigNames .size ();
6989 ((UIButton )button ).setText ("Starting Ship: " + playerSpawnConfigNames .get (playerSpawnConfigIndex ));
90+ shipPreviewImage .setImage (playerSpawnConfigTextures .get (playerSpawnConfigIndex ));
7091 });
7192
7293 // NOTE: The original code used getKeyEscape() for both the "OK" and "Cancel" buttons. This was probably a mistake.
0 commit comments