-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More Abstraction and a few changes to existing API
- Loading branch information
Showing
13 changed files
with
177 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package de.geolykt.starloader.api; | ||
|
||
public interface Identifiable { | ||
|
||
/** | ||
* Obtains the usually unique (numeric) identifier of the object. There should be no duplicates. | ||
* However due to the way the game operates, there might be duplicates, which can have unintended consquences. | ||
* @return The UID of the empire | ||
*/ | ||
public int getUID(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/de/geolykt/starloader/api/gui/AutocloseableDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.geolykt.starloader.api.gui; | ||
|
||
public interface AutocloseableDialog { | ||
|
||
/** | ||
* Obtains the time at which the dialog will be closed automatically, or -1 if automatic closing is not done. | ||
* The time is relative to the starting point of {@link System#currentTimeMillis()} and is in milliseconds. | ||
*/ | ||
public long getAutocloseTime(); | ||
|
||
} |
28 changes: 2 additions & 26 deletions
28
src/main/java/de/geolykt/starloader/api/gui/BasicDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,8 @@ | ||
package de.geolykt.starloader.api.gui; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import de.geolykt.starloader.impl.DialogCloseListenerWrapper; | ||
import snoddasmannen.galimulator.Space; | ||
import snoddasmannen.galimulator.ui.bh; | ||
|
||
/** | ||
* A simple wrapper around the dialog, a graphical component of Galimulator | ||
* A basic dialog. | ||
*/ | ||
public class BasicDialog { | ||
public interface BasicDialog extends AutocloseableDialog, ButtonDialog { | ||
|
||
/** | ||
* Creates and displays a dialog | ||
* @param title The title of the dialog | ||
* @param description The description (content/body) of the dialog | ||
* @param choices The buttons of the dialog | ||
* @param listeners The listeners that are applied to the dialog | ||
* @param duration The duration that the dialog should stay opened in seconds | ||
* @param playSFX True if the close sound should be used. | ||
*/ | ||
public BasicDialog(@NotNull String title, @NotNull String description, @Nullable List<String> choices, | ||
@NotNull ArrayList<BasicDialogCloseListener> listeners, int duration, boolean playSFX) { | ||
bh dialog = Space.a(title, description, choices, duration, null, true); | ||
dialog.a(new DialogCloseListenerWrapper(listeners, playSFX)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/de/geolykt/starloader/api/gui/ButtonDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package de.geolykt.starloader.api.gui; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface ButtonDialog { | ||
|
||
/** | ||
* This call simulates a button click. However this method can also be called if the dialog was closed automatically. | ||
* @param buttonPressed Some magic value that I don't fully understand or null, if the dialog was closed automatically | ||
*/ | ||
public void close(@Nullable Object buttonPressed); // TODO understand the parameter | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/de/geolykt/starloader/apimixins/EmpireAnnalsMixins.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package de.geolykt.starloader.apimixins; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import de.geolykt.starloader.api.Galimulator; | ||
import de.geolykt.starloader.api.empire.Empire; | ||
import snoddasmannen.galimulator.GalColor; | ||
|
||
@Mixin(snoddasmannen.galimulator.EmpireAnnals.class) | ||
public class EmpireAnnalsMixins implements Empire { | ||
|
||
@Shadow | ||
public int empireId; | ||
|
||
@Shadow | ||
public int birthYear; | ||
|
||
@Shadow | ||
public int deathYear; | ||
|
||
@Shadow | ||
public String name; | ||
|
||
@Shadow | ||
public String nameIdentifier; | ||
|
||
@Shadow | ||
public GalColor color; | ||
|
||
@Override | ||
public int getFoundationYear() { | ||
return birthYear; | ||
} | ||
|
||
@Override | ||
public int getUID() { | ||
return empireId; | ||
} | ||
|
||
@Override | ||
public int getCollapseYear() { | ||
return deathYear; | ||
} | ||
|
||
@Override | ||
public @NotNull GalColor getColor() { | ||
return color; | ||
} | ||
|
||
@Override | ||
public @NotNull String getEmpireName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public int getStarCount() { | ||
if (deathYear != -1) { | ||
return 0; | ||
} else { | ||
return Galimulator.getEmpirePerUID(getUID()).getStarCount(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean hasCollapsed() { | ||
return deathYear != -1; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package de.geolykt.starloader.impl; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import de.geolykt.starloader.api.gui.BasicDialogCloseListener; | ||
import snoddasmannen.galimulator.Space; | ||
import snoddasmannen.galimulator.ui.bh; | ||
|
||
/** | ||
* A simple wrapper around the dialog, a graphical component of Galimulator | ||
*/ | ||
public class BasicDialog implements de.geolykt.starloader.api.gui.BasicDialog { | ||
|
||
protected final bh dialog; | ||
protected final long closeTime; | ||
|
||
/** | ||
* Creates and displays a dialog | ||
* @param title The title of the dialog | ||
* @param description The description (content/body) of the dialog | ||
* @param choices The buttons of the dialog | ||
* @param listeners The listeners that are applied to the dialog | ||
* @param duration The duration that the dialog should stay opened in seconds | ||
* @param playSFX True if the close sound should be used. | ||
*/ | ||
public BasicDialog(@NotNull String title, @NotNull String description, @Nullable List<String> choices, | ||
@NotNull ArrayList<BasicDialogCloseListener> listeners, int duration, boolean playSFX) { | ||
dialog = Space.a(title, description, choices, duration, null, true); | ||
dialog.a(new DialogCloseListenerWrapper(listeners, playSFX)); | ||
// Luckily the close time is final, so we only have to get it once | ||
try { | ||
Field field = this.dialog.getClass().getField("d"); | ||
field.setAccessible(true); | ||
closeTime = field.getLong(this.dialog); | ||
field.setAccessible(false); | ||
} catch (ReflectiveOperationException | SecurityException e) { | ||
throw new RuntimeException("Something went wrong while performing the reflections for Audiosample wrapping", e); | ||
} | ||
} | ||
|
||
/** | ||
* Obtains the time at which the dialog will be closed automatically, or -1 if automatic closing is not done. | ||
* The time is relative to the starting point of {@link System#currentTimeMillis()} and is in milliseconds. | ||
*/ | ||
public long getAutocloseTime() { | ||
return closeTime; | ||
} | ||
|
||
@Override | ||
public void close(@Nullable Object buttonPressed) { | ||
dialog.a(buttonPressed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters