make the menu work
This commit is contained in:
parent
f466fafa03
commit
43e1109f40
|
@ -337,7 +337,7 @@ public class Game extends BasicGameState {
|
||||||
int width = container.getWidth();
|
int width = container.getWidth();
|
||||||
int height = container.getHeight();
|
int height = container.getHeight();
|
||||||
|
|
||||||
sbOverlay.init(input, width, height);
|
sbOverlay.init(container, input, width, height);
|
||||||
|
|
||||||
// create offscreen graphics
|
// create offscreen graphics
|
||||||
offscreen = new Image(width, height);
|
offscreen = new Image(width, height);
|
||||||
|
@ -687,7 +687,7 @@ public class Game extends BasicGameState {
|
||||||
else
|
else
|
||||||
UI.draw(g);
|
UI.draw(g);
|
||||||
|
|
||||||
sbOverlay.render(g);
|
sbOverlay.render(container, game, g);
|
||||||
|
|
||||||
if (!Dancer.hidewatermark) {
|
if (!Dancer.hidewatermark) {
|
||||||
Fonts.SMALL.drawString(0.3f, 0.3f, "opsu!dance " + Updater.get().getCurrentVersion() + " by robin_be | https://github.com/yugecin/opsu-dance");
|
Fonts.SMALL.drawString(0.3f, 0.3f, "opsu!dance " + Updater.get().getCurrentVersion() + " by robin_be | https://github.com/yugecin/opsu-dance");
|
||||||
|
@ -1227,6 +1227,10 @@ public class Game extends BasicGameState {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(int button, int x, int y) {
|
public void mouseReleased(int button, int x, int y) {
|
||||||
|
if (sbOverlay.mouseReleased(button, x, y)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Options.isMouseDisabled())
|
if (Options.isMouseDisabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1269,6 +1273,9 @@ public class Game extends BasicGameState {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseWheelMoved(int newValue) {
|
public void mouseWheelMoved(int newValue) {
|
||||||
|
if (sbOverlay.mouseWheelMoved(newValue)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Options.isMouseWheelDisabled() || Options.isMouseDisabled())
|
if (Options.isMouseWheelDisabled() || Options.isMouseDisabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,13 @@ import itdelatrisu.opsu.Options;
|
||||||
import itdelatrisu.opsu.ui.Colors;
|
import itdelatrisu.opsu.ui.Colors;
|
||||||
import itdelatrisu.opsu.ui.Fonts;
|
import itdelatrisu.opsu.ui.Fonts;
|
||||||
import org.newdawn.slick.Color;
|
import org.newdawn.slick.Color;
|
||||||
|
import org.newdawn.slick.GameContainer;
|
||||||
import org.newdawn.slick.Graphics;
|
import org.newdawn.slick.Graphics;
|
||||||
import org.newdawn.slick.Input;
|
import org.newdawn.slick.Input;
|
||||||
|
import org.newdawn.slick.state.StateBasedGame;
|
||||||
|
|
||||||
|
import java.util.Observable;
|
||||||
|
import java.util.Observer;
|
||||||
|
|
||||||
public class OptionsOverlay {
|
public class OptionsOverlay {
|
||||||
|
|
||||||
|
@ -62,15 +67,24 @@ public class OptionsOverlay {
|
||||||
|
|
||||||
private int textHeight;
|
private int textHeight;
|
||||||
private Input input;
|
private Input input;
|
||||||
|
private final ItemList list;
|
||||||
|
private GameContainer container;
|
||||||
|
private Options.GameOption selectedOption;
|
||||||
|
|
||||||
public void init(Input input, int width, int height) {
|
public OptionsOverlay() {
|
||||||
|
list = new ItemList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(GameContainer container, Input input, int width, int height) {
|
||||||
|
list.init(container);
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
this.container = container;
|
||||||
textHeight = Fonts.SMALL.getLineHeight();
|
textHeight = Fonts.SMALL.getLineHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(Graphics g) {
|
public void render(GameContainer container, StateBasedGame game, Graphics g) {
|
||||||
int hoverIdx = getOptionIdxAt(input.getMouseY());
|
int hoverIdx = getOptionIdxAt(input.getMouseY());
|
||||||
float a = Color.black.a;
|
float a = Color.black.a;
|
||||||
Color.black.a = 0.8f;
|
Color.black.a = 0.8f;
|
||||||
|
@ -78,7 +92,10 @@ public class OptionsOverlay {
|
||||||
g.fillRect(0, 0, width, height);
|
g.fillRect(0, 0, width, height);
|
||||||
Color.black.a = a;
|
Color.black.a = a;
|
||||||
for (int i = 0; i < options.length; i++) {
|
for (int i = 0; i < options.length; i++) {
|
||||||
drawOption(g, options[i], i, hoverIdx == i);
|
drawOption(g, options[i], i, selectedOption == null ? hoverIdx == i : selectedOption == options[i]);
|
||||||
|
}
|
||||||
|
if (list.isVisible()) {
|
||||||
|
list.render(container, game, g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,11 +123,72 @@ public class OptionsOverlay {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean mousePressed(int button, int x, int y) {
|
public boolean mousePressed(int button, int x, int y) {
|
||||||
return false;
|
if (list.isVisible()) {
|
||||||
|
list.mousePressed(button, x, y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int idx = getOptionIdxAt(y);
|
||||||
|
if (idx < options.length) {
|
||||||
|
final Options.GameOption option = options[idx];
|
||||||
|
selectedOption = option;
|
||||||
|
Object[] listItems = option.getListItems();
|
||||||
|
if (listItems == null) {
|
||||||
|
option.click(container);
|
||||||
|
} else {
|
||||||
|
list.setItems(listItems);
|
||||||
|
list.setClickListener(new Observer() {
|
||||||
|
@Override
|
||||||
|
public void update(Observable o, Object arg) {
|
||||||
|
option.clickListItem((int) arg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
list.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
|
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
|
||||||
|
if (list.isVisible()) {
|
||||||
|
list.mouseDragged(oldx, oldy, newx, newy);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int multiplier;
|
||||||
|
if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON))
|
||||||
|
multiplier = 4;
|
||||||
|
else if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON))
|
||||||
|
multiplier = 1;
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
|
// get direction
|
||||||
|
int diff = newx - oldx;
|
||||||
|
if (diff == 0)
|
||||||
|
return;
|
||||||
|
diff = ((diff > 0) ? 1 : -1) * multiplier;
|
||||||
|
|
||||||
|
// options (drag only)
|
||||||
|
if (selectedOption != null) {
|
||||||
|
selectedOption.drag(container, diff);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean mouseReleased(int button, int x, int y) {
|
||||||
|
selectedOption = null;
|
||||||
|
if (list.isVisible()) {
|
||||||
|
list.mouseReleased(button, x, y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean mouseWheenMoved(int newValue) {
|
||||||
|
if (list.isVisible()) {
|
||||||
|
list.mouseWheelMoved(newValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,10 @@ import itdelatrisu.opsu.objects.GameObject;
|
||||||
import itdelatrisu.opsu.states.Game;
|
import itdelatrisu.opsu.states.Game;
|
||||||
import itdelatrisu.opsu.ui.Fonts;
|
import itdelatrisu.opsu.ui.Fonts;
|
||||||
import org.newdawn.slick.Color;
|
import org.newdawn.slick.Color;
|
||||||
|
import org.newdawn.slick.GameContainer;
|
||||||
import org.newdawn.slick.Graphics;
|
import org.newdawn.slick.Graphics;
|
||||||
import org.newdawn.slick.Input;
|
import org.newdawn.slick.Input;
|
||||||
|
import org.newdawn.slick.state.StateBasedGame;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@ -51,15 +53,15 @@ public class SBOverlay {
|
||||||
options = new OptionsOverlay();
|
options = new OptionsOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(Input input, int width, int height) {
|
public void init(GameContainer container, Input input, int width, int height) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
speed = 10;
|
speed = 10;
|
||||||
gameObjects = new GameObject[0];
|
gameObjects = new GameObject[0];
|
||||||
options.init(input, width, height);
|
options.init(container, input, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(Graphics g) {
|
public void render(GameContainer container, StateBasedGame game, Graphics g) {
|
||||||
if (!isActive || hide) {
|
if (!isActive || hide) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +71,7 @@ public class SBOverlay {
|
||||||
Fonts.SMALL.drawString(10, height - 50 - lh * 2, "HIDE: H", Color.cyan);
|
Fonts.SMALL.drawString(10, height - 50 - lh * 2, "HIDE: H", Color.cyan);
|
||||||
Fonts.SMALL.drawString(10, height - 50 - lh * 3, "obj: J " + index + " K", Color.cyan);
|
Fonts.SMALL.drawString(10, height - 50 - lh * 3, "obj: J " + index + " K", Color.cyan);
|
||||||
if (menu) {
|
if (menu) {
|
||||||
options.render(g);
|
options.render(container, game, g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,4 +149,11 @@ public class SBOverlay {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean mouseReleased(int button, int x, int y) {
|
||||||
|
return menu && options.mouseReleased(button, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean mouseWheelMoved(int newValue) {
|
||||||
|
return menu && options.mouseWheenMoved(newValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user