Skip to content
Snippets Groups Projects
Commit ea31b5a5 authored by Matyáš Latner's avatar Matyáš Latner
Browse files

#58 New user button in user selecbox menu

parent 099cc693
Branches
Tags
No related merge requests found
core/assets/common/_global/application/usermenu/menubutton_background.9.png

201 B

......@@ -54,6 +54,7 @@ public class ApplicationAtlasManager extends TablexiaAtlasManager implements IAp
public static final String USERMENU_PATH = "usermenu/";
public static final String USERMENU_MENUITEM_BACKGROUND = USERMENU_PATH + "menuitem_background";
public static final String USERMENU_MENUITEM_TRIANGLE = USERMENU_PATH + "menuitem_triangle";
public static final String USERMENU_MENUBUTTON_BACKGROUND = USERMENU_PATH + "menubutton_background";
//TODO remove
public static final String USERMENU_MENUITEM_SAMPLE = USERMENU_PATH + "sample";
......
......@@ -3,10 +3,12 @@ package cz.nic.tablexia.menu.main;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import net.engio.mbassy.listener.Handler;
......@@ -17,13 +19,14 @@ import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.model.User;
import cz.nic.tablexia.util.ui.AbstractTablexiaSelectBox;
/**
* Created by Matyáš Latner.
*/
public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserItem> {
public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.IUserItem> {
private static final int TRIANGLE_WIDTH = 12;
private static final int TRIANGLE_HEIGHT = 12;
......@@ -36,15 +39,23 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserI
private static final int SELECTOR_WIDTH = 5;
private static final int SELECTOR_TOP_OFFSET = 8;
private static final Color FOREGROUND_COLOR = new Color(0.322f, 0.278f, 0.255f, 1f);
private static final Color NEWUSER_TEXT_COLOR = new Color(0.098f, 0.086f, 0.075f, 1f);
private static final int NEWUSER_TEXT_ALIGN = Align.center;
private TextureRegionDrawable triangle;
private TextureRegionDrawable selector;
public static class UserItem extends Actor {
public interface IUserItem {
void performAction();
void setBounds (float x, float y, float width, float height);
void draw(Batch batch, float parentAlpha);
}
public static class UserItem extends Actor implements IUserItem {
private final NinePatch background;
private final BitmapFont regularFont;
private final BitmapFont font;
private final TextureRegionDrawable image;
private final User user;
......@@ -52,18 +63,18 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserI
this.user = user;
background = ApplicationAtlasManager.getInstance().getPatch(ApplicationAtlasManager.USERMENU_MENUITEM_BACKGROUND);
regularFont = ApplicationFontManager.getInstance().getDefaultApplicationRegularFont();
font = ApplicationFontManager.getInstance().getDefaultApplicationRegularFont();
image = new TextureRegionDrawable(ApplicationAtlasManager.getInstance().getTextureRegion(ApplicationAtlasManager.USERMENU_MENUITEM_SAMPLE));
}
public User getUser() {
return user;
public void performAction() {
user.performAction();
}
@Override
public void draw(Batch batch, float parentAlpha) {
FOREGROUND_COLOR.a = parentAlpha;
regularFont.setColor(FOREGROUND_COLOR);
font.setColor(FOREGROUND_COLOR);
background.draw(batch, getX(), getY(), getWidth(), getHeight());
......@@ -72,7 +83,37 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserI
float textPositionX = getX() + imageWidth + TEXT_LEFT_OFFSET;
float textPositionY = getY() + getHeight() / 2;
regularFont.draw(batch, user.getName(), textPositionX, textPositionY + regularFont.getLineHeight() / 3);
font.draw(batch, user.getName(), textPositionX, textPositionY + font.getLineHeight() / 3);
}
}
public static class NewUserItem extends Actor implements IUserItem {
private final NinePatch background;
private final BitmapFont font;
private final String text;
private final GlyphLayout glyphLayout;
public NewUserItem() {
background = ApplicationAtlasManager.getInstance().getPatch(ApplicationAtlasManager.USERMENU_MENUBUTTON_BACKGROUND);
font = ApplicationFontManager.getInstance().getDefaultApplicationBoldFont();
text = ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.USERMENU_NEWUSER);
glyphLayout = new GlyphLayout();
}
public void performAction() {
}
@Override
public void draw(Batch batch, float parentAlpha) {
NEWUSER_TEXT_COLOR.a = parentAlpha;
font.setColor(NEWUSER_TEXT_COLOR);
background.draw(batch, getX(), getY(), getWidth(), getHeight());
glyphLayout.setText(font, text, NEWUSER_TEXT_COLOR, getWidth(), NEWUSER_TEXT_ALIGN, false);
font.draw(batch, glyphLayout, getX(), getY() + getHeight() / 2 + font.getLineHeight() / 3);
}
}
......@@ -80,7 +121,7 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserI
@Override
public void changed(ChangeEvent event, Actor actor) {
// TODO add confirm dialog inside
getSelected().getUser().performAction();
getSelected().performAction();
}
};
......@@ -102,7 +143,7 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserI
private void prepareActiveUsers() {
removeCaptureListener(changeListener);
UserItem selectedUserItem = null;
List<UserItem> userItems = new ArrayList<UserItem>();
List<IUserItem> userItems = new ArrayList<IUserItem>();
for (User user: User.selectActiveUsers()) {
UserItem userItem = new UserItem(user);
userItems.add(userItem);
......@@ -110,7 +151,8 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserI
selectedUserItem = userItem;
}
}
setItems(userItems.toArray(new UserItem[]{}));
userItems.add(new NewUserItem());
setItems(userItems.toArray(new IUserItem[]{}));
if (selectedUserItem != null) {
setSelected(selectedUserItem);
} else {
......@@ -120,18 +162,18 @@ public class UserSelectBox extends AbstractTablexiaSelectBox<UserSelectBox.UserI
}
@Override
protected void drawSelectedItem(Batch batch, float parentAlpha, UserItem selected, float width, float height) {
protected void drawSelectedItem(Batch batch, float parentAlpha, IUserItem selected, float width, float height) {
selected.setBounds(getX(), getY(), width, height);
selected.draw(batch, parentAlpha);
triangle.draw(batch, getX() + getWidth() - TRIANGLE_WIDTH - TRIANGLE_RIGHT_OFFSET, getY() + TRIANGLE_BOTTOM_OFFSET, TRIANGLE_WIDTH, TRIANGLE_HEIGHT);
}
@Override
protected void drawListItem(Batch batch, float parentAlpha, UserItem item, float x, float y, float width, float height) {
protected void drawListItem(Batch batch, float parentAlpha, IUserItem item, float x, float y, float width, float height) {
item.setBounds(x, y, width, height);
item.draw(batch, parentAlpha);
if (getSelection() != null && getSelection().contains(item)) {
selector.draw(batch, item.getX() + item.getWidth() - SELECTOR_RIGHT_OFFSET, item.getY() + SELECTOR_BOTTOM_OFFSET, SELECTOR_WIDTH, height - SELECTOR_TOP_OFFSET);
selector.draw(batch, x + width - SELECTOR_RIGHT_OFFSET, y + SELECTOR_BOTTOM_OFFSET, SELECTOR_WIDTH, height - SELECTOR_TOP_OFFSET);
}
}
......
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