Skip to content

Commit

Permalink
Queue manager
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyhedral committed Nov 23, 2024
1 parent 2648210 commit cceff61
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 35 deletions.
5 changes: 5 additions & 0 deletions src/generated/resources/assets/crafttracker/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"crafttracker.screen.craft_list.section.materials": "Materialien",
"crafttracker.screen.craft_list.section.products": "Produkte",
"crafttracker.screen.craft_list.title": "Bastelliste",
"crafttracker.screen.queuemgr.button.clear": "Alle l\u00F6schen",
"crafttracker.screen.queuemgr.button.dec.tooltip": "Reduzieren Sie die Menge an hergestellten",
"crafttracker.screen.queuemgr.button.del.tooltip": "Dieses Element aus der Warteschlange l\u00F6schen",
"crafttracker.screen.queuemgr.button.inc.tooltip": "Erh\u00F6hen Sie die Menge an hergestellten",
"crafttracker.screen.queuemgr.title": "Warteschlangenmanager",
"crafttracker.screen.shopping_list.title": "Einkaufsliste",
"key.addToQueue": "Zur Warteschlange hinzuf\u00FCgen",
"key.categories.crafttracker": "Handwerks-Tracker",
Expand Down
5 changes: 5 additions & 0 deletions src/generated/resources/assets/crafttracker/lang/en_gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"crafttracker.screen.craft_list.section.materials": "Materials",
"crafttracker.screen.craft_list.section.products": "Products",
"crafttracker.screen.craft_list.title": "Craft List",
"crafttracker.screen.queuemgr.button.clear": "Clear",
"crafttracker.screen.queuemgr.button.dec.tooltip": "Decrease the amount crafted",
"crafttracker.screen.queuemgr.button.del.tooltip": "Delete this item from the queue",
"crafttracker.screen.queuemgr.button.inc.tooltip": "Increase the amount crafted",
"crafttracker.screen.queuemgr.title": "Queue Manager",
"crafttracker.screen.shopping_list.title": "Shopping List",
"key.addToQueue": "Add to Queue",
"key.categories.crafttracker": "Craft Tracker",
Expand Down
6 changes: 6 additions & 0 deletions src/generated/resources/assets/crafttracker/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"crafttracker.screen.craft_list.empty_message": "The queue is empty.",
"crafttracker.screen.craft_list.have": "have %d",
"crafttracker.screen.craft_list.help_message": "To manage the queue:",
"crafttracker.screen.craft_list.section.fuel": "Fuel",
"crafttracker.screen.craft_list.section.intermediates": "Intermediates",
"crafttracker.screen.craft_list.section.materials": "Materials",
"crafttracker.screen.craft_list.section.products": "Products",
"crafttracker.screen.craft_list.title": "Craft List",
"crafttracker.screen.queuemgr.button.clear": "Clear",
"crafttracker.screen.queuemgr.button.dec.tooltip": "Decrease the amount crafted",
"crafttracker.screen.queuemgr.button.del.tooltip": "Delete this item from the queue",
"crafttracker.screen.queuemgr.button.inc.tooltip": "Increase the amount crafted",
"crafttracker.screen.queuemgr.title": "Queue Manager",
"crafttracker.screen.shopping_list.title": "Shopping List",
"key.addToQueue": "Add to Queue",
"key.categories.crafttracker": "Craft Tracker",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.sweetrpg.crafttracker.CraftTracker;
import com.sweetrpg.crafttracker.client.screen.QueueManagementScreen;
import com.sweetrpg.crafttracker.common.addon.jei.CTPlugin;
import com.sweetrpg.crafttracker.common.manager.CraftingQueueManager;
import com.sweetrpg.crafttracker.common.registry.ModKeyBindings;
Expand Down Expand Up @@ -78,21 +79,21 @@ public static void onKeyInput(final InputEvent.KeyInputEvent event) {


}
// else if(ModKeyBindings.TOGGLE_CRAFT_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) {
// CraftTracker.LOGGER.debug("#onKeyInput: TOGGLE_CRAFT_LIST_MAPPING");
//// craftListDisplayed = !craftListDisplayed;
//// PacketHandler.sendToServer(new ToggleCraftListData());
// }
// else if(ModKeyBindings.TOGGLE_SHOPPING_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) {
// CraftTracker.LOGGER.debug("#onKeyInput: TOGGLE_SHOPPING_LIST_MAPPING");
//// shoppingListDisplayed = !shoppingListDisplayed;
//// PacketHandler.sendToServer(new ToggleShoppingListData());
// }
// else if(ModKeyBindings.OPEN_QUEUE_MANAGER_MAPPING.matches(event.getKey(), event.getScanCode())) {
// CraftTracker.LOGGER.debug("#onKeyInput: OPEN_QUEUE_MANAGER_MAPPING");
//
// QueueManagementScreen.open();
// }
else if(ModKeyBindings.TOGGLE_CRAFT_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) {
CraftTracker.LOGGER.debug("#onKeyInput: TOGGLE_CRAFT_LIST_MAPPING");
// craftListDisplayed = !craftListDisplayed;
// PacketHandler.sendToServer(new ToggleCraftListData());
}
else if(ModKeyBindings.TOGGLE_SHOPPING_LIST_MAPPING.matches(event.getKey(), event.getScanCode())) {
CraftTracker.LOGGER.debug("#onKeyInput: TOGGLE_SHOPPING_LIST_MAPPING");
// shoppingListDisplayed = !shoppingListDisplayed;
// PacketHandler.sendToServer(new ToggleShoppingListData());
}
else if(ModKeyBindings.OPEN_QUEUE_MANAGER_MAPPING.matches(event.getKey(), event.getScanCode())) {
CraftTracker.LOGGER.debug("#onKeyInput: OPEN_QUEUE_MANAGER_MAPPING");

QueueManagementScreen.open();
}
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
import com.sweetrpg.crafttracker.CraftTracker;
import com.sweetrpg.crafttracker.common.addon.jei.CTPlugin;
import com.sweetrpg.crafttracker.common.config.ConfigHandler;
import com.sweetrpg.crafttracker.common.lib.CTRuntime;
import com.sweetrpg.crafttracker.common.lib.Constants;
import com.sweetrpg.crafttracker.common.manager.CraftingQueueManager;
import com.sweetrpg.crafttracker.common.registry.ModKeyBindings;
import mezz.jei.api.constants.VanillaTypes;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraftforge.client.gui.IIngameOverlay;
import net.minecraftforge.registries.ForgeRegistries;

public class CraftQueueOverlay {

static int TITLE_COLOR = 0x99999999;
static int HELP_COLOR = 0x77777777;
static int SECTION_COLOR = 0xcccccccc;
static int TEXT_COLOR = 0xffffffff;
static int MESSAGE_COLOR = 0x66666666;
Expand All @@ -28,8 +32,24 @@ public class CraftQueueOverlay {
public static final IIngameOverlay CRAFT_QUEUE = (gui, poseStack, partialTicks, width, height) -> {
CraftTracker.LOGGER.trace("CRAFT_QUEUE");

if(ConfigHandler.CLIENT.CRAFT_QUEUE_OVERLAY_HIDE_EMPTY.get() /* TODO: || user wants it to display */) {
return;
var mgr = CraftingQueueManager.INSTANCE;
var products = mgr.getEndProducts();

switch(CTRuntime.INSTANCE.queueOverlayRequestedState) {
case SHOW:
//
break;

case HIDE:
case SUPPRESS:
return;

case DO_NOT_CARE:
if(ConfigHandler.CLIENT.CRAFT_QUEUE_OVERLAY_HIDE_EMPTY.get() &&
products.isEmpty()) {
return;
}
break;
}

var x = ConfigHandler.CLIENT.CRAFT_QUEUE_OVERLAY_X.get();
Expand All @@ -46,9 +66,6 @@ public class CraftQueueOverlay {
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_TITLE),
(x + olWidth - 8) / 2, y + 6, TITLE_COLOR);

var mgr = CraftingQueueManager.INSTANCE;
var products = mgr.getEndProducts();

// if products list is empty, display "empty" message
if(products.isEmpty()) {
GuiComponent.drawCenteredString(poseStack, gui.getFont(),
Expand All @@ -57,6 +74,12 @@ public class CraftQueueOverlay {
return;
}

var helpText = String.format("%s [%s]",
I18n.get(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HELP),
ModKeyBindings.OPEN_QUEUE_MANAGER_MAPPING.getTranslatedKeyMessage().getString());
GuiComponent.drawCenteredString(poseStack, gui.getFont(), helpText,
(x + olWidth - 8) / 2, olHeight - TEXT_HEIGHT, HELP_COLOR);

int yPos = y + SECTION_TITLE_Y_OFFSET;
CraftTracker.LOGGER.trace("yPos (initial): {}", yPos);

Expand Down Expand Up @@ -88,6 +111,7 @@ public class CraftQueueOverlay {
}

// SECTION: intermediates

if(!mgr.getIntermediates().isEmpty()) {
yPos += (TEXT_HEIGHT * 1.5);
CraftTracker.LOGGER.trace("yPos (before intermediates title): {}", yPos);
Expand Down Expand Up @@ -117,6 +141,7 @@ public class CraftQueueOverlay {
}

// SECTION: raw materials

if(!mgr.getRawMaterials().isEmpty()) {
yPos += (TEXT_HEIGHT * 1.5);
CraftTracker.LOGGER.trace("yPos (before materials title): {}", yPos);
Expand Down Expand Up @@ -148,9 +173,10 @@ public class CraftQueueOverlay {
.map(inv -> inv.getCount())
.findFirst()
.ifPresent(count -> {
var text = String.format("%s [%d]",
var countText = I18n.get(Constants.TRANSLATION_KEY_GUI_CRAFTLIST_HAVE, count);
var text = String.format("%s [%s]",
item.getDescription().getString(MAX_STRING_LENGTH),
count);
countText);
CraftTracker.LOGGER.debug("text: {}", text);
GuiComponent.drawString(poseStack, gui.getFont(), text, x + ITEM_NAME_X_OFFSET, lambdaYpos + 4, TEXT_COLOR);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
package com.sweetrpg.crafttracker.client.screen;

import com.mojang.blaze3d.vertex.PoseStack;
import com.sweetrpg.crafttracker.CraftTracker;
import com.sweetrpg.crafttracker.common.addon.jei.CTPlugin;
import com.sweetrpg.crafttracker.common.lib.CTRuntime;
import com.sweetrpg.crafttracker.common.lib.Constants;
import com.sweetrpg.crafttracker.common.manager.CraftingQueueManager;
import mezz.jei.api.constants.VanillaTypes;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.List;

import static com.sweetrpg.crafttracker.common.lib.CTRuntime.OverlayState.DO_NOT_CARE;
import static com.sweetrpg.crafttracker.common.lib.CTRuntime.OverlayState.SUPPRESS;

public class QueueManagementScreen extends Screen {

public final Player player;

public static final int TITLE_COLOR = 0xbbbbbbbb;
public static final int TITLE_HEIGHT = 20;
public static final int ITEM_COLOR = 0xffffffff;
public static final int ITEM_HEIGHT = 18;
public static final int BUTTON_SIZE = ITEM_HEIGHT - 2;
public static final int BACKGROUND_COLOR = 0x66666666;
public static final int ITEM_X_ICON_OFFSET = 2;
public static final int ITEM_X_TEXT_OFFSET = 20;
public static final int ITEM_X_DELETE_BUTTON_OFFSET = -(2 + BUTTON_SIZE);
public static final int ITEM_X_UP_BUTTON_OFFSET = ITEM_X_DELETE_BUTTON_OFFSET - BUTTON_SIZE - 2;
public static final int ITEM_X_QTY_WIDTH = 30;
public static final int ITEM_X_QTY_OFFSET = ITEM_X_UP_BUTTON_OFFSET - (ITEM_X_QTY_WIDTH / 2);
public static final int ITEM_X_DOWN_BUTTON_OFFSET = ITEM_X_QTY_OFFSET - (int) (BUTTON_SIZE * 2) - 2;

final private List<CraftingQueueManager.ProductItem> productItems;

public QueueManagementScreen(Player player) {
super(new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_TITLE));
this.player = player;

this.productItems = CraftingQueueManager.INSTANCE.getEndProducts();
}

public static void open() {
Expand All @@ -30,22 +63,129 @@ public void init() {
int topX = this.width / 2;
int topY = this.height / 2;

// TODO: hide queue overlay and shopping list


// hide queue overlay and shopping list
CTRuntime.INSTANCE.queueOverlayRequestedState = SUPPRESS;
CTRuntime.INSTANCE.shoppingOverlayRequestedState = SUPPRESS;


}

@Override
public void render(PoseStack stack, int mouseX, int mouseY, float partialTicks) {
//Background
int topX = this.width / 2;
int topY = this.height / 2;

this.renderBackground(stack);


public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) {

int width = Math.max(200, this.width / 3);
int height = this.height - 100;
int topX = (this.width / 2) - (width / 2);
int topY = 20; // (this.height / 2) - (height / 2);

this.renderBackground(poseStack);

// GuiComponent.fill(poseStack, topX, topY, width, height, BACKGROUND_COLOR);

// title
GuiComponent.drawCenteredString(poseStack, this.font, I18n.get(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_TITLE), this.width / 2, topY + 2, TITLE_COLOR);

// products
for(int i = 0; i < this.productItems.size(); i++) {
var pItem = this.productItems.get(i);
final var itemIndex = i;

var item = ForgeRegistries.ITEMS.getValue(pItem.getItemId());
var itemStack = item.getDefaultInstance();
var y = topY + TITLE_HEIGHT + (i * (ITEM_HEIGHT + 4));

if(y + ITEM_HEIGHT > height) {
CraftTracker.LOGGER.debug("too many items for display (stopping at item {}, y {}", i, y);
break;
}

// background
GuiComponent.fill(poseStack, topX, y, topX + width, y + ITEM_HEIGHT + 2, BACKGROUND_COLOR);

// icon
var drawable = CTPlugin.jeiRuntime.getJeiHelpers().getGuiHelper()
.createDrawableIngredient(VanillaTypes.ITEM_STACK, itemStack);
drawable.draw(poseStack, topX + ITEM_X_ICON_OFFSET, y + 2);

// name
this.font.draw(poseStack, item.getDescription(), topX + ITEM_X_TEXT_OFFSET, y + 6, ITEM_COLOR);

// quantity and adjustment buttons
{
Button button = new Button(topX + width + ITEM_X_DOWN_BUTTON_OFFSET, y + 2, BUTTON_SIZE, BUTTON_SIZE - 2, new TextComponent("-"), btn -> {
this.productItems.set(itemIndex, new CraftingQueueManager.ProductItem(pItem.getItemId(), pItem.getQuantity() - 1, pItem.getCategories()));
CraftingQueueManager.INSTANCE.adjustProduct(player, pItem.getItemId(), -1);
}) {
@Override
public void renderToolTip(PoseStack pPoseStack, int pMouseX, int pMouseY) {
QueueManagementScreen.this.renderTooltip(poseStack, new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_DEC_BUTTON_TOOLTIP), mouseX, mouseY);
}
};
button.active = pItem.getQuantity() > 0;
this.addRenderableWidget(button);
}
{
var text = String.format("%d", pItem.getQuantity());
// this.font.draw(poseStack, text, topX + width + ITEM_X_QTY_OFFSET, y + 6, ITEM_COLOR);
GuiComponent.drawCenteredString(poseStack, this.font, text, topX + width + ITEM_X_QTY_OFFSET, y + 6, ITEM_COLOR);
}
{
Button button = new Button(topX + width + ITEM_X_UP_BUTTON_OFFSET, y + 2, BUTTON_SIZE, BUTTON_SIZE - 2, new TextComponent("+"), btn -> {
this.productItems.set(itemIndex, new CraftingQueueManager.ProductItem(pItem.getItemId(), pItem.getQuantity() + 1, pItem.getCategories()));
CraftingQueueManager.INSTANCE.adjustProduct(player, pItem.getItemId(), 1);
}) {
@Override
public void renderToolTip(PoseStack pPoseStack, int pMouseX, int pMouseY) {
QueueManagementScreen.this.renderTooltip(poseStack, new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_INC_BUTTON_TOOLTIP), mouseX, mouseY);
}
};
this.addRenderableWidget(button);
}

// variations
// TODO

// delete button
{
Button button = new Button(topX + width + ITEM_X_DELETE_BUTTON_OFFSET, y + 2, BUTTON_SIZE, BUTTON_SIZE - 2, new TextComponent("x"), btn -> {
this.productItems.remove(itemIndex);
CraftingQueueManager.INSTANCE.removeProduct(player, pItem.getItemId());
}) {
@Override
public void renderToolTip(PoseStack pPoseStack, int pMouseX, int pMouseY) {
QueueManagementScreen.this.renderTooltip(poseStack, new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_DEL_BUTTON_TOOLTIP), mouseX, mouseY);
}
};
this.addRenderableWidget(button);
}
}

// clear all button
{
Button button = new Button(topX + (width / 2) - 50, topY + height - BUTTON_SIZE - 4, 100, BUTTON_SIZE + 2,
new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_CLEAR_BUTTON),
btn -> {
CraftingQueueManager.INSTANCE.removeAll();
}) {
@Override
public void renderToolTip(PoseStack pPoseStack, int pMouseX, int pMouseY) {
QueueManagementScreen.this.renderTooltip(poseStack, new TranslatableComponent(Constants.TRANSLATION_KEY_GUI_QUEUEMGR_CLEAR_BUTTON_TOOLTIP), mouseX, mouseY);
}
};
this.addRenderableWidget(button);
}

// buttons

super.render(poseStack, mouseX, mouseY, partialTicks);
//RenderHelper.disableStandardItemLighting(); // 1.14 enableGUIStandardItemLighting

// for(Widget widget : this.renderables) {
// if(widget instanceof AbstractWidget w && w.isHoveredOrFocused()) {
// w.renderToolTip(poseStack, mouseX, mouseY);
// break;
// }
// }
}

@Override
Expand All @@ -54,7 +194,9 @@ public void removed() {

this.minecraft.keyboardHandler.setSendRepeatsToGui(false);

// TODO: restore queue overlay and shopping list
// restore queue overlay and shopping list
CTRuntime.INSTANCE.queueOverlayRequestedState = DO_NOT_CARE;
CTRuntime.INSTANCE.shoppingOverlayRequestedState = DO_NOT_CARE;
}

@Override
Expand Down
Loading

0 comments on commit cceff61

Please sign in to comment.