diff --git a/OrderHallCommander/widgets/Follower.lua b/OrderHallCommander/widgets/Follower.lua new file mode 100644 index 0000000..e69de29 diff --git a/OrderHallCommander/widgets/GUIContainer.lua b/OrderHallCommander/widgets/GUIContainer.lua new file mode 100644 index 0000000..9857c3b --- /dev/null +++ b/OrderHallCommander/widgets/GUIContainer.lua @@ -0,0 +1,53 @@ +local me,addon=... +local C=addon:GetColorTable() +local module=addon:GetWidgetsModule() +local Type,Version="OHCGUIContainer",1 +local AceGUI = LibStub and LibStub("AceGUI-3.0", true) +if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end +local m={} --#Widget +function m:Close() + self.frame.CloseButton:Click() +end +function m:OnAcquire() + self.frame:EnableMouse(true) + self:SetTitleColor(C.Yellow()) + self.frame:SetFrameStrata("HIGH") + self.frame:SetFrameLevel(999) +end +function m:SetContentWidth(x) + self.content:SetWidth(x) +end +function m:SetTitle(...) + self.frame.TitleText:SetText(...) +end +function m:SetTitleColor(...) + self.frame.TitleText:SetTextColor(...) +end +function m._Constructor() + local frame=CreateFrame("Frame",Type..AceGUI:GetNextWidgetNum(Type),nil,"GarrisonUITemplate") + frame.Top:SetAtlas("_StoneFrameTile-Top", true); + frame.Bottom:SetAtlas("_StoneFrameTile-Bottom", true); + frame.Left:SetAtlas("!StoneFrameTile-Left", true); + frame.Right:SetAtlas("!StoneFrameTile-Left", true); + frame.GarrCorners.TopLeftGarrCorner:SetAtlas("StoneFrameCorner-TopLeft", true); + frame.GarrCorners.TopRightGarrCorner:SetAtlas("StoneFrameCorner-TopLeft", true); + frame.GarrCorners.BottomLeftGarrCorner:SetAtlas("StoneFrameCorner-TopLeft", true); + frame.GarrCorners.BottomRightGarrCorner:SetAtlas("StoneFrameCorner-TopLeft", true); + local widget={frame=frame,missions={}} + widget.type=Type + for k,v in pairs(m) do widget[k]=v end + widget._Constructor=nil + frame:SetScript("OnHide",function(self) self.obj:Fire('OnClose') end) + frame.obj=widget + --Container Support + local content = CreateFrame("Frame",nil,frame) + widget.content = content + --addBackdrop(content,'Green') + content.obj = widget + content:SetPoint("TOPLEFT",25,-25) + content:SetPoint("BOTTOMRIGHT",-25,25) + AceGUI:RegisterAsContainer(widget) + return widget +end +AceGUI:RegisterWidgetType(Type,m._Constructor,Version) +print("Caricati widgets nuovi") \ No newline at end of file diff --git a/OrderHallCommander/widgets/MissionButton.lua b/OrderHallCommander/widgets/MissionButton.lua new file mode 100644 index 0000000..6e7f9af --- /dev/null +++ b/OrderHallCommander/widgets/MissionButton.lua @@ -0,0 +1,129 @@ +local me,addon=... +local C=addon:GetColorTable() +local module=addon:GetWidgetsModule() +local Type,Version="OHCMissionButton",1 +local AceGUI = LibStub and LibStub("AceGUI-3.0", true) +if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end +local m={} --#Widget +function m:OnAcquire() + local frame=self.frame + frame.info=nil + frame:SetAlpha(1) + frame:SetScale(1.0) + frame:Enable() + for i=1,#self.scripts do + frame:SetScript(self.scripts[i],nil) + end + for i=1,#frame.Rewards do + frame.Rewards[i].Icon:SetDesaturated(false) + end + wipe(self.scripts) + return +end +function m:Show() + return self.frame:Show() +end +function m:RunSpinner(start) + if start then + self.Spinner:Start() + else + self.Spinner:Stop() + end +end +function m:SetHeight(h) + return self.frame:SetHeight(h) +end +function m:Hide() + self.frame:SetHeight(1) + self.frame:SetAlpha(0) + return self.frame:Disable() +end +function m:SetScript(name,method) + tinsert(self.scripts,name) + return self.frame:SetScript(name,method) +end +function m:SetScale(s) + return self.frame:SetScale(s) +end +function m:Blacklist(blacklisted) + local mb=self.frame + if blacklisted then +--@debug@ + print("Blacklisting",mb:GetName()) +--@end-debug@ + mb.Overlay:Show() + mb.Overlay.Overlay:SetAlpha(1) + for i,v in pairs(mb.gcPANEL.Party) do + v.PortraitFrame.Portrait:SetDesaturated(true) + v.PortraitFrame.PortraitRingQuality:Hide() + v.PortraitFrame.LevelBorder:Hide() + end + for i,v in pairs(mb.Rewards) do + v.Icon:SetDesaturated(true) + v.Quantity:Hide() + end + return true + else + mb.Overlay:Hide() + mb.Overlay.Overlay:SetAlpha(0.4) + for i,v in pairs(mb.gcPANEL.Party) do + v.PortraitFrame.Portrait:SetDesaturated(false) + v.PortraitFrame.PortraitRingQuality:Show() + v.PortraitFrame.LevelBorder:Show() + end + for i,v in pairs(mb.Rewards) do + v.Icon:SetDesaturated(false) + v.Quantity:Show() + end + return false + end +end +function m:SetMission(mission,followers,perc,source) + local frame=self.frame + frame.info=mission + if not mission.followers or #mission.followers==0 then + frame.info.followers=followers + end + frame:EnableMouse(true) + frame.Title:SetText(mission.name) + local nrewards=type(mission.rewards)=="table" and #mission.rewards or 0 + local rc,message =pcall(GarrisonMissionButton_SetRewards,frame,mission.rewards,nrewards) + addon:GetMissionlistModule():AdjustMissionButton(frame,mission.rewards) +-- if #frame.Rewards > 0 then +-- local Reward=frame.Rewards[1] +-- Reward:ClearAllPoints() +-- Reward:SetPoint("RIGHT") +-- end + --@debug@ + if not rc then frame.Title:SetText(message) end + --@end-debug@ +end +function m._Constructor() + local frame=CreateFrame("Button",Type..AceGUI:GetNextWidgetNum(Type),nil,"OHCMissionButton") + --frame.Title:SetFontObject("QuestFont_Shadow_Small") + --frame.Summary:SetFontObject("QuestFont_Shadow_Small") + frame:SetScript("OnEnter",function(self) self.obj:Fire("OnEnter") end) + frame:SetScript("OnLeave",function(self)self.obj:Fire("OnLeave") end) + frame:RegisterForClicks("LeftButtonUp","RightButtonUp") + frame:SetScript("OnClick",function(self,button) print(button) return button=="RightButton" and self.obj:Fire("OnRightClick",self,button) or self.obj:Fire("OnClick",self,button) end) + frame.LocBG:SetPoint("LEFT") + frame.MissionType:SetPoint("TOPLEFT",5,-2) + frame.isResult=true + local widget={} + setmetatable(widget,{__index=frame}) + widget.frame=frame + widget.scripts={} + frame.obj=widget + for k,v in pairs(m) do widget[k]=v end + widget._Constructor=nil + -- Spinner + widget.Spinner=CreateFrame("Frame",nil,frame,"OHCSpinner") + -- Failed text string + widget.Spinner:SetPoint("CENTER") + widget.Result=frame:CreateFontString(nil,"OVERLAY","GameFontNormalHuge") + widget.Result:SetPoint("TOPLEFT",frame.Title,"BOTTOMLEFT",0,-10) + widget.Result:Hide() + return AceGUI:RegisterAsWidget(widget) +end +AceGUI:RegisterWidgetType(Type,m._Constructor,Version) + \ No newline at end of file diff --git a/OrderHallCommander/widgets/MissionsList.lua b/OrderHallCommander/widgets/MissionsList.lua new file mode 100644 index 0000000..634a3e8 --- /dev/null +++ b/OrderHallCommander/widgets/MissionsList.lua @@ -0,0 +1,180 @@ +local me,addon=... +local C=addon:GetColorTable() +local module=addon:GetWidgetsModule() +local Type,Version,unique="OHCMissionsList",1,0 +local AceGUI = LibStub and LibStub("AceGUI-3.0", true) +if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end +local C=addon:GetColorTable() +local G=C_Garrison +local GARRISON_FOLLOWER_XP_ADDED_ZONE_SUPPORT=GARRISON_FOLLOWER_XP_ADDED_ZONE_SUPPORT:gsub('%%d',C('%%d','Yellow')) +local GARRISON_FOLLOWER_XP_ADDED_ZONE_SUPPORT_LEVEL_UP=GARRISON_FOLLOWER_XP_ADDED_ZONE_SUPPORT_LEVEL_UP:gsub('%%d',C('%%d','Green')) +local GARRISON_FOLLOWER_XP_LEFT=GARRISON_FOLLOWER_XP_LEFT:gsub('%%d',C('%%d','Orange')) +local COMBATLOG_XPGAIN_FIRSTPERSON_UNNAMED=COMBATLOG_XPGAIN_FIRSTPERSON_UNNAMED:gsub('%%d',C('%%d','Green')) +local GARRISON_FOLLOWER_XP_UPGRADE_STRING=GARRISON_FOLLOWER_XP_UPGRADE_STRING +local GARRISON_FOLLOWER_XP_STRING=GARRISON_FOLLOWER_XP_STRING +local GARRISON_FOLLOWER_DISBANDED=GARRISON_FOLLOWER_DISBANDED +local BONUS_LOOT_LABEL=C(" (".. BONUS_LOOT_LABEL .. ")","Green") +local m={} --#Widget +function m:ScrollDown() + local obj=self.scroll + if (#self.missions >1 and obj.scrollbar and obj.scrollbar:IsShown()) then + obj:SetScroll(80) + obj.scrollbar.ScrollDownButton:Click() + end +end +function m:OnAcquire() + wipe(self.missions) +end +function m:Show() + self.frame:Show() +end +function m:Hide() + self.frame:Hide() + self:Release() +end +function m:AddButton(text,action) + local obj=self.scroll + local b=AceGUI:Create("Label") + b:SetFullWidth(true) + b:SetText(text) + b:SetColor(C.yellow.r,C.yellow.g,C.yellow.b) + --b:SetCallback("OnClick",action) + obj:AddChild(b) +end +function m:AddMissionButton(mission,followers,perc,source) + if not self.missions[mission.missionID] then + local obj=self.scroll + local b=AceGUI:Create("OHCMissionButton") + b:SetMission(mission,followers,perc,source) + b:SetScale(0.7) + b:SetFullWidth(true) + b:RunSpinner(true) + self.missions[mission.missionID]=b + obj:AddChild(b) + end + +end +function m:AddMissionResult(missionID,success) + local mission=self.missions[missionID] + if mission then + local frame=mission.frame + mission:RunSpinner(false) + if success then + if success > 3 then + mission.Result:SetText(GARRISON_MISSION_SUCCESS .. ' ' .. BONUS_LOOT_LABEL) + else + mission.Result:SetText(GARRISON_MISSION_SUCCESS) + end + mission.Result:SetTextColor(C:Green()) + for i=1,#frame.Rewards do + frame.Rewards[i].Icon:SetDesaturated(false) + frame.Rewards[i].Quantity:Show() + end + else + mission.Result:SetText(GARRISON_MISSION_FAILED) + mission.Result:SetTextColor(C:Red()) + + for i=1,#frame.Rewards do + frame.Rewards[i].Icon:SetDesaturated(true) + frame.Rewards[i].Quantity:Hide() + end + end + frame.Title:ClearAllPoints() + frame.Title:SetPoint("TOPLEFT",165,-7) + mission.Result:Show() + end +end +function m:AddRow(data,...) + local obj=self.scroll + local l=AceGUI:Create("InteractiveLabel") + l:SetFontObject(GameFontNormalSmall) + l:SetText(data) + l:SetColor(...) + l:SetFullWidth(true) + obj:AddChild(l) + +end +function m:AddPlayerXP(xpgain) + if xpgain>0 then + self:AddRow(COMBATLOG_XPGAIN_FIRSTPERSON_UNNAMED:format(xpgain)) + end + +end +function m:AddFollower(followerID,xp,levelup,portrait,fullname) + if xp < 0 then + return self:AddFollowerIcon(portrait,format(GARRISON_FOLLOWER_DISBANDED,fullname)) + end + local isMaxLevel=addon:GetFollowerData(followerID,'isMaxLevel',false) + if isMaxLevel and not levelup then + return +-- return self:AddFollowerIcon(followerType,follower.portraitIconID,format("%s is already at maximum xp",follower.fullname)) + end + if levelup then + PlaySound("UI_Garrison_CommandTable_Follower_LevelUp"); + end + + local message=GARRISON_FOLLOWER_XP_ADDED_ZONE_SUPPORT:format(fullname,xp) + local quality=addon:GetFollowerData(followerID,'quality') + local level=addon:GetFollowerData(followerID,'level') + local XP=addon:GetFollowerData(followerID,'xp',0) + local levelXP=addon:GetFollowerData(followerID,'levelXP',0) + if levelup then + message=message..' ' .. GARRISON_FOLLOWER_XP_ADDED_ZONE_SUPPORT_LEVEL_UP:format(fullname,level) + end + if levelXP > 0 then + message=message .. ' ' .. + GARRISON_FOLLOWER_XP_LEFT:format(levelXP-addon:GetFollowerData(followerID,'xp',levelXP)) .. + ' ' .. + (isMaxLevel and GARRISON_FOLLOWER_XP_UPGRADE_STRING or GARRISON_FOLLOWER_XP_STRING) + end + return self:AddFollowerIcon(portrait,message) +end +function m:AddFollowerIcon(icon,text) + local l=self:AddIconText(icon,text) +end +function m:AddIconText(icon,text,qt,isBonus) + local obj=self.scroll + local l=AceGUI:Create("Label") + l:SetFontObject(GameFontNormalSmall) + if (qt) then + l:SetText(format("%s x %s %s",text,qt,isBonus and BONUS_LOOT_LABEL or '')) + else + l:SetText(text) + end + l:SetImage(icon) + l:SetImageSize(24,24) + l:SetHeight(26) + l:SetFullWidth(true) + obj:AddChild(l) + if (obj.scrollbar and obj.scrollbar:IsShown()) then + obj:SetScroll(80) + obj.scrollbar.ScrollDownButton:Click() + end + return l +end +function m:AddItem(itemID,qt,isBonus) + local obj=self.scroll + local _,itemlink,itemquality,_,_,_,_,_,_,itemtexture=GetItemInfo(itemID) + if not itemlink then + self:AddIconText(itemtexture,itemID,qt,isBonus) + else + self:AddIconText(itemtexture,itemlink,qt,isBonus) + end +end +function m._Constructor() + local widget=AceGUI:Create("OHCGUIContainer") + widget:SetLayout("Fill") + widget.missions={} + local scroll = AceGUI:Create("ScrollFrame") + scroll:SetLayout("List") -- probably? + scroll:SetFullWidth(true) + scroll:SetFullHeight(true) + widget:AddChild(scroll) + for k,v in pairs(m) do widget[k]=v end + widget._Constructor=nil + widget:Show() + widget.scroll=scroll + widget.type=Type + return widget +end +AceGUI:RegisterWidgetType(Type,m._Constructor,Version) diff --git a/OrderHallCommander/widgets/Reward.lua b/OrderHallCommander/widgets/Reward.lua new file mode 100644 index 0000000..e69de29