Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
minetest_game
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
minetest_game
Commits
e3dd3d19
Commit
e3dd3d19
authored
8 years ago
by
rubenwardy
Browse files
Options
Downloads
Patches
Plain Diff
Add sfinv.set_page, plus other helper functions
parent
86849d9e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
game_api.txt
+18
-8
18 additions, 8 deletions
game_api.txt
mods/sfinv/api.lua
+38
-27
38 additions, 27 deletions
mods/sfinv/api.lua
with
56 additions
and
35 deletions
game_api.txt
+
18
−
8
View file @
e3dd3d19
...
...
@@ -412,18 +412,28 @@ Sfinv API
### sfinv Methods
* sfinv.set_player_inventory_formspec(player, context) - builds page formspec
and calls set_inventory_formspec().
If context is nil, it is either found or created.
* sfinv.get_formspec(player, context) - builds current page's formspec
* sfinv.get_nav_fs(player, context, nav, current_idx) - see above
**Pages**
* sfinv.set_page(player, pagename) - changes the page
* sfinv.get_homepage_name(player) - get the page name of the first page to show to a player
* sfinv.make_formspec(player, context, content, show_inv, size) - adds a theme to a formspec
* show_inv, defaults to false. Whether to show the player's main inventory
* size, defaults to `size[8,8.6]` if not specified
* sfinv.register_page(name, def) - register a page, see section below
* sfinv.override_page(name, def) - overrides fields of an page registered with register_page.
* Note: Page must already be defined, (opt)depend on the mod defining it.
* sfinv.set_player_inventory_formspec(player) - (re)builds page formspec
and calls set_inventory_formspec().
* sfinv.get_formspec(player, context) - builds current page's formspec
**Contexts**
* sfinv.get_or_create_context(player) - gets the player's context
* sfinv.set_context(player, context)
**Theming**
* sfinv.make_formspec(player, context, content, show_inv, size) - adds a theme to a formspec
* show_inv, defaults to false. Whether to show the player's main inventory
* size, defaults to `size[8,8.6]` if not specified
* sfinv.get_nav_fs(player, context, nav, current_idx) - creates tabheader or ""
### sfinv Members
...
...
This diff is collapsed.
Click to expand it.
mods/sfinv/api.lua
+
38
−
27
View file @
e3dd3d19
...
...
@@ -91,22 +91,42 @@ function sfinv.get_formspec(player, context)
end
end
function
sfinv
.
set_player_inventory_formspec
(
player
,
context
)
function
sfinv
.
get_or_create_context
(
player
)
local
name
=
player
:
get_player_name
()
local
context
=
sfinv
.
contexts
[
name
]
if
not
context
then
local
name
=
player
:
get_player_name
()
context
=
sfinv
.
contexts
[
name
]
if
not
context
then
context
=
{
page
=
sfinv
.
get_homepage_name
(
player
)
}
sfinv
.
contexts
[
name
]
=
context
end
context
=
{
page
=
sfinv
.
get_homepage_name
(
player
)
}
sfinv
.
contexts
[
name
]
=
context
end
return
context
end
function
sfinv
.
set_context
(
player
,
context
)
sfinv
.
contexts
[
player
:
get_player_name
()]
=
context
end
local
fs
=
sfinv
.
get_formspec
(
player
,
context
)
function
sfinv
.
set_player_inventory_formspec
(
player
,
context
)
local
fs
=
sfinv
.
get_formspec
(
player
,
context
or
sfinv
.
get_or_create_context
(
player
))
player
:
set_inventory_formspec
(
fs
)
end
function
sfinv
.
set_page
(
player
,
pagename
)
local
context
=
sfinv
.
get_or_create_context
(
player
)
local
oldpage
=
sfinv
.
pages
[
context
.
page
]
if
oldpage
and
oldpage
.
on_leave
then
oldpage
:
on_leave
(
player
,
context
)
end
context
.
page
=
pagename
local
page
=
sfinv
.
pages
[
pagename
]
if
page
.
on_enter
then
page
:
on_enter
(
player
,
context
)
end
sfinv
.
set_player_inventory_formspec
(
player
,
context
)
end
minetest
.
register_on_joinplayer
(
function
(
player
)
if
sfinv
.
enabled
then
minetest
.
after
(
0
.
5
,
function
()
...
...
@@ -132,30 +152,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
false
end
--
Handle Events
--
Was a tab selected?
if
fields
.
tabs
and
context
.
nav
then
local
tid
=
tonumber
(
fields
.
tabs
)
if
tid
and
tid
>
0
then
local
id
=
context
.
nav
[
tid
]
local
page
=
sfinv
.
pages
[
id
]
if
id
and
page
then
local
oldpage
=
sfinv
.
pages
[
context
.
page
]
if
oldpage
and
oldpage
.
on_leave
then
oldpage
:
on_leave
(
player
,
context
)
end
context
.
page
=
id
if
page
.
on_enter
then
page
:
on_enter
(
player
,
context
)
end
sfinv
.
set_player_inventory_formspec
(
player
,
context
)
sfinv
.
set_page
(
player
,
id
)
end
end
return
end
-- Pass to page
local
page
=
sfinv
.
pages
[
context
.
page
]
if
page
and
page
.
on_player_receive_fields
then
return
page
:
on_player_receive_fields
(
player
,
context
,
fields
)
else
-- Pass event to page
local
page
=
sfinv
.
pages
[
context
.
page
]
if
page
and
page
.
on_player_receive_fields
then
return
page
:
on_player_receive_fields
(
player
,
context
,
fields
)
end
end
end
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment