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

Merge branch 'feature-encyclopedia' into 'devel'

Feature-encyclopedia



See merge request !101
parents 06fcb7c2 6a5a992e
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@ import java.util.List;
import java.util.Map;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.Point;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.encyclopedia.assets.EncyclopediaAssets;
......@@ -29,16 +30,25 @@ import cz.nic.tablexia.util.ui.TablexiaButton;
public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
private static final String SOURCE_FILE_EXTENSION = ".json";
private static final Point SCREEN_SIZE = new Point(TablexiaSettings.getWorldWidth(), TablexiaSettings.getMinWorldHeight());
private static final float RIGHT_PANEL_PADDING_TOP = 10;
private static final float FONT_BUTTON_WIDTH = 70;
private static final float BUTTONS_MARGIN_LEFT = 30;
private static final float BUTTONS_GAP = 20;
private static final float CONTENT_RELATIVE_WIDTH = 0.75f;
private static final float CONTENT_RELATIVE_WIDTH = 0.70f;
private static final float MENU_RELATIVE_HEIGHT = 0.85f;
private static final int CLOSE_BUTTON_WIDTH = 35;
private static final int CLOSE_BUTTON_HEIGHT = 35;
private static final int CLOSE_BUTTON_PAD_TOP = 0;
private static final int CLOSE_BUTTON_PAD_RIGHT = 20;
private static final int CLOSE_BUTTON_PAD_LEFT = 5;
private static final int CLOSE_BUTTON_PAD_BOTTOM = 25;
private static final Color BACKGROUND_COLOR = new Color(((float) 248 / (float) 255), ((float) 236 / (float) 255), ((float) 212 / (float) 255), 1);
private static final String FONT_PLUS_TEXT = "+A";
private static final String FONT_MINUS_TEXT = "-A";
private static final String MUSIC_EXTENSION = ".mp3";
private static final String MENU_STATE_SCROLL_POSITION_Y = "menuScrollPositionY";
private static final String CONTENT_STATE_SCROLL_POSITION_Y = "contentScrollPositionY";
private static final String MENU_SELECTED_ITEM = "menuSelectedItem";
private static final int DEFAULT_SELECTED_MENU_ITEM = 0;
private Table contentStack;
private Table rightPanelStack;
......@@ -52,6 +62,23 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
private Music playedMusic;
private TablexiaButton musicButton;
@Override
protected void screenPaused(Map<String, String> screenState) {
if (menuScrollPane.getScrollPercentY() != Float.NaN) {
screenState.put(MENU_STATE_SCROLL_POSITION_Y, String.valueOf(menuScrollPane.getScrollPercentY()));
}
if (contentScrollPane.getScrollPercentY() != Float.NaN) {
screenState.put(CONTENT_STATE_SCROLL_POSITION_Y, String.valueOf(contentScrollPane.getScrollPercentY()));
}
screenState.put(MENU_SELECTED_ITEM, String.valueOf(menu.getSelectedItemIndex()));
Log.debug(this.getClass(), "SCREEN ----- SAVING -------");
for (Map.Entry<String, String> entry : screenState.entrySet()) {
Log.debug(this.getClass(), entry.getKey() + ": " + entry.getValue());
}
Log.debug(this.getClass(), "content.size: " + contentScrollPane.getMaxY());
}
@Override
protected void screenLoaded(Map<String, String> screenState) {
container = new Table();
......@@ -61,14 +88,34 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
prepareContentLayout();
prepareRightMenu();
menu.selectItem(0);
int selectedItem = DEFAULT_SELECTED_MENU_ITEM;
if (screenState.containsKey(MENU_SELECTED_ITEM)) {
selectedItem = Integer.valueOf(screenState.get(MENU_SELECTED_ITEM));
}
menu.selectItem(selectedItem);
prepareButtons();
if (screenState.containsKey(MENU_STATE_SCROLL_POSITION_Y)) {
menuScrollPane.pack();
menuScrollPane.setScrollPercentY(Float.valueOf(screenState.get(MENU_STATE_SCROLL_POSITION_Y)));
menuScrollPane.updateVisualScroll();
}
if (screenState.containsKey(CONTENT_STATE_SCROLL_POSITION_Y)) {
contentScrollPane.pack();
contentScrollPane.setScrollPercentY(Float.valueOf(screenState.get(CONTENT_STATE_SCROLL_POSITION_Y)));
contentScrollPane.updateVisualScroll();
}
container.pack();
}
private void prepareContentLayout() {
//TODO add culling
contentStack = new Table();
contentStack.setSize(CONTENT_RELATIVE_WIDTH * SCREEN_SIZE.x, SCREEN_SIZE.y);
contentStack.setBackground(new TextureRegionDrawable(getColorTextureRegion(BACKGROUND_COLOR)));
content = new Table();
// content.setCullingArea(new Rectangle(0, 0, CONTENT_RELATIVE_WIDTH * SCREEN_SIZE.x, SCREEN_SIZE.y));
contentScrollPane = new ResizableScrollPane(content);
......@@ -76,7 +123,6 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
contentScrollPane.setSize(CONTENT_RELATIVE_WIDTH * SCREEN_SIZE.x, SCREEN_SIZE.y);
// contentStack.addActor(new Image(getColorTextureRegion(BACKGROUND_COLOR)));
contentStack.setBackground(new TextureRegionDrawable(getColorTextureRegion(BACKGROUND_COLOR)));
Button closeButton = new Button(new TextureRegionDrawable(getScreenTextureRegion(EncyclopediaAssets.CLOSEBUTTON_UNPRESSED)), new TextureRegionDrawable(getScreenTextureRegion(EncyclopediaAssets.CLOSEBUTTON_PRESSED)));
closeButton.addListener(new ClickListener() {
......@@ -87,7 +133,7 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
backToInitialScreen();
}
});
contentStack.add(closeButton).bottom().padLeft(25).padBottom(25).width(35).height(35);
contentStack.add(closeButton).bottom().pad(CLOSE_BUTTON_PAD_TOP, CLOSE_BUTTON_PAD_LEFT, CLOSE_BUTTON_PAD_BOTTOM, CLOSE_BUTTON_PAD_RIGHT).size(CLOSE_BUTTON_WIDTH, CLOSE_BUTTON_HEIGHT);
contentStack.add(contentScrollPane);
container.add(contentStack);
......@@ -104,8 +150,8 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
});
menuScrollPane = new ResizableScrollPane(menu);
menuScrollPane.setScrollingDisabled(true, false);
menuScrollPane.setSize(rightPanelWidth, SCREEN_SIZE.y * MENU_RELATIVE_HEIGHT);
menuScrollPane.setSize(rightPanelWidth, SCREEN_SIZE.y * MENU_RELATIVE_HEIGHT);
buttonsPanel = new ResizableWidgetGroup();
buttonsPanel.setSize(rightPanelWidth, SCREEN_SIZE.y * (1 - MENU_RELATIVE_HEIGHT));
......@@ -120,7 +166,8 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
rightPanel.add(buttonsPanel);
rightPanelStack.setBackground(new TextureRegionDrawable(getColorTextureRegion(BACKGROUND_COLOR)));
rightPanelStack.add(rightPanel).padTop(RIGHT_PANEL_PADDING_TOP);
rightPanelStack.add(rightPanel);
rightPanelStack.pad(0);
container.add(rightPanelStack);
}
......@@ -146,10 +193,9 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
List<Content> contentList = ContentParser.parseEncyclopediaPageContent(fileHandle.readString());
for (Content c : contentList) {
c.addToCell(content,this,CONTENT_RELATIVE_WIDTH * SCREEN_SIZE.x);
c.addToCell(content, this, CONTENT_RELATIVE_WIDTH * SCREEN_SIZE.x);
content.row();
}
// getStage().setDebugUnderMouse(true);
}
public void playMusic(String music, TablexiaButton musicButton) {
......
......@@ -7,6 +7,7 @@ import java.io.IOException;
import java.util.List;
import cz.nic.tablexia.screen.encyclopedia.content.model.Content;
import cz.nic.tablexia.util.Log;
/**
* Created by Václav Tarantík on 2.9.15.
......@@ -19,7 +20,7 @@ public class ContentParser {
try {
list = mapper.readValue(jsonLine,new TypeReference<List<Content>>(){});
} catch (IOException e) {
e.printStackTrace();
Log.err(ContentParser.class, e.getMessage(), e);
}
return list;
......
......@@ -53,6 +53,7 @@ public class Header extends Content {
});
table.add(button).expandX().right().padRight(20);
}
table.validate();
return table;
}
......
......@@ -77,6 +77,7 @@ public class Hint extends Content {
contentTable.add(image).width(desiredImageWidth).height(desiredImageHeight).padLeft(20);
contentTable.add(textsTable).fillX().expandX();
contentTable.validate();
return contentTable;
}
......
package cz.nic.tablexia.screen.encyclopedia.content.model;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
......@@ -31,6 +30,8 @@ public class TextContent extends Content {
}
Label paragraph = new Label(screen.getText(getText()), labelStyle);
paragraph.setWrap(true);
paragraph.validate();
return paragraph;
}
......
......@@ -29,6 +29,7 @@ public class MenuWidget extends VerticalGroup {
private NinePatchDrawable selectionDrawable;
private AbstractTablexiaScreen screen;
private OnMenuItemClickListener onItemClickListener;
private int selectedItemIndex;
public MenuWidget(AbstractTablexiaScreen screen,Point size, String selectionDrawableResource, OnMenuItemClickListener onItemClickListener) {
menuItemValues = new Array<MenuItem>(MenuItem.values());
......@@ -40,9 +41,9 @@ public class MenuWidget extends VerticalGroup {
initItems();
}
private void initItems(){
private void initItems() {
//// FIXME: 15.10.15 Smaller font for menu items so it fits with visible bookmark
for (final MenuItem item: menuItemValues){
for (final MenuItem item: menuItemValues) {
final TextButton menuItem = new TextButton(screen.getText(item.getTitle()),createMenuItemStyle());
menuItem.getLabel().setAlignment(Align.left);
menuItem.removeListener(menuItem.getClickListener());
......@@ -57,14 +58,15 @@ public class MenuWidget extends VerticalGroup {
}
}
public void selectItem(int position){
public void selectItem(int position) {
selectedItemIndex = position;
MenuItem searchedItem = menuItemValues.get(position);
TextButton menuItem = menuItems.get(searchedItem);
if(!menuItem.isChecked()){
if (!menuItem.isChecked()) {
menuItem.setChecked(true);
for (Actor child : getChildren()) {
TextButton childButton = (TextButton)child;
if (childButton!=menuItem) {
if (childButton != menuItem) {
childButton.setChecked(false);
}
}
......@@ -73,13 +75,17 @@ public class MenuWidget extends VerticalGroup {
}
private TextButton.TextButtonStyle createMenuItemStyle(){
TextButton.TextButtonStyle style = new TextButton.TextButtonStyle(null,null,selectionDrawable,screen.getDefaultBoldFont());
private TextButton.TextButtonStyle createMenuItemStyle() {
TextButton.TextButtonStyle style = new TextButton.TextButtonStyle(null, null, selectionDrawable, screen.getDefaultBoldFont());
style.fontColor = Color.BLACK;
return style;
}
public interface OnMenuItemClickListener{
public interface OnMenuItemClickListener {
void onMenuItemClicked(MenuItem clickedMenuItem);
}
public int getSelectedItemIndex() {
return selectedItemIndex;
}
}
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