Skip to content

Commit

Permalink
Merge pull request #500 from Shimi9999/fix-searchtextfield
Browse files Browse the repository at this point in the history
Fix searchtextfield
  • Loading branch information
exch-bms2 authored Mar 2, 2020
2 parents 20550b9 + 5811bad commit 46a3fb3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/bms/player/beatoraja/input/BMSPlayerInputProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public BMSPlayerInputProcessor(Config config, PlayerConfig player) {

private boolean exitPressed;
private boolean enterPressed;
private boolean enterLocked;
private boolean deletePressed;

boolean[] cursor = new boolean[4];
Expand Down Expand Up @@ -336,7 +337,17 @@ public boolean isEnterPressed() {
}

public void setEnterPressed(boolean enterPressed) {
this.enterPressed = enterPressed;
if (!enterPressed || !enterLocked) {
this.enterPressed = enterPressed;
}
if (enterLocked) {
enterLocked = false;
}
}

public void lockEnterPress() {
setEnterPressed(false);
enterLocked = true;
}

public boolean isDeletePressed() {
Expand Down
11 changes: 10 additions & 1 deletion src/bms/player/beatoraja/select/MusicSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.logging.Logger;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.*;
import com.badlogic.gdx.utils.ObjectMap.Keys;

Expand Down Expand Up @@ -281,7 +282,9 @@ public void create() {
loadSkin(SkinType.MUSIC_SELECT);

// search text field
if (getStage() == null && ((MusicSelectSkin) getSkin()).getSearchTextRegion() != null) {
Rectangle searchRegion = ((MusicSelectSkin) getSkin()).getSearchTextRegion();
if (searchRegion != null && (getStage() == null ||
(search != null && !searchRegion.equals(search.getSearchBounds())))) {
if(search != null) {
search.dispose();
}
Expand Down Expand Up @@ -351,6 +354,7 @@ public void render() {
}
preview.stop();
main.changeState(MainStateType.DECIDE);
search.unfocus(this);
banners.disposeOld();
stagefiles.disposeOld();
} else {
Expand Down Expand Up @@ -387,6 +391,7 @@ public void render() {
}
preview.stop();
main.changeState(MainStateType.DECIDE);
search.unfocus(this);
banners.disposeOld();
stagefiles.disposeOld();
} else {
Expand All @@ -411,6 +416,7 @@ public void render() {
if(resource.nextSong()) {
preview.stop();
main.changeState(MainStateType.DECIDE);
search.unfocus(this);
banners.disposeOld();
stagefiles.disposeOld();
}
Expand All @@ -427,9 +433,11 @@ public void input() {
if (input.getNumberState()[6]) {
preview.stop();
main.changeState(MainStateType.CONFIG);
search.unfocus(this);
} else if (input.isActivated(KeyCommand.OPEN_SKIN_CONFIGURATION)) {
preview.stop();
main.changeState(MainStateType.SKINCONFIG);
search.unfocus(this);
}

musicinput.input();
Expand Down Expand Up @@ -519,6 +527,7 @@ private void readCourse(PlayMode mode) {
resource.setCourseData(course.getCourseData());
resource.setBMSFile(files[0], mode);
main.changeState(MainStateType.DECIDE);
search.unfocus(this);
banners.disposeOld();
stagefiles.disposeOld();
} else {
Expand Down
39 changes: 37 additions & 2 deletions src/bms/player/beatoraja/select/SearchTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.viewport.FitViewport;
Expand All @@ -35,6 +36,10 @@ public class SearchTextField extends Stage {
private BitmapFont searchfont;

private TextField search;
/**
* 画面クリック感知用Actor
*/
private Group screen;

public SearchTextField(MusicSelector selector, Resolution resolution) {
super(new FitViewport(resolution.width, resolution.height));
Expand All @@ -61,6 +66,7 @@ public SearchTextField(MusicSelector selector, Resolution resolution) {

public void keyTyped(TextField textField, char key) {
if (key == '\n' || key == 13) {
boolean searched = false;
if (textField.getText().length() > 0) {
SearchWordBar swb = new SearchWordBar(selector, textField.getText());
int count = swb.getChildren().length;
Expand All @@ -71,13 +77,17 @@ public void keyTyped(TextField textField, char key) {
textField.setText("");
textField.setMessageText(count + " song(s) found");
textFieldStyle.messageFontColor = Color.valueOf("00c0c0");
searched = true;
} else {
selector.main.getInputProcessor().setEnterPressed(false);
textField.setText("");
textField.setMessageText("no song found");
textFieldStyle.messageFontColor = Color.DARK_GRAY;
}
}
if (!searched) {
// Enter入力がTextFieldとInputProcessorで2回発生するので、後者のEnter入力を一時的にロックする
selector.main.getInputProcessor().lockEnterPress();
}
textField.getOnscreenKeyboard().show(false);
setKeyboardFocus(null);
}
Expand All @@ -99,7 +109,6 @@ public void keyTyped(TextField textField, char key) {
search.setBounds(r.x, r.y, r.width, r.height);
search.setMaxLength(50);
search.setFocusTraversal(false);
addActor(search);

search.setVisible(true);
search.addListener(new EventListener() {
Expand All @@ -112,11 +121,33 @@ public boolean handle(Event e) {
return false;
}
});

screen = new Group();
screen.setBounds(0, 0, resolution.width, resolution.height);
screen.addListener(new ClickListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if (getKeyboardFocus() != null && !r.contains(x, y)) {
unfocus(selector);
}
return false;
}
});
screen.addActor(search);
addActor(screen);
} catch (GdxRuntimeException e) {
Logger.getGlobal().warning("Search Text読み込み失敗");
}
}

public void unfocus(MusicSelector selector) {
search.setText("");
search.setMessageText("search song");
search.getStyle().messageFontColor = Color.GRAY;
search.getOnscreenKeyboard().show(false);
setKeyboardFocus(null);
selector.main.getInputProcessor().getKeyBoardInputProcesseor().setEnable(true);
}

public void dispose() {
// super.dispose();
if(generator != null) {
Expand All @@ -128,4 +159,8 @@ public void dispose() {
searchfont = null;
}
}

public Rectangle getSearchBounds() {
return new Rectangle(search.getX(), search.getY(), search.getWidth(), search.getHeight());
}
}

0 comments on commit 46a3fb3

Please sign in to comment.