Skip to content

Commit

Permalink
Merge branch 'zbx1425-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveNotSet committed Jun 23, 2024
2 parents 5fe3885 + c33350b commit acfa108
Show file tree
Hide file tree
Showing 26 changed files with 818 additions and 399 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import groovy.json.JsonSlurper
import org.apache.tools.ant.filters.ReplaceTokens

plugins {
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id "de.undercouch.download" version "4.1.2"
id 'maven-publish'
}
Expand Down Expand Up @@ -67,7 +67,9 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"

modApi "com.terraformersmc:modmenu:${project.mod_menu_version}"
modImplementation ("com.terraformersmc:modmenu:${project.mod_menu_version}") {
transitive = false
}
}

processResources {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org.gradle.jvmargs=-Xmx1G

# Mod Properties
mod_version=2.2.1
mod_version=2.3.0
maven_group=cn.zbx1425
archives_base_name=resourcepackupdater

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion src/main/java/cn/zbx1425/resourcepackupdater/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class Config {

public final ConfigItem<String> remoteConfigUrl = new ConfigItem<>(
"remoteConfigUrl", JsonElement::getAsString, JsonPrimitive::new, "https://mc.zbx1425.cn/jlp-srp/client_config.json");
"remoteConfigUrl", JsonElement::getAsString, JsonPrimitive::new, "https://res.xhcity.top/remoteConfig.json");

public final ConfigItem<List<SourceProperty>> sourceList = new ConfigItem<>(
"sources",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public static void dispatchSyncWork() {

while (true) {
Dispatcher syncDispatcher = new Dispatcher();
if (ResourcePackUpdater.CONFIG.selectedSource.value.baseUrl.isEmpty()) {
if (ResourcePackUpdater.CONFIG.selectedSource.value == null // TODO how did we get here?
|| ResourcePackUpdater.CONFIG.selectedSource.value.baseUrl.isEmpty()) {
if (ResourcePackUpdater.CONFIG.sourceList.value.size() > 1) {
ResourcePackUpdater.GL_PROGRESS_SCREEN.resetToSelectSource();
try {
Expand All @@ -85,6 +86,12 @@ public static void dispatchSyncWork() {
} else if (ResourcePackUpdater.CONFIG.sourceList.value.size() == 1) {
ResourcePackUpdater.CONFIG.selectedSource.value = ResourcePackUpdater.CONFIG.sourceList.value.get(0);
ResourcePackUpdater.CONFIG.selectedSource.isFromLocal = true;
} else {
ResourcePackUpdater.CONFIG.selectedSource.value = new Config.SourceProperty(
"NOT CONFIGURED",
"",
false, false, true
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public static void onAfterSetServerLock() {
}

if (localServerLock == null) {
ResourcePackUpdater.LOGGER.info("Asset coordination not required by this pack.");
ResourcePackUpdater.LOGGER.info("Asset coordination not required.");
} else if (remoteServerLock == null) {
ResourcePackUpdater.LOGGER.info("Asset coordination identifier not received.");
ResourcePackUpdater.LOGGER.info("Asset coordination received no cooperation.");
} else if (!remoteServerLock.equals(localServerLock)) {
ResourcePackUpdater.LOGGER.info("Asset coordination identifier differs.");
ResourcePackUpdater.LOGGER.info("Asset coordination received discrepancy.");
} else if (lockAllSyncedPacks) {
ResourcePackUpdater.LOGGER.info("Asset coordination is unavailable due to incomplete synchronization.");
ResourcePackUpdater.LOGGER.info("Asset coordination is unavailable for incompleteness.");
} else {
ResourcePackUpdater.LOGGER.info("Asset coordination is applicable.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public void printLog(String line) throws GlHelper.MinecraftStoppingException {
redrawScreen(true);
}

@Override
public void printLogOutsidePolling(String line) throws GlHelper.MinecraftStoppingException {
for (GlScreenForm form : forms) form.printLog(line);
ResourcePackUpdater.LOGGER.info(line);
}

@Override
public void amendLastLog(String postfix) throws GlHelper.MinecraftStoppingException {
for (GlScreenForm form : forms) form.amendLastLog(postfix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void setInfo(String value, String textValue) throws GlHelper.MinecraftSto
public void setException(Exception exception) throws GlHelper.MinecraftStoppingException {
this.exception = exception;
printLog("");
printLog("Update failed with this exception: ");
printLog("因以下异常,无法更新:");
for (String line : exception.toString().split("\n")) {
printLog(line);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ static void drawShadowRect(float width, float height, int color) {
GlHelper.blit(8, 8, width, height, 0x66000000);
GlHelper.blit(0, 0, width, height, color);
}

default void printLogOutsidePolling(String line) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,36 @@
public class ProgressForm implements GlScreenForm {

private String primaryInfo = "";
private String auxilaryInfo = "";
private String auxiliaryInfo = "";
private float primaryProgress;
private String secondaryProgress;

private static final float progressFormWidth = 600, progressFormHeight = 240;
private static final float progressFormWidth = 600, progressFormHeight = 250;

@Override
public void render() {
GlHelper.setMatCenterForm(progressFormWidth, progressFormHeight, 0.75f);
GlHelper.begin(GlHelper.PRELOAD_FONT_TEXTURE);
GlScreenForm.drawShadowRect(progressFormWidth, progressFormHeight, 0xffdee6ea);

GlHelper.drawString(20, 20, progressFormWidth - 40, 50, 20,
primaryInfo, 0xff222222, false, false);

float barBegin = 30;
float usableBarWidth = progressFormWidth - barBegin - 30;
GlHelper.blit(barBegin, 70, usableBarWidth, 30, 0xff1bbbb9);
GlHelper.blit(barBegin, 70, usableBarWidth * primaryProgress, 30, 0xff00a99d);
GlHelper.drawString(progressFormWidth / 2 - 32, 70 + 10, 80, LINE_HEIGHT, 16,
float barBegin = 0;
float usableBarWidth = progressFormWidth - barBegin - 0;
float progressTextStart = progressFormWidth / 2 - GlHelper.getStringWidth("88%", 16) / 2;
GlHelper.blit(barBegin, 0, usableBarWidth, 30, 0x4435aa8e);
GlHelper.drawString(progressTextStart, 0 + 10, 80, LINE_HEIGHT, 16,
String.format("%d%%", Math.round(primaryProgress * 100)), 0xff328a75, false, true);
GlHelper.end();
GlHelper.begin(GlHelper.PRELOAD_FONT_TEXTURE);
GlHelper.enableScissor(0, 0, usableBarWidth * primaryProgress, 30);
GlHelper.blit(barBegin, 0, usableBarWidth, 30, 0xff35aa8e);
GlHelper.drawString(progressTextStart, 0 + 10, 80, LINE_HEIGHT, 16,
String.format("%d%%", Math.round(primaryProgress * 100)), 0xffffffff, false, true);
GlHelper.end();
GlHelper.begin(GlHelper.PRELOAD_FONT_TEXTURE);
GlHelper.disableScissor();

GlHelper.drawString(20, 45, progressFormWidth - 40, 50, 20,
primaryInfo, 0xff222222, false, false);

/*
GlHelper.blit(barBegin, 110, usableBarWidth, 30, 0x4449baee);
Expand All @@ -37,12 +46,15 @@ public void render() {
String.format("%d%%", Math.round(secondaryProgress * 100)), 0xff49baee, false, true);
*/

GlHelper.drawString(barBegin, 110, usableBarWidth, 170 - 110, 16,
secondaryProgress, 0xff222222, false, false);
if (secondaryProgress.contains("\n")) {
GlHelper.blit(0, 70, progressFormWidth, 185 - 70, 0x3399abab);
}
GlHelper.drawString(20, 80, progressFormWidth - 40, 180 - 80, 16,
secondaryProgress, 0xff222222, false, true);

boolean monospace = !auxilaryInfo.isEmpty() && auxilaryInfo.charAt(0)== ':';
GlHelper.drawString(20, 180, progressFormWidth - 40, 30, 18,
monospace ? auxilaryInfo.substring(1) : auxilaryInfo, 0xff222222, monospace, false);
boolean monospace = !auxiliaryInfo.isEmpty() && auxiliaryInfo.charAt(0)== ':';
GlHelper.drawString(20, 195, progressFormWidth - 40, 30, 18,
monospace ? auxiliaryInfo.substring(1) : auxiliaryInfo, 0xff222222, monospace, false);

String escBtnHint = ResourcePackUpdater.CONFIG.sourceList.value.size() > 1 ? "取消下载 / 使用另一下载源" : "取消下载";
GlHelper.drawString(20, progressFormHeight - 20, progressFormWidth - 40, 16, 16, escBtnHint + ": 按住 ESC", 0xff222222, false, true);
Expand All @@ -61,7 +73,7 @@ public boolean shouldStopPausing() {
@Override
public void reset() {
primaryInfo = "";
auxilaryInfo = "";
auxiliaryInfo = "";
primaryProgress = 0;
secondaryProgress = "";
}
Expand All @@ -84,7 +96,7 @@ public void setProgress(float primary, float secondary) throws GlHelper.Minecraf
@Override
public void setInfo(String secondary, String textValue) throws GlHelper.MinecraftStoppingException {
this.secondaryProgress = secondary;
this.auxilaryInfo = textValue;
this.auxiliaryInfo = textValue;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void render() {
} else {
GlHelper.blit(30, 30 + 30 + i * 40, selectSourceFormWidth - 60, 30, 0xffc0d2db);
}
String btnLabel = i == sourceSize - 1 ? "[Cancel Update]" : ResourcePackUpdater.CONFIG.sourceList.value.get(i).name;
String btnLabel = i == sourceSize - 1 ? "[取消更新]" : ResourcePackUpdater.CONFIG.sourceList.value.get(i).name;
GlHelper.drawString(30 + 15, 30 + 30 + i * 40 + 5, selectSourceFormWidth - 90, 40, 20,
btnLabel, 0xff222222, false, false);
}
Expand Down
51 changes: 49 additions & 2 deletions src/main/java/cn/zbx1425/resourcepackupdater/gui/gl/GlHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Matrix4f;
import com.mojang.math.Vector3f;
import com.mojang.math.Vector4f;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;

public class GlHelper {

Expand Down Expand Up @@ -45,7 +48,7 @@ public static void resetGlStates() {
}

public static final ResourceLocation PRELOAD_FONT_TEXTURE =
new ResourceLocation(ResourcePackUpdater.MOD_ID, "textures/font/harmony.png");
new ResourceLocation(ResourcePackUpdater.MOD_ID, "textures/font/cantarell.png");
public static final SimpleFont preloadFont = new SimpleFont(PRELOAD_FONT_TEXTURE);

private static BufferBuilder bufferBuilder;
Expand Down Expand Up @@ -108,7 +111,9 @@ public static void drawString(float x1, float y1, float width, float height, flo
} else if (chr == '\r') {
// Ignore CR
} else if (chr == '\t') {
x += (preloadFont.spaceWidthPl * 4 + CHAR_SPACING) * fontSize;
// Align to 8 spaces
float alignToPixels = (preloadFont.spaceWidthPl + CHAR_SPACING) * 8 * fontSize;
x = (float) (Math.ceil((x - x1) / alignToPixels) * alignToPixels + x1);
} else if (chr == ' ') {
x += (preloadFont.spaceWidthPl + CHAR_SPACING) * fontSize;
} else {
Expand All @@ -135,6 +140,31 @@ public static void drawString(float x1, float y1, float width, float height, flo
}
}

public static float getStringWidth(String text, float fontSize) {
float CHAR_SPACING = 0f;

float width = 0;
float x = 0;
for (char chr : text.toCharArray()) {
if (chr == '\n') {
width = Math.max(width, x);
x = 0;
} else if (chr == '\r') {
// Ignore CR
} else if (chr == '\t') {
// Align to 8 spaces
float alignToPixels = (preloadFont.spaceWidthPl + CHAR_SPACING) * 8 * fontSize;
x = (float) (Math.ceil(x / alignToPixels) * alignToPixels);
} else if (chr == ' ') {
x += (preloadFont.spaceWidthPl + CHAR_SPACING) * fontSize;
} else {
SimpleFont.GlyphProperty glyph = preloadFont.getGlyph(chr);
x += glyph.advancePl * fontSize + CHAR_SPACING * fontSize;
}
}
return Math.max(width, x);
}

public static void setMatIdentity() {
RenderSystem.getModelViewStack().setIdentity();
}
Expand All @@ -159,6 +189,23 @@ public static void setMatScaledPixel() {
RenderSystem.setProjectionMatrix(matrix);
}

public static void enableScissor(float x, float y, float width, float height) {
Matrix4f posMap = RenderSystem.getProjectionMatrix();
Vector4f bottomLeft = new Vector4f(x, y + height, 0, 1);
bottomLeft.transform(posMap);
Vector4f topRight = new Vector4f(x + width, y, 0, 1);
topRight.transform(posMap);
float x1 = (float)Mth.map(bottomLeft.x(), -1, 1, 0, Minecraft.getInstance().getWindow().getWidth());
float y1 = (float)Mth.map(bottomLeft.y(), -1, 1, 0, Minecraft.getInstance().getWindow().getHeight());
float x2 = (float)Mth.map(topRight.x(), -1, 1, 0, Minecraft.getInstance().getWindow().getWidth());
float y2 = (float)Mth.map(topRight.y(), -1, 1, 0, Minecraft.getInstance().getWindow().getHeight());
RenderSystem.enableScissor((int)x1, (int)y1, (int)(x2 - x1), (int)(y2 - y1));
}

public static void disableScissor() {
RenderSystem.disableScissor();
}

public static int getWidth() {
int rawWidth = Minecraft.getInstance().getWindow().getWidth();
if (rawWidth < 854) {
Expand Down
Loading

0 comments on commit acfa108

Please sign in to comment.