update streets mod's "smartfs" component

master
Vanessa Ezekowitz 2015-08-05 12:31:32 -04:00
parent 58427ecdf2
commit 9b215dd1f1
6 changed files with 281 additions and 121 deletions

View File

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

View File

@ -0,0 +1,215 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#############
## Windows detritus
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg

View File

@ -32,16 +32,16 @@ The first argument is a unique string that identifies the form. The second argum
--sets the form's size
-- (width, hieght)
state:size(5,5)
--creates a label and places it on the form
--(x-pos, y-pos, name, text)
state:label(3,3,"label1", "A label!")
end)
Forms can be shown to the player by using the show(target) function. The target argument is the name of the player that will see the form.
myform:show("singleplayer")
Here is a list of steps the library takes.
* You create a new form using smartfs.create().
* The form is registered and stored for later use.
@ -49,7 +49,7 @@ Here is a list of steps the library takes.
* The state is created and stored.
* The function in smartfs.create runs and creates the elements.
* The form is displayed to the player.
## Modifying Elements
Elements have functions of the form element:function(args) where you need to have access to the element object.
@ -73,8 +73,8 @@ Now that you have located your element you can modify it.
## Inventory Support
Smartfs supports adding a button to Inventory+ or Unified Inventory which will open one of your own custom forms. Use the smartfs.add\_to\_inventory(form, icon, title) function where form is the smartfs form linked to by the button, icon is the button image (only for unified inventory), and title is the button text (only for inventory+).
smartfs.add_to_inventory(form, icon, title)
smartfs.add_to_inventory(form_name, icon, title)
## Dynamic forms
Dynamic forms allow you to make a form without having to register it before the game finished loading.
@ -84,5 +84,5 @@ Dynamic forms allow you to make a form without having to register it before the
print("Button clicked!")
end)
state:show()
Make sure you call state:show()

View File

@ -1,11 +1,10 @@
#Full API
##Smartfs
* smartfs( name ) - returns the form regisered with the name 'name'
* smartfs.create( name,function ) - creates a new form and adds elements to it by running the function. Use before Minetest loads. (like minetest.register_node)
* smartfs.element( name, data ) - creates a new element type.
* smartfs.dynamic( formname, playername ) - creates a dynamic form. Returns state. See example.lua for example. Remember to call state:show()
* smartfs.add\_to\_inventory(form, icon, title) - Adds a form to an installed advanced inventory. Returns true on success.
* smartfs.inventory_mod() - Returns the name of an installed and supported inventory mod that will be used above, or null.
* smartfs.add\_to\_inventory( name,icon,title ) - Adds a form to an installed advanced inventory.
* smartfs.inventory_mod() - Returns the name of an installed advanced inventory, or null.
* smartfs.override\_load\_checks() - Allows you to use smartfs.create after the game loads. Not recommended!
##Form
@ -29,7 +28,6 @@
* state:pwdfield( x,y,w,h,name,label ) - create a password field
* state:textarea( x,y,w,h,name,label ) - create a new textarea
* state:image( x,y,w,h,name,imagepath ) - create an image box.
* state:inventory( x,y,w,h,name ) - create an inventory listing (use 'main' as name for the main player inventory)
* state:checkbox( x,y,name,label,selected ) - create a check box.
* state:element( element_type, data ) - Semi-private, create an element with type and data.
@ -87,19 +85,6 @@
* element:removeItem( idx ) - remove item
* element:popItem() - removes last item and returns
##Inventory listing
* element:setPosition( x,y ) - set the position
* element:getPosition() - returns {x=x, y=y}
* element:setSize( w,h ) - set the size
* element:getSize() - gets the size {w=w, h=h}
* element:setLocation( location ) - set a custom inventory location or nil for the default (current_player)
* element:usePosition( position ) - use a node metadata attached inventory of the node at the given positon
* element:useDetached( name ) - use a detached inventory with the given name
* element:usePlayer( name ) - use a player inventory other than the current player
* element:getLocation() - returns the inventory location (default: current_player)
* element:setIndex( index ) - set the inventory starting index
* element:getIndex() - returns the inventory starting index
##Custom Code
* element:onSubmit( func(self) ) - on form submit
* element:onBuild( func(self) ) - run every time form is shown. You can set code from here

View File

@ -1,2 +1 @@
dofile(minetest.get_modpath("smartfs").."/smartfs.lua")
--dofile(minetest.get_modpath("smartfs").."/example.lua")

View File

@ -10,26 +10,25 @@ smartfs = {
inv = {}
}
-- the smartfs() function
function smartfs.__call(self, name)
return smartfs._fdef[name]
end
-----------------------------------------------------------------
-------------------------- THE API ----------------------------
-----------------------------------------------------------------
-- Register forms and elements
function smartfs.create(name,onload)
if smartfs._fdef[name] then
error("SmartFS - (Error) Form "..name.." already exists!")
error("Form "..name.." already exists!")
end
if smartfs.loaded and not smartfs._loaded_override then
error("SmartFS - (Error) Forms should be declared while the game loads.")
error("[SMARTFS, ERROR] Forms should be declared while the game loads.")
end
smartfs._fdef[name] = {
_reg = onload,
name = name,
show = smartfs._show_
}
return smartfs._fdef[name]
end
function smartfs.override_load_checks()
@ -40,10 +39,7 @@ minetest.after(0, function()
smartfs.loaded = true
end)
function smartfs.dynamic(name,player)
if not smartfs._dynamic_warned then
smartfs._dynamic_warned = true
print("SmartFS - (Warning) On the fly forms are being used. May cause bad things to happen")
end
print ("[SMARTFS, WARNING!] On the fly forms are being used. May cause bad things to happen")
local state = smartfs._makeState_({name=name},player,nil,false)
state.show = state._show_
smartfs.opened[player] = state
@ -51,7 +47,7 @@ function smartfs.dynamic(name,player)
end
function smartfs.element(name,data)
if smartfs._edef[name] then
error("SmartFS - (Error) Element type "..name.." already exists!")
error("Element type "..name.." already exists!")
end
smartfs._edef[name] = data
return smartfs._edef[name]
@ -76,25 +72,23 @@ function smartfs.add_to_inventory(form,icon,title)
unified_inventory.register_page(form.name, {
get_formspec = function(player, formspec)
local name = player:get_player_name()
local opened = smartfs._show_(form, name, nil, true)
return {formspec = opened:_getFS_(false)}
opened = smartfs._show_(form,name,nil,true)
return {formspec=opened:_getFS_(false)}
end
})
return true
elseif inventory_plus then
minetest.register_on_joinplayer(function(player)
inventory_plus.register_button(player, form.name, title)
inventory_plus.register_button(player,form.name,title)
end)
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "" and fields[form.name] then
local name = player:get_player_name()
local opened = smartfs._show_(form, name, nil, true)
opened = smartfs._show_(form,name,nil,true)
inventory_plus.set_inventory_formspec(player, opened:_getFS_(true))
end
end)
return true
else
return false
print("[SMARTFS, WARNING!] No advanced inventories are installed")
end
end
@ -123,7 +117,7 @@ function smartfs._makeState_(form,player,params,is_inv)
res = res .. val:build()
end
return res
end,
end,
_show_ = function(self)
if self.is_inv then
if unified_inventory then
@ -133,6 +127,7 @@ function smartfs._makeState_(form,player,params,is_inv)
end
else
local res = self:_getFS_(true)
print ("FS: "..res)
minetest.show_formspec(player,form.name,res)
end
end,
@ -154,11 +149,11 @@ function smartfs._makeState_(form,player,params,is_inv)
end,
save = function(self,file)
local res = {ele={}}
if self._size then
res.size = self._size
end
for key,val in pairs(self._ele) do
res.ele[key] = val.data
end
@ -203,12 +198,9 @@ function smartfs._makeState_(form,player,params,is_inv)
listbox = function(self,x,y,w,h,name)
return self:element("list", { pos={x=x,y=y}, size={w=w,h=h}, name=name })
end,
inventory = function(self,x,y,w,h,name)
return self:element("inventory", { pos={x=x,y=y}, size={w=w,h=h}, name=name })
end,
element = function(self,typen,data)
local type = smartfs._edef[typen]
if not type then
error("Element type "..typen.." does not exist!")
end
@ -230,7 +222,7 @@ function smartfs._makeState_(form,player,params,is_inv)
for key,val in pairs(type) do
ele[key] = val
end
self._ele[data.name] = ele
return self._ele[data.name]
@ -239,12 +231,12 @@ function smartfs._makeState_(form,player,params,is_inv)
end
-- Show a formspec to a user
function smartfs._show_(form, player, params, is_inv)
local state = smartfs._makeState_(form, player, params, is_inv)
function smartfs._show_(form,player,params,is_inv)
local state = smartfs._makeState_(form,player,params,is_inv)
state.show = state._show_
if form._reg(state)~=false then
if not is_inv then
smartfs.opened[player] = state
if is_inv~=true then
smartfs.opened[player] = state
state:_show_()
else
smartfs.inv[player] = state
@ -261,7 +253,9 @@ local function _sfs_recieve_(state,name,fields)
end
return true
end
print(dump(fields))
for key,val in pairs(fields) do
if state._ele[key] then
state._ele[key].data.value = val
@ -289,14 +283,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local name = player:get_player_name()
if smartfs.opened[name] and not smartfs.opened[name].is_inv then
if smartfs.opened[name].def.name == formname then
local state = smartfs.opened[name]
local state = smartfs.opened[name]
return _sfs_recieve_(state,name,fields)
else
smartfs.opened[name] = nil
end
elseif smartfs.inv[name] and smartfs.inv[name].is_inv then
local state = smartfs.inv[name]
_sfs_recieve_(state,name,fields)
local state = smartfs.inv[name]
return _sfs_recieve_(state,name,fields)
end
return false
end)
@ -348,7 +342,7 @@ smartfs.element("button",{
if fields[self.name] and self._click then
self:_click(self.root)
end
if self.data.closes then
return true
end
@ -384,7 +378,7 @@ smartfs.element("button",{
return self.data.img
end,
setClose = function(self,bool)
self.data.closes = bool
self.data.closes = bool
end
})
@ -613,8 +607,8 @@ smartfs.element("list",{
listformspec = string.sub(listformspec, 0, -2) --removes extra ,
--close out the list items section
listformspec = listformspec..";"
--TODO support selected idx and transparency
--TODO support selected idx and transparency
--close formspec definition and return formspec
listformspec = listformspec.."]"
@ -670,68 +664,13 @@ smartfs.element("list",{
popItem = function(self)
if not self.data.items then
self.data.items = {" "}
end
end
local item = self.data.items[#self.data.items]
table.remove(self.data.items)
return item
end
})
smartfs.element("inventory",{
build = function(self)
return "list["..
(self.data.location or "current_player") ..
";"..
self.name..
";"..
self.data.pos.x..","..self.data.pos.y..
";"..
self.data.size.w..","..self.data.size.h..
";"..
(self.data.index or "") ..
"]"
end,
setPosition = function(self,x,y)
self.data.pos = {x=x,y=y}
end,
getPosition = function(self,x,y)
return self.data.pos
end,
setSize = function(self,w,h)
self.data.size = {w=w,h=h}
end,
getSize = function(self,x,y)
return self.data.size
end,
-- available inventory locations
-- "current_player": Player to whom the menu is shown
-- "player:<name>": Any player
-- "nodemeta:<X>,<Y>,<Z>": Any node metadata
-- "detached:<name>": A detached inventory
-- "context" does not apply to smartfs, since there is no node-metadata as context available
setLocation = function(self,location)
self.data.location = location
end,
getLocation = function(self)
return self.data.location or "current_player"
end,
usePosition = function(self, pos)
self.data.location = string.format("nodemeta:%d,%d,%d", pos.x, pos.y, pos.z)
end,
usePlayer = function(self, name)
self.data.location = "player:" .. name
end,
useDetached = function(self, name)
self.data.location = "detached:" .. name
end,
setIndex = function(self,index)
self.data.index = index
end,
getIndex = function(self)
return self.data.index
end
})
smartfs.element("code",{
build = function(self)
if self._build then