Commit 3abe360e authored by Matyáš Latner's avatar Matyáš Latner

After merge fix: reworked sync request dialog

parent 7fdfa54c
......@@ -7,7 +7,7 @@ system_confirm=Ano
system_decline=Ne
system_exit=Konec
system_retry=Znovu
system_confirm=Potvrdit
system_confirm2=Potvrdit
zipassetloader_error=Chyba: Nemohu stáhnout dodatečná data! Zkontrolujte prosím připojení k internetu.
zipassetloader_download_request: Právě využíváte mobilní připojení k internetu. Tablexia potřebuje stáhnout ~150 MB herních dat. Přejete si je stáhnout nyní ?
......@@ -159,3 +159,5 @@ user_consecutivelyallgames2stars=Hlídací pes
user_consecutivelyallgames2stars_description=Za všechny hry po sobě na střední obtížnost a tři poháry
user_consecutivelyallgames3stars=Detektivní šelma
user_consecutivelyallgames3stars_description=Za všechny hry po sobě na těžkou obtížnost a tři poháry
sync_request_dialog_text=Zadej číslo průkazu:
......@@ -3,10 +3,11 @@ language_czech=Tschechisch
language_slovak=Slowakisch
language_german=Deutsch
system_confirm=Ja
system_decline=Nein
system_exit=Verlassen
system_retry=Wieder
system_confirm=Bestätigen
system_confirm2=Bestätigen
zipassetloader_error=Fehler: Nicht, um zusätzliche Daten Download! Bitte überprüfen Sie Ihre Internetverbindung.
zipassetloader_download_request: [DE - Upravit v application_de.properities] Právě využíváte mobilní připojení k internetu. Tablexia potřebuje stáhnout ~150 MB herních dat. Přejete si je stáhnout nyní ?
......@@ -157,3 +158,5 @@ user_consecutivelyallgames2stars=Wachhund
user_consecutivelyallgames2stars_description=Für alle Spiele nacheinander auf der mittleren Stufe mit drei Pokalen
user_consecutivelyallgames3stars=Als DetektivIn ein Raubtier
user_consecutivelyallgames3stars_description=Für alle Spiele nacheinander auf der schwierigen Stufe mit drei Pokalen
sync_request_dialog_text=Trage deine Ausweisnummer ein:
......@@ -3,10 +3,11 @@ language_czech=Čeština
language_slovak=Slovenčina
language_german=Nemčina
system_confirm=Áno
system_decline=Nie
system_exit=Koniec
system_retry=Znovu
system_confirm=Potvrdiť
system_confirm2=Potvrdiť
zipassetloader_error=Chyba: Nemôžem stiahnuť dodatočná dáta! Skontrolujte prosím pripojenie k internetu.
zipassetloader_download_request: [SK upravit v application_sk.properties] Právě využíváte mobilní připojení k internetu. Tablexia potřebuje stáhnout ~150 MB herních dat. Přejete si je stáhnout nyní ?
......@@ -158,3 +159,5 @@ user_consecutivelyallgames2stars=Strážný pes
user_consecutivelyallgames2stars_description=Za všetky hry po sebe na strednú obtiažnosť a tri poháre.
user_consecutivelyallgames3stars=Detektívna šelma
user_consecutivelyallgames3stars_description=Za všetky hry po sebe na ťažkú obtiažnosť a tri poháre.
sync_request_dialog_text=Zadaj číslo preukazu:
......@@ -87,6 +87,8 @@ public class ApplicationTextManager extends TablexiaDataManager<I18NBundle> impl
public static final String GAME_AVERAGE_SCORE_ERROR = "game_averagescore_error";
public static final String GAME_AVERAGE_SCORE_DURATION = "game_averagescore_duration";
public static final String GAME_QUIT_QUESTION = "game_quit_question";
public static final String SYNC_REQUEST_DIALOG_TEXT = "sync_request_dialog_text";
}
private static final String APPLICATION_TEXT_RESOURCE_FILE = "text/application/application";
......
package cz.nic.tablexia.menu.user;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import net.engio.mbassy.listener.Handler;
......@@ -26,7 +20,6 @@ import cz.nic.tablexia.TablexiaApplication;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.event.DeleteUserSynchronizationEvent;
import cz.nic.tablexia.bus.event.MenuControlEvent;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.loader.application.ApplicationInternalSoundManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.AbstractMenu;
......@@ -38,10 +31,16 @@ import cz.nic.tablexia.sync.work.DownloadUser;
import cz.nic.tablexia.sync.work.PushDataToServer;
import cz.nic.tablexia.sync.work.SyncWork;
import cz.nic.tablexia.util.ui.ClickListenerWithSound;
import cz.nic.tablexia.util.ui.TablexiaButton;
import cz.nic.tablexia.util.ui.dialog.TwoButtonDialog;
import cz.nic.tablexia.util.ui.dialog.text.DialogTextContent;
import cz.nic.tablexia.util.ui.dialog_new.TablexiaComponentDialogFactory;
import cz.nic.tablexia.util.ui.dialog_new.components.AdaptiveSizeDialogComponent;
import cz.nic.tablexia.util.ui.dialog_new.components.CenterPositionDialogComponent;
import cz.nic.tablexia.util.ui.dialog_new.components.DimmerDialogComponent;
import cz.nic.tablexia.util.ui.dialog_new.components.FixedSpaceContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog_new.components.ResizableSpaceContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog_new.components.TextContentDialogComponent;
import cz.nic.tablexia.util.ui.dialog_new.components.TextFiledDialogComponent;
import cz.nic.tablexia.util.ui.dialog_new.components.ViewportMaximumSizeComponent;
import cz.nic.tablexia.util.ui.dialog_new.components.YesNoButtonContentDialogComponent;
/**
* UserMenu container
......@@ -54,6 +53,11 @@ public class UserMenu extends AbstractMenu {
private static final boolean MENU_SCREEN_PAUSE = false;
private static final int USER_ITEM_HEIGHT = 80;
private static final int SYNC_REQUEST_DIALOG_WIDTH = 450;
private static final int SYNC_REQUEST_DIALOG_HEIGHT = 300;
private static final String SYNC_REQUEST_DIALOG_PLACEHOLDER_TEXT = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
private static final int SYNC_REQUEST_DIALOG_MAXIMUM_LENGTH = 40;
private List<User> users;
public UserMenu(Float width, Float height) {
......@@ -136,12 +140,37 @@ public class UserMenu extends AbstractMenu {
});
menuItemsLayout.addActor(userMenuNewSelectBoxItemGroup);
final SyncDialog dialog = new SyncDialog(300, 300, 500, 300);
final UserMenuDownloadSelectBoxItemGroup userDownload = new UserMenuDownloadSelectBoxItemGroup() {
@Override
public void performAction() {
dialog.show(getStage());
final TextFiledDialogComponent textFiledDialogComponent = new TextFiledDialogComponent(SYNC_REQUEST_DIALOG_MAXIMUM_LENGTH, SYNC_REQUEST_DIALOG_PLACEHOLDER_TEXT);
TablexiaComponentDialogFactory.getInstance().createDialog(
new CenterPositionDialogComponent(),
new DimmerDialogComponent(),
new ViewportMaximumSizeComponent(),
new AdaptiveSizeDialogComponent(),
new ResizableSpaceContentDialogComponent(),
new TextContentDialogComponent(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.SYNC_REQUEST_DIALOG_TEXT)),
new ResizableSpaceContentDialogComponent(),
textFiledDialogComponent,
new ResizableSpaceContentDialogComponent(),
new YesNoButtonContentDialogComponent(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
DownloadUser syncWork = new DownloadUser(textFiledDialogComponent.getText());
syncWork.registerListener(new SyncWork.RestSyncListener() {
@Override
public void onSuccess(User user) {
ApplicationBus.getInstance().post(new RefreshUserMenu()).asynchronously();
}
});
RestSynchronizationService.doSyncWork(syncWork);
}
}),
new FixedSpaceContentDialogComponent()
).show(SYNC_REQUEST_DIALOG_WIDTH, SYNC_REQUEST_DIALOG_HEIGHT);
}
@Override
......@@ -198,60 +227,4 @@ public class UserMenu extends AbstractMenu {
public static class RefreshUserMenu implements ApplicationBus.ApplicationEvent {
}
private class SyncDialog extends TwoButtonDialog {
private TextField textField;
public SyncDialog(float x, float y, float width, float height) {
super(x, y, width, height, BackGroundType.DIALOG_RECTANGLE, new DialogTextContent("Download user"), TablexiaButton.ButtonType.GREEN, TablexiaButton.ButtonType.RED, "ok", "cancel");
textField = new TextField("", new TextField.TextFieldStyle(ApplicationFontManager.getInstance().getFont(ApplicationFontManager.FontType.ROBOTO_BOLD_16), Color.BLACK, createCursorForTextField(), null, createBackground()));
textField.setWidth(250);
}
@Override
protected void prepareContent() {
super.prepareContent();
getContentTable().row();
getContentTable().add(textField).fillX();
}
@Override
protected void leftButtonAction() {
DownloadUser syncWork = new DownloadUser(textField.getText());
syncWork.registerListener(new SyncWork.RestSyncListener() {
@Override
public void onSuccess(User user) {
ApplicationBus.getInstance().post(new RefreshUserMenu()).asynchronously();
}
});
RestSynchronizationService.doSyncWork(syncWork);
hide();
}
@Override
protected void rightButtonAction() {
hide();
}
private Drawable createCursorForTextField() {
Pixmap pixmap = new Pixmap(1, 16, Pixmap.Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.drawLine(0, 0, 0, 16);
Texture texture = new Texture(pixmap);
pixmap.dispose();
Image img = new Image(texture);
return img.getDrawable();
}
private Drawable createBackground() {
Pixmap pixmap = new Pixmap(250, 16, Pixmap.Format.RGBA8888);
pixmap.setColor(Color.BLUE);
pixmap.drawRectangle(0, 0, 250, 16);
Texture texture = new Texture(pixmap);
pixmap.dispose();
Image img = new Image(texture);
return img.getDrawable();
}
}
}
......@@ -9,6 +9,7 @@ import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.utils.Align;
/**
* Some older Android keyboards have bug with backspace not working after pressing enter to stop editing
......@@ -18,13 +19,21 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextField;
*/
public class TextFieldWithPlaceholder extends TextField {
private static final Color DEFAULT_PLACEHOLDER_COLOR = Color.GRAY;
private static final int DEFAULT_PLACEHOLDER_ALIGN = Align.left;
private Label placeholder;
public TextFieldWithPlaceholder(String text, TextFieldStyle style, String placeholderText) {
this(text, style, placeholderText, DEFAULT_PLACEHOLDER_ALIGN);
}
public TextFieldWithPlaceholder(String text, TextFieldStyle style, String placeholderText, int placeholderAlign) {
super(text, style);
placeholder = new Label(placeholderText, new Label.LabelStyle(style.font, Color.GRAY));
placeholder = new Label(placeholderText, preparePlaceholderStyle(style));
placeholder.setTouchable(Touchable.disabled);
placeholder.setAlignment(placeholderAlign);
refreshPlaceholderState();
}
......@@ -58,6 +67,14 @@ public class TextFieldWithPlaceholder extends TextField {
}
}
@Override
public void setStyle(TextFieldStyle textFieldStyle) {
if (placeholder != null) {
placeholder.setStyle(preparePlaceholderStyle(textFieldStyle));
}
super.setStyle(textFieldStyle);
}
@Override
public void setText (String str) {
super.setText(str);
......@@ -69,6 +86,10 @@ public class TextFieldWithPlaceholder extends TextField {
addListener(new TextFieldWithPlaceholderClickListener());
}
private Label.LabelStyle preparePlaceholderStyle(TextFieldStyle textFieldStyle) {
return new Label.LabelStyle(textFieldStyle.font, DEFAULT_PLACEHOLDER_COLOR);
}
public class TextFieldWithPlaceholderClickListener extends InputListener {
@Override
......
......@@ -11,9 +11,9 @@ import cz.nic.tablexia.util.ui.ComponentScaleUtil;
*/
public class AdaptiveSizeDialogComponent extends TablexiaDialogComponentAdapter {
private static final float DIALOG_SCALE_DENSITY_THRESHOLD = 2.15f;
public static final float DIALOG_SCALE_RATIO = 2.15f;
private boolean isScaled;
private boolean isScaled;
public AdaptiveSizeDialogComponent() {
this.isScaled = false;
......@@ -44,8 +44,8 @@ public class AdaptiveSizeDialogComponent extends TablexiaDialogComponentAdapter
if (ComponentScaleUtil.isUnderThreshold()) {
if (!isScaled) {
width = getDialog().getOriginalWidth() * DIALOG_SCALE_DENSITY_THRESHOLD;
height = getDialog().getOriginalHeight() * DIALOG_SCALE_DENSITY_THRESHOLD;
width = getDialog().getOriginalWidth() * DIALOG_SCALE_RATIO;
height = getDialog().getOriginalHeight() * DIALOG_SCALE_RATIO;
isScaled = true;
}
} else {
......
package cz.nic.tablexia.util.ui.dialog_new.components;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.Align;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.util.ui.ComponentScaleUtil;
import cz.nic.tablexia.util.ui.TextFieldWithPlaceholder;
/**
* Created by Matyáš Latner.
*/
public class TextFiledDialogComponent extends TablexiaDialogComponentAdapter {
private static final Color DEFAULT_FONT_COLOR = Color.BLACK;
private static final ApplicationFontManager.FontType DEFAULT_FONT_TYPE = ApplicationFontManager.FontType.ROBOTO_REGULAR_20;
private static final int FONT_SIZE_RESIZE_THRESHOLD_STEP = 25;
private static final String DEFAULT_PLACEHOLDER_TEXT = "";
private static final int DEFAULT_TEXTFIELD_ALIGN = Align.center;
private boolean isScaled;
private final Color fontColor;
private Integer maximumLength;
private String placeholderText;
private ApplicationFontManager.FontType fontType;
private ApplicationFontManager.FontType actualFontType;
private TextFieldWithPlaceholder uuidTextField;
private Cell content;
public TextFiledDialogComponent() {
this(null, DEFAULT_PLACEHOLDER_TEXT, DEFAULT_FONT_TYPE, DEFAULT_FONT_COLOR);
}
public TextFiledDialogComponent(String placeholderText) {
this(null, placeholderText);
}
public TextFiledDialogComponent(Integer maximumLength, String placeholderText) {
this(maximumLength, placeholderText, DEFAULT_FONT_TYPE, DEFAULT_FONT_COLOR);
}
public TextFiledDialogComponent(Integer maximumLength, String placeholderText, ApplicationFontManager.FontType fontType, Color fontColor) {
this.placeholderText = placeholderText;
this.fontType = fontType;
this.actualFontType = fontType;
this.fontColor = fontColor;
this.maximumLength = maximumLength;
}
public String getText() {
return uuidTextField.getText();
}
@Override
public void prepareContent(Cell content) {
this.content = content;
uuidTextField = prepareTextField(placeholderText);
content.setActor(uuidTextField).fillX();
}
@Override
public void adaptiveSizeThresholdChanged() {
if (ComponentScaleUtil.isUnderThreshold()) {
if (!isScaled) {
actualFontType = ApplicationFontManager.FontType.getProximateFontTypeForSize(fontType.getSize() + FONT_SIZE_RESIZE_THRESHOLD_STEP, fontType.isBold(), fontType.isFiltering());
isScaled = true;
}
} else {
if (isScaled) {
actualFontType = fontType;
isScaled = false;
}
}
uuidTextField.setStyle(prepareTextFieldStyle());
content.width(getDialog().getWidth());
}
private TextFieldWithPlaceholder prepareTextField(String placeholderText) {
TextFieldWithPlaceholder fieldWithPlaceholder = new TextFieldWithPlaceholder("", prepareTextFieldStyle(), placeholderText, DEFAULT_TEXTFIELD_ALIGN);
if (maximumLength != null) {
fieldWithPlaceholder.setMaxLength(maximumLength);
}
fieldWithPlaceholder.setAlignment(DEFAULT_TEXTFIELD_ALIGN);
return fieldWithPlaceholder;
}
public TextField.TextFieldStyle prepareTextFieldStyle() {
return new TextField.TextFieldStyle(ApplicationFontManager.getInstance().getFont(actualFontType), fontColor, createCursorForTextField(), null, null);
}
private Drawable createCursorForTextField() {
Texture texture = ApplicationAtlasManager.getInstance().getColorTexture(Color.BLACK);
return new Image(texture).getDrawable();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment