Better sector icons

This commit is contained in:
Anuken
2020-11-16 16:31:55 -05:00
parent 80130c69e4
commit 74f083b897
6 changed files with 48 additions and 14 deletions

View File

@@ -1354,7 +1354,7 @@ public class Blocks implements ContentList{
//region storage
coreShard = new CoreBlock("core-shard"){{
requirements(Category.effect, BuildVisibility.editorOnly, with(Items.copper, 1500, Items.lead, 1000));
requirements(Category.effect, BuildVisibility.editorOnly, with(Items.copper, 1000, Items.lead, 1000));
alwaysUnlocked = true;
unitType = UnitTypes.alpha;

View File

@@ -18,7 +18,7 @@ import static mindustry.Vars.*;
public class Planet extends UnlockableContent{
/** Default spacing between planet orbits in world units. */
private static final float orbitSpacing = 9f;
private static final float orbitSpacing = 10f;
/** intersect() temp var. */
private static final Vec3 intersectResult = new Vec3();
/** Mesh used for rendering. Created on load() - will be null on the server! */

View File

@@ -3,16 +3,16 @@ package mindustry.type;
import arc.*;
import arc.func.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.scene.style.*;
import arc.struct.*;
import arc.util.*;
import mindustry.*;
import mindustry.game.Saves.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.g3d.PlanetGrid.*;
import mindustry.ui.*;
import mindustry.world.modules.*;
import static mindustry.Vars.*;
@@ -122,8 +122,8 @@ public class Sector{
}
@Nullable
public TextureRegionDrawable icon(){
return info.icon == null ? null : Icon.icons.get(info.icon);
public TextureRegion icon(){
return info.icon == null ? null : Fonts.getLargeIcon(info.icon);
}
public boolean isCaptured(){

View File

@@ -25,13 +25,16 @@ import arc.util.*;
import mindustry.*;
import mindustry.core.*;
import mindustry.ctype.*;
import mindustry.gen.*;
import java.util.*;
public class Fonts{
private static final String mainFont = "fonts/font.woff";
private static final ObjectSet<String> unscaled = ObjectSet.with("iconLarge");
private static ObjectIntMap<String> unicodeIcons = new ObjectIntMap<>();
private static ObjectMap<String, String> stringIcons = new ObjectMap<>();
private static ObjectMap<String, TextureRegion> largeIcons = new ObjectMap<>();
private static TextureRegion[] iconTable;
private static int lastCid;
@@ -39,6 +42,7 @@ public class Fonts{
public static Font outline;
public static Font chat;
public static Font icon;
public static Font iconLarge;
public static Font tech;
public static TextureRegion logicIcon(int id){
@@ -67,6 +71,7 @@ public class Fonts{
}
public static void loadFonts(){
largeIcons.clear();
FreeTypeFontParameter param = fontParameter();
Core.assets.load("default", Font.class, new FreeTypeFontLoaderParameter(mainFont, param)).loaded = f -> Fonts.def = (Font)f;
@@ -76,6 +81,25 @@ public class Fonts{
incremental = true;
characters = "\0";
}})).loaded = f -> Fonts.icon = (Font)f;
Core.assets.load("iconLarge", Font.class, new FreeTypeFontLoaderParameter("fonts/icon.ttf", new FreeTypeFontParameter(){{
size = 48;
incremental = false;
characters = "\0" + Iconc.all;
borderWidth = Scl.scl(5f);
borderColor = Color.darkGray;
}})).loaded = f -> Fonts.iconLarge = (Font)f;
}
public static TextureRegion getLargeIcon(String name){
return largeIcons.get(name, () -> {
var region = new TextureRegion();
int code = Iconc.codes.get(name, '\uF8D4');
var glyph = iconLarge.getData().getGlyph((char)code);
region.set(iconLarge.getRegion().texture);
region.set(glyph.u, glyph.v2, glyph.u2, glyph.v);
return region;
});
}
public static void loadContentIcons(){
@@ -150,7 +174,8 @@ public class Fonts{
parameter.fontParameters.borderWidth = Scl.scl(2f);
parameter.fontParameters.spaceX -= parameter.fontParameters.borderWidth;
}
if(!scaled.contains(parameter.fontParameters)){
if(!scaled.contains(parameter.fontParameters) && !unscaled.contains(fileName)){
parameter.fontParameters.size = (int)(Scl.scl(parameter.fontParameters.size));
scaled.add(parameter.fontParameters);
}

View File

@@ -326,18 +326,18 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
@Override
public void renderProjections(Planet planet){
float isize = 38f/4f;
float iw = 48f/4f;
for(Sector sec : planet.sectors){
if(sec != hovered){
var preficon = sec.icon();
var icon = (sec.isAttacked() ? Icon.warning : !sec.hasBase() && sec.preset != null && sec.preset.unlocked() && preficon == null ? Icon.terrain : preficon);
var icon = (sec.isAttacked() ? Fonts.getLargeIcon("warning") : !sec.hasBase() && sec.preset != null && sec.preset.unlocked() && preficon == null ? Fonts.getLargeIcon("terrain") : preficon);
var color = sec.preset != null && !sec.hasBase() ? Team.derelict.color : Team.sharded.color;
if(icon != null){
planets.drawPlane(sec, () -> {
Draw.color(color, selectAlpha);
Draw.rect(icon.getRegion(), 0, 0, isize, isize);
Draw.rect(icon, 0, 0, iw, iw * icon.height / icon.width);
});
}
}
@@ -349,10 +349,10 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
planets.drawPlane(hovered, () -> {
Draw.color(hovered.isAttacked() ? Pal.remove : Color.white, Pal.accent, Mathf.absin(5f, 1f));
var icon = hovered.locked() && !canSelect(hovered) ? Icon.lock : hovered.isAttacked() ? Icon.warning : hovered.icon();
var icon = hovered.locked() && !canSelect(hovered) ? Fonts.getLargeIcon("lock") : hovered.isAttacked() ? Fonts.getLargeIcon("warning") : hovered.icon();
if(icon != null){
Draw.rect(icon.getRegion(), 0, 0, isize, isize);
Draw.rect(icon, 0, 0, iw, iw * icon.height / icon.width);
}
Draw.reset();
@@ -603,7 +603,6 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
Table stable = sectorTop;
if(sector == null){
//stable.remove();
return;
}
@@ -769,7 +768,6 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
float dot = planets.cam.direction.dot(Tmp.v31);
stable.color.a = Math.max(dot, 0f)*2f;
if(dot*2f <= -0.1f){
//stable.remove();
selected = null;
updateSelected();
}