Skip to content

Commit

Permalink
Add "seek to previous map" to random button
Browse files Browse the repository at this point in the history
  • Loading branch information
Rian8337 committed Aug 15, 2023
1 parent b087352 commit 0e68384
Showing 1 changed file with 59 additions and 8 deletions.
67 changes: 59 additions & 8 deletions src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@
import org.anddev.andengine.util.MathUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
import java.util.*;

import ru.nsu.ccfit.zuev.audio.BassSoundProvider;
import ru.nsu.ccfit.zuev.audio.Status;
Expand Down Expand Up @@ -110,6 +105,11 @@ public class SongMenu implements IUpdateHandler, MenuItemListener,
private AsyncTask boardTask;
private GroupType groupType = GroupType.MapSet;

private Timer previousSelectionTimer;
private final long previousSelectionInterval = 1000;
private boolean previousSelectionPerformed;
private final LinkedList<MenuItem> previousSelectedItems = new LinkedList<>();

public SongMenu() {
}

Expand Down Expand Up @@ -493,7 +493,6 @@ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
boolean moved = false;
private float dx = 0, dy = 0;


@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
Expand All @@ -502,14 +501,53 @@ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
moved = false;
dx = pTouchAreaLocalX;
dy = pTouchAreaLocalY;

if (previousSelectionTimer != null) {
previousSelectionTimer.cancel();
}

previousSelectionTimer = new Timer();
previousSelectionTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
MenuItem previousItem = previousSelectedItems.pollLast();
if (previousItem == null) {
cancel();
return;
}

previousSelectionPerformed = true;

ResourceManager.getInstance().getSound("menuclick")
.play();
previousItem.select(true, true);
}

@Override
public boolean cancel() {
if (previousSelectionTimer != null) {
previousSelectionTimer.cancel();
previousSelectionTimer = null;
}

return super.cancel();
}
}, previousSelectionInterval, previousSelectionInterval);

previousSelectionPerformed = false;
return true;
}
if (pSceneTouchEvent.isActionUp()) {
setFrame(0);
if (!isSelectComplete) {
return true;
}
if (!moved) {

if (previousSelectionTimer != null) {
previousSelectionTimer.cancel();
}

if (!moved && !previousSelectionPerformed) {
velocityY = 0;
if (items.size() <= 1) {
return true;
Expand All @@ -535,6 +573,8 @@ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
.play();
items.get(index).select(true, true);
}

previousSelectionPerformed = false;
return true;
}
if (pSceneTouchEvent.isActionOutside()
Expand All @@ -543,6 +583,10 @@ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
pTouchAreaLocalY) > 50)) {
moved = true;
setFrame(0);

if (pSceneTouchEvent.isActionOutside() && previousSelectionTimer != null) {
previousSelectionTimer.cancel();
}
}
return false;
}
Expand Down Expand Up @@ -830,6 +874,13 @@ public void select(final MenuItem item) {
secondsSinceLastSelect = 0;
if (selectedItem != null) {
selectedItem.deselect();

if (!previousSelectionPerformed) {
while (previousSelectedItems.size() >= 10) {
previousSelectedItems.pollFirst();
}
previousSelectedItems.addLast(selectedItem);
}
}

selectedItem = item;
Expand Down

0 comments on commit 0e68384

Please sign in to comment.