Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple fast inventory #1179

Closed
wants to merge 1 commit into from
Closed

Conversation

rubenwardy
Copy link
Member

@rubenwardy rubenwardy commented Jul 4, 2016

Allows mods to define tabs for the 'i' inventory, even when creative mode is off.

sfinv.register_page("mymod:crafting2", {
    title = "Crafting2",
    get = function(self, player, context, vars)
        return sfinv.make_formspec(player, context, [[
                list[current_player;craft;1.75,0.5;3,3;]
                list[current_player;craftpreview;5.75,1.5;1,1;]
                image[4.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]
                listring[current_player;main]
                listring[current_player;craft]
                image[0,4.75;1,1;gui_hb_bg.png]
                image[1,4.75;1,1;gui_hb_bg.png]
                image[2,4.75;1,1;gui_hb_bg.png]
                image[3,4.75;1,1;gui_hb_bg.png]
                image[4,4.75;1,1;gui_hb_bg.png]
                image[5,4.75;1,1;gui_hb_bg.png]
                image[6,4.75;1,1;gui_hb_bg.png]
                image[7,4.75;1,1;gui_hb_bg.png]
            ]], true)
    end,
    on_player_receive_fields = function(self, player, context, fields)
        print(dump(fields))
    end
})

Potential Problems

  • Allowing mods to inject formspec into existing pages - eg: armor mods. This could be done currently, and would work with the default layout given, but if a layout used containers then the injected content would not be shifted down. TL;DR: it is possible for mods to inject content, but it would break layout support for that page a little

Planned improvements

When this PR is merged, I'll work on:

  • Unified inventory support using a wrapper
  • Creative inventory improvements:
    • Sort by description (more natural)
    • Add sub sections for nodes, such as natural items / decorations / mechanics / etc
    • ...


sfinv.register_page("sfinv:crafting", {
title = "Crafting",
is_in_nav = function(self, player, context)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed as not needed

@sofar
Copy link
Contributor

sofar commented Jul 5, 2016

I've been waiting for something like this, so, I'm very positive about a change like this.

@benrob0329
Copy link
Member

+1

return [[
size[8,8.6]
bgcolor[#080808BB;true]
background[5,5;1,1;gui_formbg.png;true]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these overwritten later with default.gui_bg .. default.gui_bg_img ..?

Copy link
Member Author

@rubenwardy rubenwardy Jul 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Background is an image which is drawn below all other elements, this background image is at (5, 5) and has size (1, 1). I imagine that default.gui_bg covers the entire window

@rubenwardy
Copy link
Member Author

Fixed all issues except page number coloring


* `title` - human readable page name (required)
* `get(self, player, context, vars)` - returns a formspec string. See formspec variables. (required)
* `is_in_nav(self, player, context)` - return true if it appears in tab header
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit confusing, how about Return true to show it in the tab header?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed (hopefully to your satisfaction)

@Ekdohibs
Copy link
Member

Ekdohibs commented Jul 5, 2016

I haven't tested it, but I'm very positive about the idea as well.
While you're at it, could you please do the page number coloring change, as t4im suggested?

@rubenwardy
Copy link
Member Author

It now uses a label and colorize instead of a table.
However the text is not center aligned.
Does anyone know how to make it so?
If not, then it will have to be reverted

@C1ffisme
Copy link

C1ffisme commented Jul 5, 2016

Very useful for things like armor, etc.

We can finally get rid of inventory_plus and it's like!

@Ekdohibs
Copy link
Member

Ekdohibs commented Jul 5, 2016

@rubenwardy Hm, wouldn't there be problems with the text overlapping other buttons if it's center-aligned?

@rubenwardy
Copy link
Member Author

rubenwardy commented Jul 5, 2016

@rubenwardy Hm, wouldn't there be problems with the text overlapping other buttons if it's center-aligned?

Ideally you'd be able to specify a rectangle for the text to be in, then center align it there

We can finally get rid of inventory_plus and it's like!

That's the aim!

@Ekdohibs
Copy link
Member

Ekdohibs commented Jul 5, 2016

Hm, I don't know if this is possible though. I think keeping it left-aligned is good anyway.

@rubenwardy
Copy link
Member Author

Is using a table that much of a problem? It's a bit overkill, but at least it looks right

@rubenwardy
Copy link
Member Author

rubenwardy commented Jul 5, 2016

Please note than an older version of this code has been running on the capture the flag server with no noticed performance issues. The sfinv code is only really called on player join and tab switch

@paramat
Copy link
Contributor

paramat commented Jul 7, 2016

I have no opinion on this so am neutral. I can't review as am useless with inventory / formspec stuff.
Luckily it seems you have the attention of 2 mtgame devs already.

@0-afflatus
Copy link

Great idea, don't have time to review properly.

@Fixer-007
Copy link
Contributor

This should be a nice thing, I'm tired of clicking via buttons in inventory plus, should be much faster and easier with tabs 👍

@rubenwardy
Copy link
Member Author

rebased

@rubenwardy
Copy link
Member Author

rubenwardy commented Aug 1, 2016

Found something weird: searching for "bone" gets no results even though bone is seen on the first page, and has bone in the description. Very weird.
Ok, bones appear if you click left after searching for it. This makes me think that the start idx isn't being reset correctly.

player:set_inventory_formspec(fs)
end

minetest.register_on_joinplayer(function(player)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense to free the contexts on leave player, to free unused memory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@tobyplowy
Copy link

+1

@paramat
Copy link
Contributor

paramat commented Nov 14, 2016

2 weeks to freeze, want this in release?

@sofar
Copy link
Contributor

sofar commented Nov 14, 2016

I'd really like to get this in, I think it'll be a good step forward for mods.

@rubenwardy rubenwardy added this to the 0.4.15 milestone Nov 14, 2016
@rubenwardy
Copy link
Member Author

Does anyone have any more objections/points?

It isn't possible to modify set_inventory_formspec, the mods would have to do sfinv.enabled = false

@paramat
Copy link
Contributor

paramat commented Nov 15, 2016

Sorry i can't comment being useless with inventory stuff. I have no objection to the intent.
Conflict with creative?

@tobyplowy
Copy link

@rubenwardy @sofar @paramat Will it get there for 0.4.15?

@sofar
Copy link
Contributor

sofar commented Nov 26, 2016

Works ok. Did the trash icon background disappear in this PR?

@sofar
Copy link
Contributor

sofar commented Nov 26, 2016

I'd recommend a huge squash+merge. 37 commits is way too much. As squashed PR it's not that big

 game_api.txt                |  106 +++++++++++++++++++
 mods/creative/depends.txt   |    1 
 mods/creative/init.lua      |  237 --------------------------------------------
 mods/creative/inventory.lua |  170 +++++++++++++++++++++++++++++++
 mods/sfinv/README.md        |   21 +++
 mods/sfinv/api.lua          |  158 +++++++++++++++++++++++++++++
 mods/sfinv/depends.txt      |    1 
 mods/sfinv/init.lua         |   22 ++++
 8 files changed, 482 insertions(+), 234 deletions(-)

@rubenwardy
Copy link
Member Author

rubenwardy commented Nov 26, 2016

Of course - I was leaving squash until later

@rubenwardy
Copy link
Member Author

done

@rubenwardy
Copy link
Member Author

readded trash background

@sofar
Copy link
Contributor

sofar commented Nov 26, 2016

👍

@paramat
Copy link
Contributor

paramat commented Nov 27, 2016

d42ae71

@paramat paramat closed this Nov 27, 2016
@paramat
Copy link
Contributor

paramat commented Nov 27, 2016

But,

-if creative_mode then
-	local digtime = 42
-	local caps = {times = {digtime, digtime, digtime}, uses = 0, maxlevel = 256}
+if minetest.setting_getbool("creative_mode") then
+	local digtime = 0.5
+	local caps = {times = {digtime, digtime, digtime}, uses = 0, maxlevel = 3}

Why was this changed? 42 and 256 are intentional @rubenwardy
See 0664570
Sorry i missed this.

@rubenwardy
Copy link
Member Author

Sfinv was started before that change, so that was a rebasing error

@rubenwardy
Copy link
Member Author

The problems with email are due to that mod using an outdated sfinv api. Will fix later

@paramat
Copy link
Contributor

paramat commented Nov 27, 2016

Ok.

@rubenwardy rubenwardy deleted the sfinv branch December 5, 2016 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet