Commit f5e50d1d authored by Drahomír Karchňák's avatar Drahomír Karchňák

Merge branch 'feature-desktop-mouse-scroll' into 'V3.5.1'

Feature desktop mouse scroll

See merge request !588
parents f3ef51c9 59917864
......@@ -199,6 +199,12 @@ public class CrimeSceneGame extends AbstractTablexiaGame<CrimeSceneGameState> {
setUpSizeAndPositionOfComponents();
}
@Override
public void setScrollableLayoutFocus() {
if(actionsStripWidget != null)
actionsStripWidget.setScrollFocus();
}
@Override
protected List<SummaryMessage> getSummaryMessageForGameResult(Game game) {
return Arrays.asList(new SummaryMessage(SummaryImage.STATS,
......
......@@ -361,6 +361,12 @@ public class InTheDarknessGame extends AbstractTablexiaGame<List<MapWidget>> imp
alignScreenContent();
}
@Override
public void setScrollableLayoutFocus() {
if(actionsStripWidget != null)
actionsStripWidget.setScrollFocus();
}
@Override
protected List<SummaryMessage> getSummaryMessageForGameResult(Game game) {
return Arrays.asList(new SummaryMessage(SummaryImage.STATS, getFormattedText("result_errors_count", game.getGameScore(SCORE_KEY_ERRORS_COUNT, "0"))));
......
......@@ -67,6 +67,8 @@ public abstract class AbstractMenu extends Stack implements Disposable {
private static final String TABLEXIA_VERSION_LABEL = "%s\r\n%s";
protected static final float SCROLL_PANE_INIT_SIZE = 200f;
protected enum MenuControlType {
MANUAL (true, false, true),
......@@ -448,6 +450,7 @@ public abstract class AbstractMenu extends Stack implements Disposable {
private void menuHidden() {
moveAction = null;
isClosing = false;
disableScroll(true);
}
void closeMenu(boolean animated, boolean force) {
......@@ -470,12 +473,15 @@ public abstract class AbstractMenu extends Stack implements Disposable {
setPosition(menuClosePositionX, menuPositionY);
menuClosed();
}
}else {
disableScroll(true);
}
}
private void menuClosed() {
moveAction = null;
isClosing = false;
disableScroll(true);
setMenuReady(SCENARIO_STEP_READY_MENU);
}
......@@ -499,15 +505,22 @@ public abstract class AbstractMenu extends Stack implements Disposable {
setPosition(menuOpenPositionX, menuPositionY);
menuOpened();
}
}else {
disableScroll(false);
}
}
private void menuOpened() {
moveAction = null;
isOpening = false;
disableScroll(false);
setMenuReady(SCENARIO_STEP_OPENED_MENU);
}
protected void disableScroll(boolean disable){
}
public void doMenuAction(MenuAction menuAction, boolean animated, boolean force) {
if (menuAction != null) {
menuAction.doAction(this, animated, force);
......
......@@ -32,6 +32,7 @@ import net.engio.mbassy.listener.Handler;
import java.util.HashMap;
import java.util.Map;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.event.SubMenuControlEvent;
......@@ -52,10 +53,10 @@ public class MainMenu extends AbstractMenu {
private static final int SELECTBOX_USER_HEIGHT = 70;
private static final float MENU_PADDING = 15;
private static final float USER_SELECT_BOX_PADDING = 10;
private static final float SCROLL_PANE_INIT_SIZE = 200f;
private Map<IMenuItem, Group> subMenus = new HashMap<IMenuItem, Group>();
private VerticalGroup mainMenuVerticalGroup;
private ScrollPane scrollPane;
private Container scrollPaneContainer;
public MainMenu(Float width, Float height) {
......@@ -119,7 +120,7 @@ public class MainMenu extends AbstractMenu {
Table layoutTable = new Table();
UserSelectBox userSelectBox = new UserSelectBox(SELECTBOX_USER_HEIGHT);
ScrollPane scrollPane = new ScrollPane(mainMenuVerticalGroup);
scrollPane = new ScrollPane(mainMenuVerticalGroup);
scrollPaneContainer = new Container();
layoutTable.add(userSelectBox).fill().align(Align.top).pad(USER_SELECT_BOX_PADDING);
......@@ -137,6 +138,7 @@ public class MainMenu extends AbstractMenu {
scrollPaneContainer.width(background.getWidth() - MENU_PADDING);
scrollPane.setScrollingDisabled(true, false);
Tablexia.getActualScreen().getStage().setScrollFocus(scrollPane);
}
private void performMenuAction(IMenuItem menuItem) {
......@@ -156,6 +158,21 @@ public class MainMenu extends AbstractMenu {
ApplicationBus.getInstance().unsubscribe(this);
}
@Override
protected void disableScroll(boolean disable) {
if(scrollPane == null || scrollPane.isScrollY() == !disable)
return;
scrollPane.setScrollingDisabled(true, disable);
if(disable)
Tablexia.getActualScreen().setScrollableLayoutFocus();
else
Tablexia.getActualScreen().getStage().setScrollFocus(scrollPane);
scrollPane.layout();
}
private InputListener menuTouchInputListener = new ClickListener() {
@Override
......
......@@ -28,6 +28,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
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.utils.Align;
import net.engio.mbassy.listener.Handler;
......@@ -97,6 +98,8 @@ public class UserMenu extends AbstractMenu {
private String lastSyncUUID;
private TablexiaComponentDialog syncDialog;
private UserUuidSyncDialogComponent uuidSyncDialogComponent;
private ScrollPane scrollPane;
private Container container;
public UserMenu(Float width, Float height) {
super(width, height);
......@@ -106,9 +109,24 @@ public class UserMenu extends AbstractMenu {
@Override
protected boolean isScreenPause() {
resizeContainerSize();
return MENU_SCREEN_PAUSE;
}
@Override
protected void sizeChanged() {
resizeContainerSize();
super.sizeChanged();
}
private void resizeContainerSize(){
if(getStage() != null && container != null) {
float scrollPaneHeight = TablexiaSettings.getViewportHeight(getStage());
container.height(scrollPaneHeight);
container.invalidateHierarchy();
}
}
@Override
protected MenuControlType getMenuControlType() {
return MENU_CONTROL_TYPE;
......@@ -118,9 +136,6 @@ public class UserMenu extends AbstractMenu {
public void initMenuItems(Container<Group> layoutContainer) {
final VerticalGroup menuItemsLayout = new VerticalGroup();
final ScrollPane scrollPane = new ScrollPane(menuItemsLayout);
final Container<ScrollPane> container = new Container<ScrollPane>(scrollPane);
container.setFillParent(true);
final float userMenuItemWidth = getBackground().getWidth();
this.users = UserDAO.selectActiveUsers();
for (final User user : users) {
......@@ -156,6 +171,7 @@ public class UserMenu extends AbstractMenu {
}
});
menuItemsLayout.addActor(userItemGroup);
menuItemsLayout.expand().fill();
userItemGroup.setName(user.getName());
}
final UserMenuNewSelectBoxItemGroup userMenuNewSelectBoxItemGroup = new UserMenuNewSelectBoxItemGroup() {
......@@ -172,6 +188,7 @@ public class UserMenu extends AbstractMenu {
};
userMenuNewSelectBoxItemGroup.setName(NEW_USER_BUTTON);
userMenuNewSelectBoxItemGroup.setSize(userMenuItemWidth, USER_ITEM_HEIGHT);
userMenuNewSelectBoxItemGroup.addListener(new ClickListener() {
@Override
......@@ -181,6 +198,7 @@ public class UserMenu extends AbstractMenu {
}
});
menuItemsLayout.addActor(userMenuNewSelectBoxItemGroup);
menuItemsLayout.expand().fill();
final UserMenuDownloadSelectBoxItemGroup userDownload = new UserMenuDownloadSelectBoxItemGroup() {
@Override
......@@ -203,8 +221,23 @@ public class UserMenu extends AbstractMenu {
}
});
menuItemsLayout.addActor(userDownload);
menuItemsLayout.expand().fill();
scrollPane = new ScrollPane(menuItemsLayout);
container = new Container();
container.setActor(scrollPane);
container.align(Align.top);
if(getStage() == null)
container.height(SCROLL_PANE_INIT_SIZE);
else
container.height(TablexiaSettings.getViewportHeight(getStage()));
layoutContainer.setActor(container);
scrollPane.setScrollingDisabled(true,false);
Tablexia.getActualScreen().getStage().setScrollFocus(scrollPane);
}
private void showSyncDialog(final String syncUUID) {
......@@ -380,6 +413,21 @@ public class UserMenu extends AbstractMenu {
ApplicationBus.getInstance().unsubscribe(this);
}
@Override
protected void disableScroll(boolean disable) {
if(scrollPane == null || scrollPane.isScrollY() == !disable)
return;
if(disable){
scrollPane.setScrollingDisabled(true,true);
Tablexia.getActualScreen().setScrollableLayoutFocus();
}else {
scrollPane.setScrollingDisabled(true,false);
Tablexia.getActualScreen().getStage().setScrollFocus(scrollPane);
}
scrollPane.layout();
}
//////////////////////////// CREATE USER EVENT HANDLING
......
......@@ -579,6 +579,8 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
return ComponentScaleUtil.isUnderThreshold();
}
public void setScrollableLayoutFocus() {}
//////////////////////////// INPUT PROCESSORS
......
......@@ -110,6 +110,13 @@ public class AboutScreen extends AbstractTablexiaScreen<Void> {
screenState.put(SCREEN_STATE_SCROLL_POSITION_Y, String.valueOf(contentScrollPane.getScrollPercentY()));
}
@Override
public void setScrollableLayoutFocus() {
if(contentScrollPane != null){
getStage().setScrollFocus(contentScrollPane);
}
}
@Override
protected void screenLoaded(Map<String, String> screenState) {
TextureRegionDrawable backgroundTexture = new TextureRegionDrawable(getColorTextureRegion(DEFAULT_BACKGROUND_COLOR));
......@@ -151,6 +158,7 @@ public class AboutScreen extends AbstractTablexiaScreen<Void> {
getStage().addActor(backgroundTable);
getStage().addActor(contentScrollPane);
getStage().addActor(contentStack);
getStage().setScrollFocus(contentScrollPane);
contentStack.setDebug(TablexiaSettings.getInstance().isShowBoundingBoxes(), true);
}
......
......@@ -22,6 +22,7 @@ import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
......@@ -101,6 +102,7 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
private Music playedMusic;
private PlaybackStateButton musicButton;
private ResizeFontListener resizeFontListener;
private float rightPanePosition;
private static EncyclopediaFont actualRegularFont = EncyclopediaFont.DEFAULT_REGULAR;
private static EncyclopediaFont actualBoldFont = EncyclopediaFont.DEFAULT_BOLD;
private static EncyclopediaFont actualHeaderFont = EncyclopediaFont.DEFAULT_HEADER;
......@@ -119,6 +121,13 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
return new ExtendViewport(TablexiaSettings.getWorldSize(), TablexiaSettings.getMinWorldHeight());
}
@Override
public void setScrollableLayoutFocus() {
if(menuScrollPane != null){
getStage().setScrollFocus(contentScrollPane);
}
}
@Override
protected void screenPaused(Map<String, String> screenState) {
if (menuScrollPane.getScrollPercentY() != Float.NaN) {
......@@ -168,6 +177,9 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
contentScrollPane.updateVisualScroll();
}
prepareMouseListener();
getStage().setScrollFocus(contentScrollPane);
contentStack.pack();
}
......@@ -224,7 +236,7 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
menuScrollPane.setSize(rightPanelWidth, getViewportHeight() * MENU_RELATIVE_HEIGHT);
rightPanePosition = getViewportWidth() - rightPanelWidth;
buttonsPanel = new ResizableWidgetGroup();
buttonsPanel.setSize(rightPanelWidth, getViewportHeight() * (1 - MENU_RELATIVE_HEIGHT));
......@@ -232,7 +244,7 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
rightPanelStack = new Table();
rightPanel = new Table();
rightPanel.setPosition(getViewportWidth() - rightPanelWidth, getViewportHeight());
rightPanel.setPosition(rightPanePosition, getViewportHeight());
rightPanel.setSize(rightPanelWidth, getViewportHeight());
rightPanel.add(menuScrollPane);
rightPanel.row();
......@@ -243,8 +255,23 @@ public class EncyclopediaScreen extends AbstractTablexiaScreen<Void> {
menu.setName(MENU);
menu.updateSize(rightPanelWidth);
}
private void prepareMouseListener() {
if (TablexiaSettings.getInstance().getPlatform() == TablexiaSettings.Platform.DESKTOP) {
container.addListener(new InputListener() {
@Override
public boolean mouseMoved(InputEvent event, float x, float y) {
if (x > rightPanePosition && getStage().getScrollFocus() != menuScrollPane) {
getStage().setScrollFocus(menuScrollPane);
} else if (x < rightPanePosition && getStage().getScrollFocus() != contentScrollPane) {
getStage().setScrollFocus(contentScrollPane);
}
return super.mouseMoved(event, x, y);
}
});
}
}
private void prepareButtons() {
......
......@@ -177,6 +177,13 @@ public class HallOfFameScreen extends AbstractTablexiaScreen<Map<ITrophyDefiniti
screenState.put(SCREEN_STATE_SCROLL_POSITION_X, String.valueOf(scrollPane.getScrollPercentX()));
}
@Override
public void setScrollableLayoutFocus() {
if(scrollPane != null){
getStage().setScrollFocus(scrollPane);
}
}
// GFX
@Override
protected void prepareScreenAtlases(List<String> atlasesNames) {
......@@ -213,6 +220,8 @@ public class HallOfFameScreen extends AbstractTablexiaScreen<Map<ITrophyDefiniti
}
handleMouseRankUpDialog();
getStage().setScrollFocus(scrollPane);
}
@Override
......
......@@ -210,6 +210,13 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
screenState.put(SCREEN_STATE_SWITCH_KEY, String.valueOf(graphStyle == GraphStyle.DAILY ? 0 : 2));
}
@Override
public void setScrollableLayoutFocus() {
if(scrollPane != null){
getStage().setScrollFocus(scrollPane);
}
}
@Override
protected void screenLoaded(Map<String, String> screenState) {
getStage().setDebugAll(TablexiaSettings.getInstance().isShowBoundingBoxes());
......@@ -359,6 +366,7 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
}
getStage().addActor(content);
getStage().setScrollFocus(scrollPane);
screenResized(0, 0);
......
......@@ -317,7 +317,47 @@ public class ActionsStripWidget extends Group implements ActionListener {
scrollPaneTrackedPosition = scrollPane.getY() - offsetY;
}
}
@Override
public boolean scrolled(InputEvent event, float x, float y, int amount) {
if(isScrollEnabled()){
scrollPaneTracked = true;
float selectedActionHeight = selectedActions.size() * (actionSizeBigger + actionOffset);
float mouseWheelY = Math.min(getHeight(), Math.max(getHeight() * 0.9f, selectedActionHeight * 0.1f) / 4);
float offsetY = (mouseWheelY / 2) * (amount * -1);
scrollPaneLastPosition = y;
accel5 = (accel0 + accel1 + accel2 + accel3 + accel4 + offsetY) / 6;
accel0 = accel1;
accel1 = accel2;
accel3 = accel4;
accel4 = accel5;
accel5 = accel5 * SCROLL_ACCEL_SPEEDUP;
scrollPaneTrackedPosition = scrollPane.getY() - offsetY;
return true;
}
return false;
}
@Override
public void dragStart(InputEvent event, float x, float y, int pointer) {
super.dragStart(event, x, y, pointer);
}
});
setScrollFocus();
}
public void setScrollFocus(){
if(scrollPane != null) {
tablexiaGame.getStage().setScrollFocus(scrollPane);
}
}
private void moveScrollOffset(float offset, Runnable finishHandler) {
......@@ -358,7 +398,7 @@ public class ActionsStripWidget extends Group implements ActionListener {
private int getScrollPaneBottomPosition(int position) {
return -position * (actionSizeBigger + actionOffset);
}
/* //////////////////////////////////////////// NEXT ACTION FIELD */
......
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