mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-10 18:57:39 +07:00
Functional loading
This commit is contained in:
parent
1e80bdf19f
commit
5dfc3fd576
@ -17,6 +17,11 @@ gameover = Game Over
|
||||
gameover.pvp = The[accent] {0}[] team is victorious!
|
||||
highscore = [accent]New highscore!
|
||||
|
||||
load.sound = Sounds
|
||||
load.map = Maps
|
||||
load.image = Images
|
||||
load.content = Content
|
||||
|
||||
stat.wave = Waves Defeated:[accent] {0}
|
||||
stat.enemiesDestroyed = Enemies Destroyed:[accent] {0}
|
||||
stat.built = Buildings Built:[accent] {0}
|
||||
|
@ -16,12 +16,17 @@ import static io.anuke.arc.Core.*;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class ClientLauncher extends ApplicationCore{
|
||||
private static final int loadingFPS = 20;
|
||||
|
||||
private float smoothProgress, smoothTime;
|
||||
private long lastTime;
|
||||
private long beginTime;
|
||||
private boolean finished = false;
|
||||
|
||||
@Override
|
||||
public void setup(){
|
||||
Log.setUseColors(false);
|
||||
beginTime = Time.millis();
|
||||
|
||||
Time.setDeltaProvider(() -> {
|
||||
float result = Core.graphics.getDeltaTime() * 60f;
|
||||
@ -32,11 +37,14 @@ public class ClientLauncher extends ApplicationCore{
|
||||
assets = new AssetManager();
|
||||
atlas = TextureAtlas.blankAtlas();
|
||||
|
||||
Time.mark();
|
||||
UI.loadDefaultFont();
|
||||
UI.loadSystemCursors();
|
||||
Log.info("UI init: {0}", Time.elapsed());
|
||||
|
||||
assets.load(new Vars());
|
||||
assets.load(new AssetDescriptor<>("sprites/sprites.atlas", TextureAtlas.class)).loaded = t -> atlas = (TextureAtlas)t;
|
||||
|
||||
UI.loadSystemCursors();
|
||||
|
||||
Musics.load();
|
||||
Sounds.load();
|
||||
|
||||
@ -47,7 +55,7 @@ public class ClientLauncher extends ApplicationCore{
|
||||
add(netServer = new NetServer());
|
||||
add(netClient = new NetClient());
|
||||
|
||||
assets.loadRun("content::init+load", ContentLoader.class, () -> {
|
||||
assets.loadRun("Content", ContentLoader.class, () -> {
|
||||
content.init();
|
||||
content.load();
|
||||
});
|
||||
@ -80,10 +88,11 @@ public class ClientLauncher extends ApplicationCore{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
if(!assets.update()){
|
||||
if(!assets.update(1000 / loadingFPS)){
|
||||
drawLoading();
|
||||
}else{
|
||||
if(!finished){
|
||||
Log.info("Time to load: {0}", Time.timeSinceMillis(beginTime));
|
||||
post();
|
||||
finished = true;
|
||||
Events.fire(new ClientLoadEvent());
|
||||
@ -122,14 +131,28 @@ public class ClientLauncher extends ApplicationCore{
|
||||
}
|
||||
|
||||
void drawLoading(){
|
||||
smoothProgress = Mathf.lerpDelta(smoothProgress, assets.getProgress(), 0.1f);
|
||||
smoothTime += Time.delta();
|
||||
|
||||
Core.graphics.clear(Color.BLACK);
|
||||
Draw.proj().setOrtho(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight());
|
||||
float height = UnitScl.dp.scl(100f);
|
||||
float height = UnitScl.dp.scl(50f);
|
||||
|
||||
Draw.color(Pal.darkerGray);
|
||||
Fill.rect(graphics.getWidth()/2f, graphics.getHeight()/2f, graphics.getWidth(), height);
|
||||
Draw.color(Pal.accent);
|
||||
Fill.crect(0, graphics.getHeight()/2f - height/2f, graphics.getWidth() * assets.getProgress(), height);
|
||||
Draw.color(Pal.accent, Color.WHITE, Mathf.absin(smoothTime, 5f, 1f) * 0.5f);
|
||||
Fill.crect(0, graphics.getHeight()/2f - height/2f, graphics.getWidth() * smoothProgress, height);
|
||||
|
||||
if(assets.isLoaded("outline")){
|
||||
BitmapFont font = assets.get("outline");
|
||||
font.draw((int)(assets.getProgress() * 100) + "%", graphics.getWidth() / 2f, graphics.getHeight() / 2f, Align.center);
|
||||
|
||||
if(assets.getCurrentLoading() != null){
|
||||
String name = assets.getCurrentLoading().fileName.toLowerCase();
|
||||
String key = name.contains("msav") ? "map" : name.contains("ogg") || name.contains("mp3") ? "sound" : name.contains("png") ? "image" : "content";
|
||||
font.draw(bundle.get("load." + key, ""), graphics.getWidth() / 2f, graphics.getHeight() / 2f - height / 2f - 10f, Align.center);
|
||||
}
|
||||
}
|
||||
Draw.flush();
|
||||
}
|
||||
}
|
||||
|
@ -72,9 +72,6 @@ public class UI implements ApplicationListener, Loadable{
|
||||
public Cursor drillCursor, unloadCursor;
|
||||
|
||||
public UI(){
|
||||
FileHandleResolver resolver = new InternalFileHandleResolver();
|
||||
Core.assets.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
|
||||
Core.assets.setLoader(BitmapFont.class, null, new FreetypeFontLoader(resolver));
|
||||
skin = new Skin();
|
||||
setupFonts();
|
||||
}
|
||||
@ -89,6 +86,7 @@ public class UI implements ApplicationListener, Loadable{
|
||||
//TODO type-safe skin files
|
||||
skin.addRegions(Core.atlas);
|
||||
loadExtraStyle(skin);
|
||||
skin.add("outline", Core.assets.get("outline"));
|
||||
skin.getFont("default").getData().markupEnabled = true;
|
||||
skin.getFont("default").setOwnsTexture(false);
|
||||
skin.load(Core.files.internal("sprites/uiskin.json"));
|
||||
@ -132,6 +130,23 @@ public class UI implements ApplicationListener, Loadable{
|
||||
Core.graphics.restoreCursor();
|
||||
}
|
||||
|
||||
/** Called from a static context for use in the loading screen.*/
|
||||
public static void loadDefaultFont(){
|
||||
FileHandleResolver resolver = new InternalFileHandleResolver();
|
||||
Core.assets.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
|
||||
Core.assets.setLoader(BitmapFont.class, null, new FreetypeFontLoader(resolver));
|
||||
|
||||
FreeTypeFontParameter param = new FreeTypeFontParameter(){{
|
||||
size = fontParameter().size;
|
||||
borderColor = Color.DARK_GRAY;
|
||||
borderWidth = UnitScl.dp.scl(2f);
|
||||
spaceX -= borderWidth;
|
||||
incremental = true;
|
||||
}};
|
||||
|
||||
Core.assets.load("outline", BitmapFont.class, new FreeTypeFontLoaderParameter("fonts/font.ttf", param));
|
||||
}
|
||||
|
||||
void loadExtraStyle(Skin skin){
|
||||
AtlasRegion region = Core.atlas.find("flat-down-base");
|
||||
int[] splits = region.splits;
|
||||
@ -156,27 +171,22 @@ public class UI implements ApplicationListener, Loadable{
|
||||
unloadCursor = Core.graphics.newCursor("unload");
|
||||
}
|
||||
|
||||
void setupFonts(){
|
||||
public void setupFonts(){
|
||||
String fontName = "fonts/font.ttf";
|
||||
|
||||
FreeTypeFontParameter param = new FreeTypeFontParameter(){{
|
||||
FreeTypeFontParameter param = fontParameter();
|
||||
|
||||
Core.assets.load("default", BitmapFont.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> skin.add("default", f);
|
||||
Core.assets.load("chat", BitmapFont.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> skin.add("chat", f);
|
||||
}
|
||||
|
||||
static FreeTypeFontParameter fontParameter(){
|
||||
return new FreeTypeFontParameter(){{
|
||||
size = (int)(UnitScl.dp.scl(18f));
|
||||
shadowColor = Color.DARK_GRAY;
|
||||
shadowOffsetY = 2;
|
||||
incremental = true;
|
||||
}};
|
||||
|
||||
FreeTypeFontParameter outlined = new FreeTypeFontParameter(){{
|
||||
size = param.size;
|
||||
borderColor = Color.DARK_GRAY;
|
||||
borderWidth = UnitScl.dp.scl(2f);
|
||||
spaceX -= borderWidth;
|
||||
incremental = true;
|
||||
}};
|
||||
|
||||
Core.assets.load("outline", BitmapFont.class, new FreeTypeFontLoaderParameter(fontName, outlined)).loaded = f -> skin.add("outline", f);
|
||||
Core.assets.load("default", BitmapFont.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> skin.add("default", f);
|
||||
Core.assets.load("chat", BitmapFont.class, new FreeTypeFontLoaderParameter(fontName, param)).loaded = f -> skin.add("chat", f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user