-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
364 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/megatrex4/ukrainian_dlight/manual/ManualData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.megatrex4.ukrainian_dlight.manual; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.resource.Resource; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class ManualData { | ||
private final Map<String, JsonObject> manualEntries = new HashMap<>(); | ||
private final Map<String, String> categories = new HashMap<>(); | ||
|
||
public void loadManualEntries(ResourceManager resourceManager) { | ||
String namespace = "ukrainian_delight"; | ||
String path = "manual/en_us/"; | ||
|
||
for (String noteFile : getNoteFileNames()) { | ||
Identifier resourceId = new Identifier(namespace, path + noteFile); | ||
try { | ||
Optional<Resource> resourceOptional = resourceManager.getResource(resourceId); | ||
if (resourceOptional.isPresent()) { | ||
try (Reader reader = new InputStreamReader(resourceOptional.get().getInputStream())) { | ||
JsonObject jsonObject = JsonParser.parseReader(reader).getAsJsonObject(); | ||
String category = jsonObject.get("category").getAsString(); | ||
String noteName = jsonObject.get("header").getAsString(); // Assuming note name is present | ||
manualEntries.put(noteName, jsonObject); | ||
categories.put(category, noteName); | ||
} | ||
} else { | ||
System.err.println("Resource not found: " + resourceId); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
private List<String> getNoteFileNames() { | ||
// This should return a list of note file names; adjust this method based on your file structure | ||
return List.of("example_note.json"); // Example, replace with actual file names or dynamic retrieval | ||
} | ||
|
||
public Map<String, String> getCategories() { | ||
return categories; | ||
} | ||
|
||
public String getNoteContent(String noteName) { | ||
JsonObject entry = manualEntries.get(noteName); | ||
if (entry != null) { | ||
return entry.get("text").getAsString(); | ||
} | ||
return null; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/megatrex4/ukrainian_dlight/manual/ManualDataInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.megatrex4.ukrainian_dlight.manual; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
|
||
public class ManualDataInitializer { | ||
|
||
private final ManualData manualData = new ManualData(); | ||
|
||
public void initialize() { | ||
manualData.loadManualEntries(MinecraftClient.getInstance().getResourceManager()); | ||
} | ||
|
||
public ManualData getManualData() { | ||
return manualData; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/megatrex4/ukrainian_dlight/manual/ManualDefine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.megatrex4.ukrainian_dlight.manual; | ||
|
||
import net.minecraft.text.Text; | ||
|
||
public class ManualDefine { | ||
|
||
public static Text getCategoryName(String categoryKey) { | ||
return Text.translatable("manual.category." + categoryKey); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/megatrex4/ukrainian_dlight/manual/ManualItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.megatrex4.ukrainian_dlight.manual; | ||
|
||
import com.megatrex4.ukrainian_dlight.manual.screen.ManualScreen; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemUsageContext; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.ActionResult; | ||
|
||
public class ManualItem extends Item { | ||
|
||
public ManualItem() { | ||
super(new Item.Settings()); | ||
} | ||
|
||
@Override | ||
public ActionResult useOnBlock(ItemUsageContext context) { | ||
MinecraftClient.getInstance().execute(() -> { | ||
ClientPlayerEntity player = MinecraftClient.getInstance().player; | ||
if (player != null) { | ||
ManualDataInitializer dataInitializer = new ManualDataInitializer(); | ||
dataInitializer.initialize(); | ||
MinecraftClient.getInstance().setScreen(new ManualScreen(Text.of("Manual Title"), dataInitializer.getManualData())); | ||
} | ||
}); | ||
return ActionResult.success(context.getWorld().isClient); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/megatrex4/ukrainian_dlight/manual/ManualReloadListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.megatrex4.ukrainian_dlight.manual; | ||
|
||
import com.megatrex4.ukrainian_dlight.UkrainianDelight; | ||
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; | ||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.resource.ResourceType; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.profiler.Profiler; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.Executor; | ||
|
||
import static com.megatrex4.ukrainian_dlight.UkrainianDelight.LOGGER; | ||
import static com.megatrex4.ukrainian_dlight.UkrainianDelight.MOD_ID; | ||
|
||
public class ManualReloadListener implements IdentifiableResourceReloadListener { | ||
|
||
@Override | ||
public Identifier getFabricId() { | ||
return new Identifier(MOD_ID, "manual_reload_listener"); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Void> reload(Synchronizer synchronizer, ResourceManager resourceManager, | ||
Profiler serverProfiler, Profiler clientProfiler, | ||
Executor serverExecutor, Executor clientExecutor) { | ||
return CompletableFuture.runAsync(() -> { | ||
ManualData manualData = new ManualData(); | ||
manualData.loadManualEntries(resourceManager); | ||
LOGGER.info(MOD_ID + "Manual entries loaded successfully!"); | ||
}, serverExecutor).thenCompose(synchronizer::whenPrepared); | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
src/main/java/com/megatrex4/ukrainian_dlight/manual/screen/ManualScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.megatrex4.ukrainian_dlight.manual.screen; | ||
|
||
import com.megatrex4.ukrainian_dlight.UkrainianDelight; | ||
import com.megatrex4.ukrainian_dlight.manual.ManualData; | ||
import com.megatrex4.ukrainian_dlight.manual.ManualDefine; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.font.TextRenderer; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ManualScreen extends Screen { | ||
private static final Identifier TEXTURE = new Identifier(UkrainianDelight.MOD_ID, "textures/gui/manual_gui.png"); | ||
private final ManualData manualData; | ||
private ScreenState currentState = ScreenState.CATEGORY_SELECTION; | ||
private String selectedCategory; | ||
private String selectedNote; | ||
private Map<String, String> categories; | ||
private Map<String, Integer[]> categoryPositions; // To store category positions | ||
|
||
public ManualScreen(Text title, ManualData manualData) { | ||
super(title); | ||
this.manualData = manualData; | ||
} | ||
|
||
@Override | ||
protected void init() { | ||
super.init(); | ||
categories = manualData.getCategories(); // Load categories from ManualData | ||
categoryPositions = new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public void renderBackground(DrawContext context) { | ||
context.drawTexture(TEXTURE, 0, 0, 0, 0, width, height); | ||
} | ||
|
||
@Override | ||
public void render(DrawContext context, int mouseX, int mouseY, float delta) { | ||
renderBackground(context); | ||
super.render(context, mouseX, mouseY, delta); | ||
switch (currentState) { | ||
case CATEGORY_SELECTION: | ||
drawCategorySelection(context, mouseX, mouseY); | ||
break; | ||
case NOTE_SELECTION: | ||
drawNoteSelection(context); | ||
break; | ||
case NOTE_CONTENT: | ||
drawNoteContent(context); | ||
break; | ||
} | ||
} | ||
|
||
private void drawCategorySelection(DrawContext context, int mouseX, int mouseY) { | ||
MatrixStack matrices = context.getMatrices(); | ||
var textRenderer = MinecraftClient.getInstance().textRenderer; | ||
int y = 20; | ||
|
||
for (Map.Entry<String, String> entry : categories.entrySet()) { | ||
String category = entry.getKey(); | ||
Text categoryText = ManualDefine.getCategoryName(category); | ||
int textWidth = textRenderer.getWidth(categoryText); | ||
int x = (width - textWidth) / 2; | ||
|
||
// Draw category text | ||
textRenderer.draw(categoryText, x, y, 0xFFFFFF, true, matrices.peek().getPositionMatrix(), | ||
MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(), | ||
TextRenderer.TextLayerType.NORMAL, 0x000000, 15728880); | ||
|
||
// Store position for clickable area | ||
categoryPositions.put(category, new Integer[]{x, y, textWidth, 10}); // 10 is the height of the text | ||
|
||
y += 20; // Adjust as needed | ||
} | ||
} | ||
|
||
@Override | ||
public boolean mouseClicked(double mouseX, double mouseY, int button) { | ||
if (currentState == ScreenState.CATEGORY_SELECTION) { | ||
for (Map.Entry<String, Integer[]> entry : categoryPositions.entrySet()) { | ||
Integer[] pos = entry.getValue(); | ||
String category = entry.getKey(); | ||
if (mouseX >= pos[0] && mouseX <= pos[0] + pos[2] && | ||
mouseY >= pos[1] && mouseY <= pos[1] + pos[3]) { | ||
selectCategory(category); | ||
return true; | ||
} | ||
} | ||
} | ||
return super.mouseClicked(mouseX, mouseY, button); | ||
} | ||
|
||
private void drawNoteSelection(DrawContext context) { | ||
// Implement similar to drawCategorySelection but for notes | ||
} | ||
|
||
private void drawNoteContent(DrawContext context) { | ||
MatrixStack matrices = context.getMatrices(); | ||
var textRenderer = MinecraftClient.getInstance().textRenderer; | ||
if (selectedNote != null) { | ||
String noteContent = manualData.getNoteContent(selectedNote); | ||
Text noteText = Text.of(noteContent); | ||
int textWidth = textRenderer.getWidth(noteText); | ||
int x = (width - textWidth) / 2; | ||
int y = (height - 8) / 2; | ||
textRenderer.draw(noteText, x, y, 0xFFFFFF, true, matrices.peek().getPositionMatrix(), | ||
MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(), | ||
TextRenderer.TextLayerType.NORMAL, 0x000000, 15728880); | ||
} | ||
} | ||
|
||
public void selectCategory(String category) { | ||
this.selectedCategory = category; | ||
this.currentState = ScreenState.NOTE_SELECTION; | ||
} | ||
|
||
public void selectNote(String note) { | ||
this.selectedNote = note; | ||
this.currentState = ScreenState.NOTE_CONTENT; | ||
} | ||
|
||
private enum ScreenState { | ||
CATEGORY_SELECTION, | ||
NOTE_SELECTION, | ||
NOTE_CONTENT | ||
} | ||
} |
Oops, something went wrong.