From ea31b5a534d4f4049afd0a4af3b48b1e10b7e5e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Latner?= <matyas.latner@nic.cz>
Date: Tue, 20 Oct 2015 15:33:47 +0200
Subject: [PATCH] #58 New user button in user selecbox menu

---
 .../usermenu/menubutton_background.9.png      | Bin 0 -> 201 bytes
 .../application/ApplicationAtlasManager.java  |   1 +
 .../nic/tablexia/menu/main/UserSelectBox.java |  70 ++++++++++++++----
 3 files changed, 57 insertions(+), 14 deletions(-)
 create mode 100644 core/assets/common/_global/application/usermenu/menubutton_background.9.png

diff --git a/core/assets/common/_global/application/usermenu/menubutton_background.9.png b/core/assets/common/_global/application/usermenu/menubutton_background.9.png
new file mode 100644
index 0000000000000000000000000000000000000000..ffda5082419b9f370e9e7727519ad0c2095452fb
GIT binary patch
literal 201
zcmeAS@N?(olHy`uVBq!ia0vp^Vj#@H1|*Mc$*~4fY)RhkE(}2o?hKCS=bfDn6yYrJ
zh%9Dc;1&j9Muu5)B!GhKC7!;n?Dx4ucub_es_NeY3Wa&PIEGl9PEI+%@?Y`<bC1Lv
zg>v^I-osqi-rhNXg6Z*&+p`0XUYN^%-T({?FK`$H3M~6^pnle_iYpHSo85WkOlL?m
pOSVty7BuBp^JMv~lUr8#Fm6-gElG}@{T*lngQu&X%Q~loCIFqTKeYe=

literal 0
HcmV?d00001

diff --git a/core/src/cz/nic/tablexia/loader/application/ApplicationAtlasManager.java b/core/src/cz/nic/tablexia/loader/application/ApplicationAtlasManager.java
index 4401a36b2..ce42c499f 100644
--- a/core/src/cz/nic/tablexia/loader/application/ApplicationAtlasManager.java
+++ b/core/src/cz/nic/tablexia/loader/application/ApplicationAtlasManager.java
@@ -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";
 
diff --git a/core/src/cz/nic/tablexia/menu/main/UserSelectBox.java b/core/src/cz/nic/tablexia/menu/main/UserSelectBox.java
index 391a327af..6cf4540f2 100644
--- a/core/src/cz/nic/tablexia/menu/main/UserSelectBox.java
+++ b/core/src/cz/nic/tablexia/menu/main/UserSelectBox.java
@@ -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);
         }
     }
 
-- 
GitLab