Trouble using DropdownListField #677
Replies: 4 comments
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022).
Posted: 2019-07-16 23:00:17
User: CalvinMT [] (age: 1451 days 🔥; posts: 114)
Hi!
As the title says, I'm having trouble using the ~~[b]~~DropdownListField[/b] component. It basically doesn't show up.
When calling
*~~false*. And calling~~isVisible()
, it returns **~~NullPointerException* error, as if the~~toggleDropDown()
gives an *[code]~~public class SettingsScreen extends Screen {~~prepare()
method wasn't called.What I'm trying to do is to make a drop down list of all possible resolutions (16:9 and 16:10).
Here's parts of my code involved with the problem:
`
// [...]
private final double titleHeight = 125.0;
private ImageComponent title;
private double textInitialX;
private double textInitialY;
private double textWidth;
private double textHeight;
private ImageComponent volume;
private ImageComponent fullscreen;
private ImageComponent resolution;
private final double nbOfSettings = 3.0;
private String[] arrayResolution;
private double itemInitialX;
private double itemInitialY;
private double itemWidth;
private double itemHeight;
private HorizontalSlider sliderVolume;
private CheckBox checkBoxFullscreen;
private DropdownListField dropdownListResolution;
// [...]
@OverRide
public void prepare () {
super.prepare();
Game.window().cursor().setVisible(true);
SubEngine.gameState = GameState.SETTINGS;
}
@OverRide
protected void initializeComponents () {
this.iniManager = INIManager.getInstance();
this.settings = this.iniManager.load();
this.title = new ImageComponent(0.0, 0.0, Game.window().getResolution().getWidth(), this.titleHeight, null, "Settings", null);
this.textInitialX = 0.0;
this.textInitialY = this.title.getY() + this.titleHeight;
this.textWidth = Game.window().getResolution().getWidth() / 2.0;
this.textHeight = (Game.window().getResolution().getHeight() - this.textInitialY) / this.nbOfSettings;
this.volume = new ImageComponent(this.textInitialX, this.textInitialY, this.textWidth, this.titleHeight, null, "Volume", null);
this.fullscreen = new ImageComponent(this.textInitialX, this.textInitialY+this.textHeight, this.textWidth, this.titleHeight, null, "Fullscreen", null);
this.resolution = new ImageComponent(this.textInitialX, this.textInitialY+(this.textHeight2), this.textWidth, this.titleHeight, null, "Resolution", null);
this.volume.setTextAlign(Align.LEFT);
this.fullscreen.setTextAlign(Align.LEFT);
this.resolution.setTextAlign(Align.LEFT);
this.arrayResolution = this.getResolutions();
float currentVolume = Float.parseFloat(this.settings.get(INIManager.AUDIO_SECTION).get("volume"));
boolean currentFullsreen = Boolean.valueOf(this.settings.get(INIManager.GRAPHICS_SECTION).get("fullscreen"));
int currentResolution = Arrays.asList(this.arrayResolution).indexOf(this.settings.get(INIManager.GRAPHICS_SECTION).get("resolution"));
this.itemInitialX = this.textWidth;
this.itemInitialY = this.textInitialY;
this.itemWidth = this.textWidth;
this.itemHeight = this.textHeight;
this.sliderVolume = new HorizontalSlider(this.itemInitialX, this.itemInitialY, this.itemWidth, this.itemHeight, 0.0f, 100.0f, 1.0f);
this.checkBoxFullscreen = new CheckBox(this.itemInitialX, this.itemInitialY+this.itemHeight, this.itemWidth, this.itemHeight, null, currentFullsreen);
this.dropdownListResolution = new DropdownListField(this.itemInitialX, this.itemInitialY+(this.itemHeight2), this.itemWidth, this.itemHeight, this.arrayResolution, currentResolution);
this.sliderVolume.setCurrentValue(currentVolume);
this.sliderVolume.getSliderComponent().setImageAlign(Align.LEFT);
this.checkBoxFullscreen.setTextAlign(Align.LEFT);
//this.dropdownListResolution.getDropDownButton().setTextAlign(Align.LEFT);
this.getComponents().add(this.title);
this.getComponents().add(this.volume);
this.getComponents().add(this.fullscreen);
this.getComponents().add(this.resolution);
this.getComponents().add(this.sliderVolume);
this.getComponents().add(this.checkBoxFullscreen);
this.getComponents().add(this.dropdownListResolution);
}
private String[] getResolutions () {
List result = new ArrayList ();
try {
for (Field field : Resolution.Ratio16x9.class.getDeclaredFields()) {
String resolution = ((Resolution) field.get(this)).getWidth() + "x" + ((Resolution) field.get(this)).getHeight();
result.add(resolution);
}
for (Field field : Resolution.Ratio16x10.class.getDeclaredFields()) {
String resolution = ((Resolution) field.get(this)).getWidth() + "x" + ((Resolution) field.get(this)).getHeight();
result.add(resolution);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Object[] tmp = result.toArray();
return Arrays.copyOf(tmp, tmp.length, String[].class);
}
}
[/code]`
As you can see, I've also got a ~~*~~slider* and a ~~*~~checkbox* ~~~~~~~~which both work great~~~~. Edit: The checkbox works fine, but the buttons of the slider won't work (nor the dragging of the mouse on the slider).
I've also created a ~~*~~getResolutions()* method which I think would be interesting to have directly through the LITIengine. Maybe not implemented in the same way, but I think it could be useful to be able to retrieve groups of resolution as done in the ~~*~~for* loops of ~~*~~getResolutions()*.
Anyways, any ideas of where the problem might come from?
Beta Was this translation helpful? Give feedback.
All reactions