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 org.newdawn.slick.Graphics;
import yugecin.opsudance.events.ResolutionChangedListener; import yugecin.opsudance.events.ResolutionChangedListener;
import yugecin.opsudance.events.SkinChangedListener;
import java.io.StringWriter; import java.io.StringWriter;
import static yugecin.opsudance.core.InstanceContainer.*; 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 * 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() { public BaseOpsuState() {
displayContainer.addResolutionChangedListener(this); displayContainer.addResolutionChangedListener(this);
skinservice.addSkinChangedListener(this);
} }
protected void revalidate() { protected void revalidate() {
@ -50,9 +53,18 @@ public abstract class BaseOpsuState implements OpsuState, ResolutionChangedListe
@Override @Override
public void render(Graphics g) { public void render(Graphics g) {
} }
@Override
public void onSkinChanged(String name) {
makeDirty();
}
@Override @Override
public void onResolutionChanged(int w, int h) { public void onResolutionChanged(int w, int h) {
makeDirty();
}
private void makeDirty() {
if (isCurrentState) { if (isCurrentState) {
revalidate(); revalidate();
return; return;

View File

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