Commit 2262592d authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko

#58 Long press delete user

parent 817bf37d
......@@ -19,6 +19,9 @@ mainmenu_screendebug=Debug Screen
mainmenu_panorama=Panorama
usermenu_newuser=+ Nový detektiv
usermenu_deleteuser= Smazat uživatele
usermenu_dialog_yes = Ano
usermenu_dialog_no = Ne
preloader_title=Jak hrát?
confirm_button=Rozumím
......
......@@ -20,6 +20,9 @@ mainmenu_panorama=Panorama
usermenu_newuser=+ Neuer Detektiv
usermenu_deleteuser=Benutzer löschen
usermenu_dialog_yes=Ja
usermenu_dialog_no=Nein
preloader_title=Wie spielt man?
confirm_button=Ich verstehe
......
......@@ -20,6 +20,9 @@ mainmenu_panorama=Panorama
usermenu_newuser=+ Nový detektív
usermenu_deleteuser=Zmazať užívateľa ?
usermenu_dialog_yes=Áno
usermenu_dialog_no=Nie
preloader_title=Ako hrať?
confirm_button=Rozumiem
......
......@@ -25,6 +25,10 @@ public class ApplicationTextManager extends TablexiaDataManager<I18NBundle> impl
public static final String VICTORYSCREEN_NEW_TROPHY = "victoryscreen_new_trophy";
public static final String USERMENU_NEWUSER = "usermenu_newuser";
public static final String USERMENU_DELETE_USER = "usermenu_deleteuser";
public static final String USERMENU_DIALOGUE_YES = "usermenu_dialog_yes";
public static final String USERMENU_DIALOGUE_NO = "usermenu_dialog_no";
public static final String PRELOADER_TITLE = "preloader_title";
public static final String CONFIRM_BUTTON = "confirm_button";
......
......@@ -3,7 +3,10 @@ package cz.nic.tablexia.menu.main.user;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import net.engio.mbassy.listener.Handler;
......@@ -16,11 +19,16 @@ import cz.nic.tablexia.TablexiaApplication;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.user.UserMenuNewSelectBoxItemGroup;
import cz.nic.tablexia.menu.user.UserMenuSelectBoxItemGroup;
import cz.nic.tablexia.model.User;
import cz.nic.tablexia.screen.createuser.PanoramaScreen;
import cz.nic.tablexia.util.ui.AbstractTablexiaSelectBox;
import cz.nic.tablexia.util.ui.ClickListenerWithSound;
import cz.nic.tablexia.util.ui.TablexiaButton;
import cz.nic.tablexia.util.ui.dialog.DialogFactory;
import cz.nic.tablexia.util.ui.dialog.TextDialog;
/**
* Created by Matyáš Latner.
......@@ -45,6 +53,11 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserS
private static final Color FOREGROUND_COLOR = new Color(0.322f, 0.278f, 0.255f, 1f);
private static final int ITEMS_OVERLAP_SIZE = 1;
private static final int BUTTON_OK_ID = 0;
private static final int BUTTON_CANCEL_ID = 1;
private static final int BUTTON_WIDTH = 100;
private static final int BUTTON_SPACE = 15;
private TextureRegionDrawable triangle;
private TextureRegionDrawable selector;
......@@ -54,6 +67,50 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserS
// TODO add confirm dialog inside
getSelected().performAction();
}
};
private final ActorGestureListener gestureListener = new ActorGestureListener() {
@Override
public void touchDown(InputEvent event, float x, float y, int pointer, int button) {
super.touchDown(event, x, y, pointer, button);
}
@Override
public boolean longPress(Actor actor, float x, float y) {
final int index = Math.min(getItems().size - 1, (int) ((getList().getHeight() - y) / getList().getItemHeight()));
final UserMenuSelectBoxItemGroup selected = (UserMenuSelectBoxItemGroup) getItems().get(index);
if (!TablexiaSettings.getInstance().getSelectedUser().equals(selected.getUser())) {
// TODO: 12.1.16 rework dialog
// TODO: 12.1.16 check DE/SK delete user text
final TextDialog dialog = DialogFactory.createSquerBorderDialog(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.USERMENU_DELETE_USER) + " " + selected.getUser().getName() + " ?");
TablexiaButton buttonCancel = new TablexiaButton(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.USERMENU_DIALOGUE_NO), TablexiaButton.ButtonType.RED);
TablexiaButton buttonOK = new TablexiaButton(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.USERMENU_DIALOGUE_YES), TablexiaButton.ButtonType.GREEN);
buttonOK.setUserObject(BUTTON_OK_ID);
buttonCancel.setUserObject(BUTTON_CANCEL_ID);
ClickListener clickListener = new ClickListenerWithSound() {
@Override
public void onClick(InputEvent event, float x, float y) {
if (event.getListenerActor().getUserObject().equals(BUTTON_OK_ID)) {
selected.getUser().setDeleted(true);
User.updateUser(selected.getUser());
prepareActiveUsers();
}
dialog.hide();
}
};
buttonCancel.addListener(clickListener);
buttonOK.addListener(clickListener);
buttonOK.setDisabled(true);
buttonCancel.setDisabled(true);
dialog.add(buttonOK).width(BUTTON_WIDTH).spaceRight(BUTTON_SPACE);
dialog.add(buttonCancel).width(BUTTON_WIDTH).spaceLeft(BUTTON_SPACE);
dialog.setPosition(getStage().getWidth() / 2 - dialog.getWidth() / 2, getStage().getHeight() / 2 - dialog.getHeight() / 2);
dialog.show(getStage());
}
return true;
}
};
public UserSelectBox(float itemHeight) {
......@@ -68,6 +125,7 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserS
private void prepareActiveUsers() {
removeCaptureListener(changeListener);
removeListener(gestureListener);
UserMenuSelectBoxItemGroup selectedUserItem = null;
List<UserSelectBoxItem> userItems = new ArrayList<UserSelectBoxItem>();
for (User user: User.selectActiveUsers()) {
......@@ -89,6 +147,7 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserS
setSelected(selectedUserItem);
}
addCaptureListener(changeListener);
getList().addListener(gestureListener);
}
@Override
......
......@@ -40,6 +40,10 @@ public class UserMenuSelectBoxItemGroup extends Group implements UserSelectBox.U
user.performAction();
}
public User getUser() {
return user;
}
@Override
public void draw(Batch batch, float parentAlpha) {
FOREGROUND_COLOR.a = parentAlpha;
......
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