Skip to content

Commit

Permalink
Adds new assets
Browse files Browse the repository at this point in the history
  • Loading branch information
itsthatguy committed May 2, 2020
1 parent 5c9df70 commit efbe4f9
Show file tree
Hide file tree
Showing 14 changed files with 473 additions and 8 deletions.
10 changes: 10 additions & 0 deletions Colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local defaultColors = {
DARK_RED = { 173, 42, 62 },
ORANGE = { 242, 115, 45 },
BLUE = { 47, 151, 247 },
DARK_BLUE = { 65, 80, 196 },
PALE_BLUE = { 83, 154, 219 },
GREEN = { 115, 222, 89 },
DARK_GREEN = { 65, 172, 49 },
Expand Down Expand Up @@ -68,6 +69,15 @@ function Colors:ToList(alpha)
return self.r, self.g, self.b, alpha or self.a
end

function Colors:ToTable(alpha)
return {
r = self.r,
g = self.g,
b = self.b,
a = (alpha or self.a)
}
end

function Colors:ToHex()
local r = 255 * (self.r+0.0001)
local g = 255 * (self.g+0.0001)
Expand Down
4 changes: 4 additions & 0 deletions VikingSharedLib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,20 @@ local PrintColors = {
}

function lib:Print(...)
--@debug@
local n = 0
(self.name or addonName):gsub(".", function(c) n = n + string.byte(c) end)
local color = PrintColors[((n - 1) % #PrintColors) + 1]
print(color .. (self.name or addonName) .. [[:|r]], ...)
--@end-debug@
end

function lib:Debug(strName, tData)
--@debug@
if ViragDevTool_AddData then
ViragDevTool_AddData(tData, strName)
end
--@end-debug@
end

function lib:RegisterName(name)
Expand Down
Binary file added assets/textures/channel.tga
Binary file not shown.
Binary file added assets/textures/sprites-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/textures/sprites.tga
Binary file not shown.
63 changes: 55 additions & 8 deletions assets/textures/textures.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,42 @@ VH_TEXTURES = {
name = "Druid Icon",
path = [[Interface\Addons\]] .. folder .. [[druid.tga]],
},
{
HUNTER_ICON = {
type = "background",
name = "Hunter Icon",
path = [[Interface\Addons\]] .. folder .. [[hunter.tga]],
},
{
MAGE_ICON = {
type = "background",
name = "Mage Icon",
path = [[Interface\Addons\]] .. folder .. [[mage.tga]],
},
{
PALADIN_ICON = {
type = "background",
name = "Paladin Icon",
path = [[Interface\Addons\]] .. folder .. [[paladin.tga]],
},
{
PRIEST_ICON = {
type = "background",
name = "Priest Icon",
path = [[Interface\Addons\]] .. folder .. [[priest.tga]],
},
{
ROGUE_ICON = {
type = "background",
name = "Rogue Icon",
path = [[Interface\Addons\]] .. folder .. [[rogue.tga]],
},
{
SHAMAN_ICON = {
type = "background",
name = "Shaman Icon",
path = [[Interface\Addons\]] .. folder .. [[shaman.tga]],
},
{
WARLOCK_ICON = {
type = "background",
name = "Warlock Icon",
path = [[Interface\Addons\]] .. folder .. [[warlock.tga]],
},
{
WARRIOR_ICON = {
type = "background",
name = "Warrior Icon",
path = [[Interface\Addons\]] .. folder .. [[warrior.tga]],
Expand All @@ -59,6 +59,7 @@ VH_TEXTURES = {
name = "solid",
path = [[Interface\Addons\]] .. folder .. [[solid.tga]],
},

STATUSBAR = {
type = "statusbar",
name = "slanted dash",
Expand All @@ -69,6 +70,25 @@ VH_TEXTURES = {
name = "slanted dash right",
path = [[Interface\Addons\]] .. folder .. [[status-bar-right.tga]]
},

X_ICON = {
type = "background",
name = "x icon",
path = [[Interface\Addons\]] .. folder .. [[x.tga]]
},

TRASH_ICON = {
type = "background",
name = "trash icon",
path = [[Interface\Addons\]] .. folder .. [[trash.tga]]
},

CHANNEL_ICON = {
type = "background",
name = "channel icon",
path = [[Interface\Addons\]] .. folder .. [[channel.tga]]
},

}

-- From SharedMedia
Expand All @@ -86,9 +106,17 @@ local SPRITES = {
sprites = {
-- col, row
plus = { 1, 1 },
plusFill = { 2, 1 },
lock = { 1, 2 },
unlock = { 2, 2 },
settings = { 3, 3 },
trash = { 3, 1 },
x = { 1, 3 },
edit = { 2, 3 },
resize = { 3, 2 },
channel = { 4, 3 },
expand = { 6, 1 },
collapse = { 5, 1 }
}
}
}
Expand All @@ -105,6 +133,25 @@ function Sprites:GetSprite(file, name)
return sheet.path, {left, right, top, bottom}
end

function Sprites:GetTextSprite(file, name, color)
local sheet = SPRITES[file]
local positions = sheet.sprites[name]
local left = (positions[1] - 1) * sheet.grid
local right = (positions[1]) * sheet.grid
local top = (positions[2] - 1) * sheet.grid
local bottom = (positions[2]) * sheet.grid

return "|T" ..
sheet.path ..
":0:0:0:0:128:128:" ..
left .. ":" ..
right .. ":" ..
top .. ":" ..
bottom ..
(color and ":" .. color.r * 255 .. ":" .. color.g * 255 .. ":" .. color.b * 255 or "") ..
"|t"
end

function Sprites:SetSprite(tex, file, name)
local path, coords = self:GetSprite(file, name)
tex:SetTexture(path)
Expand Down
Binary file added assets/textures/trash.tga
Binary file not shown.
Binary file added assets/textures/x.tga
Binary file not shown.
9 changes: 9 additions & 0 deletions libs/LibMVC-1.0/LibMVC-1.0.toc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Interface: 70300

## Title: Lib: LibMVC
## Notes: LibMVC
## Author: Thaoky (EU-Marécages de Zangar)
## X-Category: Library
## X-License: Public Domain

LibMVC-1.0.xml
4 changes: 4 additions & 0 deletions libs/LibMVC-1.0/LibMVC-1.0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<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">
<Script file="LibMVC.lua"/>
</Ui>
189 changes: 189 additions & 0 deletions libs/LibMVC-1.0/LibMVC.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
--[[ *** LibMVC ***
Written by : Thaoky, EU-Marécages de Zangar
April 30th, 2017
License: Public Domain
This library provides a light way to implement the MVC pattern in an add-on.
The goal is to provide an easy way to manage views (= frames defined in XML) via controllers.
The Model part, which is supposed to provide the data to the controller is up to the developer,
but in a way similar to AngularJS, it is possible to define services, and to inject them into the controller.
See example.xml & example.lua for usage (in the same directory as this file)
No data binding is implemented at this point, maybe later.
--]]

local LIB_VERSION_MAJOR, LIB_VERSION_MINOR = "LibMVC-1.0", 1
local lib = LibStub:NewLibrary(LIB_VERSION_MAJOR, LIB_VERSION_MINOR)

if not lib then return end -- No upgrade needed

lib.embeds = lib.embeds or {} -- what objects embed this lib

local registeredServices = {}
local registeredControllers = {}

local function GetDependencies(name, objectArgs)
-- objectArgs: The expected format is { "data2", "data3", function(data2, data3) ... end }
-- so an array where all elements are strings (service names), except the last element which is a function
local dependencies = {}

for i = 1, #objectArgs - 1 do
local service = registeredServices[objectArgs[i]]

if service then
table.insert(dependencies, service)
else
print(format("LibMVC: Invalid dependency found for %s.", name))
end
end

return dependencies
end

local function GetProvider(objectArgs)
-- The expected format is { "data2", "data3", function(data2, data3) ... end }
-- so an array, where the last element is a function
return objectArgs[#objectArgs]
end

local function RegisterObject(name, args, storage)
-- This function will register a controller or a service, and deal with injecting dependencies
assert(type(name) == "string")
assert(type(storage) == "table")

-- The easy case (no injection)
-- addon:Service("Equipment", { registeredObject })
-- addon:Controller("MessageBox", { registeredObject })
local registeredObject = args

if type(args) == "function" then
-- addon:Service("formatter", function() return { *stuff* } end
registeredObject = args()

elseif args[1] then
-- The complex case
-- if there is something in the first element of the array part of the table, we have dependencies to inject
-- addon:Controller("MessageBox", { "data2", "data3", function(data2, data3) ... end })

local services = GetDependencies(name, args)
local provider = GetProvider(args)

if type(provider) ~= "function" then
print(format("LibMVC: No valid provider found for %s.", name))
return
end

-- call the provider to get the object
registeredObject = provider(unpack(services))
end

if type(registeredObject) ~= "table" then
print(format("LibMVC: No object to register in for %s.", name))
return
end

if storage[name] then
print(format("LibMVC: Object %s already registered.", name))
return
end

storage[name] = registeredObject
end

-- *** Model ***
function lib:Service(name, args)
RegisterObject(name, args, registeredServices)
end

-- *** View ***
local function SetViewMethods(frame, controller)
-- simply assign all of the controller's methods to the frame
for methodName, method in pairs(controller) do
frame[methodName] = method
end
end

function lib:BindViewToController(frame, controller, inherits)
-- controller: (must be string)
-- single controller (ex: "MessageBox")
-- inherits: (string or nil)
-- multiple controllers (ex: "Button,ClassIcon"), this covers a pseudo-inheritance.
-- the goal is mostly to run the "OnBind" of the controllers to initialize them in a specific order (left to right)
--
-- Ex: addon:BindViewToController(self, "RealmPicker", "Frame,DropDownMenu" )
-- This binds the frame to the "RealmPicker", and will run the 'OnBind' methods of "Frame" then "DropDownMenu" then "RealmPicker"

local controllers = registeredControllers
if not controllers[controller] then
print(format("LibMVC:BindViewToController() Controller %s does not exist.", controller))
return
end

SetViewMethods(frame, controllers[controller])

-- execute the OnBind methods
-- .. first the inherited ones (if any), from left to right
if inherits then
for item in inherits:gmatch("([^,]+)") do
local c = controllers[item] -- dereference inherited controller

if c then
SetViewMethods(frame, c)

if c.OnBind then
c.OnBind(frame)
end
end
end
end

-- .. then the actual controller's OnBind
if frame.OnBind then
frame:OnBind()
end
end

function lib:UnbindViewFromController(frame, controller)
for methodName, _ in pairs(registeredControllers[controller]) do
frame[methodName] = nil
end
end

-- *** Controller ***
--[[
Note :
(30/04/2017)
Each frame's new method contain a pointer to the actual function in memory.
I tried an approach that used a metatable, it worked, but since it's called for EVERY method of the frame (Show, Hide, ..), the risk
of tainting/conflicting is real, so I did not go through with it. Better keep a simple method that works (function pointers) rather than
a more complex (yet more direct) method that could cause troubles.
The previous approach using class extensions did almost the same, but did not support inheritance of the OnBind method, which I often needed in the past.
--]]

function lib:Controller(name, args)
RegisterObject(name, args, registeredControllers)
end

local mixins = {
"Service",
"Controller",
"BindViewToController",
"UnbindViewFromController",
}

function lib:Embed(target)
for _, v in pairs(mixins) do
target[v] = self[v]
end
self.embeds[target] = true
return target
end

for target, _ in pairs(lib.embeds) do
lib:Embed(target)
end
Loading

0 comments on commit efbe4f9

Please sign in to comment.