simple bar notifications
This commit is contained in:
parent
3ba50ebe60
commit
9da723c50b
|
@ -37,6 +37,7 @@ import yugecin.opsudance.core.events.EventBus;
|
||||||
import yugecin.opsudance.core.errorhandling.ErrorDumpable;
|
import yugecin.opsudance.core.errorhandling.ErrorDumpable;
|
||||||
import yugecin.opsudance.core.inject.InstanceContainer;
|
import yugecin.opsudance.core.inject.InstanceContainer;
|
||||||
import yugecin.opsudance.core.state.OpsuState;
|
import yugecin.opsudance.core.state.OpsuState;
|
||||||
|
import yugecin.opsudance.core.state.specialstates.BarNotificationState;
|
||||||
import yugecin.opsudance.core.state.specialstates.FpsRenderState;
|
import yugecin.opsudance.core.state.specialstates.FpsRenderState;
|
||||||
import yugecin.opsudance.core.state.transitions.*;
|
import yugecin.opsudance.core.state.transitions.*;
|
||||||
import yugecin.opsudance.events.ResolutionChangedEvent;
|
import yugecin.opsudance.events.ResolutionChangedEvent;
|
||||||
|
@ -57,6 +58,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
||||||
private final InstanceContainer instanceContainer;
|
private final InstanceContainer instanceContainer;
|
||||||
|
|
||||||
private FpsRenderState fpsState;
|
private FpsRenderState fpsState;
|
||||||
|
private BarNotificationState barNotifState;
|
||||||
|
|
||||||
private TransitionState outTransitionState;
|
private TransitionState outTransitionState;
|
||||||
private TransitionState inTransitionState;
|
private TransitionState inTransitionState;
|
||||||
|
@ -123,6 +125,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
||||||
state.enter();
|
state.enter();
|
||||||
|
|
||||||
fpsState = instanceContainer.provide(FpsRenderState.class);
|
fpsState = instanceContainer.provide(FpsRenderState.class);
|
||||||
|
barNotifState = instanceContainer.provide(BarNotificationState.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,6 +158,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
|
||||||
state.preRenderUpdate(timeSinceLastRender);
|
state.preRenderUpdate(timeSinceLastRender);
|
||||||
state.render(graphics);
|
state.render(graphics);
|
||||||
fpsState.render(graphics);
|
fpsState.render(graphics);
|
||||||
|
barNotifState.render(graphics, timeSinceLastRender);
|
||||||
|
|
||||||
realRenderInterval = timeSinceLastRender;
|
realRenderInterval = timeSinceLastRender;
|
||||||
timeSinceLastRender = 0;
|
timeSinceLastRender = 0;
|
||||||
|
|
|
@ -20,6 +20,7 @@ package yugecin.opsudance.core.inject;
|
||||||
import yugecin.opsudance.PreStartupInitializer;
|
import yugecin.opsudance.PreStartupInitializer;
|
||||||
import yugecin.opsudance.core.DisplayContainer;
|
import yugecin.opsudance.core.DisplayContainer;
|
||||||
import yugecin.opsudance.core.events.EventBus;
|
import yugecin.opsudance.core.events.EventBus;
|
||||||
|
import yugecin.opsudance.core.state.specialstates.BarNotificationState;
|
||||||
import yugecin.opsudance.core.state.specialstates.FpsRenderState;
|
import yugecin.opsudance.core.state.specialstates.FpsRenderState;
|
||||||
import yugecin.opsudance.core.state.transitions.EmptyTransitionState;
|
import yugecin.opsudance.core.state.transitions.EmptyTransitionState;
|
||||||
import yugecin.opsudance.core.state.transitions.FadeInTransitionState;
|
import yugecin.opsudance.core.state.transitions.FadeInTransitionState;
|
||||||
|
@ -39,6 +40,7 @@ public class OpsuDanceInjector extends Injector {
|
||||||
bind(ErrorHandler.class).asEagerSingleton();
|
bind(ErrorHandler.class).asEagerSingleton();
|
||||||
|
|
||||||
bind(FpsRenderState.class).asEagerSingleton();
|
bind(FpsRenderState.class).asEagerSingleton();
|
||||||
|
bind(BarNotificationState.class).asEagerSingleton();
|
||||||
|
|
||||||
bind(EmptyTransitionState.class).asEagerSingleton();
|
bind(EmptyTransitionState.class).asEagerSingleton();
|
||||||
bind(FadeInTransitionState.class).asEagerSingleton();
|
bind(FadeInTransitionState.class).asEagerSingleton();
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* opsu!dance - fork of opsu! with cursordance auto
|
||||||
|
* Copyright (C) 2017 yugecin
|
||||||
|
*
|
||||||
|
* opsu!dance is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* opsu!dance is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with opsu!dance. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package yugecin.opsudance.core.state.specialstates;
|
||||||
|
|
||||||
|
import itdelatrisu.opsu.ui.Fonts;
|
||||||
|
import org.newdawn.slick.Color;
|
||||||
|
import org.newdawn.slick.Graphics;
|
||||||
|
import yugecin.opsudance.core.DisplayContainer;
|
||||||
|
import yugecin.opsudance.core.events.EventBus;
|
||||||
|
import yugecin.opsudance.core.events.EventListener;
|
||||||
|
import yugecin.opsudance.events.BarNotificationEvent;
|
||||||
|
import yugecin.opsudance.events.ResolutionChangedEvent;
|
||||||
|
|
||||||
|
public class BarNotificationState implements EventListener<BarNotificationEvent> {
|
||||||
|
|
||||||
|
private final int NOTIFICATION_TIME = 5000;
|
||||||
|
|
||||||
|
private final DisplayContainer displayContainer;
|
||||||
|
private final Color bgcol;
|
||||||
|
|
||||||
|
private int timeShown;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
private int textX;
|
||||||
|
private int textY;
|
||||||
|
private int barY;
|
||||||
|
private int barHeight;
|
||||||
|
|
||||||
|
public BarNotificationState(DisplayContainer displayContainer, EventBus eventBus) {
|
||||||
|
this.displayContainer = displayContainer;
|
||||||
|
this.bgcol = new Color(0f, 0f, 0f, 0f);
|
||||||
|
this.timeShown = NOTIFICATION_TIME;
|
||||||
|
eventBus.subscribe(BarNotificationEvent.class, this);
|
||||||
|
eventBus.subscribe(ResolutionChangedEvent.class, new EventListener<ResolutionChangedEvent>() {
|
||||||
|
@Override
|
||||||
|
public void onEvent(ResolutionChangedEvent event) {
|
||||||
|
if (timeShown >= NOTIFICATION_TIME) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
calculatePosition();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(Graphics g, int delta) {
|
||||||
|
if (timeShown >= NOTIFICATION_TIME) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
timeShown += delta;
|
||||||
|
g.setColor(bgcol);
|
||||||
|
g.fillRect(0, barY, displayContainer.width, barHeight);
|
||||||
|
Fonts.LARGE.drawString(textX, textY, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculatePosition() {
|
||||||
|
int textHeight = Fonts.LARGE.getHeight(message);
|
||||||
|
int textWidth = Fonts.LARGE.getWidth(message);
|
||||||
|
textX = (displayContainer.width - textWidth) / 2;
|
||||||
|
textY = (displayContainer.height - textHeight) / 2;
|
||||||
|
barY = textY - 5; // TODO uiscale stuff?
|
||||||
|
barHeight = textHeight + 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(BarNotificationEvent event) {
|
||||||
|
this.message = event.message;
|
||||||
|
calculatePosition();
|
||||||
|
timeShown = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
28
src/yugecin/opsudance/events/BarNotificationEvent.java
Normal file
28
src/yugecin/opsudance/events/BarNotificationEvent.java
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* opsu!dance - fork of opsu! with cursordance auto
|
||||||
|
* Copyright (C) 2017 yugecin
|
||||||
|
*
|
||||||
|
* opsu!dance is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* opsu!dance is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with opsu!dance. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package yugecin.opsudance.events;
|
||||||
|
|
||||||
|
public class BarNotificationEvent {
|
||||||
|
|
||||||
|
public final String message;
|
||||||
|
|
||||||
|
public BarNotificationEvent(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ import org.newdawn.slick.Color;
|
||||||
import org.newdawn.slick.Graphics;
|
import org.newdawn.slick.Graphics;
|
||||||
import yugecin.opsudance.core.DisplayContainer;
|
import yugecin.opsudance.core.DisplayContainer;
|
||||||
import yugecin.opsudance.core.state.OpsuState;
|
import yugecin.opsudance.core.state.OpsuState;
|
||||||
|
import yugecin.opsudance.events.BarNotificationEvent;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
@ -93,6 +94,7 @@ public class EmptyRedState implements OpsuState {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseReleased(int button, int x, int y) {
|
public boolean mouseReleased(int button, int x, int y) {
|
||||||
|
displayContainer.eventBus.post(new BarNotificationEvent("this is a\nbar notification"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user