Skip to content
Snippets Groups Projects
Commit 5352418a authored by Anton Danilov's avatar Anton Danilov Committed by Anton Danilov
Browse files

#396 Refactored code

parent a200d9a6
No related branches found
No related tags found
No related merge requests found
......@@ -87,9 +87,9 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
private static final float BOOKMARKS_POSITION_Y_SCALE = 0.15f;
private static final float BOOKMARKS_PADDING = 0.1f;
private static final float UP_DOWN_BUTTON_SIZE = 65;
private static final float UP_BUTTON_Y_SCALE = 0.72f;
private static final float UP_DOWN_BUTTON_X_SCALE = 0.2f;
private static final float DOWN_BUTTON_Y_SCALE = 0.08f;
private static final float UP_BUTTON_POSITION_Y_SCALE = 0.72f;
private static final float UP_DOWN_BUTTON_POSITION_X_SCALE = 0.2f;
private static final float DOWN_BUTTON_POSITION_Y_SCALE = 0.08f;
private static final float SELECTED_GAME_WIDTH = 0.66f;
public static final String GFX_PATH = "gfx/";
......@@ -262,36 +262,33 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
}
private void createUpAndDownButtons() {
upButton = new TablexiaButton(null, false, getScreenTextureRegion(GFX_PATH + ARROW_UP_TEXT), getScreenTextureRegion(GFX_PATH + ARROW_UP_TEXT + PRESSED_TEXT), null, null);
upButton.setButtonSize(UP_DOWN_BUTTON_SIZE, UP_DOWN_BUTTON_SIZE)
.setButtonPosition(getViewportWidth() * UP_DOWN_BUTTON_X_SCALE, getViewportHeight() * UP_BUTTON_Y_SCALE)
.adaptiveSizePositionFix(false)
.setEnabled()
.setInputListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
int nextValue = selectedGameDefinition.getGameNumber() - 1;
if(nextValue < 1) nextValue = GameDefinition.values().length;
selectGame(GameDefinition.getGameDefinitionForGameNumber(nextValue));
}
});
content.addActor(upButton = createButton(UP_BUTTON_POSITION_Y_SCALE, ARROW_UP_TEXT, new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
int nextValue = selectedGameDefinition.getGameNumber() - 1;
if(nextValue < 1) nextValue = GameDefinition.values().length;
selectGame(GameDefinition.getGameDefinitionForGameNumber(nextValue));
}
}));
content.addActor(downButton = createButton(DOWN_BUTTON_POSITION_Y_SCALE, ARROW_DOWN_TEXT, new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
int nextValue = selectedGameDefinition.getGameNumber() + 1;
if(nextValue > GameDefinition.values().length) nextValue = 1;
selectGame(GameDefinition.getGameDefinitionForGameNumber(nextValue));
}
}));
}
downButton = new TablexiaButton(null, false, getScreenTextureRegion(GFX_PATH + ARROW_DOWN_TEXT), getScreenTextureRegion(GFX_PATH + ARROW_DOWN_TEXT + PRESSED_TEXT), null, null);
downButton.setButtonSize(UP_DOWN_BUTTON_SIZE, UP_DOWN_BUTTON_SIZE)
.setButtonPosition(getViewportWidth() * UP_DOWN_BUTTON_X_SCALE, getViewportHeight() * DOWN_BUTTON_Y_SCALE)
private TablexiaButton createButton(float positionYScale, String texture, ClickListener listener) {
TablexiaButton button = new TablexiaButton(null, false, getScreenTextureRegion(GFX_PATH + texture), getScreenTextureRegion(GFX_PATH + texture + PRESSED_TEXT), null, null);
button.setButtonSize(UP_DOWN_BUTTON_SIZE, UP_DOWN_BUTTON_SIZE)
.setButtonPosition(getViewportWidth() * UP_DOWN_BUTTON_POSITION_X_SCALE, getViewportHeight() * positionYScale)
.adaptiveSizePositionFix(false)
.setEnabled()
.setInputListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
int nextValue = selectedGameDefinition.getGameNumber() + 1;
if(nextValue > GameDefinition.values().length) nextValue = 1;
selectGame(GameDefinition.getGameDefinitionForGameNumber(nextValue));
}
});
content.addActor(upButton);
content.addActor(downButton);
.setInputListener(listener);
return button;
}
private void selectFirstGameAndDifficultyAvailable() {
......@@ -667,8 +664,8 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
switchGraphType.setPosition(getStage().getWidth() * SWITCH_GRAPH_POSITION_X_SCALE, getStage().getHeight() * SWITCH_GRAPH_POSITION_Y_SCALE);
difficulties.setPosition(getStage().getWidth() * DIFFICULTIES_POSITION_X_SCALE, getStage().getHeight() * DIFFICULTIES_POSITION_Y_SCALE);
notebook.setBounds(getStage().getWidth() * NOTEBOOK_POSITION_SCALE, 0, getStage().getWidth() * NOTEBOOK_WIDTH_SCALE, getStage().getHeight() * NOTEBOOK_HEIGHT_SCALE);
upButton.setButtonPosition(getViewportWidth() * UP_DOWN_BUTTON_X_SCALE, getViewportHeight() * UP_BUTTON_Y_SCALE);
downButton.setPosition(getViewportWidth() * UP_DOWN_BUTTON_X_SCALE, getViewportHeight() * DOWN_BUTTON_Y_SCALE);
upButton.setButtonPosition(getViewportWidth() * UP_DOWN_BUTTON_POSITION_X_SCALE, getViewportHeight() * UP_BUTTON_POSITION_Y_SCALE);
downButton.setPosition(getViewportWidth() * UP_DOWN_BUTTON_POSITION_X_SCALE, getViewportHeight() * DOWN_BUTTON_POSITION_Y_SCALE);
bookmarksGroup.setPosition(getStage().getWidth() * BOOKMARKS_POSITION_X_SCALE, getStage().getHeight() * BOOKMARKS_POSITION_Y_SCALE);
for(Actor button : bookmarksGroup.getChildren()) {
button.setY((GameMenuDefinition.values().length - bookmarksGroup.getChildren().indexOf(button, true)) * BOOKMARKS_PADDING * getViewportHeight());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment