mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-22 12:38:05 +07:00
Mod subtitles
This commit is contained in:
parent
f892811ac3
commit
1075e4b1b7
@ -5,15 +5,7 @@ let modName = "none"
|
||||
|
||||
const log = (context, obj) => Vars.mods.scripts.log(context, String(obj))
|
||||
const print = text => log(modName + "/" + scriptName, text)
|
||||
const readString = path => Vars.mods.scripts.readString(path)
|
||||
const readBytes = path => Vars.mods.scripts.readBytes(path)
|
||||
const loadMusic = path => Vars.mods.scripts.loadMusic(path)
|
||||
const loadSound = path => Vars.mods.scripts.loadSound(path)
|
||||
|
||||
const readFile = (purpose, ext, cons) => Vars.mods.scripts.readFile(purpose, ext, cons);
|
||||
const readBinFile = (purpose, ext, cons) => Vars.mods.scripts.readBinFile(purpose, ext, cons);
|
||||
const writeFile = (purpose, ext, str) => Vars.mods.scripts.writeFile(purpose, ext, str);
|
||||
const writeBinFile = (purpose, ext, bytes) => Vars.mods.scripts.writeBinFile(purpose, ext, bytes);
|
||||
const newFloats = cap => Vars.mods.getScripts().newFloats(cap);
|
||||
|
||||
//these are not strictly necessary, but are kept for edge cases
|
||||
|
@ -7,15 +7,7 @@ let modName = "none"
|
||||
|
||||
const log = (context, obj) => Vars.mods.scripts.log(context, String(obj))
|
||||
const print = text => log(modName + "/" + scriptName, text)
|
||||
const readString = path => Vars.mods.scripts.readString(path)
|
||||
const readBytes = path => Vars.mods.scripts.readBytes(path)
|
||||
const loadMusic = path => Vars.mods.scripts.loadMusic(path)
|
||||
const loadSound = path => Vars.mods.scripts.loadSound(path)
|
||||
|
||||
const readFile = (purpose, ext, cons) => Vars.mods.scripts.readFile(purpose, ext, cons);
|
||||
const readBinFile = (purpose, ext, cons) => Vars.mods.scripts.readBinFile(purpose, ext, cons);
|
||||
const writeFile = (purpose, ext, str) => Vars.mods.scripts.writeFile(purpose, ext, str);
|
||||
const writeBinFile = (purpose, ext, bytes) => Vars.mods.scripts.writeBinFile(purpose, ext, bytes);
|
||||
const newFloats = cap => Vars.mods.getScripts().newFloats(cap);
|
||||
|
||||
//these are not strictly necessary, but are kept for edge cases
|
||||
@ -49,6 +41,7 @@ function extend(/*Base, ..., def*/){
|
||||
return instance
|
||||
}
|
||||
|
||||
|
||||
importPackage(Packages.arc)
|
||||
importPackage(Packages.arc.audio)
|
||||
importPackage(Packages.arc.func)
|
||||
|
@ -139,6 +139,8 @@ public class Vars implements Loadable{
|
||||
public static final int port = 6567;
|
||||
/** multicast discovery port.*/
|
||||
public static final int multicastPort = 20151;
|
||||
/** Maximum char length of mod subtitles in browser/viewer. */
|
||||
public static final int maxModSubtitleLength = 40;
|
||||
/** multicast group for discovery.*/
|
||||
public static final String multicastGroup = "227.2.7.7";
|
||||
/** whether the graphical game client has loaded */
|
||||
|
@ -2,7 +2,7 @@ package mindustry.mod;
|
||||
|
||||
/** Mod listing as a data class. */
|
||||
public class ModListing{
|
||||
public String repo, name, author, lastUpdated, description, minGameVersion;
|
||||
public String repo, name, subtitle, author, lastUpdated, description, minGameVersion;
|
||||
public boolean hasScripts, hasJava;
|
||||
public String[] contentTypes = {};
|
||||
public int stars;
|
||||
|
@ -1136,7 +1136,7 @@ public class Mods implements Loadable{
|
||||
|
||||
/** Mod metadata information.*/
|
||||
public static class ModMeta{
|
||||
public String name, displayName, author, description, version, main, minGameVersion = "0", repo;
|
||||
public String name, displayName, author, description, subtitle, version, main, minGameVersion = "0", repo;
|
||||
public Seq<String> dependencies = Seq.with();
|
||||
/** Hidden mods are only server-side or client-side, and do not support adding new content. */
|
||||
public boolean hidden;
|
||||
@ -1147,11 +1147,16 @@ public class Mods implements Loadable{
|
||||
return displayName == null ? name : displayName;
|
||||
}
|
||||
|
||||
public String shortDescription(){
|
||||
return Strings.truncate(subtitle == null ? (description == null || description.length() > maxModSubtitleLength ? "" : description) : subtitle, maxModSubtitleLength, "...");
|
||||
}
|
||||
|
||||
//removes all colors
|
||||
public void cleanup(){
|
||||
if(displayName != null) displayName = Strings.stripColors(displayName);
|
||||
if(author != null) author = Strings.stripColors(author);
|
||||
if(description != null) description = Strings.stripColors(description);
|
||||
if(subtitle != null) subtitle = Strings.stripColors(subtitle).replace("\n", "");
|
||||
}
|
||||
|
||||
public int getMinMajor(){
|
||||
|
@ -2,10 +2,8 @@ package mindustry.mod;
|
||||
|
||||
import arc.*;
|
||||
import arc.files.*;
|
||||
import arc.func.*;
|
||||
import arc.util.*;
|
||||
import arc.util.Log.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.mod.Mods.*;
|
||||
import rhino.*;
|
||||
@ -67,60 +65,10 @@ public class Scripts implements Disposable{
|
||||
Log.log(level, "[@]: @", source, message);
|
||||
}
|
||||
|
||||
//region utility mod functions
|
||||
|
||||
public float[] newFloats(int capacity){
|
||||
return new float[capacity];
|
||||
}
|
||||
|
||||
public String readString(String path){
|
||||
return Vars.tree.get(path, true).readString();
|
||||
}
|
||||
|
||||
public byte[] readBytes(String path){
|
||||
return Vars.tree.get(path, true).readBytes();
|
||||
}
|
||||
|
||||
/** Ask the user to select a file to read for a certain purpose like "Please upload a sprite" */
|
||||
public void readFile(String purpose, String ext, Cons<String> cons){
|
||||
selectFile(true, purpose, ext, fi -> cons.get(fi.readString()));
|
||||
}
|
||||
|
||||
/** readFile but for a byte[] */
|
||||
public void readBinFile(String purpose, String ext, Cons<byte[]> cons){
|
||||
selectFile(true, purpose, ext, fi -> cons.get(fi.readBytes()));
|
||||
}
|
||||
|
||||
/** Ask the user to write a file. */
|
||||
public void writeFile(String purpose, String ext, String contents){
|
||||
if(contents == null) contents = "";
|
||||
final String fContents = contents;
|
||||
selectFile(false, purpose, ext, fi -> fi.writeString(fContents));
|
||||
}
|
||||
|
||||
/** writeFile but for a byte[] */
|
||||
public void writeBinFile(String purpose, String ext, byte[] contents){
|
||||
if(contents == null) contents = Streams.emptyBytes;
|
||||
final byte[] fContents = contents;
|
||||
selectFile(false, purpose, ext, fi -> fi.writeBytes(fContents));
|
||||
}
|
||||
|
||||
private void selectFile(boolean open, String purpose, String ext, Cons<Fi> cons){
|
||||
purpose = purpose.startsWith("@") ? Core.bundle.get(purpose.substring(1)) : purpose;
|
||||
//add purpose and extension at the top
|
||||
String title = Core.bundle.get(open ? "open" : "save") + " - " + purpose + " (." + ext + ")";
|
||||
Vars.platform.showFileChooser(open, title, ext, fi -> {
|
||||
try{
|
||||
cons.get(fi);
|
||||
}catch(Exception e){
|
||||
Log.err("Failed to select file '@' for a mod", fi);
|
||||
Log.err(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
public void run(LoadedMod mod, Fi file){
|
||||
currentMod = mod;
|
||||
run(file.readString(), file.name(), true);
|
||||
|
@ -242,8 +242,13 @@ public class ModsDialog extends BaseDialog{
|
||||
|
||||
title1.table(text -> {
|
||||
boolean hideDisabled = !item.isSupported() || item.hasUnmetDependencies() || item.hasContentErrors();
|
||||
String shortDesc = item.meta.shortDescription();
|
||||
|
||||
text.add("[accent]" + Strings.stripColors(item.meta.displayName()) + "\n" +
|
||||
(shortDesc.length() > 0 ? "[lightgray]" + shortDesc + "\n" : "")
|
||||
+ "[gray]v" + Strings.stripColors(trimText(item.meta.version))
|
||||
+ (item.enabled() || hideDisabled ? "" : "\n" + Core.bundle.get("mod.disabled") + ""))
|
||||
|
||||
text.add("[accent]" + Strings.stripColors(item.meta.displayName()) + "\n[lightgray]v" + Strings.stripColors(trimText(item.meta.version)) + (item.enabled() || hideDisabled ? "" : "\n" + Core.bundle.get("mod.disabled") + ""))
|
||||
.wrap().top().width(300f).growX().left();
|
||||
|
||||
text.row();
|
||||
@ -472,9 +477,9 @@ public class ModsDialog extends BaseDialog{
|
||||
con.add(
|
||||
"[accent]" + mod.name.replace("\n", "") +
|
||||
(installed.contains(mod.repo) ? "\n[lightgray]" + Core.bundle.get("mod.installed") : "") +
|
||||
//"[white]\n[lightgray]Author:[] " + trimText(mod.author) +
|
||||
"\n[lightgray]\uE809 " + mod.stars +
|
||||
(Version.isAtLeast(mod.minGameVersion) ? "" : "\n" + Core.bundle.format("mod.requiresversion", mod.minGameVersion)))
|
||||
(Version.isAtLeast(mod.minGameVersion) ? mod.subtitle == null ? "" : "\n[lightgray]" + Strings.truncate(mod.subtitle, maxModSubtitleLength) :
|
||||
"\n" + Core.bundle.format("mod.requiresversion", mod.minGameVersion)))
|
||||
.width(358f).wrap().grow().pad(4f, 2f, 4f, 6f).top().left().labelAlign(Align.topLeft);
|
||||
|
||||
}, Styles.clearPartialt, () -> {
|
||||
|
@ -25,4 +25,4 @@ org.gradle.caching=true
|
||||
#used for slow jitpack builds; TODO see if this actually works
|
||||
org.gradle.internal.http.socketTimeout=100000
|
||||
org.gradle.internal.http.connectionTimeout=100000
|
||||
archash=a625ec1c93
|
||||
archash=646d76bb50
|
||||
|
Loading…
Reference in New Issue
Block a user