mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Add support for highlighting selected menu item
This commit is contained in:
@@ -56,7 +56,7 @@ public abstract class FDropDownMenu extends FDropDown {
|
||||
|
||||
return new ScrollBounds(width, y);
|
||||
}
|
||||
|
||||
|
||||
public void addItem(FMenuItem item) {
|
||||
if (item.isVisible()) {
|
||||
items.add(add(item));
|
||||
|
||||
@@ -32,8 +32,7 @@ public class FMenuItem extends FDisplayObject implements IButton {
|
||||
private final String text;
|
||||
private final FImage icon;
|
||||
private final FEventHandler handler;
|
||||
private boolean pressed;
|
||||
private boolean allowForIcon;
|
||||
private boolean pressed, allowForIcon, selected;
|
||||
private float textWidth;
|
||||
|
||||
public FMenuItem(String text0, FEventHandler handler0) {
|
||||
@@ -97,7 +96,7 @@ public class FMenuItem extends FDisplayObject implements IButton {
|
||||
}
|
||||
|
||||
protected boolean showPressedColor() {
|
||||
return pressed;
|
||||
return pressed || selected;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,10 +133,11 @@ public class FMenuItem extends FDisplayObject implements IButton {
|
||||
}
|
||||
@Override
|
||||
public boolean isSelected() {
|
||||
return false;
|
||||
return selected;
|
||||
}
|
||||
@Override
|
||||
public void setSelected(boolean b0) {
|
||||
selected = b0;
|
||||
}
|
||||
@Override
|
||||
public boolean requestFocusInWindow() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package forge.screens.quest;
|
||||
|
||||
import forge.Forge;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.interfaces.IButton;
|
||||
import forge.interfaces.ICheckBox;
|
||||
@@ -49,7 +48,6 @@ public class QuestDuelsScreen extends LaunchScreen {
|
||||
|
||||
@Override
|
||||
protected boolean buildLaunchParams(LaunchParams launchParams) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import forge.properties.ForgeConstants;
|
||||
import forge.quest.IVQuestStats;
|
||||
import forge.quest.data.QuestPreferences.QPref;
|
||||
import forge.quest.io.QuestDataIO;
|
||||
import forge.screens.FScreen;
|
||||
import forge.screens.LoadingOverlay;
|
||||
import forge.toolbox.FEvent;
|
||||
import forge.toolbox.FEvent.FEventHandler;
|
||||
@@ -29,14 +30,22 @@ public class QuestMenu extends FPopupMenu implements IVQuestStats {
|
||||
private static final QuestStatsScreen statsScreen = new QuestStatsScreen();
|
||||
private static final QuestTournamentsScreen tournamentsScreen = new QuestTournamentsScreen();
|
||||
|
||||
private static final FMenuItem unlockSetsItem = new FMenuItem("Unlock Sets", FSkinImage.QUEST_MAP, new FEventHandler() {
|
||||
private static final FMenuItem duelsItem = new FMenuItem("Duels", FSkinImage.QUEST_GEAR, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
Forge.openScreen(duelsScreen);
|
||||
}
|
||||
});
|
||||
private static final FMenuItem travelItem = new FMenuItem("Travel", FSkinImage.QUEST_MAP, new FEventHandler() {
|
||||
private static final FMenuItem challengesItem = new FMenuItem("Challenges", FSkinImage.QUEST_HEART, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
Forge.openScreen(challengesScreen);
|
||||
}
|
||||
});
|
||||
private static final FMenuItem tournamentsItem = new FMenuItem("Tournaments", FSkinImage.PACK, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
Forge.openScreen(tournamentsScreen);
|
||||
}
|
||||
});
|
||||
private static final FMenuItem spellShopItem = new FMenuItem("Spell Shop", FSkinImage.QUEST_BOOK, new FEventHandler() {
|
||||
@@ -51,6 +60,22 @@ public class QuestMenu extends FPopupMenu implements IVQuestStats {
|
||||
Forge.openScreen(bazaarScreen);
|
||||
}
|
||||
});
|
||||
private static final FMenuItem statsItem = new FMenuItem("Statistics", FSkinImage.MULTI, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
Forge.openScreen(statsScreen);
|
||||
}
|
||||
});
|
||||
private static final FMenuItem unlockSetsItem = new FMenuItem("Unlock Sets", FSkinImage.QUEST_MAP, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
}
|
||||
});
|
||||
private static final FMenuItem travelItem = new FMenuItem("Travel", FSkinImage.QUEST_MAP, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
public static QuestMenu getMenu() {
|
||||
return questMenu;
|
||||
@@ -81,34 +106,15 @@ public class QuestMenu extends FPopupMenu implements IVQuestStats {
|
||||
|
||||
@Override
|
||||
protected void buildMenu() {
|
||||
addItem(new FMenuItem("Duels", FSkinImage.QUEST_GEAR, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
Forge.openScreen(duelsScreen);
|
||||
}
|
||||
}));
|
||||
addItem(new FMenuItem("Challenges", FSkinImage.QUEST_HEART, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
Forge.openScreen(challengesScreen);
|
||||
}
|
||||
}));
|
||||
addItem(new FMenuItem("Tournaments", FSkinImage.PACK, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
Forge.openScreen(tournamentsScreen);
|
||||
}
|
||||
}));
|
||||
FScreen currentScreen = Forge.getCurrentScreen();
|
||||
addItem(duelsItem); duelsItem.setSelected(currentScreen == duelsScreen);
|
||||
addItem(challengesItem); challengesItem.setSelected(currentScreen == challengesScreen);
|
||||
addItem(tournamentsItem); tournamentsItem.setSelected(currentScreen == tournamentsScreen);
|
||||
addItem(spellShopItem); spellShopItem.setSelected(currentScreen == spellShopScreen);
|
||||
addItem(bazaarItem); bazaarItem.setSelected(currentScreen == bazaarScreen);
|
||||
addItem(statsItem); statsItem.setSelected(currentScreen == statsScreen);
|
||||
addItem(unlockSetsItem);
|
||||
addItem(travelItem);
|
||||
addItem(spellShopItem);
|
||||
addItem(bazaarItem);
|
||||
addItem(new FMenuItem("Statistics", FSkinImage.MULTI, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
Forge.openScreen(statsScreen);
|
||||
}
|
||||
}));
|
||||
addItem(new FMenuItem("Change Deck", FSkinImage.DECKLIST, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
|
||||
@@ -177,12 +177,16 @@ public class FComboBox<E> extends FTextField implements IComboBox<E> {
|
||||
@Override
|
||||
protected void buildMenu() {
|
||||
for (final E item : FComboBox.this.items) {
|
||||
addItem(new FMenuItem(item.toString(), new FEventHandler() {
|
||||
FMenuItem menuItem = new FMenuItem(item.toString(), new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
setSelectedItem(item);
|
||||
}
|
||||
}));
|
||||
});
|
||||
if (selectedItem == item) {
|
||||
menuItem.setSelected(true);
|
||||
}
|
||||
addItem(menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user