Quantcast

Working on a better method

Brandon James Talbot [01-04-16 - 05:47]
Working on a better method
Filename
DJUI.toc
bag/bag.lua
bag/bag.xml
bag/core.lua
bag/events.lua
bag/settings.lua
bag/ui.xml
core/core.xml
core/fonts.xml
diff --git a/DJUI.toc b/DJUI.toc
deleted file mode 100644
index 0902994..0000000
--- a/DJUI.toc
+++ /dev/null
@@ -1,8 +0,0 @@
-## Interface: 60200
-## Author: Darkjaguar91
-## Version: 0.01
-## Title: DJUI
-## Notes: NOTE!!.
-
-bag/bag.lua
-bag/bag.xml
\ No newline at end of file
diff --git a/bag/bag.lua b/bag/bag.lua
deleted file mode 100644
index 0a830bc..0000000
--- a/bag/bag.lua
+++ /dev/null
@@ -1,161 +0,0 @@
-local bagItems = {}
-local itemSize, columns, padding, titleSize = 37, 5, 4, 15
-
-local function GetItems()
-	bagItems = {}
-
-	for bag = 0, NUM_BAG_SLOTS do
-		for slot = 1, GetContainerNumSlots(bag) do
-			local id = GetContainerItemID(bag, slot)
-			if id then
-				local texture, count, locked, quality, readable, lootable, link, isFiltered = GetContainerItemInfo(bag, slot)
-				local name, _, _, ilevel, reqLevel, class, subclass, maxStack, equipSlot, _, vendorPrice = GetItemInfo(id)
-
-				if not bagItems[class] then
-					bagItems[class] = {}
-				end
-
-				table.insert(bagItems[class], {
-					id = id,
-					name = name,
-					texture = texture,
-					link = link,
-					count = count,
-					quality = quality,
-					ilevel = ilevel,
-					maxStack = maxStack,
-				})
-			end
-		end
-	end
-end
-
-local function CreateBag(parent, name, items)
-	if #items == 0 then return end
-
-	local function sortIt(a, b)
-		if a.quality == b.quality then
-			if a.name == b.name then
-				return a.count > b.count
-			end
-
-			return a.name < b.name
-		end
-
-		return a.quality > b.quality
-	end
-
-	table.sort(items, sortIt)
-
-	if not parent.frames then
-		parent.frames = {}
-	end
-	local frame = parent.frames[name]
-	if not frame then
-		parent.frames[name] = CreateFrame("Frame", "BagFrame" .. name, parent)
-		frame = parent.frames[name]
-		frame.name = name
-		frame.items = {}
-		frame.buttonPool = {}
-		frame.createItem = function(self, item)
-			local button = table.remove(self.buttonPool)
-
-			if not button then
-				button = CreateFrame("Button", nil, self, "DJUIBagItemTemplate")
-				button.count:SetFontObject("DJUI_Small")
-			end
-
-			button.link = item.link
-			button.icon:SetTexture(item.texture)
-
-			if item.count > 1 then
-				button.count:SetText(item.count)
-				button.count:SetVertexColor(1, 1, 1, 1)
-				button.count:Show()
-			elseif item.maxStack == 1 and item.ilevel > 1 then
-				print(item.name)
-				button.count:SetText(item.ilevel)
-				button.count:SetVertexColor(GetItemQualityColor(item.quality))
-				button.count:Show()
-			else
-				button.count:Hide()
-			end
-
-			if item.quality > 1 then
-				button.glow:SetVertexColor(GetItemQualityColor(item.quality))
-				button.glow:Show()
-			else
-				button.glow:Hide()
-			end
-			table.insert(self.items, button)
-			return button
-		end
-		frame.title = frame:CreateFontString("BagBuddy_Title", "OVERLAY", "GameFontNormal")
-		frame.title:SetFontObject("DJUITitle")
-		frame.title:SetPoint("TOP", 0, -1)
-		frame.background = frame:CreateTexture(nil, "BACKGROUND")
-		frame.background:SetAllPoints()
-		frame.background:SetTexture(0, 0, 0, 0.6)
-		frame:SetBackdrop({
-		 edgeFile="Interface\\ChatFrame\\ChatFrameBackground",
-		 edgeSize= 0.6,
-		})
-	end
-
-	local frame = parent.frames[name]
-	for k, v in pairs(frame.items) do
-		v:Hide()
-		v.link = nil
-		v:ClearAllPoints()
-		table.insert(frame.buttonPool, v)
-	end
-
-	frame.items = {}
-	frame.title:SetText(name)
-
-	local count = 0
-	for k, v in pairs(items) do
-		local btn = frame:createItem(v)
-
-		local x = padding + itemSize * (count % columns) + padding * (count % columns)
-		local y = -(frame.title:GetStringHeight() + padding + padding * math.floor(count / 5) + itemSize * math.floor(count / 5))
-		btn:SetPoint("TOPLEFT", x, y)
-
-		count = count + 1
-	end
-	local numRows = math.ceil(#items / 5)
-	local x = padding * (columns + 1) + itemSize * columns
-	local y = numRows * itemSize + frame.title:GetStringHeight() + padding + padding * numRows
-	frame:SetSize(x, y)
-	return x, y, frame
-end
-
-local function UpdateItems(parent)
-	GetItems()
-	local w, h = 0, 0
-	for k, v in pairs(bagItems) do
-		local w1, h1, frame = CreateBag(parent, k, v)
-		w = math.max(w, w1)
-		frame:SetPoint("BOTTOMRIGHT", 0, h)
-		frame:Show()
-		h = h + h1
-	end
-	parent:SetSize(w + 5, h + 5)
-	parent:Show()
-end
-
-function DJUIBag_OnLoad(self)
-	UpdateItems(self)
-end
-
-function DJUIBag_ItemEnter(self, motion)
-	if self.link then
-		GameTooltip:SetOwner(self, "ANCHOR_TOPRIGHT")
-		GameTooltip:SetHyperlink(self.link)
-		GameTooltip:Show()
-	end
-end
-
-function DJUIBag_ItemLeave(self, motion)
-	GameTooltip:Hide()
-end
\ No newline at end of file
diff --git a/bag/bag.xml b/bag/bag.xml
index 6f10fb0..f826814 100644
--- a/bag/bag.xml
+++ b/bag/bag.xml
@@ -1,4 +1,5 @@
 <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/  http://wowprogramming.com/FrameXML/UI.xsd">
-	<Script file="bag/bag.lua" />
-	<Include file="bag/ui.xml" />
+	<Script file="bag/settings.lua" />
+	<Script file="bag/core.lua" />
+	<Script file="bag/events.lua" />
 </Ui>
\ No newline at end of file
diff --git a/bag/core.lua b/bag/core.lua
new file mode 100644
index 0000000..515ac40
--- /dev/null
+++ b/bag/core.lua
@@ -0,0 +1,113 @@
+local addonName, ns = ...
+
+local settings = ns.bag.settings
+
+local impl = {}
+impl.__index = impl
+
+ns.bag.impl = impl
+
+ns.buttons = {
+
+}
+
+impl.mainFrame = CreateFrame("Frame", "DJUIBag", UIParent)
+
+function impl:ADDON_LOADED(name)
+	if name == addonName then
+		-- TODO - Load real settings
+		self.mainFrame:SetPoint("BOTTOMRIGHT", -300, 125)
+
+		local buttons = {}
+
+		for bag = 0, NUM_BAG_SLOTS do
+			for slot = 1, GetContainerNumSlots(bag) do
+				local button = self:UpdateButton(bag, slot)
+
+				table.insert(buttons, button)
+				button:SetParent(self.mainFrame)
+			end
+		end
+
+		self:ArangeItems(self.mainFrame, buttons, settings.saved.columns, settings.saved.itemPadding, settings.saved.itemSize)
+		local w, h = self:GetButtonFrameSize(#buttons, settings.saved.columns, settings.saved.itemPadding, settings.saved.itemSize)
+		self.mainFrame:SetSize(w, h)
+		self.mainFrame:Show()
+	end
+end
+
+function impl:GetButton(bag, slot)
+	if not ns.buttons[bag] then
+		ns.buttons[bag] = {}
+	end
+	if ns.buttons[bag][slot] then
+		return ns.buttons[bag][slot]
+	end
+
+	local parentFrame = CreateFrame("Frame", nil, nil)
+	parentFrame:SetID(bag)
+
+	local button = CreateFrame("Button", string.format("DJUIBagButton%d_%d", bag, slot), parentFrame, "ContainerFrameItemButtonTemplate")
+
+	parentFrame.button = button
+
+	button:SetAllPoints()
+	button.bagID = bag
+	button.slotID = slot
+	button:SetID(slot)
+	button:Show()
+	parentFrame:Show()
+
+	ns.buttons[bag][slot] = parentFrame
+
+	return parentFrame
+end
+
+function impl:ArangeItems(container, items, columns, itemPadding, itemSize)
+	local cnt = 0
+	for k, v in pairs(items) do
+		v:ClearAllPoints()
+		v:SetParent(container)
+		v:SetSize(settings.saved.itemSize, settings.saved.itemSize)
+
+		local col = math.ceil(cnt % columns)
+		local row = math.floor(cnt / columns)
+		local x = col * itemSize + col * itemPadding
+		local y = row * itemSize + row * itemPadding
+
+		v:SetPoint("TOPLEFT", x, -y)
+
+		cnt = cnt + 1
+	end
+end
+
+function impl:GetButtonFrameSize(count, columns, itemPadding, itemSize)
+	local x = columns * itemSize + (columns - 1) * itemPadding
+	local rows = math.ceil(count / columns)
+	local y = rows * itemSize + (rows - 1) * itemPadding
+
+	return x, y
+end
+
+function impl:UpdateButton(bag, slot)
+	local parentFrame = self:GetButton(bag, slot)
+	local button = parentFrame.button
+
+	local texture, count, locked, quality, readable, lootable, link, isFiltered = GetContainerItemInfo(bag, slot)
+
+	if not texture then
+		button.Count:Hide()
+		button.icon:SetTexture(nil)
+	else
+		button.icon:SetTexture(texture)
+
+		if count > 1 then
+			button.Count:SetText(count)
+			button.Count:Show()
+		else
+			button.Count:Hide()
+		end
+	end
+
+	return parentFrame
+end
\ No newline at end of file
diff --git a/bag/events.lua b/bag/events.lua
new file mode 100644
index 0000000..c1eb1b3
--- /dev/null
+++ b/bag/events.lua
@@ -0,0 +1,16 @@
+local _, ns = ...
+
+local impl = ns.bag.impl
+
+SLASH_DJBAG1, SLASH_DJBAG2 = '/djb', '/djbag'
+function SlashCmdList.DJBAG(msg, editbox)
+
+end
+
+impl.mainFrame:RegisterEvent("ADDON_LOADED")
+
+impl.mainFrame:SetScript("OnEvent", function(self, event, ...)
+	if impl[event] then
+		impl[event](impl, ...)
+	end
+end)
\ No newline at end of file
diff --git a/bag/settings.lua b/bag/settings.lua
new file mode 100644
index 0000000..2f18ac7
--- /dev/null
+++ b/bag/settings.lua
@@ -0,0 +1,94 @@
+local _, ns = ...
+
+if not ns.bag then
+	ns.bag = {}
+	ns.bag.__index = ns.bag
+end
+
+local settings = {}
+ns.bag.settings = settings
+
+settings.iLevelTypes = {
+	"Weapon",
+	"Armor"
+}
+
+settings.saved = {
+	itemSize = 37,
+	columns = 8,
+	itemPadding = 3,
+	padding = 5,
+	bagPadding = 3,
+	titleSize = 15,
+	countFontSize = 10,
+	savedTypes = {},
+	bagSettings = {},
+	bagColumns = {
+		left = {
+			"Sets",
+			"Armor",
+			"Weapon",
+		},
+		right = {
+			"Miscellaneous",
+			"Consumable",
+			"Trade Goods",
+			"Quest",
+		},
+	},
+}
+
+settings.setNames = {}
+
+settings.isSet = function(key)
+	for k, v in pairs(settings.setNames) do
+		if v == key then
+			return true
+		end
+	end
+end
+
+settings.bagColumnSorter = function (itemTable)
+	local function getKey(itm)
+		itm = settings.isSet(itm) and "Sets" or itm
+		for k, v in pairs(itemTable) do
+			if v == itm then
+				return k
+			end
+		end
+		return nil
+	end
+
+	return function(a, b)
+		local valA =  getKey(a)
+		local valB =  getKey(b)
+
+		if valA and valB then
+			if valA ~= valB then
+				return valA < valB
+			end
+		elseif valA then
+			return true
+		elseif valB then
+			return false
+		end
+		return a < b
+	end
+end
+
+settings.sortingFunction = {
+	["default"] = function (a, b)
+		if a.quality == b.quality then
+			if a.name == b.name then
+				return a.count > b.count
+			end
+			return a.name < b.name
+		end
+		return a.quality > b.quality
+	end,
+	["name"] = function (a, b)
+		return a.name < b.name
+	end,
+}
+
+_G["DJUIBagSettings"] = settings
\ No newline at end of file
diff --git a/bag/ui.xml b/bag/ui.xml
deleted file mode 100644
index f44d738..0000000
--- a/bag/ui.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-<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/  http://wowprogramming.com/FrameXML/UI.xsd">
-	<Button name="DJUIBagItemTemplate" virtual="true">
-		<Size>
-			<AbsDimension x="37" y="37"/>
-		</Size>
-		<Layers>
-			<Layer level="BORDER">
-				<Texture name="$parentIconTexture" parentKey="icon"/>
-				<FontString hidden="true" inherits="NumberFontNormal" justifyH="RIGHT" name="$parentCount" parentKey="count">
-					<Anchors>
-						<Anchor point="BOTTOMRIGHT">
-							<Offset>
-								<AbsDimension x="0" y="1"/>
-							</Offset>
-						</Anchor>
-					</Anchors>
-				</FontString>
-			</Layer>
-			<Layer level="OVERLAY">
-				<Texture alphaMode="ADD" file="Interface\Buttons\UI-ActionButton-Border" name="$parentGlow" parentKey="glow">
-					<Size x="70" y="70"/>
-					<Anchors>
-						<Anchor point="CENTER"/>
-					</Anchors>
-					<Color a="0.6" b="1.0" g="1.0" r="1.0"/>
-				</Texture>
-			</Layer>
-		</Layers>
-
-		<Scripts>
-			<OnEnter function="DJUIBag_ItemEnter" />
-			<OnLeave function="DJUIBag_ItemLeave" />
-		</Scripts>
-
-		<NormalTexture file="Interface\Buttons\UI-Quickslot2" name="$parentNormalTexture">
-			<Size>
-				<AbsDimension x="64" y="64"/>
-			</Size>
-			<Anchors>
-				<Anchor point="CENTER">
-					<Offset>
-						<AbsDimension x="0" y="-1"/>
-					</Offset>
-				</Anchor>
-			</Anchors>
-		</NormalTexture>
-		<PushedTexture file="Interface\Buttons\UI-Quickslot-Depress"/>
-		<HighlightTexture alphaMode="ADD" file="Interface\Buttons\ButtonHilight-Square"/>
-	</Button>
-	<Frame name="DJUIBag" parent="UIParent">
-		<Anchors>
-			<Anchor point="CENTER" relativePoint="CENTER" relativeTo="UIParent"/>
-		</Anchors>
-		<Scripts>
-			<OnLoad function="DJUIBag_OnLoad" />
-		</Scripts>
-	</Frame>
-</Ui>
\ No newline at end of file
diff --git a/core/core.xml b/core/core.xml
index 11117b9..db12b74 100644
--- a/core/core.xml
+++ b/core/core.xml
@@ -1,3 +1,2 @@
 <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/  http://wowprogramming.com/FrameXML/UI.xsd">
-	<Include file="core/fonts.xml" />
 </Ui>
\ No newline at end of file
diff --git a/core/fonts.xml b/core/fonts.xml
deleted file mode 100644
index 338cf2d..0000000
--- a/core/fonts.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<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/  http://wowprogramming.com/FrameXML/UI.xsd">
-	<Font name="DJUITitle" font="Fonts\FRIZQT__.TTF" outline="NORMAL" virtual="true">
-		<Shadow>
-			<Offset>
-				<AbsDimension x="2" y="-2" />
-			</Offset>
-			<Color r="0" g="0" b="0" />
-		</Shadow>
-		<Color r="0.8" g="0.4" b="0" />
-		<FontHeight>
-			<AbsValue val="15" />
-		</FontHeight>
-	</Font>
-	<Font name="DJUI_Small" font="Fonts\FRIZQT__.TTF" outline="NORMAL" virtual="true">
-		<Shadow>
-			<Offset>
-				<AbsDimension x="1" y="-1" />
-			</Offset>
-			<Color r="0" g="0" b="0" />
-		</Shadow>
-		<Color r="1" g="1" b="1" />
-		<FontHeight>
-			<AbsValue val="8" />
-		</FontHeight>
-	</Font>
-</Ui>
\ No newline at end of file