37 Commits

Author SHA1 Message Date
0f3ed05da9 Document the API version 2021-03-09 14:54:41 -05:00
784a4a60a5 pngcrush+optipng the new slot textures
and remove the slot image .xcf project file
2021-03-09 14:44:08 -05:00
ce160eea55 add a version number variable to the main table 2021-03-09 14:39:44 -05:00
eb3b8d9626 translate some strings inside their table 2021-03-09 14:26:36 -05:00
c84c23ff04 replace excessive spaces with tabs 2021-03-09 14:25:14 -05:00
7ad7a6b3a9 minor tweaks to the slot images
to make them better-resemble their pre-9-sliced versions
(going to that mode made them slightly bigger and the corners
slightly less round since they aren't blurry anymore)
2021-03-09 05:53:26 -05:00
d558d0355d Get rid of the image button left of the crafting guide
It had the same function as clicking the craft result on the
right (just inverted), making it redundant. Click either one more
than once and UI would alternately show usages or recipes.
2021-03-08 16:06:13 -05:00
ff200762c8 Move craft guide a little to the right to make some room. 2021-03-08 14:48:11 -05:00
1334ca0202 make craft arrow 128px
(same reason as the trash icon)
2021-03-08 14:11:45 -05:00
cfe21b93fb swap the craft type icon with its word
(makes it look like it used to)
2021-03-08 14:04:02 -05:00
036804716e make trash slot icon 128px
MT nearest-neighbor-scales images to about 75px if they're 1x1
slot in size (at least on my screen).  Use the next power of 2
above that, so that MT can scale down instead of up.
2021-03-08 13:15:24 -05:00
6da359e9d2 remove unused var, excess whitespace 2021-03-08 12:56:04 -05:00
e4f6e1adc4 fix missing "XYZ" and "no" icon on waypoints show coordinates button 2021-03-08 12:53:14 -05:00
ea4151dfa7 Use 9-slicing to build inventory-type backgrounds
This way the slots are all nice and crisp regardless of GUI scale or
image size, and we only need the single slot and its bright version.

This also makes the standard crafting grid into a style table entry that
can be referenced to insert the crafting grid at its proper
style-specific position in any formspec.

And it also makes the craft grid arrow, its X position, and the crafting
grid's result slot X position into style table entries.

Includes a few public helper functions to do most of the work:

`ui.single_slot(xpos, ypos, bright)`

    Does just what it sounds like: it returns a single slot image.
    `xpos` and `ypos` are normal coordinates in slots, as you'd use in
    `image[]` element.  `bright` is a flag that switches to the brighter
    version of the slot image.

`ui.make_trash_slot(xpos, ypos)`

    Creates a single slot, with a one-item `list[]` and a trash can icon
    overlay.

`ui.make_inv_img_grid(xpos, ypos, width, height, bright)`

    Generates a `width` by `height` grid of slot images, using the
    single_slot function above, starting at (`xpos`,`ypos`) for the
    top-left.  Position is as in any `image[]` element, and dimensions
    are in integer numbers of slots (so 8,4 would be a standard inventory).
    `bright` is as above.

All three return a string that can be directly inserted into a formspec.
2021-03-08 12:32:13 -05:00
d063af1d27 Draw the trash slot by overlaying the bare trash can icon
over the single slot image instead of baking it in.
2021-03-08 09:53:25 -05:00
250d038d0b don't display the refill slot image if no creative priv/mode
(leftover from when it was part of the craft grid image)

Also fixed a typo in the corresponding list[] element that
made it not work.
2021-03-08 09:14:21 -05:00
8a7d8268ad use local ui=unified_inventory shorthand in init.lua as elsewhere 2021-03-08 05:10:16 -05:00
51de368949 using a table.copy() to pass the style tables around requires
setting-up items_per_page, standard_inv, and standard_inv_bg
for both tables at init time.
2021-03-08 05:10:16 -05:00
e61ae0e149 always modify and return a table.copy() of the style table 2021-03-08 05:10:00 -05:00
531442c63e move S() calls into waypoints' button table
instead of inside the loop
2021-03-08 05:10:00 -05:00
62881d9938 Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.

2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.

3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs".  I settled on just
one name, "formspec", as it's more readable, if longer.

4) There was a mix of styles of adding items to those tables:

* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
  with `n` being increased or reset every so often.

Most of them should now be of the third form, with a few of the second.
2021-03-08 05:10:00 -05:00
55692900f9 use local "ui" to reference "unified_inventory", where practical
(makes code shorter, easier to read and write)
2021-03-08 05:10:00 -05:00
d52303a89e Ditto for bags. 2021-03-08 05:10:00 -05:00
b9e4b9e455 make waypoints explicitly reference full-style vars
(since it does not support lite mode)
2021-03-08 05:10:00 -05:00
4d52ebe774 put style-specific settings in their own tables
and switch between them directly, instead of copy-and-modify.
2021-03-08 05:10:00 -05:00
73ce55646c "Please continue to use string.format here to avoid messy code"
Derp :-)
2021-03-08 05:10:00 -05:00
4b39bc86cb fix indent 2021-03-08 05:10:00 -05:00
0df814d9d4 remove a used-only-once variable 2021-03-08 05:10:00 -05:00
8056bdf966 use string.format() to create the standard_inv variables
do it just once, after the lite mode settings are applied
(if applicable)
2021-03-08 05:10:00 -05:00
7e27f584eb get rid of uninv global
make all uses of it back into `unified_inventory.`
2021-03-08 05:09:54 -05:00
5140853a3a increase spacing around the text above the items page
("Filter:" and its search key, and the page or "No matches)
Adjust main and page flipping buttons' positions to compensate
2021-03-07 04:26:11 -05:00
a0c06516f4 increase size and tweak position of "give/to grid" buttons
and make them vary in pos with lite vs full mode
2021-03-07 04:13:36 -05:00
5ec4b986bb shift the craft grid and guide down a bit
to make more room for the result string
(and shift the result string down a hair to follow)
2021-03-07 03:57:39 -05:00
0616d1f76b 9-slice the background image 2021-03-06 19:05:27 -05:00
eb6697aa0d remove a couple of unused variables 2021-03-06 16:37:35 -05:00
a5a09bcd3a bump minimum version to 5.4.0 2021-03-06 13:35:34 -05:00
e8e1d4d705 Convert over to formspec version 4
I recreated the original layout as best as practical, but by necessity
there are a few minor positioning changes, since the underlying
hard-wired inventory slots are square now and image positioning is now
scaled by exactly 1.250 in both dimensions (as opposed to roughly 1.25
by 1.16).

Backstage, I also needed to fix the aspect ratios of the various
inventory slot elements.  That meant redesigning the single-slot image
from scratch.  It was already blurry/grainy and a little ugly, and
trying to alter it would have only made it worse.

The slot image is now exactly 56x56 pixels square, set on a 64x64
canvas, so there's a 4 pixel empty space around the edges. The full
256px .xcf workfile is included in the UI folder.

I've re-tiled all slot/inv images from the new single slot.

I also re-rendered the trash can icon from it since it was blurry and
oddly-sized. I couldn't find the original upstream image, so since
they're free, I used one of my Linux system's icons which happens to
resemble it.

I also removed a couple more improper uses of `background[]` where
`image[]` is more appropriate.

There are tons of minor tweaks throughout the code to re-align
everything, and I had to rewrite a few sections to avoid code
duplication and to allow for a little more flexibility (mainly to make
"lite" mode look right).
2021-03-06 13:22:20 -05:00
2 changed files with 3 additions and 3 deletions

View File

@ -24,7 +24,7 @@ Unified Inventory replaces the default survival and creative inventory.
## Requirements
* Minetest 5.4.0+
* Minetest 5.0.0+
# Licenses
@ -96,4 +96,4 @@ Other files from Wikimedia Commons:
RealBadAngel: (CC-BY-4.0)
* Everything else.
* Everything else.

View File

@ -137,7 +137,7 @@ end
local function load_bags_metadata(player, bags_inv)
local player_inv = player:get_inventory()
local meta = player:get_meta()
local bags_meta = meta:get("unified_inventory:bags")
local bags_meta = meta:get_string("unified_inventory:bags")
local bags = bags_meta and minetest.deserialize(bags_meta) or {}
local dirty_meta = false
if not bags_meta then