WIP objective system
This commit is contained in:
@@ -568,6 +568,8 @@ map.multiplayer = Only the host can view sectors.
|
|||||||
uncover = Uncover
|
uncover = Uncover
|
||||||
configure = Configure Loadout
|
configure = Configure Loadout
|
||||||
|
|
||||||
|
objective.research = [accent]Research:\n[]{0}[lightgray]{1}
|
||||||
|
|
||||||
loadout = Loadout
|
loadout = Loadout
|
||||||
resources = Resources
|
resources = Resources
|
||||||
resources.max = Max
|
resources.max = Max
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package mindustry.content;
|
package mindustry.content;
|
||||||
|
|
||||||
|
import mindustry.game.MapObjectives.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
|
|
||||||
import static mindustry.content.Planets.*;
|
import static mindustry.content.Planets.*;
|
||||||
@@ -112,6 +113,15 @@ public class SectorPresets{
|
|||||||
addStartingItems = true;
|
addStartingItems = true;
|
||||||
alwaysUnlocked = true;
|
alwaysUnlocked = true;
|
||||||
difficulty = 1;
|
difficulty = 1;
|
||||||
|
|
||||||
|
rules = r -> {
|
||||||
|
r.objectives.addAll(new ResearchObjective(Items.beryllium){{
|
||||||
|
markers = new ObjectiveMarker[]{
|
||||||
|
new TextMarker("Units can mine [accent]resources[] from walls.", 1984f, 2240f + 16f),
|
||||||
|
new ShapeMarker(1984f, 2240f),
|
||||||
|
};
|
||||||
|
}});
|
||||||
|
};
|
||||||
}};
|
}};
|
||||||
|
|
||||||
two = new SectorPreset("two", erekir, 88){{
|
two = new SectorPreset("two", erekir, 88){{
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ public class Logic implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateWeather(){
|
protected void updateWeather(){
|
||||||
state.rules.weather.removeAll(w -> w.weather == null);
|
state.rules.weather.removeAll(w -> w.weather == null);
|
||||||
|
|
||||||
for(WeatherEntry entry : state.rules.weather){
|
for(WeatherEntry entry : state.rules.weather){
|
||||||
@@ -297,6 +297,40 @@ public class Logic implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void updateObjectives(){
|
||||||
|
//update objectives; do not get completed clientside
|
||||||
|
if(state.rules.objectives.size > 0){
|
||||||
|
var first = state.rules.objectives.first();
|
||||||
|
first.update();
|
||||||
|
|
||||||
|
//initialize markers
|
||||||
|
for(var marker : first.markers){
|
||||||
|
if(!marker.wasAdded){
|
||||||
|
marker.wasAdded = true;
|
||||||
|
marker.added();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!net.client() && first.complete()){
|
||||||
|
state.rules.objectives.remove(0);
|
||||||
|
if(!headless){
|
||||||
|
//delete markers
|
||||||
|
for(var marker : first.markers){
|
||||||
|
if(marker.wasAdded){
|
||||||
|
marker.removed();
|
||||||
|
marker.wasAdded = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO call packet for this?
|
||||||
|
if(net.server()){
|
||||||
|
Call.setRules(state.rules);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Remote(called = Loc.server)
|
@Remote(called = Loc.server)
|
||||||
public static void sectorCapture(){
|
public static void sectorCapture(){
|
||||||
//the sector has been conquered - waves get disabled
|
//the sector has been conquered - waves get disabled
|
||||||
@@ -436,20 +470,7 @@ public class Logic implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO objectives clientside???
|
//TODO objectives clientside???
|
||||||
|
updateObjectives();
|
||||||
//update objectives; do not get completed clientside
|
|
||||||
if(state.rules.objectives.size > 0){
|
|
||||||
var first = state.rules.objectives.first();
|
|
||||||
first.update();
|
|
||||||
if(!net.client() && first.complete()){
|
|
||||||
state.rules.objectives.remove(0);
|
|
||||||
|
|
||||||
//TODO call packet for this?
|
|
||||||
if(net.server()){
|
|
||||||
Call.setRules(state.rules);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(state.rules.waves && state.rules.waveTimer && !state.gameOver){
|
if(state.rules.waves && state.rules.waveTimer && !state.gameOver){
|
||||||
if(!isWaitingWave()){
|
if(!isWaitingWave()){
|
||||||
|
|||||||
@@ -31,7 +31,11 @@ public abstract class WorldLabelComp implements Posc, Drawc, Syncc{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(){
|
public void draw(){
|
||||||
Draw.z(z);
|
drawAt(text, x, y, z, flags, fontSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawAt(String text, float x, float y, float layer, int flags, float fontSize){
|
||||||
|
Draw.z(layer);
|
||||||
float z = Drawf.text();
|
float z = Drawf.text();
|
||||||
|
|
||||||
Font font = (flags & flagOutline) != 0 ? Fonts.outline : Fonts.def;
|
Font font = (flags & flagOutline) != 0 ? Fonts.outline : Fonts.def;
|
||||||
|
|||||||
@@ -1,13 +1,52 @@
|
|||||||
package mindustry.game;
|
package mindustry.game;
|
||||||
|
|
||||||
|
import arc.*;
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
import arc.struct.*;
|
import arc.graphics.*;
|
||||||
|
import arc.graphics.g2d.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import mindustry.content.*;
|
||||||
|
import mindustry.ctype.*;
|
||||||
|
import mindustry.gen.*;
|
||||||
|
import mindustry.graphics.*;
|
||||||
|
|
||||||
public class MapObjectives{
|
public class MapObjectives{
|
||||||
public static Seq<Prov<MapObjective>> allObjectiveTypes = Seq.with();
|
public static Prov<MapObjective>[] allObjectiveTypes = new Prov[]{
|
||||||
|
ResearchObjective::new
|
||||||
|
};
|
||||||
|
|
||||||
public abstract class MapObjective{
|
public static Prov<ObjectiveMarker>[] allMarkerTypes = new Prov[]{
|
||||||
|
TextMarker::new, ShapeMarker::new
|
||||||
|
};
|
||||||
|
|
||||||
|
public static class ResearchObjective extends MapObjective{
|
||||||
|
public UnlockableContent content = Items.copper;
|
||||||
|
|
||||||
|
public ResearchObjective(UnlockableContent content){
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResearchObjective(){
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String text(){
|
||||||
|
return Core.bundle.format("objective.research", content.emoji(), content.localizedName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean complete(){
|
||||||
|
return content.unlocked();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String details(){
|
||||||
|
return super.details();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class MapObjective{
|
||||||
|
public ObjectiveMarker[] markers = {};
|
||||||
|
|
||||||
public boolean complete(){
|
public boolean complete(){
|
||||||
return false;
|
return false;
|
||||||
@@ -22,8 +61,76 @@ public class MapObjectives{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable String text(){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable String details(){
|
public @Nullable String details(){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ShapeMarker extends ObjectiveMarker{
|
||||||
|
public float x, y, radius = 6f, rotation = 0f;
|
||||||
|
public int sides = 4;
|
||||||
|
public Color color = Pal.accent;
|
||||||
|
|
||||||
|
public ShapeMarker(float x, float y){
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShapeMarker(){
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(){
|
||||||
|
Lines.stroke(3f, Pal.gray);
|
||||||
|
Lines.poly(x, y, sides, radius + 1f, rotation);
|
||||||
|
Lines.stroke(1f, color);
|
||||||
|
Lines.poly(x, y, sides, radius + 1f, rotation);
|
||||||
|
Draw.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TextMarker extends ObjectiveMarker{
|
||||||
|
public String text = "sample text";
|
||||||
|
public float x, y, fontSize = 1f;
|
||||||
|
public byte flags = WorldLabel.flagBackground | WorldLabel.flagOutline;
|
||||||
|
|
||||||
|
public TextMarker(String text, float x, float y, float fontSize, byte flags){
|
||||||
|
this.text = text;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.fontSize = fontSize;
|
||||||
|
this.flags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextMarker(String text, float x, float y){
|
||||||
|
this.text = text;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextMarker(){
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(){
|
||||||
|
WorldLabel.drawAt(text, x, y, Draw.z(), flags, fontSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Marker used for drawing UI to indicate something along with an objective. */
|
||||||
|
public static abstract class ObjectiveMarker{
|
||||||
|
/** makes sure markers are only added once */
|
||||||
|
public transient boolean wasAdded;
|
||||||
|
|
||||||
|
/** Called in the overlay draw layer.*/
|
||||||
|
public void draw(){}
|
||||||
|
/** Add any UI elements necessary. */
|
||||||
|
public void added(){}
|
||||||
|
/** Remove any UI elements, if necessary. */
|
||||||
|
public void removed(){}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,11 +113,18 @@ public class OverlayRenderer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//draw objective markers, if any
|
||||||
|
if(state.rules.objectives.size > 0){
|
||||||
|
var first = state.rules.objectives.first();
|
||||||
|
for(var marker : first.markers){
|
||||||
|
marker.draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(player.dead()) return; //dead players don't draw
|
if(player.dead()) return; //dead players don't draw
|
||||||
|
|
||||||
InputHandler input = control.input;
|
InputHandler input = control.input;
|
||||||
|
|
||||||
|
|
||||||
Sized select = input.selectedUnit();
|
Sized select = input.selectedUnit();
|
||||||
if(select == null) select = input.selectedControlBuild();
|
if(select == null) select = input.selectedControlBuild();
|
||||||
if(!Core.input.keyDown(Binding.control)) select = null;
|
if(!Core.input.keyDown(Binding.control)) select = null;
|
||||||
|
|||||||
@@ -747,6 +747,16 @@ public class HudFragment{
|
|||||||
table.labelWrap(() -> {
|
table.labelWrap(() -> {
|
||||||
builder.setLength(0);
|
builder.setLength(0);
|
||||||
|
|
||||||
|
//objectives override mission?
|
||||||
|
if(state.rules.objectives.size > 0){
|
||||||
|
var first = state.rules.objectives.first();
|
||||||
|
String text = first.text();
|
||||||
|
if(text != null){
|
||||||
|
builder.append(text);
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//mission overrides everything
|
//mission overrides everything
|
||||||
if(state.rules.mission != null){
|
if(state.rules.mission != null){
|
||||||
builder.append(state.rules.mission);
|
builder.append(state.rules.mission);
|
||||||
|
|||||||
Reference in New Issue
Block a user