Skip to content
Snippets Groups Projects
Commit 89e2f4b0 authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko
Browse files

#559 Changed TablexiaProgressBar class to support ninePatch files. Added event...

#559 Changed TablexiaProgressBar class to support ninePatch files. Added event to refresh mainMenu progressBars percents.
parent 1ae1ce7f
Branches feature-wallofgames
No related tags found
No related merge requests found
core/assets/common/_global/application/ui/progressbar_background.9.png

223 B | W: | H:

core/assets/common/_global/application/ui/progressbar_background.9.png

223 B | W: | H:

core/assets/common/_global/application/ui/progressbar_background.9.png
core/assets/common/_global/application/ui/progressbar_background.9.png
core/assets/common/_global/application/ui/progressbar_background.9.png
core/assets/common/_global/application/ui/progressbar_background.9.png
  • 2-up
  • Swipe
  • Onion skin
core/assets/common/screen/officemenu/gfx/wallofgames/progressbar_background.9.png

144 B | W: | H:

core/assets/common/screen/officemenu/gfx/wallofgames/progressbar_background.9.png

162 B | W: | H:

core/assets/common/screen/officemenu/gfx/wallofgames/progressbar_background.9.png
core/assets/common/screen/officemenu/gfx/wallofgames/progressbar_background.9.png
core/assets/common/screen/officemenu/gfx/wallofgames/progressbar_background.9.png
core/assets/common/screen/officemenu/gfx/wallofgames/progressbar_background.9.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -51,7 +51,6 @@ import cz.nic.tablexia.loader.application.ApplicationInternalSoundManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.AbstractMenu;
import cz.nic.tablexia.menu.main.MainMenu;
import cz.nic.tablexia.menu.user.UserMenu;
import cz.nic.tablexia.model.UserDAO;
import cz.nic.tablexia.model.UserDifficultySettingsDAO;
import cz.nic.tablexia.model.game.GameDAO;
......@@ -1340,7 +1339,6 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
GameDAO.endGame(game);
Log.info(getClass(), "[DB] Ended game: " + game);
ApplicationBus.getInstance().publishAsync(new StartIncrementalSynchronizationEvent(getSelectedUser().getId()));
ApplicationBus.getInstance().publishAsync(new UserMenu.RefreshUserMenu());
}
private void forceGameEnd(GameResult gameResult) {
......
......@@ -9,6 +9,7 @@ import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.game.GameMenuItemGroup;
import cz.nic.tablexia.model.game.GameDAO;
import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.User;
......@@ -367,7 +368,9 @@ public class UserRankManager {
}
});
rankComputeDataMap.put(user.getId(), rankComputeData);
ApplicationBus.getInstance().post(new GameMenuItemGroup.RefreshMainMenuProgressBarsEvent()).asynchronously();
//This isn't first refresh for the user and lastRankUpTime changed...
if(!firstRefresh && lastRankUpTime < rankComputeData.getLastRankUp()) {
//User has ranked up since the last time we checked....
......
......@@ -24,7 +24,7 @@ import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.menu.IMenuItem;
import cz.nic.tablexia.util.ui.TablexiaLabel;
import cz.nic.tablexia.util.ui.TablexiaProgressBar2;
import cz.nic.tablexia.util.ui.TablexiaProgressBar;
/**
* Created by Matyáš Latner.
......@@ -46,14 +46,14 @@ public class GameMenuItemGroup extends Container<Table> {
private static final float CONTAINER_BOTTOM_PADDING = 4f;
private static final float LEFT_PADDING = 5f;
private final Table layoutContainer;
private final Image arrowIcon;
private final Image restartIcon;
private final Cell<Image> iconCell;
private final Image highliter;
private NinePatchDrawable background;
private TextureRegionDrawable highlitedBackground;
private TablexiaProgressBar2 tablexiaProgressBar2;
private final Table layoutContainer;
private final Image arrowIcon;
private final Image restartIcon;
private final Cell<Image> iconCell;
private final Image highliter;
private NinePatchDrawable background;
private TextureRegionDrawable highlitedBackground;
private TablexiaProgressBar tablexiaProgressBar;
private Class<? extends AbstractTablexiaGame> abstractTablexiaGameClass;
private GameDefinition gameDefinition;
......@@ -99,8 +99,12 @@ public class GameMenuItemGroup extends Container<Table> {
TablexiaLabel descriptionLabel = new TablexiaLabel(menuItem.getDescription(), new TablexiaLabel.TablexiaLabelStyle(DESCRIPTION_FONT_TYPE, DESCRIPTION_FONT_COLOR));
descriptionLabel.setWrap(true);
tablexiaProgressBar2 = new TablexiaProgressBar2(ApplicationAtlasManager.getInstance().getPatch(ApplicationAtlasManager.PROGRESS_BAR_BACKGROUND_9PATCH),ApplicationAtlasManager.getInstance().getTextureRegion(ApplicationAtlasManager.PROGRESS_BAR_FILL));
tablexiaProgressBar2.setVisible(false);
tablexiaProgressBar = new TablexiaProgressBar(ApplicationAtlasManager.getInstance().getPatch(ApplicationAtlasManager.PROGRESS_BAR_BACKGROUND_9PATCH),
ApplicationAtlasManager.getInstance().getTextureRegion(ApplicationAtlasManager.PROGRESS_BAR_FILL));
if (TablexiaSettings.getInstance().getSelectedUser()!=null){
updateProgressBars();
}
Table labelsContainer = new Table();
labelsContainer.add(titleLabel).align(Align.left);
labelsContainer.row();
......@@ -122,7 +126,7 @@ public class GameMenuItemGroup extends Container<Table> {
changeIconToArrow();
labelsContainer.row();
labelsContainer.add(tablexiaProgressBar2);
labelsContainer.add(tablexiaProgressBar);
// highliter size
highliter.getDrawable().setMinWidth(5);
......@@ -158,6 +162,11 @@ public class GameMenuItemGroup extends Container<Table> {
private void setPressed() {
layoutContainer.setBackground(highlitedBackground);
}
private void updateProgressBars(){
UserRankManager.RankProgress rankProgress = UserRankManager.getInstance().getGameRankProgress(TablexiaSettings.getInstance().getSelectedUser(), gameDefinition);
tablexiaProgressBar.setPercent(rankProgress.getPercentDone());
}
@Handler
public void onScreenChangedEvent(TablexiaApplication.ScreenChangedEvent screenChangedEvent) {
......@@ -173,9 +182,19 @@ public class GameMenuItemGroup extends Container<Table> {
@Handler
public void handleSelectedUserEvent(TablexiaSettings.SelectedUserEvent selectedUserEvent) {
if (selectedUserEvent.isUserSelected()) {
UserRankManager.RankProgress rankProgress = UserRankManager.getInstance().getGameRankProgress(TablexiaSettings.getInstance().getSelectedUser(), gameDefinition);
tablexiaProgressBar2.setCurrentPercent(rankProgress.getPercentDone());
tablexiaProgressBar2.setVisible(true);
updateProgressBars();
}
}
@Handler
public void handleRefreshMainMenuProgressBarsEvent(RefreshMainMenuProgressBarsEvent progressBarsEvent){
if (TablexiaSettings.getInstance().getSelectedUser()!=null){
updateProgressBars();
}
}
public static class RefreshMainMenuProgressBarsEvent implements ApplicationBus.ApplicationEvent {
}
}
......@@ -16,13 +16,12 @@ import cz.nic.tablexia.TablexiaApplication;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.common.TablexiaRandom;
import cz.nic.tablexia.game.ranksystem.UserRankManager;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.screen.gamemenu.OfficeMenuAssets;
import cz.nic.tablexia.screen.gamemenu.gamepages.GamePageScreen;
import cz.nic.tablexia.util.ui.TablexiaLabel;
import cz.nic.tablexia.util.ui.TablexiaProgressBar2;
import cz.nic.tablexia.util.ui.TablexiaProgressBar;
/**
* Created by Vitaliy Vashchenko on 24.8.16.
......@@ -158,11 +157,11 @@ public class WallOfGames extends Group {
UserRankManager.RankProgress rankProgress = UserRankManager.getInstance().getGameRankProgress(TablexiaSettings.getInstance().getSelectedUser(), gameIconDefinition.gameDefinition);
TablexiaProgressBar2 tablexiaProgressBar2 = new TablexiaProgressBar2(resourcesRetriever.getNinePatch(OfficeMenuAssets.WALL_OF_GAMES_PROGRESS_BAR_BACKGROUND), resourcesRetriever.getTextureRegion(OfficeMenuAssets.WALL_OF_GAMES_PROGRESS_BAR_FOREGROUND));
tablexiaProgressBar2.setPosition(gameIconTablexiaButton.getX() + gameIconTablexiaButton.getWidth() /2f - tablexiaProgressBar2.getWidth()/2,
gameNameLabel.getY() - tablexiaProgressBar2.getHeight() - PROGRESS_BAR_TOP_PADDING);
tablexiaProgressBar2.setCurrentPercent(rankProgress.getPercentDone());
buttonOverlayLayer.addActor(tablexiaProgressBar2);
TablexiaProgressBar tablexiaProgressBar = new TablexiaProgressBar(resourcesRetriever.getNinePatch(OfficeMenuAssets.WALL_OF_GAMES_PROGRESS_BAR_BACKGROUND), resourcesRetriever.getTextureRegion(OfficeMenuAssets.WALL_OF_GAMES_PROGRESS_BAR_FOREGROUND));
tablexiaProgressBar.setPosition(gameIconTablexiaButton.getX() + gameIconTablexiaButton.getWidth() /2f - tablexiaProgressBar.getWidth()/2,
gameNameLabel.getY() - tablexiaProgressBar.getHeight() - PROGRESS_BAR_TOP_PADDING);
tablexiaProgressBar.setPercent(rankProgress.getPercentDone());
buttonOverlayLayer.addActor(tablexiaProgressBar);
}
buttonsGroup.addActor(buttonOverlayLayer);
......
package cz.nic.tablexia.util.ui;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
public class TablexiaProgressBar extends Actor {
public class TablexiaProgressBar extends Group {
private float fillOffsetX;
private float fillOffsetY;
......@@ -13,28 +15,54 @@ public class TablexiaProgressBar extends Actor {
private float visualPercent;
private float speed;
private boolean smooth;
private TextureRegion progressbar;
private boolean patchOffset = false;
private static final int DEFAULT_PATH_WIDTH = 80;
private static final int DEFAULT_PATCH_HEIGHT = 8;
private static final int DEFAULT_OFFSET_X = 1;
private static final int DEFAULT_OFFSET_Y = 1;
private Image progressbar;
private TextureRegion fill;
public TablexiaProgressBar(NinePatch progressbarPath, TextureRegion fill){
this(progressbarPath, fill, DEFAULT_PATH_WIDTH, DEFAULT_PATCH_HEIGHT);
}
public TablexiaProgressBar(NinePatch progressbarPath, TextureRegion fill, int width, int height){
this.progressbar = new Image(progressbarPath);
this.progressbar.setSize(width, height);
this.fill = fill;
patchOffset = true;
setWidth(width);
}
public TablexiaProgressBar(TextureRegion progressbar, TextureRegion fill) {
this.progressbar = progressbar;
this(new Image(progressbar), fill, progressbar.getRegionWidth());
}
public TablexiaProgressBar(Image progressbarImage, TextureRegion fill, int width){
this.progressbar = progressbarImage;
this.fill = fill;
setWidth(progressbar.getRegionWidth());
setWidth(width);
}
@Override
public void setWidth(float width) {
float height = width * (progressbar.getRegionHeight() / (float) progressbar.getRegionWidth());
float height = width * (progressbar.getHeight() / (float) progressbar.getWidth());
super.setSize(width, height);
float scale_x = width / progressbar.getRegionWidth();
float scale_y = height / progressbar.getRegionHeight();
fillOffsetX = (this.progressbar.getRegionWidth() - this.fill.getRegionWidth()) / 2 * scale_x;
fillOffsetY = (this.progressbar.getRegionHeight() - this.fill.getRegionHeight()) / 2 * scale_y;
if (!patchOffset){
float scale_x = getWidth() / progressbar.getWidth();
float scale_y = getHeight() / progressbar.getHeight();
fillOffsetX = (this.progressbar.getWidth() - this.fill.getRegionWidth()) / 2 * scale_x;
fillOffsetY = (this.progressbar.getHeight() - this.fill.getRegionHeight()) / 2 * scale_y;
}else {
fillOffsetX = DEFAULT_OFFSET_X;
fillOffsetY = DEFAULT_OFFSET_Y;
}
}
@Override
......@@ -102,8 +130,8 @@ public class TablexiaProgressBar extends Actor {
);
fill.setRegionWidth(origRegionWidth);
}
batch.draw(progressbar, getX(), getY(), getWidth(), getHeight());
progressbar.getDrawable().draw(batch, getX(), getY(), getWidth(), getHeight());
batch.setColor(batch.getColor().r, batch.getColor().g, batch.getColor().b, origAlpha);
}
......
package cz.nic.tablexia.util.ui;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
/**
* Created by Vitaliy Vashchenko on 30.9.16.
*/
// TODO: 4.10.16 refactor name
public class TablexiaProgressBar2 extends Group {
Image background;
TextureRegion foregroundRegion;
private float currentPercent = 0f;
private TextureRegion currPercentForegroundRegion;
private static final int PATCH_PAD = 2;
private static final int DEFAULT_WIDTH = 100;
private static final int DEFAULT_HEIGHT = 8;
public TablexiaProgressBar2(NinePatch backgroundPatch, TextureRegion foregroundRegion) {
this(DEFAULT_WIDTH, DEFAULT_HEIGHT, 0f, backgroundPatch, foregroundRegion);
}
public TablexiaProgressBar2(int width, int height, float currentPercent, NinePatch backgroundPatch, TextureRegion foregroundRegion) {
this.background = new Image(backgroundPatch);
this.foregroundRegion = foregroundRegion;
this.currentPercent = currentPercent;
initBar(width, height);
}
public void setCurrentPercent(float currentPercent) {
this.currentPercent = MathUtils.clamp(currentPercent, 0, 1);
currPercentForegroundRegion = new TextureRegion(foregroundRegion, 0, 0, (int) (foregroundRegion.getRegionWidth() * currentPercent), foregroundRegion.getRegionHeight());
}
private void initBar(float width, float height) {
addActor(background);
setSize(width, height);
currPercentForegroundRegion = new TextureRegion(foregroundRegion, 0, 0, (int) (foregroundRegion.getRegionWidth() * currentPercent), foregroundRegion.getRegionHeight());
}
@Override
public void draw(Batch batch, float parentAlpha) {
background.getDrawable().draw(batch, (int)getX(), (int)getY(), (int)getWidth(), (int)getHeight());
batch.draw(currPercentForegroundRegion, (int)getX() + PATCH_PAD, (int)getY() + PATCH_PAD,
((int)getWidth() - PATCH_PAD * 2) * currentPercent,
(int)getHeight() - PATCH_PAD * 2);
}
}
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