Offer Mod Info Screen

This commit is contained in:
Frank 2021-08-25 14:11:48 +02:00
parent 9d7fa9f925
commit b959e17c18
7 changed files with 41 additions and 18 deletions

View file

@ -40,6 +40,9 @@ import java.util.stream.Collectors;
* For Details refer to {@link HelloServer}
*/
public class HelloClient extends DataHandler.FromServer {
public interface IServerModMap extends Map<String, Pair<String, Integer>> {}
public static class ServerModMap extends HashMap<String, Pair<String, Integer>> implements IServerModMap {}
public static DataHandlerDescriptor DESCRIPTOR = new DataHandlerDescriptor(new ResourceLocation(BCLib.MOD_ID, "hello_client"), HelloClient::new, false, false);
public HelloClient() {
@ -132,7 +135,8 @@ public class HelloClient extends DataHandler.FromServer {
}
String bclibVersion = "0.0.0";
Map<String, Pair<String, Integer>> modVersion = new HashMap<>();
IServerModMap modVersion = new ServerModMap();
List<AutoSync.AutoSyncTriple> autoSyncedFiles = null;
List<SyncFolderDescriptor> autoSynFolders = null;
@ -145,7 +149,7 @@ public class HelloClient extends DataHandler.FromServer {
//read Plugin Versions
modVersion = new HashMap<>();
modVersion = new ServerModMap();
int count = buf.readInt();
for (int i = 0; i < count; i++) {
final String id = readString(buf);
@ -374,7 +378,7 @@ public class HelloClient extends DataHandler.FromServer {
}
}
client.setScreen(new SyncFilesScreen(modFiles, configFiles, singleFiles, folderFiles, filesToRemove.size(), (downloadMods, downloadConfigs, downloadFiles, removeFiles) -> {
client.setScreen(new SyncFilesScreen(modFiles, configFiles, singleFiles, folderFiles, filesToRemove.size(), modVersion, (downloadMods, downloadConfigs, downloadFiles, removeFiles) -> {
if (downloadMods || downloadConfigs || downloadFiles) {
BCLib.LOGGER.info("Updating local Files:");
List<AutoSyncID.WithContentOverride> localChanges = new ArrayList<>(files.toArray().length);

View file

@ -156,7 +156,8 @@ public class SendFiles extends DataHandler.FromServer {
if (e instanceof AutoFileSyncEntry.ForModFileRequest mase){
removeAfter = path;
int count = 0;
String name = "bclib_synced_" + mase.modID + "_" + mase.version.replace(".", "_") + ".jar";
final String prefix = "_bclib_synced";
String name = prefix + mase.modID + "_" + mase.version.replace(".", "_") + ".jar";
do {
if (path != null) {
//move to the same directory as the existing Mod
@ -168,7 +169,7 @@ public class SendFiles extends DataHandler.FromServer {
path = PathUtil.MOD_FOLDER.resolve(name);
}
count++;
name = "bclib_synced_" + mase.modID + "_" + mase.version.replace(".", "_") + "__" + String.format("%03d", count) + ".jar";
name = prefix + mase.modID + "_" + mase.version.replace(".", "_") + "__" + String.format("%03d", count) + ".jar";
} while (path.toFile().exists());
}

View file

@ -134,7 +134,7 @@ public class GridLayout extends GridColumn {
GridElement el = this.buildElement((int)this.width, 0, 1, 0,0, elements);
this.height = el.height;
if (centerVertically && el.height + initialTopPadding < screenHeight) {
topPadding = (screenHeight - el.height - initialTopPadding) >> 1;
topPadding = (screenHeight - el.height) >> 1;
} else {
topPadding = initialTopPadding;
}

View file

@ -144,12 +144,11 @@ public abstract class GridScreen extends Screen {
}
public int getMaxScrollPos() {
return height-getScrollHeight();
return height - (getScrollHeight() + topPadding);
}
public boolean isScrollable() {
if (grid==null) return false;
return height<grid.getHeight();
return height<getScrollHeight();
}
public boolean isMouseOverScroller(double x, double y) {
@ -166,7 +165,7 @@ public abstract class GridScreen extends Screen {
final int y1 = height;
final int y0 = 0;
final int yd = y1 - y0;
final int maxPosition = getScrollHeight();
final int maxPosition = getScrollHeight() + topPadding;
final int x0 = width-SCROLLER_WIDTH;
final int x1 = width;

View file

@ -159,7 +159,7 @@ public class ModListScreen extends BCLibScreen {
if (description != null) {
grid.addSpacerRow();
grid.addRow().addMessage(description, font, GridLayout.Alignment.CENTER);
grid.addSpacerRow(20);
grid.addSpacerRow(8);
}
GridRow row = grid.addRow();
@ -167,7 +167,7 @@ public class ModListScreen extends BCLibScreen {
GridColumn col = row.addColumn(200, GridLayout.GridValueType.CONSTANT);
addModDesc(col, mods, serverInfo, this);
grid.addSpacerRow(10);
grid.addSpacerRow(8);
row = grid.addRow();
row.addFiller();
row.addButton(CommonComponents.GUI_BACK, 20, font, (n)-> {
@ -175,8 +175,6 @@ public class ModListScreen extends BCLibScreen {
System.out.println("Closing");
});
row.addFiller();
grid.addSpacerRow(topPadding);
}
}

View file

@ -2,12 +2,15 @@ package ru.bclib.gui.screens;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import ru.bclib.api.dataexchange.handler.autosync.HelloClient;
import ru.bclib.gui.gridlayout.GridCheckboxCell;
import ru.bclib.gui.gridlayout.GridLayout.Alignment;
import ru.bclib.gui.gridlayout.GridRow;
import ru.bclib.util.ModUtil;
@Environment(EnvType.CLIENT)
public class SyncFilesScreen extends BCLibScreen {
@ -17,10 +20,11 @@ public class SyncFilesScreen extends BCLibScreen {
private final boolean hasFiles;
private final boolean hasMods;
private final boolean shouldDelete;
public SyncFilesScreen(int modFiles, int configFiles, int singleFiles, int folderFiles, int deleteFiles, Listener listener) {
private final HelloClient.IServerModMap serverInfo;
public SyncFilesScreen(int modFiles, int configFiles, int singleFiles, int folderFiles, int deleteFiles, HelloClient.IServerModMap serverInfo, Listener listener) {
super(new TranslatableComponent("title.bclib.syncfiles"));
this.serverInfo = serverInfo;
this.description = new TranslatableComponent("message.bclib.syncfiles");
this.listener = listener;
@ -45,6 +49,19 @@ public class SyncFilesScreen extends BCLibScreen {
row = grid.addRow();
mods = row.addCheckbox(new TranslatableComponent("message.bclib.syncfiles.mods"), hasMods, BUTTON_HEIGHT, this.font);
mods.setEnabled(hasMods);
if (hasMods) {
row.addSpacer();
row.addButton(new TranslatableComponent("title.bclib.more"), 20, font, (button)->{
ModListScreen scr = new ModListScreen(
this,
new TranslatableComponent("title.bclib.syncfiles.modlist"),
new TranslatableComponent("message.bclib.syncfiles.modlist"),
ModUtil.getMods(),
serverInfo
);
Minecraft.getInstance().setScreen(scr);
});
}
grid.addSpacerRow();

View file

@ -27,5 +27,9 @@
"title.config.bclib.client.auto_sync.acceptFiles": "Accept incoming Files",
"title.config.bclib.client.auto_sync.acceptMods": "Accept incoming Mods",
"title.config.bclib.client.auto_sync.syncModFolder": "Sync entire Mod-Folder from Server",
"title.config.bclib.client.auto_sync.debugHashes": "Print Auto-Sync Debug-Hashes to Log"
"title.config.bclib.client.auto_sync.debugHashes": "Print Auto-Sync Debug-Hashes to Log",
"title.bclib.more": "More",
"title.bclib.syncfiles.modlist": "Mod Information",
"message.bclib.syncfiles.modlist": "The following shows the state of your installed installed Mods.\n\nAll Mods that do not exist locally, or have a different version will on the Server will be synchronized."
}