Major update; nearing release

Changes:
 - Literally everything
 - Everything else too
This commit is contained in:
Openarl
2016-08-29 21:52:56 +10:00
parent cfdb7c0198
commit bae83782f4
55 changed files with 7891 additions and 3844 deletions

View File

@@ -1,163 +1,75 @@
-- Path of Building
--
-- Module: BuildList
-- Module: Build List
-- Displays the list of builds.
--
local launch, main = ...
local pairs = pairs
local ipairs = ipairs
local t_insert = table.insert
local listMode = { }
local listMode = common.New("ControlHost")
function listMode:Init(selBuildName)
self.anchor = common.New("Control", nil, 0, 4, 0, 0)
self.anchor.x = function()
return main.screenW / 2
end
self.controls.new = common.New("ButtonControl", {"TOP",self.anchor,"TOP"}, -68*2, 0, 60, 20, "New", function()
self:New()
end)
self.controls.open = common.New("ButtonControl", {"TOP",self.anchor,"TOP"}, -68, 0, 60, 20, "Open", function()
self:LoadSel()
end)
self.controls.open.enabled = function() return self.sel ~= nil end
self.controls.copy = common.New("ButtonControl", {"TOP",self.anchor,"TOP"}, 0, 0, 60, 20, "Copy", function()
self:CopySel()
end)
self.controls.copy.enabled = function() return self.sel ~= nil end
self.controls.rename = common.New("ButtonControl", {"TOP",self.anchor,"TOP"}, 68, 0, 60, 20, "Rename", function()
self:RenameSel()
end)
self.controls.rename.enabled = function() return self.sel ~= nil end
self.controls.delete = common.New("ButtonControl", {"TOP",self.anchor,"TOP"}, 68*2, 0, 60, 20, "Delete", function()
self:DeleteSel()
end)
self.controls.delete.enabled = function() return self.sel ~= nil end
self.controls.buildList = common.New("BuildList", {"TOP",self.anchor,"TOP"}, 0, 24, 500, 0, self)
self.controls.buildList.height = function()
return main.screenH - 32
end
self:BuildList()
self:SelByFileName(selBuildName and selBuildName..".xml")
self.controls = { }
t_insert(self.controls, common.New("ButtonControl", function() return main.screenW/2 - 30 - 68*2 end, 4, 60, 20, "Open", function()
self:LoadSel()
end, function()
return self.sel ~= nil
end))
t_insert(self.controls, common.New("ButtonControl", function() return main.screenW/2 - 30 - 68*1 end, 4, 60, 20, "New", function()
self:New()
end))
t_insert(self.controls, common.New("ButtonControl", function() return main.screenW/2 - 30 end, 4, 60, 20, "Copy", function()
self:CopySel()
end, function()
return self.sel ~= nil
end))
t_insert(self.controls, common.New("ButtonControl", function() return main.screenW/2 + 38 end, 4, 60, 20, "Rename", function()
self:RenameSel()
end, function()
return self.sel ~= nil
end))
t_insert(self.controls, common.New("ButtonControl", function() return main.screenW/2 + 38 + 68*1 end, 4, 60, 20, "Delete", function()
self:DeleteSel()
end, function()
return self.sel ~= nil
end))
self:SelectControl(self.controls.buildList)
end
function listMode:Shutdown()
if self.edit then
self:EditCancel()
end
end
function listMode:OnFrame(inputEvents)
for id, event in ipairs(inputEvents) do
if event.type == "KeyDown" then
self:OnKeyDown(event.key, event.doubleClick)
elseif event.type == "KeyUp" then
self:OnKeyUp(event.key)
elseif event.type == "Char" then
self:OnChar(event.key)
end
end
SetDrawColor(0.5, 0.5, 0.5)
DrawImage(main.tree.assets.Background1.handle, 0, 0, main.screenW, main.screenH, 0, 0, main.screenW / 100, main.screenH / 100)
common.controlsDraw(self)
for index, build in ipairs(self.list) do
local y = 8 + index * 20
local x = main.screenW/2 - 250
if self.sel == index then
SetDrawColor(1, 1, 1)
else
SetDrawColor(0.5, 0.5, 0.5)
end
DrawImage(nil, x, y, 500, 20)
if self.sel == index then
SetDrawColor(0.33, 0.33, 0.33)
elseif index % 2 == 0 then
SetDrawColor(0.05, 0.05, 0.05)
else
SetDrawColor(0, 0, 0)
end
DrawImage(nil, x + 1, y + 1, 498, 18)
if self.edit == index then
self.editField:Draw(x + 2, y + 2, 16)
else
DrawString(x + 4, y + 2, "LEFT", 16, "VAR", "^7"..build.fileName:gsub("%.xml$",""))
SetDrawColor(build.className and data.colorCodes[build.className:upper()] or "^7")
DrawString(x + 350, y + 2, "LEFT", 16, "VAR", string.format("Level %d %s", build.level or 1, (build.ascendClassName ~= "None" and build.ascendClassName) or build.className or "?"))
end
end
end
function listMode:OnKeyDown(key, doubleClick)
if self.edit then
if key == "RETURN" then
self:EditFinish()
elseif key == "ESCAPE" then
self:EditCancel()
else
self.editField:OnKeyDown(key)
end
elseif key == "LEFTBUTTON" then
self.selControl = nil
local cx, cy = GetCursorPos()
for _, control in pairs(self.controls) do
if control.IsMouseOver and control:IsMouseOver() then
control:OnKeyDown(key)
self.selControl = control
return
end
end
self.sel = nil
if cx >= main.screenW/2 - 250 and cx < main.screenW/2 + 250 then
for index, fileName in ipairs(self.list) do
local y = 8 + index * 20
if cy >= y and cy < y + 20 then
self.sel = index
if doubleClick then
self:LoadSel()
end
return
if self.edit then
if event.key == "RETURN" then
self:EditFinish()
inputEvents[id] = nil
elseif event.key == "ESCAPE" then
self:EditCancel()
inputEvents[id] = nil
end
end
end
elseif key == "RETURN" then
if self.sel then
self:LoadSel()
end
elseif key == "UP" then
if not self.sel then
self.sel = #self.list
else
self.sel = (self.sel - 2) % #self.list + 1
end
elseif key == "DOWN" then
if not self.sel then
self.sel = 1
else
self.sel = self.sel % #self.list + 1
end
elseif key == "F2" then
if self.sel then
self:RenameSel()
end
elseif key == "DELETE" then
if self.sel then
self:DeleteSel()
end
end
end
self:ProcessControlsInput(inputEvents)
function listMode:OnKeyUp(key)
if self.edit then
self.editField:OnKeyUp(key)
elseif self.selControl then
self.selControl:OnKeyUp(key)
self.selControl = nil
end
end
SetDrawColor(0.5, 0.5, 0.5)
DrawImage(main.tree.assets.Background1.handle, 0, 0, main.screenW, main.screenH, 0, 0, main.screenW / 100, main.screenH / 100)
function listMode:OnChar(key)
if self.edit then
self.editField:OnChar(key)
end
self:DrawControls()
end
function listMode:BuildList()
@@ -170,6 +82,7 @@ function listMode:BuildList()
local fileName = handle:GetFileName()
local build = { }
build.fileName = fileName
build.buildName = fileName:gsub("%.xml$","")
local dbXML = common.xml.LoadXMLFile(main.buildPath..fileName)
if dbXML and dbXML[1].elem == "PathOfBuilding" then
for _, node in ipairs(dbXML[1]) do
@@ -194,6 +107,7 @@ function listMode:SortList()
if oldSelFileName then
self:SelByFileName(oldSelFileName)
end
self.controls.buildList:ScrollSelIntoView()
end
function listMode:SelByFileName(selFileName)
@@ -201,6 +115,7 @@ function listMode:SelByFileName(selFileName)
for index, build in ipairs(self.list) do
if build.fileName == selFileName then
self.sel = index
self.controls.buildList:ScrollSelIntoView()
break
end
end
@@ -209,28 +124,25 @@ end
function listMode:EditInit(finFunc)
self.edit = self.sel
self.editFinFunc = finFunc
self.editField = common.newEditField(self.list[self.sel].fileName:gsub("%.xml$",""), nil, "[%w _+.()]")
self.editField.x = 2
self.editField.y = 6 + self.sel * 20
self.editField.width = main.screenW
self.editField.height = 16
self.controls.buildList:ScrollSelIntoView()
self.controls.buildList.controls.nameEdit:SetText(self.list[self.sel].buildName or "")
end
function listMode:EditFinish()
local msg = self.editFinFunc(self.editField.buf)
local msg = self.editFinFunc(self.controls.buildList.controls.nameEdit.buf)
if msg then
launch:ShowPrompt(1, 0.5, 0, msg.."\n\nEnter/Escape to dismiss")
main:OpenMessagePopup("Message", msg)
return
end
self.edit = nil
self.editField = nil
self:SelectControl(self.controls.buildList)
end
function listMode:EditCancel()
self.sel = nil
self.edit = nil
self.editField = nil
self:BuildList()
self:BuildList()
self:SelectControl(self.controls.buildList)
end
function listMode:New()
@@ -253,12 +165,13 @@ function listMode:New()
outFile:write('<?xml version="1.0" encoding="UTF-8"?>\n<PathOfBuilding>\n</PathOfBuilding>')
outFile:close()
self.list[self.sel].fileName = fileName
self.list[self.sel].buildName = buf
self:SortList()
end)
end
function listMode:LoadSel()
main:SetMode("BUILD", main.buildPath..self.list[self.sel].fileName, (self.list[self.sel].fileName:gsub("%.xml$","")))
main:SetMode("BUILD", main.buildPath..self.list[self.sel].fileName, self.list[self.sel].buildName)
end
function listMode:CopySel()
@@ -288,6 +201,7 @@ function listMode:CopySel()
inFile:close()
outFile:close()
self.list[self.sel].fileName = dstName
self.list[self.sel].buildName = buf
self:SortList()
end)
end
@@ -314,18 +228,16 @@ function listMode:RenameSel()
return "Couldn't rename '"..oldName.."' to '"..newName.."': "..msg
end
self.list[self.sel].fileName = newName
self.list[self.sel].buildName = buf
self:SortList()
end)
end
function listMode:DeleteSel()
launch:ShowPrompt(1, 0, 0, "Are you sure you want to delete\n'"..self.list[self.sel].fileName.."' ? (y/n)", function(key)
if key == "y" then
os.remove(main.buildPath..self.list[self.sel].fileName)
self:BuildList()
self.sel = nil
end
return true
main:OpenConfirmPopup("Confirm Delete", "Are you sure you want to delete build:\n"..self.list[self.sel].buildName.."\nThis cannot be undone.", "Delete", function()
os.remove(main.buildPath..self.list[self.sel].fileName)
self:BuildList()
self.sel = nil
end)
end