Skip to content

Commit

Permalink
Adjust new resolution picking to intialize once and cycle through sor…
Browse files Browse the repository at this point in the history
…ted resolution possibilities without duplicates
  • Loading branch information
Cervator committed Jun 22, 2015
1 parent c1abffe commit b249937
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
36 changes: 25 additions & 11 deletions main/src/com/miloshpetrov/sol2/GameOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.badlogic.gdx.Graphics;
import com.badlogic.gdx.Input;

import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;

public class GameOptions {
public static final String FILE_NAME = "settings.ini";
Expand Down Expand Up @@ -36,8 +39,8 @@ public class GameOptions {
private String keyChangeShipMenuName;
private String keyHireShipMenuName;


private int resPos = -1;
private SortedSet<String> supportedResolutions = new TreeSet<String>();
private Iterator<String> resolutionIterator = null;

public GameOptions(boolean mobile, SolFileReader reader) {
IniReader r = new IniReader(FILE_NAME, reader, false);
Expand Down Expand Up @@ -68,18 +71,29 @@ public GameOptions(boolean mobile, SolFileReader reader) {
}

public void advanceReso() {
// Get the resolutions that are supported
Graphics.DisplayMode displayModes[] = Gdx.graphics.getDisplayModes();
if (resolutionIterator == null) {
// Initialize resolution choices - get the resolutions that are supported
Graphics.DisplayMode displayModes[] = Gdx.graphics.getDisplayModes();

for (Graphics.DisplayMode d : displayModes) {
supportedResolutions.add(d.width + "x" + d.height);
}

// resPos is static, so increment to display next resolution
resPos++;
if (resPos >= displayModes.length) {
resPos = 0;
resolutionIterator = supportedResolutions.iterator();
}

String nextResolution;
if (resolutionIterator.hasNext()) {
nextResolution = resolutionIterator.next();
} else {
// Probably somehow possible to get no entries at all which would crash, but then we're doomed anyway
resolutionIterator = supportedResolutions.iterator();
nextResolution = resolutionIterator.next();
}

// display the next supported resolution
x = displayModes[resPos].width;
y = displayModes[resPos].height;
// TODO: Probably should validate, but then there are still many things we should probably add! :-)
x = Integer.parseInt(nextResolution.substring(0, nextResolution.indexOf("x")));
y = Integer.parseInt(nextResolution.substring(nextResolution.indexOf("x") + 1, nextResolution.length()));

save();
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/com/miloshpetrov/sol2/menu/ResolutionScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void drawImgs(UiDrawer uiDrawer, SolApplication cmp) {

@Override
public void drawText(UiDrawer uiDrawer, SolApplication cmp) {
uiDrawer.drawString("Please restart to apply changes", .5f * uiDrawer.r, .3f, FontSize.MENU, true, SolColor.W);
uiDrawer.drawString("Click 'Back' to apply changes", .5f * uiDrawer.r, .3f, FontSize.MENU, true, SolColor.W);
}

@Override
Expand Down

0 comments on commit b249937

Please sign in to comment.