Skip to content
Snippets Groups Projects
Commit 0bc2aaa1 authored by Luboš Horáček's avatar Luboš Horáček
Browse files

Menu overlay resizing fix with color texture refactoring

parent adceaf72
No related branches found
No related tags found
No related merge requests found
......@@ -91,6 +91,14 @@ public class Tablexia extends TablexiaApplication {
getStage().addActor(mainMenuContainer);
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
if(mainMenuContainer != null) {
mainMenuContainer.setSize(getStage().getWidth(), getStage().getHeight());
}
}
private void startLoading(Locale locale) {
// sync loaded screen with loader image
setScreenIfIsDifferent(new LoaderScreen());
......
......@@ -5,11 +5,10 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import cz.nic.tablexia.bus.ApplicationBus;
......@@ -315,15 +314,8 @@ public abstract class TablexiaApplication implements ApplicationListener {
@Override
public void processTransaction(Stage stage, final AbstractTablexiaScreen<?> lastScreen, final AbstractTablexiaScreen<?> newScreen, final Runnable newScreenHandler, final Runnable lastScreenHandler, final Runnable finishHandler) {
final int transactionSpeed = 1;
final TextureRegion texture = ApplicationAtlasManager.getInstance().getColorTextureRegion(Color.BLACK, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
final Actor screenDimmer = new Actor() {
public void draw(Batch batch, float parentAlpha) {
batch.setColor(getColor());
batch.draw(texture, 0, 0);
batch.setColor(Color.WHITE);
}
};
final Actor screenDimmer = new Image(ApplicationAtlasManager.getInstance().getColorTexture(Color.BLACK));
screenDimmer.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
newScreen.setLoadingListener(new ScreenLoadingListener() {
@Override
......
......@@ -2,7 +2,6 @@ package cz.nic.tablexia.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
......@@ -51,17 +50,8 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
private Actor screenDimmer;
public AbstractTablexiaGame() {
final TextureRegion texture = getColorTextureRegion(Color.BLACK, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
screenDimmer = new Actor() {
public void draw(Batch batch, float parentAlpha) {
batch.setColor(getColor());
batch.draw(texture, 0, 0);
batch.setColor(Color.WHITE);
}
;
};
screenDimmer = new Image(getColorTextureRegion(Color.BLACK));
screenDimmer.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
screenDimmer.addAction(alpha(0));
getStage().addActor(screenDimmer);
}
......
......@@ -99,11 +99,7 @@ public class TablexiaAtlasManager extends TablexiaAbstractFileManager {
return colorMap.get(color);
}
public TextureRegion getColorTextureRegion(Color color, int width, int heigth) {
return new TextureRegion(getColorTexture(color), width, heigth);
}
public TextureRegion getColorTextureRegion(Color color) {
return getColorTextureRegion(color, 1, 1);
return new TextureRegion(getColorTexture(color),1,1);
}
}
package cz.nic.tablexia.menu;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Interpolation.PowOut;
......@@ -13,6 +14,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
......@@ -68,10 +70,14 @@ public class MainMenu extends Stack {
menuButtonStyle = new TextButtonStyle();
menuButtonStyle.font = ApplicationFontManager.getInstance().getFont(ApplicationFontManager.FONT_ROBOTO_REGULAR);
menuButtonStyle.fontColor = MENU_TEXT_COLOR;
menuButtonStyle.up = new TextureRegionDrawable(ApplicationAtlasManager.getInstance().getColorTextureRegion(Color.BLUE, 50, 50));
menuButtonStyle.up = new SpriteDrawable(new Sprite(ApplicationAtlasManager.getInstance().getColorTextureRegion(Color.BLUE)));
menuButtonStyle.up.setMinWidth(50); // temprorary button size
menuButtonStyle.up.setMinHeight(50); // temprorary button size
// open close button
openCloseButton = new Button(new TextureRegionDrawable(ApplicationAtlasManager.getInstance().getColorTextureRegion(Color.RED, OPEN_MENU_BUTTON_WIDTH, OPEN_MENU_BUTTON_HEIGHT)));
openCloseButton = new Button(new TextureRegionDrawable(ApplicationAtlasManager.getInstance().getColorTextureRegion(Color.RED)));
openCloseButton.getStyle().up.setMinWidth(OPEN_MENU_BUTTON_WIDTH); // temprorary button size
openCloseButton.getStyle().up.setMinHeight(OPEN_MENU_BUTTON_HEIGHT); // temprorary button size
openCloseButton.addAction(Actions.alpha(0));
openCloseButton.align(Align.topRight);
openCloseButton.addListener(new ClickListener() {
......
......@@ -39,6 +39,14 @@ public class MainMenuContainer extends Group {
});
}
@Override
protected void sizeChanged() {
super.sizeChanged();
if(screenDimmer!= null) {
screenDimmer.setSize(getWidth(), getHeight());
}
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
......
package cz.nic.tablexia.menu;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import cz.nic.tablexia.loader.TablexiaAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
/**
......@@ -12,25 +11,12 @@ import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
*
* @author Matyáš Latner
*/
public class MainMenuDimmer extends Actor {
public class MainMenuDimmer extends Image {
private static final float MAIN_MENU_DIMMER_MAX_ALPHA = 0.7f;
public static final Color DIMMER_COLOR = Color.BLACK;
private final TextureRegion texture;
public static final Color DIMMER_COLOR = TablexiaAtlasManager.COLOR_OVERLAY;
public MainMenuDimmer(float width, float height) {
setBounds(0, 0, width, height);
texture = ApplicationAtlasManager.getInstance().getColorTextureRegion(DIMMER_COLOR, (int)width, (int)height);
}
@Override
public void draw(Batch batch, float parentAlpha) {
Color color = getColor();
color.a = color.a * MAIN_MENU_DIMMER_MAX_ALPHA;
batch.setColor(getColor());
batch.draw(texture, 0, 0);
batch.setColor(Color.WHITE);
super(ApplicationAtlasManager.getInstance().getColorTextureRegion(DIMMER_COLOR));
setSize(width, height);
}
}
......@@ -557,10 +557,6 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
return ApplicationAtlasManager.getInstance().getColorTextureRegion(color);
}
public TextureRegion getColorTextureRegion(Color color, int width, int height) {
return ApplicationAtlasManager.getInstance().getColorTextureRegion(color, width, height);
}
public Sound getSound(String soundName) {
return soundManager.getSound(createLocalAssetPath(soundName));
}
......
......@@ -49,7 +49,9 @@ public class PreferencesScreen extends AbstractTablexiaScreen<Void> {
// Languages SelectBox
ScrollPane.ScrollPaneStyle scrollPaneStyle = new ScrollPane.ScrollPaneStyle();
scrollPaneStyle.background = new TextureRegionDrawable(getColorTextureRegion(Color.GRAY, 50, 50));
scrollPaneStyle.background = new TextureRegionDrawable(getColorTextureRegion(Color.GRAY));
scrollPaneStyle.background.setMinWidth(50); // temporary size
scrollPaneStyle.background.setMinHeight(50);
List.ListStyle listStyle = new List.ListStyle();
listStyle.selection = new TextureRegionDrawable(getColorTextureRegion(Color.GRAY));
listStyle.font = font;
......@@ -57,7 +59,9 @@ public class PreferencesScreen extends AbstractTablexiaScreen<Void> {
selectBoxStyle.font = font;
selectBoxStyle.scrollStyle = scrollPaneStyle;
selectBoxStyle.listStyle = listStyle;
selectBoxStyle.background = new TextureRegionDrawable(getColorTextureRegion(Color.GRAY, 50, 50));
selectBoxStyle.background = new TextureRegionDrawable(getColorTextureRegion(Color.GRAY));
selectBoxStyle.background.setMinWidth(50); // temporary size
selectBoxStyle.background.setMinHeight(50);
SelectBox<TablexiaSettings.LocaleDefinition> languagesSelectBox = new SelectBox<TablexiaSettings.LocaleDefinition>(selectBoxStyle);
languagesSelectBox.setItems(TablexiaSettings.LocaleDefinition.values());
languagesSelectBox.setSelected(TablexiaSettings.getInstance().getLocaleDefinition());
......
......@@ -40,23 +40,34 @@ public class ViewPager extends ScrollPane {
private void setup() {
content = new Table();
super.setWidget(content);
content.setSize(100,100);
content.setSize(100, 100);
content.defaults().space(0);
//setClamp(false);
//setScrollingDisabled(false, true);
setScrollingDisabled(false, true);
setFlingTime(0.1f);
}
@Override
public void setSize(float width, float height) {
super.setSize(width, height);
private void fixChildrenSizes() {
if (content != null) {
for (Actor a : content.getChildren()) {
a.setSize(width, height);
a.setSize(getWidth(), getHeight());
}
}
}
@Override
public void setSize(float width, float height) {
super.setSize(width, height);
fixChildrenSizes();
}
@Override
public void setBounds(float x, float y, float width, float height) {
super.setBounds(x, y, width, height);
fixChildrenSizes();
}
public void addPages(Actor... pages) {
for (Actor page : pages) {
content.add(page).expandY().fillY();
......@@ -137,7 +148,6 @@ public class ViewPager extends ScrollPane {
* @param page
*/
public void scrollToPage(int page) {
// TODO cleanup
if (content.getChildren().size <= page) {
throw new IllegalArgumentException("Page index " + page + " out of bounds");
}
......
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