mark states as dirty when the skin changes

This commit is contained in:
yugecin 2018-07-20 20:26:56 +02:00
parent 8d109df629
commit 5a057a229e
No known key found for this signature in database
GPG Key ID: 2C5AC035A7068E44
2 changed files with 15 additions and 4 deletions

View File

@ -19,13 +19,15 @@ package yugecin.opsudance.core.state;
import org.newdawn.slick.Graphics;
import yugecin.opsudance.events.ResolutionChangedListener;
import yugecin.opsudance.events.SkinChangedListener;
import java.io.StringWriter;
import static yugecin.opsudance.core.InstanceContainer.*;
public abstract class BaseOpsuState implements OpsuState, ResolutionChangedListener {
public abstract class BaseOpsuState implements OpsuState, ResolutionChangedListener,
SkinChangedListener
{
/**
* state is dirty when resolution or skin changed but hasn't rendered yet
*/
@ -34,6 +36,7 @@ public abstract class BaseOpsuState implements OpsuState, ResolutionChangedListe
public BaseOpsuState() {
displayContainer.addResolutionChangedListener(this);
skinservice.addSkinChangedListener(this);
}
protected void revalidate() {
@ -51,8 +54,17 @@ public abstract class BaseOpsuState implements OpsuState, ResolutionChangedListe
public void render(Graphics g) {
}
@Override
public void onSkinChanged(String name) {
makeDirty();
}
@Override
public void onResolutionChanged(int w, int h) {
makeDirty();
}
private void makeDirty() {
if (isCurrentState) {
revalidate();
return;

View File

@ -19,6 +19,5 @@ package yugecin.opsudance.events;
public interface SkinChangedListener
{
void onSkinChanged(String stringName);
void onSkinChanged(String name);
}