[Mobile] enable mouseMoved and update some selectable element

This commit is contained in:
Anthony Calosa
2021-09-29 17:42:03 +08:00
parent 9a7fe7c4f0
commit 660d827c54
24 changed files with 92 additions and 44 deletions

View File

@@ -922,9 +922,10 @@ public class Forge implements ApplicationListener {
private int mouseMovedX, mouseMovedY;
@Override
public boolean mouseMoved(int x, int y) {
mouseMovedX = x;
mouseMovedY = y;
public boolean mouseMoved(int screenX, int screenY) {
mouseMovedX = screenX;
mouseMovedY = screenY;
updatePotentialListeners(screenX, screenY);
return true;
}

View File

@@ -331,10 +331,18 @@ public class FSkinFont {
return fontSize > MIN_FONT_SIZE;
}
public boolean canIncrease() {
return MAX_FONT_SIZE - fontSize > 2;
}
public FSkinFont shrink() {
return _get(fontSize - 1);
}
public FSkinFont increase() {
return _get(fontSize + 3);
}
public String getCharacterSet(String langCode) {
if (langUniqueCharacterSet.containsKey(langCode)) {
return langUniqueCharacterSet.get(langCode);

View File

@@ -87,9 +87,9 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
private final TextSearchFilter<? extends T> searchFilter;
private final FLabel btnSearch = new FLabel.ButtonBuilder()
.icon(Forge.hdbuttons ? FSkinImage.HDSEARCH : FSkinImage.SEARCH).iconScaleFactor(0.9f).build();
.icon(Forge.hdbuttons ? FSkinImage.HDSEARCH : FSkinImage.SEARCH).iconScaleFactor(0.9f).selectable().build();
private final FLabel btnView = new FLabel.ButtonBuilder()
.iconScaleFactor(0.9f).build(); //icon set later
.iconScaleFactor(0.9f).selectable().build(); //icon set later
private final FLabel btnAdvancedSearchOptions = new FLabel.Builder()
.selectable(true).align(Align.center)
.icon(Forge.hdbuttons ? FSkinImage.HDPREFERENCE : FSkinImage.SETTINGS).iconScaleFactor(0.9f)

View File

@@ -120,6 +120,9 @@ public class FMenuItem extends FDisplayObject implements IButton {
float w = getWidth();
float h = HEIGHT;
if (isHovered() && !pressed)
g.fillRect(PRESSED_COLOR.brighter().alphaColor(0.4f), 0, 0, w, h);
if (showPressedColor()) {
g.fillRect(PRESSED_COLOR, 0, 0, w, h);
}

View File

@@ -99,6 +99,8 @@ public class FMenuTab extends FDisplayObject {
y = PADDING;
w = getWidth() - 2 * PADDING;
h = getHeight() - 2 * PADDING;
if (isHovered())
g.fillRect(SEL_BACK_COLOR.brighter(), x, y, w, h);
g.drawText(text, FONT, foreColor, x, y, w, h, false, Align.center, true);
}
}

View File

@@ -78,11 +78,12 @@ public abstract class LaunchScreen extends FScreen {
@Override
public void draw(Graphics g) {
if (Forge.hdstart)
g.drawImage(pressed ? FSkinImage.HDBTN_START_DOWN : FSkinImage.HDBTN_START_UP,
0, 0, getWidth(), getHeight());
g.drawImage(pressed ? FSkinImage.HDBTN_START_DOWN :
isHovered() ? FSkinImage.HDBTN_START_OVER : FSkinImage.HDBTN_START_UP,
isHovered() ? -2 : 0, 0, getWidth(), getHeight());
else
g.drawImage(pressed ? FSkinImage.BTN_START_DOWN : FSkinImage.BTN_START_UP,
0, 0, getWidth(), getHeight());
g.drawImage(pressed ? FSkinImage.BTN_START_DOWN :
isHovered() ? FSkinImage.BTN_START_OVER : FSkinImage.BTN_START_UP, 0, 0, getWidth(), getHeight());
//its must be enabled or you can't start any game modes
if (!Forge.isLoadingaMatch()) {
if(!btnStart.isEnabled())

View File

@@ -396,8 +396,7 @@ public class TabPageScreen<T extends TabPageScreen<T>> extends FScreen {
g.drawText(caption, font, TAB_FORE_COLOR, x, y, w, h, false, Align.left, true);
g.endClip();
}
}
else {
} else {
float y = h - padding - TAB_FONT.getCapHeight();
g.drawText(caption, TAB_FONT, TAB_FORE_COLOR, padding, y - padding, w, h - y + padding, false, Align.center, true);
@@ -408,7 +407,8 @@ public class TabPageScreen<T extends TabPageScreen<T>> extends FScreen {
iconHeight *= w / iconWidth;
iconWidth = w;
}
g.drawImage(icon, padding + (w - iconWidth) / 2, (y - iconHeight) / 2, iconWidth, iconHeight);
float mod = isHovered() ? iconWidth/8f : 0;
g.drawImage(icon, (padding + (w - iconWidth) / 2)-mod/2, ((y - iconHeight) / 2)-mod/2, iconWidth+mod, iconHeight+mod);
}
}

View File

@@ -60,8 +60,8 @@ public class PlayerPanel extends FContainer {
private LobbySlotType type = LobbySlotType.LOCAL;
private final FLabel nameRandomiser;
private final FLabel avatarLabel = new FLabel.Builder().opaque(true).iconScaleFactor(0.99f).alphaComposite(1).iconInBackground(true).build();
private final FLabel sleeveLabel = new FLabel.Builder().opaque(true).iconScaleFactor(0.99f).alphaComposite(1).iconInBackground(true).build();
private final FLabel avatarLabel = new FLabel.Builder().opaque(true).iconScaleFactor(0.99f).selectable().alphaComposite(1).iconInBackground(true).build();
private final FLabel sleeveLabel = new FLabel.Builder().opaque(true).iconScaleFactor(0.99f).selectable().alphaComposite(1).iconInBackground(true).build();
private int avatarIndex, sleeveIndex;
final Localizer localizer = Localizer.getInstance();

View File

@@ -314,7 +314,7 @@ public class HomeScreen extends FScreen {
public void draw(Graphics g) {
if (Forge.isLandscapeMode()) {
//draw text only for Landscape mode
g.drawText(getText(), getFont(), getForeColor(), 0, 0, getWidth(), getHeight(), false, Align.left, true);
g.drawText(getText(), isHovered() && getFont().canIncrease() ? getFont().increase() : getFont(), getForeColor(), 0, 0, getWidth(), getHeight(), false, Align.left, true);
}
else { //draw buttons normally for portrait mode
super.draw(g);

View File

@@ -126,8 +126,8 @@ public class VAvatar extends FDisplayObject {
@Override
public void draw(Graphics g) {
float w = getWidth();
float h = getHeight();
float w = isHovered() ? getWidth()/16f+getWidth() : getWidth();
float h = isHovered() ? getWidth()/16f+getHeight() : getHeight();
if (avatarAnimation != null && !MatchController.instance.getGameView().isMatchOver()) {
if (player.wasAvatarLifeChanged()) {

View File

@@ -159,8 +159,8 @@ public class VPhaseIndicator extends FContainer {
else {
backColor = FSkinColor.get(Colors.CLR_PHASE_INACTIVE_DISABLED);
}
g.fillRect(backColor, x, 0, w, h);
g.drawText(caption, font, Color.BLACK, x, 0, w, h, false, Align.center, true);
g.fillRect(isHovered() ? backColor.brighter() : backColor, x, 0, w, h);
g.drawText(caption, isHovered() && font.canIncrease() ? font.increase() : font, Color.BLACK, x, 0, w, h, false, Align.center, true);
}
}
}

View File

@@ -610,7 +610,8 @@ public class VPlayerPanel extends FContainer {
if (lblLife.getRotate180()) {
g.startRotateTransform(x + w / 2, y + h / 2, 180);
}
g.drawImage(icon, x, y, w, h);
float mod = isHovered() ? w/8f:0;
g.drawImage(icon, x-mod/2, y-mod/2, w+mod, h+mod);
if (lblLife.getRotate180()) {
g.endTransform();
}
@@ -637,7 +638,8 @@ public class VPlayerPanel extends FContainer {
h = icon.getHeight() * w / icon.getWidth();
x = (getWidth() - w) / 2;
y = INFO_TAB_PADDING_Y;
g.drawImage(icon, x, y, w, h);
float mod = isHovered() ? w/8f:0;
g.drawImage(icon, x-mod/2, y-mod/2, w+mod, h+mod);
y += h + INFO_TAB_PADDING_Y;
g.drawText(value, INFO_FONT, INFO_FORE_COLOR, 0, y, getWidth(), getHeight() - y + 1, false, Align.center, false);

View File

@@ -373,7 +373,7 @@ public class VStack extends FDropDown {
g.startClip(0, 0, w, getHeight()); //clip based on actual height
g.fillRect(Color.BLACK, x, y, w, h); //draw rectangle for border
g.fillRect(isHovered() ? Color.GRAY : Color.BLACK, x, y, w, h); //draw rectangle for border
x += BORDER_THICKNESS;
y += BORDER_THICKNESS;

View File

@@ -38,7 +38,7 @@ public class ViewWinLose extends FOverlay implements IWinLoseView<FButton> {
private static final float GAP_Y_FACTOR = 0.02f;
private final FButton btnContinue, btnRestart, btnQuit;
private final FLabel lblTitle, lblLog, lblStats, btnCopyLog, btnMinimize;
private final FLabel lblTitle, lblLog, lblStats, btnCopyLog, btnShowBattlefield;
private final FTextArea txtLog;
private final OutcomesPanel pnlOutcomes;
private final GameView game;
@@ -109,14 +109,14 @@ public class ViewWinLose extends FOverlay implements IWinLoseView<FButton> {
});
txtLog.setFont(FSkinFont.get(12));
btnCopyLog = add(new FLabel.ButtonBuilder().text(localizer.getMessage("btnCopyToClipboard")).command(new FEventHandler() {
btnCopyLog = add(new FLabel.ButtonBuilder().text(localizer.getMessage("btnCopyToClipboard")).selectable().command(new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
Forge.getClipboard().setContents(txtLog.getText());
}
}).build());
btnMinimize = add(new FLabel.ButtonBuilder().text(localizer.getMessage("lblMinimize")).font(FSkinFont.get(12)).command(new FEventHandler() {
btnShowBattlefield = add(new FLabel.ButtonBuilder().text(localizer.getMessage("lblShowBattlefield")).font(FSkinFont.get(12)).selectable().command(new FEventHandler() {
@Override
public void handleEvent(FEvent e) {
hide();
@@ -208,7 +208,7 @@ public class ViewWinLose extends FOverlay implements IWinLoseView<FButton> {
float y2 = height - dy - h;
btnCopyLog.setBounds(width / 4, y2, width / 2, h);
txtLog.setBounds(x, y, w, y2 - y - dy);
btnMinimize.setBounds(width / 4,0,width / 2, h);
btnShowBattlefield.setBounds(width / 4,0,width / 2, h);
}
private static class OutcomesPanel extends FContainer {

View File

@@ -28,6 +28,7 @@ public class FButton extends FDisplayObject implements IButton {
private FSkinFont font;
private FSkinColor foreColor = DEFAULT_FORE_COLOR;
private boolean toggled = false;
private boolean pressed = false;
private FEventHandler command;
public enum Corner {
@@ -182,6 +183,7 @@ public class FButton extends FDisplayObject implements IButton {
@Override
public final boolean press(float x, float y) {
pressed = true;
if (isToggled()) { return true; }
imgL = FSkinImage.BTN_DOWN_LEFT;
imgM = FSkinImage.BTN_DOWN_CENTER;
@@ -203,6 +205,7 @@ public class FButton extends FDisplayObject implements IButton {
@Override
public final boolean release(float x, float y) {
pressed = false;
if (isToggled()) { return true; }
resetImg();
return true;
@@ -245,21 +248,21 @@ public class FButton extends FDisplayObject implements IButton {
switch (corner) {
case None:
if (w > 2 * h) {
g.drawImage(imgL, 0, 0, h, h);
g.drawImage(imgM, h, 0, w - (2 * h), h);
g.drawImage(imgR, w - h, 0, h, h);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_LEFT : FSkinImage.BTN_OVER_LEFT : imgL, 0, 0, h, h);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_CENTER : FSkinImage.BTN_OVER_CENTER : imgM, h, 0, w - (2 * h), h);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_RIGHT : FSkinImage.BTN_OVER_RIGHT : imgR, w - h, 0, h, h);
}
else {
g.drawImage(imgL, 0, 0, cornerButtonWidth, h);
g.drawImage(imgR, cornerButtonWidth, 0, w - cornerButtonWidth, h);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_LEFT : FSkinImage.BTN_OVER_LEFT : imgL, 0, 0, cornerButtonWidth, h);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_RIGHT : FSkinImage.BTN_OVER_RIGHT : imgR, cornerButtonWidth, 0, w - cornerButtonWidth, h);
}
x += PADDING;
w -= 2 * PADDING;
break;
case BottomLeft:
g.startClip(x, y, w, h);
g.drawImage(imgM, 0, 0, cornerButtonWidth, cornerButtonHeight);
g.drawImage(imgR, cornerButtonWidth, 0, cornerButtonWidth, cornerButtonHeight);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_CENTER : FSkinImage.BTN_OVER_CENTER : imgM, 0, 0, cornerButtonWidth, cornerButtonHeight);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_RIGHT : FSkinImage.BTN_OVER_RIGHT : imgR, cornerButtonWidth, 0, cornerButtonWidth, cornerButtonHeight);
g.endClip();
w -= cornerTextOffsetX;
y += cornerTextOffsetY;
@@ -267,8 +270,8 @@ public class FButton extends FDisplayObject implements IButton {
break;
case BottomRight:
g.startClip(x, y, w, h);
g.drawImage(imgL, 0, 0, cornerButtonWidth, cornerButtonHeight);
g.drawImage(imgM, cornerButtonWidth, 0, cornerButtonWidth, cornerButtonHeight);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_LEFT : FSkinImage.BTN_OVER_LEFT : imgL, 0, 0, cornerButtonWidth, cornerButtonHeight);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_CENTER : FSkinImage.BTN_OVER_CENTER : imgM, cornerButtonWidth, 0, cornerButtonWidth, cornerButtonHeight);
g.endClip();
x += cornerTextOffsetX;
w -= cornerTextOffsetX;
@@ -279,9 +282,9 @@ public class FButton extends FDisplayObject implements IButton {
g.startClip(x, y, w, h);
cornerButtonWidth = w / 3;
cornerTextOffsetX = cornerButtonWidth / 2;
g.drawImage(imgL, 0, 0, cornerButtonWidth, cornerButtonHeight);
g.drawImage(imgM, cornerButtonWidth, 0, w - 2 * cornerButtonWidth, cornerButtonHeight);
g.drawImage(imgR, w - cornerButtonWidth, 0, cornerButtonWidth, cornerButtonHeight);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_LEFT : FSkinImage.BTN_OVER_LEFT : imgL, 0, 0, cornerButtonWidth, cornerButtonHeight);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_CENTER : FSkinImage.BTN_OVER_CENTER : imgM, cornerButtonWidth, 0, w - 2 * cornerButtonWidth, cornerButtonHeight);
g.drawImage(isHovered() && !pressed ? hdbuttonskin() ? FSkinImage.HDBTN_OVER_RIGHT : FSkinImage.BTN_OVER_RIGHT : imgR, w - cornerButtonWidth, 0, cornerButtonWidth, cornerButtonHeight);
g.endClip();
x += cornerTextOffsetX / 2;
w -= cornerTextOffsetX;

View File

@@ -96,11 +96,13 @@ public class FCardPanel extends FDisplayObject {
public void draw(Graphics g) {
if (card == null) { return; }
boolean animate = Forge.animatedCardTapUntap;
//TODO: FCardPanel ishovered and CardStackPosition is BehindHorz or BehindVert...
float mod = isHighlighted()||isHovered() ? getWidth()/16f : 0f;
float padding = getPadding();
float x = padding;
float y = padding;
float w = getWidth() - 2 * padding;
float h = getHeight() - 2 * padding;
float x = padding-mod/2;
float y = padding-mod/2;
float w = (getWidth() - 2 * padding)+mod;
float h = (getHeight() - 2 * padding)+mod;
if (w == h) { //adjust width if needed to make room for tapping
w = h / ASPECT_RATIO;
}

View File

@@ -13,6 +13,7 @@ public abstract class FDisplayObject {
private boolean enabled = true;
private boolean rotate90 = false;
private boolean rotate180 = false;
private boolean hovered = false;
private final Rectangle bounds = new Rectangle();
public final Rectangle screenPos = new Rectangle();
@@ -86,6 +87,13 @@ public abstract class FDisplayObject {
visible = b0;
}
public boolean isHovered() {
return hovered;
}
public void setHovered(boolean b0) {
hovered = b0;
}
public boolean getRotate90() {
return rotate90;
}
@@ -117,10 +125,15 @@ public abstract class FDisplayObject {
}
public abstract void draw(Graphics g);
public float scrX, scrY;
public void buildTouchListeners(float screenX, float screenY, List<FDisplayObject> listeners) {
if (enabled && visible && screenPos.contains(screenX, screenY)) {
listeners.add(this);
}
//TODO: needs better logic, it must be the only current selectable
setHovered(this.enabled && this.visible && this.screenPos.contains(screenX, screenY));
scrX = screenX;
scrY = screenY;
}
public boolean press(float x, float y) {

View File

@@ -1,5 +1,6 @@
package forge.toolbox;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Align;
@@ -378,8 +379,8 @@ public class FLabel extends FDisplayObject implements IButton {
}
y += (h - iconHeight) / 2;
}
g.drawImage(icon, x, y, iconWidth, iconHeight);
float mod = isHovered() && selectable ? iconWidth < iconHeight ? iconWidth/8f : iconHeight/8f : 0;
g.drawImage(icon, x-mod/2, y-mod/2, iconWidth+mod, iconHeight+mod);
if (!text.isEmpty()) {
x += iconOffset;
@@ -388,6 +389,12 @@ public class FLabel extends FDisplayObject implements IButton {
}
}
else if (!text.isEmpty()) {
float oldAlpha = g.getfloatAlphaComposite();
if (isHovered() && selectable) {
g.setAlphaComposite(0.4f);
g.fillRect(Color.GRAY, x, y, w, h);
g.setAlphaComposite(oldAlpha);
}
drawText(g, x, y, w, h, alignment);
}
}

View File

@@ -2591,6 +2591,7 @@ lblUnlockTitleBar=Entriegle Titelzeile
lblRestoreDown=Unten wiederherstellen
lblMaximize=Mximieren
lblMinimize=Minimieren
lblShowBattlefield=Show Battlefield
#QuestFileLister.java
lblNameAndRank=Name | Rang
lblModeAndDifficulty=Modus | Schwierigkeit

View File

@@ -2589,6 +2589,7 @@ lblUnlockTitleBar=Unlock Title Bar
lblRestoreDown=Restore Down
lblMaximize=Maximize
lblMinimize=Minimize
lblShowBattlefield=Show Battlefield
#QuestFileLister.java
lblNameAndRank=Name | Rank
lblModeAndDifficulty=Mode | Difficulty

View File

@@ -2589,6 +2589,7 @@ lblUnlockTitleBar=desbloquear la barra de título
lblRestoreDown=Restaurar abajo
lblMaximize=Maximizar
lblMinimize=Minimizar
lblShowBattlefield=Show Battlefield
#QuestFileLister.java
lblNameAndRank=Nombre | Rango
lblModeAndDifficulty=Modo | Dificultad

View File

@@ -2588,6 +2588,7 @@ lblUnlockTitleBar=Sblocca barra del titolo
lblRestoreDown=Ripristina
lblMaximize=Massimizza
lblMinimize=Minimizza
lblShowBattlefield=Show Battlefield
#QuestFileLister.java
lblNameAndRank=Nome | Rango
lblModeAndDifficulty=Modo | Difficoltà

View File

@@ -2588,6 +2588,7 @@ lblUnlockTitleBar=タイトルバーをアンロック
lblRestoreDown=元に戻す
lblMaximize=最大化
lblMinimize=最小化
lblShowBattlefield=Show Battlefield
#QuestFileLister.java
lblNameAndRank=名前 | ランク
lblModeAndDifficulty=モード | 難易度

View File

@@ -2590,6 +2590,7 @@ lblUnlockTitleBar=解锁标题栏
lblRestoreDown=还原
lblMaximize=最大化
lblMinimize=最小化
lblShowBattlefield=Show Battlefield
#QuestFileLister.java
lblNameAndRank=名称 | 等级
lblModeAndDifficulty=模式 | 难度