mirror of
https://github.com/Retera/WarsmashModEngine.git
synced 2022-07-31 17:38:59 +02:00
Some list box changes
This commit is contained in:
parent
ef61a0926c
commit
03bd5fcbaf
@ -381,4 +381,7 @@ public abstract class AbstractRenderableFrame implements UIFrame {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Rectangle getRenderBounds() {
|
||||
return this.renderBounds;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
@ -13,14 +16,35 @@ import com.etheller.warsmash.parsers.fdf.datamodel.FramePoint;
|
||||
import com.etheller.warsmash.parsers.fdf.datamodel.TextJustify;
|
||||
|
||||
public class ListBoxFrame extends ControlFrame {
|
||||
// TODO where are these colors in the UI definition files?
|
||||
private static final Color SELECT_COLOR = Color.BLUE;
|
||||
private static final Color MOUSE_OVER_HIGHLIGHT_COLOR = new Color(0.3f, 0.3f, 1.0f, 0.25f);
|
||||
|
||||
private final List<String> listItems = new ArrayList<>();
|
||||
private final List<SingleStringFrame> stringFrames = new ArrayList<>();
|
||||
private BitmapFont frameFont;
|
||||
private float listBoxBorder;
|
||||
private int selectedIndex = -1;
|
||||
private int mouseOverIndex = -1;
|
||||
|
||||
private final TextureFrame selectionFrame;
|
||||
private final TextureFrame mouseHighlightFrame;
|
||||
private GameUI gameUI;
|
||||
private Viewport viewport;
|
||||
|
||||
public ListBoxFrame(final String name, final UIFrame parent, final Viewport viewport) {
|
||||
super(name, parent);
|
||||
this.listBoxBorder = GameUI.convertX(viewport, 0.01f);
|
||||
this.selectionFrame = new TextureFrame(null, this, false, null);
|
||||
this.mouseHighlightFrame = new TextureFrame(null, this, false, null);
|
||||
final Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
|
||||
pixmap.setColor(SELECT_COLOR);
|
||||
pixmap.fill();
|
||||
this.selectionFrame.setTexture(new Texture(pixmap));
|
||||
final Pixmap mousePixmap = new Pixmap(1, 1, Format.RGBA8888);
|
||||
mousePixmap.setColor(MOUSE_OVER_HIGHLIGHT_COLOR);
|
||||
mousePixmap.fill();
|
||||
this.mouseHighlightFrame.setTexture(new Texture(mousePixmap));
|
||||
}
|
||||
|
||||
public void setListBoxBorder(final float listBoxBorder) {
|
||||
@ -37,6 +61,8 @@ public class ListBoxFrame extends ControlFrame {
|
||||
|
||||
@Override
|
||||
protected void innerPositionBounds(final GameUI gameUI, final Viewport viewport) {
|
||||
this.gameUI = gameUI;
|
||||
this.viewport = viewport;
|
||||
super.innerPositionBounds(gameUI, viewport);
|
||||
updateUI(gameUI, viewport);
|
||||
}
|
||||
@ -45,11 +71,15 @@ public class ListBoxFrame extends ControlFrame {
|
||||
for (final SingleStringFrame frame : this.stringFrames) {
|
||||
frame.positionBounds(gameUI, viewport);
|
||||
}
|
||||
this.selectionFrame.positionBounds(gameUI, viewport);
|
||||
this.mouseHighlightFrame.positionBounds(gameUI, viewport);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void internalRender(final SpriteBatch batch, final BitmapFont baseFont, final GlyphLayout glyphLayout) {
|
||||
super.internalRender(batch, baseFont, glyphLayout);
|
||||
this.selectionFrame.render(batch, baseFont, glyphLayout);
|
||||
this.mouseHighlightFrame.render(batch, baseFont, glyphLayout);
|
||||
for (final SingleStringFrame frame : this.stringFrames) {
|
||||
frame.render(batch, baseFont, glyphLayout);
|
||||
}
|
||||
@ -76,15 +106,27 @@ public class ListBoxFrame extends ControlFrame {
|
||||
// updateUI(gameUI, viewport);
|
||||
}
|
||||
|
||||
public void setSelectedIndex(final int selectedIndex) {
|
||||
this.selectedIndex = selectedIndex;
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
return this.selectedIndex;
|
||||
}
|
||||
|
||||
private void updateUI(final GameUI gameUI, final Viewport viewport) {
|
||||
this.stringFrames.clear();
|
||||
SingleStringFrame prev = null;
|
||||
int i = 0;
|
||||
boolean foundSelected = false;
|
||||
boolean foundMouseOver = false;
|
||||
for (final String string : this.listItems) {
|
||||
final boolean selected = (i == this.selectedIndex);
|
||||
final boolean mousedOver = (i == this.mouseOverIndex);
|
||||
final SingleStringFrame stringFrame = new SingleStringFrame("LISTY" + i++, this, Color.WHITE,
|
||||
TextJustify.LEFT, TextJustify.MIDDLE, this.frameFont);
|
||||
stringFrame.setText(string);
|
||||
stringFrame.setWidth(this.renderBounds.width);
|
||||
stringFrame.setWidth(this.renderBounds.width - (this.listBoxBorder * 2));
|
||||
stringFrame.setHeight(this.frameFont.getLineHeight());
|
||||
if (prev != null) {
|
||||
stringFrame.addSetPoint(new SetPoint(FramePoint.TOPLEFT, prev, FramePoint.BOTTOMLEFT, 0, 0));
|
||||
@ -95,16 +137,60 @@ public class ListBoxFrame extends ControlFrame {
|
||||
}
|
||||
this.stringFrames.add(stringFrame);
|
||||
prev = stringFrame;
|
||||
if (selected) {
|
||||
this.selectionFrame
|
||||
.addSetPoint(new SetPoint(FramePoint.TOPLEFT, stringFrame, FramePoint.TOPLEFT, 0, 0));
|
||||
this.selectionFrame
|
||||
.addSetPoint(new SetPoint(FramePoint.BOTTOMRIGHT, stringFrame, FramePoint.BOTTOMRIGHT, 0, 0));
|
||||
foundSelected = true;
|
||||
}
|
||||
else if (mousedOver) {
|
||||
this.mouseHighlightFrame
|
||||
.addSetPoint(new SetPoint(FramePoint.TOPLEFT, stringFrame, FramePoint.TOPLEFT, 0, 0));
|
||||
this.mouseHighlightFrame
|
||||
.addSetPoint(new SetPoint(FramePoint.BOTTOMRIGHT, stringFrame, FramePoint.BOTTOMRIGHT, 0, 0));
|
||||
foundMouseOver = true;
|
||||
}
|
||||
}
|
||||
this.selectionFrame.setVisible(foundSelected);
|
||||
this.mouseHighlightFrame.setVisible(foundMouseOver);
|
||||
positionChildren(gameUI, viewport);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UIFrame touchDown(final float screenX, final float screenY, final int button) {
|
||||
if (isVisible() && this.renderBounds.contains(screenX, screenY)) {
|
||||
|
||||
int index = 0;
|
||||
for (final SingleStringFrame stringFrame : this.stringFrames) {
|
||||
if (stringFrame.getRenderBounds().contains(screenX, screenY)) {
|
||||
this.selectedIndex = index;
|
||||
System.out.println("selected: " + index);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
updateUI(this.gameUI, this.viewport);
|
||||
return this;
|
||||
}
|
||||
return super.touchDown(screenX, screenY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UIFrame getFrameChildUnderMouse(final float screenX, final float screenY) {
|
||||
if (isVisible() && this.renderBounds.contains(screenX, screenY)) {
|
||||
int index = 0;
|
||||
int mouseOverIndex = -1;
|
||||
for (final SingleStringFrame stringFrame : this.stringFrames) {
|
||||
if (stringFrame.getRenderBounds().contains(screenX, screenY)) {
|
||||
mouseOverIndex = index;
|
||||
System.out.println("moused over: " + index);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (this.mouseOverIndex != mouseOverIndex) {
|
||||
this.mouseOverIndex = mouseOverIndex;
|
||||
updateUI(this.gameUI, this.viewport);
|
||||
}
|
||||
}
|
||||
return super.getFrameChildUnderMouse(screenX, screenY);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user