diff --git a/data/config.example.lua b/data/config.example.lua
index 613c212..524b737 100644
--- a/data/config.example.lua
+++ b/data/config.example.lua
@@ -1,6 +1,8 @@
return {
pkey = "",
name = "",
+ submsg = "",
+ monSide = "",
storage = {
""
},
diff --git a/data/pages/index.xml b/data/pages/index.xml
index 23ddf46..0a5ab43 100644
--- a/data/pages/index.xml
+++ b/data/pages/index.xml
@@ -1,17 +1,20 @@
-
+
-
+
+
-
-
+
+
-
+
+
+
\ No newline at end of file
diff --git a/data/pages/widget.xml b/data/pages/widget.xml
index 7eb18af..91a3069 100644
--- a/data/pages/widget.xml
+++ b/data/pages/widget.xml
@@ -1,16 +1,21 @@
-
+
-
-
+
+
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/data/products.lua b/data/products.lua
index 189ab26..e9d992f 100644
--- a/data/products.lua
+++ b/data/products.lua
@@ -3,24 +3,28 @@
displayName = "Dirt",
description = "Has good quality.",
price = 999,
- id = "minecraft:dirt"
+ id = "minecraft:dirt",
+ metaname = "drt",
},
{
displayName = "Diamond",
description = "Only for a limited time!",
price = 14,
- id = "minecraft:diamond"
+ id = "minecraft:diamond",
+ metaname = "dia",
},
{
displayName = "Emerald",
description = "Peps with longe nose like those stuff..",
price = 2,
- id = "minecraft:emerald"
+ id = "minecraft:emerald",
+ metaname = "mald",
},
{
displayName = "Paper",
description = "Maby you need it, i dunno.",
price = 1,
- id = "minecraft:paper"
+ id = "minecraft:paper",
+ metaname = "ppa",
},
}
diff --git a/src/frontend.lua b/src/frontend.lua
index b274eb0..4b45fda 100644
--- a/src/frontend.lua
+++ b/src/frontend.lua
@@ -1,6 +1,9 @@
local ctx = ({...})[1]
local basalt = require("libs/basalt")
+local storage = require(fs.combine("libs", "inv"))(ctx.config.storage)
+storage.refreshStorage()
+
local function searchObject(base, id)
local obj = base:getObject(id)
if not obj then
@@ -19,18 +22,55 @@
-- Button functoins
basalt.setVariable("openHelpDialog", function()
- --basalt.debug("But nobody came.")
- os.queueEvent("kstUpdateProducts")
-end)
-basalt.setVariable("selectNewCategory", function()
- basalt.debug("")
+ basalt.debug("But nobody came.")
end)
-- Create frame
local base = basalt.createFrame()
+ :setMonitor(ctx.config.monSide)
:setTheme(ctx.theme)
:addLayout(fs.combine(ctx.path.page, "index.xml"))
+-- Adjust theme
+local title = searchObject(base, "_title")
+ :setText("@"..ctx.config.name)
+local nW = title:getSize()
+local nX = title:getPosition()
+
+local titleEnd = searchObject(base, "_title_end")
+local _,nY = titleEnd:getPosition()
+titleEnd:setPosition(nX+nW*title:getFontSize(), nY)
+
+local watermark = searchObject(base, "_watermark")
+ :setText("Kristify")
+
+local helpBtn = searchObject(base, "_helpButton")
+ :setText("?")
+
+local subtitle = searchObject(base, "_subtitle")
+
+local moveSubtitle = base:addThread()
+ :start(function()
+ local nW = subtitle:getSize()
+ if #ctx.config.submsg <= nW then return end
+
+ local i,cooldown = 1,7
+ while true do
+ if cooldown <= 0 then
+ i = i+1
+ if i > (#ctx.config.submsg)+5 then
+ i = 1
+ cooldown = 7
+ end
+ else
+ cooldown = cooldown-1
+ end
+ subtitle:setText(ctx.config.submsg:sub(i))
+ sleep(0.2)
+ end
+ end
+)
+
-- Events
basalt.onEvent(function(event)
if event == "kstUpdateProducts" then
@@ -43,9 +83,10 @@
-- Sort
local tItems = {}
for _,item in ipairs(ctx.products) do
- if --[[INSERT CHECK IF IT IS AVAILABLE]] true then
+ local amount = storage.getCount(item.id)
+ if amount ~= 0 then
local newItem = {
- amount = 1, -- INSERT AVAILABLE AMOUNT
+ amount = amount
}
for k,v in pairs(item) do
newItem[k] = v
@@ -59,26 +100,30 @@
-- Get size of widget
local dummy = body:addLayout(fs.combine(ctx.path.page, "widget.xml"))
dummy = dummy:getObject("_widget")
- local nW,_ = body:getSize()
+ local nW,nH = body:getSize()
local nSubW,nSubH = dummy:getSize()
body:removeObject(dummy)
-- Insert
- local spaceW = nW/nSubW-1
+ local spaceW,spaceH = nW/nSubW-1, nH/nSubH-1
+ local nYOff = (spaceH <= 1) and (nH/2)-(nSubH/2) or 0
+
local nX,nY = 0,0
for i,item in ipairs(tItems) do
body:addLayout(fs.combine(ctx.path.page, "widget.xml"))
local widget = body:getObject("_widget")
- :setPosition(nSubW*nX+1, nSubH*nY+1)
+ :setPosition(nSubW*nX+1, nSubH*nY+1+nYOff)
widget.name = "_widget_"..i
-- Adjust data
local name = searchObject(widget, "_name")
:setText(item.displayName)
- local amount = searchObject(widget, "_onStock")
- :setText(item.amount.."x")
+ local amount = searchObject(widget, "_stock")
+ :setText(item.amount)
+ local metaname = searchObject(widget, "_metaname")
+ :setText(item.metaname)
- local button = searchObject(widget, "_purchase")
+ local button = searchObject(widget, "_price")
local _,h = button:getSize()
local btnLabel = item.price.."kst"
button
@@ -90,9 +135,13 @@
if nX > spaceW then
nX = 0
nY = nY+1
+ if nY >= spaceH then
+ break
+ end
end
end
end
end)
+os.queueEvent("kstUpdateProducts")
basalt.autoUpdate(base)
\ No newline at end of file
diff --git a/src/init.lua b/src/init.lua
index 6d431ea..f8a07b4 100644
--- a/src/init.lua
+++ b/src/init.lua
@@ -10,7 +10,8 @@
-- [Context]
ctx = { products = {}, theme = {}, config = {}, pages = {} }
ctx.path = {
- page = sPage
+ page = sPage,
+ src = sSrc
}
-- [Pages]