Skip to content

Commit

Permalink
added basic gui
Browse files Browse the repository at this point in the history
  • Loading branch information
solidity0815 committed Mar 26, 2022
1 parent 6708f1c commit 56bc65c
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 7 deletions.
11 changes: 11 additions & 0 deletions .vs/CraftLog/project-colors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Version": 1,
"ProjectMap": {
"a2fe74e1-b743-11d0-ae1a-00a0c90fffc3": {
"ProjectGuid": "a2fe74e1-b743-11d0-ae1a-00a0c90fffc3",
"DisplayName": "Sonstige Dateien",
"ColorIndex": -1
}
},
"NextColorIndex": 0
}
7 changes: 7 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\LICENSE",
"PreviewInSolutionExplorer": false
}
1 change: 1 addition & 0 deletions CraftLog.toc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
## SavedVariables: CraftLog

main.lua

5 changes: 4 additions & 1 deletion CraftLog.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
<Editbox name="RecipeExporter">
<Editbox name="Craft Log">
<Size>
<AbsDimension x="400" y="600" />
</Size>
<Anchors>
<Anchor point="CENTER" />
</Anchors>
<Scripts>
<OnShow>
message("Hello!");
</OnShow>
</Scripts>
</Editbox>
</Ui>
194 changes: 188 additions & 6 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
-- create local variables

-- frame to register events
local f = CreateFrame("Frame")
-- setup frame to register events and for output
local f = CreateFrame("Frame", "CraftLogFrame", UIParent, "BasicFrameTemplateWithInset")

-- temp storage for current castGUID
local castGUID, delayedSpell, delayedTimestamp

-- toggle for debug log
-- settings
local debugToggle = false
local filterCreated, filterUsed, filter1d, filter7d, filter30d, filterAll = true, true, true, true, true, true

-- optional reagents ilvl effect and temp storage for current inventory
local optionalReagentsIlvl = {
Expand Down Expand Up @@ -74,15 +75,195 @@ f:RegisterEvent("ADDON_LOADED")

-- slash command handler
function SlashCraftLog(arg1)
if (arg1 == "") then
if (arg1 == "help") or (arg1 == "?") then
print("use /craftlog debug to toggle debug mode")

--toggle debug mode
elseif (arg1 == "debug") then
debugToggle = not debugToggle
if (debugToggle) then
print("CraftLog Debug Mode is now on")
print("CraftLog: Debug Mode is now on")
else
print("CraftLog Debug Mode is now off")
print("CraftLog: Debug Mode is now off")
end

-- show main window
elseif (arg1 == "") then
if (debugToggle) then print("CraftLog: showing Frame") end
f:Show()
f:ShowData()
end
end

-- output frame handling
function f:Setup ()
f:SetPoint("CENTER")
f:SetSize(800, 600)
f:SetMinResize(300, 200)

-- close on ESC
_G["CraftLogFrame"] = f
tinsert(UISpecialFrames, "CraftLogFrame")

-- make movable/resizable
f:SetMovable(true)
f:SetResizable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")

--moving
f:SetScript("OnDragStart", function(self)
self:StartMoving()
end)
f:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
end)

--resizing
local br = CreateFrame("Button", nil, f)
br:EnableMouse(true)
br:SetPoint("BOTTOMRIGHT")
br:SetSize(16,16)
br:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
br:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
br:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
br:SetScript("OnMouseDown", function(self)
self:GetParent():StartSizing("BOTTOMRIGHT")
end)
br:SetScript("OnMouseUp", function(self)
self:GetParent():StopMovingOrSizing()
end)

-- fill the frame

--filter area

local filterHeader = f:CreateFontString(f, "ARTWORK", "GameFontNormal")
filterHeader:SetPoint("TOPLEFT", 20, -40)
filterHeader:SetText("Filter:")

local cbCreated = CreateFrame("CheckButton", nil, f, "InterfaceOptionsCheckButtonTemplate")
cbCreated:SetPoint("TOPLEFT", 20, -60)
cbCreated.Text:SetText("crafted items")
cbCreated:SetChecked(filterCreated)
cbCreated.SetValue = function(_, value)
filterCreated = (value == "1")
end

local cbUsed = CreateFrame("CheckButton", nil, f, "InterfaceOptionsCheckButtonTemplate")
cbUsed:SetPoint("TOPLEFT", 20, -80)
cbUsed.Text:SetText("used items")
cbUsed:SetChecked(filterUsed)
cbUsed.SetValue = function(_, value)
filterUsed = (value == "1")
end

local timeframeHeader = f:CreateFontString(f, "ARTWORK", "GameFontNormal")
timeframeHeader:SetPoint("TOPLEFT", 20, -120)
timeframeHeader:SetText("Timeframes:")

local cbTimeframe1d = CreateFrame("CheckButton", nil, f, "InterfaceOptionsCheckButtonTemplate")
cbTimeframe1d:SetPoint("TOPLEFT", 20, -140)
cbTimeframe1d.Text:SetText("1 day")
cbTimeframe1d:SetChecked(filter1d)
cbTimeframe1d.SetValue = function(_, value)
filter1d = (value == "1")
end

local cbTimeframe7d = CreateFrame("CheckButton", nil, f, "InterfaceOptionsCheckButtonTemplate")
cbTimeframe7d:SetPoint("TOPLEFT", 20, -160)
cbTimeframe7d.Text:SetText("7 days")
cbTimeframe7d:SetChecked(filter7d)
cbTimeframe7d.SetValue = function(_, value)
filter7d = (value == "1")
end

local cbTimeframe30d = CreateFrame("CheckButton", nil, f, "InterfaceOptionsCheckButtonTemplate")
cbTimeframe30d:SetPoint("TOPLEFT", 20, -180)
cbTimeframe30d.Text:SetText("30 days")
cbTimeframe30d:SetChecked(filter30d)
cbTimeframe30d.SetValue = function(_, value)
filter30d = (value == "1")
end

local cbTimeframeAll = CreateFrame("CheckButton", nil, f, "InterfaceOptionsCheckButtonTemplate")
cbTimeframeAll:SetPoint("TOPLEFT", 20, -200)
cbTimeframeAll.Text:SetText("all time")
cbTimeframeAll:SetChecked(filterAll)
cbTimeframeAll.SetValue = function(_, value)
filterAll = (value == "1")
end

--settings
local cb = CreateFrame("CheckButton", nil, f, "InterfaceOptionsCheckButtonTemplate")
cb:SetPoint("BOTTOMLEFT", 20, 20)
cb.Text:SetText("debugToggle")
cb.SetValue = function(_, value)
debugToggle = (value == "1")
end
end

function f:ShowData()
-- headers for Timeframes
local header1d = f:CreateFontString(f, "ARTWORK", "GameFontNormal")
header1d:SetPoint("TOPLEFT", 350, -40)
header1d:SetText("1 day")

local header7d = f:CreateFontString(f, "ARTWORK", "GameFontNormal")
header7d:SetPoint("TOPLEFT", 450, -40)
header7d:SetText("7 days")

local header30d = f:CreateFontString(f, "ARTWORK", "GameFontNormal")
header30d:SetPoint("TOPLEFT", 550, -40)
header30d:SetText("30 days")

local headerAll = f:CreateFontString(f, "ARTWORK", "GameFontNormal")
headerAll:SetPoint("TOPLEFT", 650, -40)
headerAll:SetText("total")

-- scrollable itemlist
local dataScroll = CreateFrame("Scrollframe", "CraftLogDataScroll", f, "UIPanelScrollFrameTemplate")
dataScroll:SetPoint("TOPLEFT", 150, -60)
dataScroll:SetPoint("BOTTOMRIGHT", -20, 20)

local scrollChild = CreateFrame("Frame")
dataScroll:SetScrollChild(scrollChild)
scrollChild:SetWidth(InterfaceOptionsFramePanelContainer:GetWidth()-20)
scrollChild:SetHeight(1)

local itemTable = GetDistinctItems()
local yOffset = 40
local n = 0
for itemkey, itemvalue in pairs(itemTable) do
local itemName = scrollChild:CreateFontString(scrollChild, "ARTWORK", "GameFontNormal")
itemName:SetPoint("TOPLEFT", 20, -20-n*yOffset)
itemName:SetText(itemkey)
n = n + 1
end
end

function GetDistinctItems()
local t = {}
for datekey, datevalue in pairs(CraftLog) do
for itemkey, itemvalue in pairs(datevalue) do
if (t[itemkey] == nil) then t[itemkey] = {} end
for ilvlkey, ilvlvalue in pairs(itemvalue) do
if(t[itemkey][ilvlkey] == nil) then t[itemkey][ilvlkey] = ilvlvalue end
end
end
end
return t
end

function FilterByTimeframe(timeframe)
local t = {}
for datekey, datevalue in pairs(CraftLog) do
local year, month, day = datekey:match("(%d+)-(%d+)-(%d+)")
local age = floor((time() - time({day=day, month=month, year=year}))/86400)
if (timeframe == -1) or (age<=timeframe) then
for itemkey, itemvalue in pairs(datevalue) do
print(datekey..": "..itemkey)
end
end
end
end
Expand All @@ -97,6 +278,7 @@ f:SetScript("OnEvent", function(self, event, ...)
OnBagUpdateDelayed(event, ...)
elseif (event == "ADDON_LOADED") then
InitializeSavedVariables(...)
f:Setup()
end
end)

Expand Down

0 comments on commit 56bc65c

Please sign in to comment.