Skip to content

Commit

Permalink
✨ Added check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AssisrMatheus committed Sep 15, 2019
1 parent 5d56415 commit cb7954d
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 28 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@

# TodoChecklister
I have bad memory so I made this. A todolist/checklist AddOn for World of Warcraft

## Reference material

- [A Guide and Reference for Creating WoW Addons: WoW Programming](http://garde.sylvanas.free.fr/ressources/Guides/Macros-Addons/Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons.pdf)
- [Documentation reference](http://wowprogramming.com/docs.html)
- [Widget API](https://wowwiki.fandom.com/wiki/Widget_API)
1 change: 1 addition & 0 deletions TodoChecklister.toc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## SavedVariables: TodoChecklisterDB

constants.lua
tableUtils.lua
utils.lua
debug.lua

Expand Down
84 changes: 69 additions & 15 deletions components/TodoChecklister.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,79 @@ local TodoChecklisterFrame = core.TodoChecklisterFrame

local Constants = core.Constants
local ResponsiveFrame = core.ResponsiveFrame
local TableUtils = core.TableUtils;

--------------------------------------
-- TodoChecklisterFrame functions
--------------------------------------
function TodoChecklisterFrame:OnUpdate()
local todoList = {
{text="Item one", isChecked=false},
{text="Item Two", isChecked=false},
{text="Item Three", isChecked=true},
{text="Item four", isChecked=false}
}
function TodoChecklisterFrame:AddItem(text)
table.insert(TodoChecklisterDB, #TodoChecklisterDB+1, { text=text, isChecked=false })
self:OnUpdate()
end

function TodoChecklisterFrame:RemoveItem(text)
local indexToRemove = TableUtils:IndexOf(TodoChecklisterDB, function(x) return x.text == text end)

if(indexToRemove > 0) then
table.remove(TodoChecklisterDB, indexToRemove)
self:OnUpdate()
end
end

function TodoChecklisterFrame:CheckItem(text)
local indexToCheck = TableUtils:IndexOf(TodoChecklisterDB, function(x) return x.text == text end)

if(indexToCheck > 0) then
local item = TodoChecklisterDB[indexToCheck];
TodoChecklisterDB[indexToCheck] = { text=item.text, isChecked=(not item.isChecked) };
self:OnUpdate()
end
end

--------------------------------------
-- TodoChecklisterFrame Events
--------------------------------------
function TodoChecklisterFrame:OnUpdate()
local scrollFrame = TodoItemsScrollFrame
if (scrollFrame and scrollFrame.buttons) then
local list = TodoChecklisterDB or {}
if (scrollFrame and scrollFrame.buttons and list) then
local offset = HybridScrollFrame_GetOffset(scrollFrame)

if (#list > 0) then
self.frame.Background.BlankText:SetText('')
else
self.frame.Background.BlankText:SetText('Oh no! \r\n You have no items on your list \r\n\r\n Start by typing them in the box above \r\n\r\n =)')
end

for i=1, #scrollFrame.buttons do
local idx = i + offset
local button = scrollFrame.buttons[i]

if ( idx <= #todoList ) then
local todoItem = todoList[idx]


if ( idx <= #list ) then
local todoItem = list[idx]
button.todoItem = todoItem

-- Update button values
button.TodoContent:GetNormalFontObject():SetJustifyH("LEFT")
button.TodoContent:SetWidth(scrollFrame:GetWidth() - button.RemoveButton:GetWidth() - 30)
button.TodoContent:SetText(todoItem.text)

if (todoItem.isChecked) then
button.TodoContent:SetNormalFontObject(GameFontDarkGraySmall);
else
button.TodoContent:SetNormalFontObject(GameFontNormalSmall);
end

-- Update checkbox values
button.TodoCheckButton:SetChecked(todoItem.isChecked)

button:Show()
else
button:Hide()
end
end

HybridScrollFrame_Update(scrollFrame, (scrollFrame.buttons[1]:GetHeight()) * #todoList, scrollFrame:GetHeight())
HybridScrollFrame_Update(scrollFrame, (scrollFrame.buttons[1]:GetHeight()) * #list, scrollFrame:GetHeight())
end
end

Expand All @@ -49,7 +89,7 @@ function TodoChecklisterFrame:OnLoad(frame)
ResponsiveFrame:OnLoad(frame)

-- Set up elements
frame.Title:SetText(Constants.addonName)
frame.Title:SetText(Constants.addonName)

local scrollFrame = frame.ScrollFrame
scrollFrame.update = function() TodoChecklisterFrame:OnUpdate() end
Expand All @@ -76,5 +116,19 @@ function OnShow(frame)
end

function OnSizeChanged(frame)
TodoChecklisterFrame:OnSizeChanged(frame)
TodoChecklisterFrame:OnSizeChanged(frame)
end

function OnSaveItem(frame)
TodoChecklisterFrame:AddItem(TodoChecklister.TodoText:GetText())
TodoChecklister.TodoText:SetText("")
TodoChecklister.TodoText:ClearFocus()
end

function OnRemoveItem(frame)
TodoChecklisterFrame:RemoveItem(frame:GetParent().TodoContent:GetText())
end

function OnCheckItem(frame)
TodoChecklisterFrame:CheckItem(frame:GetParent().TodoContent:GetText())
end
85 changes: 73 additions & 12 deletions components/TodoChecklister.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,51 @@
..\FrameXML\UI.xsd">
<Script file="TodoChecklister.lua"/>

<CheckButton name="TodoItemTemplate" inherits="UICheckButtonTemplate" virtual="true">
<Size x="24" y="24"/>
<Layers>
<Layer level="ARTWORK">
<FontString name="$parentText" inherits="GameFontNormalSmall" parentKey="TodoContent">
<Anchors>
<Anchor point="LEFT" relativePoint="RIGHT" x="-2" y="0"/>
</Anchors>
</FontString>
</Layer>
</Layers>
</CheckButton>
<Frame name="TodoItemTemplate" virtual="true">
<Size x="200" y="30"/>
<Frames>
<CheckButton parentKey="TodoCheckButton" name="$parentTodoCheckButton" inherits="UICheckButtonTemplate">
<Size x="24" y="24"/>

<Scripts>
<OnClick>
OnCheckItem(self)
</OnClick>
</Scripts>

<Anchors>
<Anchor point="LEFT" relativeTo="$parent" relativePoint="LEFT" />
</Anchors>
</CheckButton>

<Button name="$parentText" parentKey="TodoContent">
<Size>
<AbsDimension x="150" y="16" />
</Size>
<Anchors>
<Anchor point="LEFT" relativeTo="$parentTodoCheckButton" relativePoint="RIGHT" />
</Anchors>
<NormalFont style="GameFontNormalSmall"/>
</Button>

<Button parentKey="RemoveButton" name="$parentRemoveButton" inherits="CollapseButtonTemplate">
<Anchors>
<Anchor point="RIGHT" relativeTo="$parentText" relativePoint="RIGHT">
<Offset x="15" y="0"/>
</Anchor>
</Anchors>

<NormalTexture file="Interface\Buttons\UI-MinusButton-Up" />
<PushedTexture file="Interface\Buttons\UI-MinusButton-Down" />

<Scripts>
<OnClick>
OnRemoveItem(self)
</OnClick>
</Scripts>
</Button>
</Frames>
</Frame>

<Frame name="TodoChecklister" inherits="TodoChecklisterResponsiveFrameTemplate">
<Scripts>
Expand All @@ -38,6 +71,11 @@
<Frames>
<EditBox parentKey="TodoText" name="$parentTodoText" autoFocus="false" inherits="InputBoxTemplate">
<Size x="0" y="20"/>
<Scripts>
<OnEnterPressed>
OnSaveItem(self)
</OnEnterPressed>
</Scripts>
<Anchors>
<Anchor point="TOPLEFT" relativeTo="$parent" relativePoint="TOPLEFT">
<Offset x="20" y="-32"/>
Expand All @@ -53,6 +91,12 @@
<AbsDimension x="18" y="18"/>
</Size>

<Scripts>
<OnClick>
OnSaveItem(self)
</OnClick>
</Scripts>

<Anchors>
<Anchor point="LEFT" relativeTo="$parentTodoText" relativePoint="RIGHT">
<Offset x="3" y="-1"/>
Expand Down Expand Up @@ -86,8 +130,25 @@
<AbsValue val="16" />
</EdgeSize>
</Backdrop>

<Layers>
<Layer level="OVERLAY">
<FontString parentKey="BlankText" inherits="GameFontHighlight">
<Anchors>
<Anchor point="CENTER" />
</Anchors>
</FontString>

<FontString parentKey="BlankText" inherits="GameFontNormal">
<Anchors>
<Anchor point="CENTER" />
</Anchors>
</FontString>
</Layer>
</Layers>
</Frame>


<ScrollFrame parentKey="ScrollFrame" name="TodoItemsScrollFrame" inherits="HybridScrollFrameTemplate">
<Anchors>
<Anchor point="TOPLEFT" relativeTo="$parentBackground" relativePoint="TOPLEFT">
Expand Down
6 changes: 5 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ local addonName, core = ...; -- Namespace

-- WARNING: self keyword automatically becomes events frame!
function core:Init(event, name)
if (name ~= addonName) then return end
if (name ~= addonName) then return end

if (not TodoChecklisterDB) then
TodoChecklisterDB = {}
end

core.Debug:Init();
core.Chat:Init();
Expand Down
16 changes: 16 additions & 0 deletions tableUtils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--------------------------------------
-- Namespaces
--------------------------------------
local addonName, core = ...;
core.TableUtils = {}; -- adds Config table to addon namespace

local TableUtils = core.TableUtils;

--------------------------------------
-- TableUtils functions
--------------------------------------
function TableUtils:IndexOf(tb, comparator)
for i=1, #tb do
if(comparator(tb[i])) then return i end
end
end

0 comments on commit cb7954d

Please sign in to comment.