Towdium / JustEnoughCalculation

A simple minecraft mod help you calculate the cost for recipes
Other
53 stars 38 forks source link

Calculator widget for all container screens #98

Closed ekgame closed 2 years ago

ekgame commented 2 years ago

Apologies for the large pull request.

I love the crafting calculator, but one issue I've always had is the amount of context switching you have to do while collecting items and following the crafting steps. Here's how I do it:

  1. Open the calculator, select the item and setup it's crafting recipes;
  2. For every item in the input slot:
    1. Open the calculator, check what item and how much of it I need;
    2. Find the item and add it to my inventory.
  3. Add all of the items in the steps page to JEI favorites;
  4. For every item in the steps page:
    1. Open the calculator, to check what item and how much of it to craft next;
    2. Open the JEI crafting information page for the item, press the "+" button to move items to the crafting area and craft the items.
  5. Done.

This change aims to skip the steps of putting all of the items to JEI favorites and opening the calculator for every input and crafting step - making the whole experience more efficient and less frustrating. This is done by adding a function to enable a mini crafting widget for every container screen, where you can see a miniature version of the crafting calculator with the inputs and steps - exactly as you would on the full sized one.

paveikslas

It works as you might expect:

  1. Displays the item selected in the crafting calculator. Does not support inserting a new item - you still need the full sized calculator to select the item and setup the crafting recipes.
  2. Switch between input/output/catalysts/steps pages, enable/disable inventory.
  3. Functionality to change the crafting amount.
  4. The widget is not displayed by default, must be enabled in the full sized calculator.
  5. The widget can be dragged around like a little window. The little "x" button closes it.
  6. Multiple widgets are supported if you have multiple crafting calculators. The widgets overlap with each other like you would expect - clicking on the window moves it to the top.
  7. JEI "extra GUI areas" are implemented to handle cases where the calculator is moved over the JEI overlays.
  8. The widgets are updated when the inventory contents change.
  9. The widget UI reflects the settings of the full sized calculator and vice versa.
  10. The widget can not be moved outside of the screen.

https://user-images.githubusercontent.com/1730245/132209013-045dcd72-dff4-4967-9648-9ca633c77ff0.mp4

Some possible improvements for the future:

  1. Refactor the checkbox to handle clicking the label to toggle widget or replace the checkbox with an icon button. Maybe add a tooltip to better explain what the option does.
  2. Should be possible to implement a mini math calculator, just for completeness sake.
  3. The widget is rendered wrong when it is moved over inventory items. Not a big deal, because it's outside the inventory by default, it can be moved anywhere on the screen and JEI reflows to make space for them. I have no idea how to fix this, but it's not a deal-breaker for me anyway.

paveikslas

Towdium commented 2 years ago

Thanks for your contribution! I'll merge your changes into a develop branch first, then merge into mainline after some tweaks.

ekgame commented 2 years ago

No problem. Let me know if any changes are needed from my end.