---------------------------------------------------------------------------------------------------------- -- GreenThumb -- -- written by PetraAreon -- released under the Creative Commons License By-Nc-Sa: http://creativecommons.org/licenses/by-nc-sa/3.0/ -- -- Get the current version at: http://rom.curse.com/downloads/rom-addons/details/greenthumb.aspx ---------------------------------------------------------------------------------------------------------- function GreenThumb_OnLoad(this) local Sol = LibStub("Sol"); GreenThumb = { Name = "GreenThumb", Fade = {}, Version = "v1.6", ErrMsg = ""; planted = false, watered = 0, fertilized = 0, watertarget = nil, fertilizertarget = nil, Materials = { Water = { {TEXT('Sys203819_name'), 1}, {TEXT('Sys203816_name'),19}, {TEXT('Sys203817_name'),37}, {TEXT('Sys203818_name'),55}, }, Fertilizer = { {TEXT('Sys203829_name'), 1}, {TEXT('Sys203824_name'),19}, {TEXT('Sys203825_name'),37}, {TEXT('Sys203826_name'),55}, }, }, seedTypes = { [0]=TEXT('SYS_ITEMTYPE_00'), [1]=TEXT('SYS_PLANT_TYPE_1'), [2]=TEXT('SYS_PLANT_TYPE_2'), [3]=TEXT('SYS_PLANT_TYPE_3'), }, BlockMessages = { TEXT('SYS_PLANT_SEED_SUCCEED'), TEXT('SYS_PLANT_WATER_SUCCEED'), TEXT('SYS_PLANT_TOPDRESS_SUCCEED'), }, Defaults = { MaxLevelMaterial = 4, }, }; GreenThumb.Language = string.upper(string.sub(GetLanguage(),1,2)); local func, err = loadfile("Interface/Addons/GreenThumb/Locales/"..GreenThumb.Language..".lua"); if (err) then GreenThumb.ErrMsg = "\n\n|cffff0000No Locales found for your language \""..GreenThumb.Language.."\", switching to fallback \"EN\"|r"; GreenThumb.Language = "EN"; end; dofile("Interface/Addons/GreenThumb/Locales/"..GreenThumb.Language..".lua"); this:RegisterEvent("VARIABLES_LOADED"); end; function GreenThumb_OnEvent(event,arg1,arg2) if (event == "VARIABLES_LOADED") then if (GreenThumb_Settings==nil) then GreenThumb_Settings = GreenThumb.Defaults; end; if AddonManager then local addon = { name = "|cff00a000"..GreenThumb.Name.."|r", description = GreenThumb.Strings.Description..GreenThumb.ErrMsg, category = "Economy", version = "|cff99ff4d"..GreenThumb.Version.."|r", author = "PetraAreon", icon = "interface/icons/item_her_034.dds", } if AddonManager.RegisterAddonTable then AddonManager.RegisterAddonTable(addon) else AddonManager.RegisterAddon(addon.name, addon.description, addon.icon, addon.category, addon.configFrame, addon.slashCommands, addon.miniButton, addon.onClickScript) end else DEFAULT_CHAT_FRAME:AddMessage("Addon loaded: |cff00a000"..GreenThumb.Name.." "..GreenThumb.Version.."|r"..string.gsub(GreenThumb.ErrMsg,"\n\n"," - ")); end --------- Change Anchors and Size of PlantFrame PlantFrame:SetSize(315,420); PlantSeedInfoFrame :ClearAllAnchors(); PlantSeedInfoFrame :SetAnchor("BOTTOM", "BOTTOM", PlantFrameBackdropFrame, -18, -238); PlantWaterInfoFrame:ClearAllAnchors(); PlantWaterInfoFrame:SetAnchor("BOTTOM", "BOTTOM", PlantFrameBackdropFrame, -18, -98); PlantStateBer01 :ClearAllAnchors(); PlantStateBer01 :SetAnchor("BOTTOM", "BOTTOM", PlantFrameBackdropFrame, -18, -210); GreenThumbFrame_Label_Title :SetText("["..GreenThumb.Name.."]"); GreenThumbFrame_Label_Title :SetColor(0,0.63,0); GreenThumbFrame_CreditLink_Text :SetColor(0.6,1,0.3); GreenThumbFrame_Progress_Text :SetColor(0.6,1,0.3); GreenThumbFrame_PotInfoFrame :Show(); GreenThumbFrame_PotInfoFrameButton :Disable(); GreenThumbFrame_PotInfoFramePottitle :SetText(GreenThumb.Strings.Potname..":"); GreenThumbFrame_PotInfoFrameTypetitle:SetText(GreenThumb.Strings.Pottype..":"); GreenThumbFrame_PotInfoFramePottitle :SetColor(0,0.63,0); GreenThumbFrame_PotInfoFrameTypetitle:SetColor(0,0.63,0); GreenThumbFrame_PotInfoFramePottext :SetColor(0.6,1,0.3); GreenThumbFrame_PotInfoFrameTypetext :SetColor(0.6,1,0.3); GreenThumbFrame_SeedInfoFrameMsg2Text:SetColor(0.6,1,0.3); GreenThumbFrame_CarePlantButton :Show(); GreenThumbFrame_Progress :Show(); for i=1,10 do getglobal("GreenThumbFrame_CareState_"..i):ClearAllAnchors(); getglobal("GreenThumbFrame_CareState_"..i):SetAnchor("TOP", "TOP", GreenThumbFrame_StateBackground, 0, (i-1)*27+10); end; GreenThumbFrame_StateBackground :Show(); GreenThumbFrame_CareState_X :Show(); GreenThumbFrame_PotInfoFrameBackground:Show(); GreenThumb_DisplayMaxLevelMaterial(); GreenThumbFrame:RegisterEvent("STORE_OPEN"); GreenThumbFrame:RegisterEvent("HOUSES_PLANT_OPEN"); GreenThumbFrame:RegisterEvent("ZONE_CHANGED"); Sol.hooks.Hook(GreenThumb.Name, "ChatFrame_OnEvent", GreenThumb_ChatFrame_OnEvent); Sol.hooks.Hook(GreenThumb.Name, "PlantFrame_Update", GreenThumb_PlantFrame_Update); Sol.hooks.Hook(GreenThumb.Name, "HouseFurnishingsFrame_OnHide", GreenThumb_HouseFurnishingsFrame_OnHide); Sol.hooks.Hook(GreenThumb.Name, "StoreFrame_SellUpdate", GreenThumb_StoreFrame_SellUpdate); SaveVariables("GreenThumb_Settings"); elseif (event == "ZONE_CHANGED") then if (arg2 == 400) then GreenThumb.Cared = {}; -- Reset CareStates, when entering House end; elseif (event == "HOUSES_PLANT_OPEN") then GreenThumb_CareForPlants(); elseif (event == "STORE_OPEN") then local icon, name, price, moneyType, count, stock = GetStoreSellItemInfo(1); if (string.match(GreenThumb.Materials.Water[1][1],name) or string.match(GreenThumb.Materials.Water[4][1],name)) then GreenThumbFrame_PlantStoreModifications:Show(); GreenThumb_UpdateMaterialHighlights(); if (IsCtrlKeyDown()) then GreenThumb_BuyMaterials(); end; else GreenThumbFrame_PlantStoreModifications:Hide(); end; end; end; ---------------------------------------------------------------------------------------------------- -------------------- PlantFrame Modifications ------------------------------------------------------ ---------------------------------------------------------------------------------------------------- function GreenThumb_GetFocusFurnishingID() local maxItems, StorageName, FurnishingID = Houses_GetItemInfo( Houses_GetFocusFurnishingID() , -1 ); return FurnishingID; end; function GreenThumb_PlantFrame_Update() if (GreenThumb.FurnitureID == nil) then GreenThumb_FindPots(); end; Sol.hooks.GetOriginalFn(GreenThumb.Name, "PlantFrame_Update")(); local szState, szPotName, nPotType, szSeedName, szSeedTexture, szSeedLink, fGrowRate, fHealthRate, nReapTime, nFeedPoint, nWaterPoint, nTopdressPoint, nBestWaterPoint, nBestTopdressPoint, fDecWater, fDecTopdress = Plant_GetInfo(); local currValue, extraValue, maxValue = GetPlayerSkilled("PLANT"); PlantFrameTitle:SetText(LIFESKILL_PLANT..", "..C_LEVEL.." "..math.floor(currValue)..", "..string.format("%.1f",100*(currValue-math.floor(currValue))).."%"); -- Care for plant after planting a new one if (szState == "grow" and GreenThumb.planted==true) then GreenThumb.planted = false; GreenThumb_CareForPlants(); end; -- Modify PlantFrame if (szState == "grow" or szState == "ripe" ) then GreenThumbFrame_CarePlantButton:Enable(); else GreenThumbFrame_CarePlantButton:Disable(); end; if (szState == "grow") then GreenThumbFrame_InfoTooltip:SetHyperLink(szSeedLink); GreenThumbFrame_Progress:Show(); GreenThumbFrame_Progress_Text:SetText(tostring(math.floor(fGrowRate*100)).."%"); GreenThumbFrame_SeedInfoFrameMsg2:Show(); GreenThumbFrame_SeedInfoFrameMsg2Text:SetText(string.gsub(GreenThumbFrame_InfoTooltipTextLeft3:GetText(),"^.*: ","")..", "..C_LEVEL.." "..string.gsub(GreenThumbFrame_InfoTooltipTextLeft4:GetText(),"[^0-9]","").."\n"..GreenThumb_TimeFormat(nReapTime).."\n"..os.date(GreenThumb.Strings.Date,os.time()+nReapTime)); PlantSeedInfoFrameMsg:SetText("|cff00a000"..GreenThumb.Strings.Seed..":\n"..GreenThumb.Strings.RipeIn..":\n"..GreenThumb.Strings.Ripe..":"); else GreenThumbFrame_Progress:Hide(); GreenThumbFrame_SeedInfoFrameMsg2:Hide(); end; local enable, name, texture , Placed = Houses_GetFurnitureItemInfo(GreenThumb_GetFocusFurnishingID()); SetItemButtonTexture(GreenThumbFrame_PotInfoFrameButton, texture); GreenThumbFrame_InfoTooltip:SetHouseItem( -1 , GreenThumb_GetFocusFurnishingID() ); GreenThumbFrame_PotInfoFramePottext:SetText(szPotName); for n=2,7 do if (string.find(getglobal("GreenThumbFrame_InfoTooltipTextLeft"..n):GetText(),string.gsub(TEXT('SYS_NEED_PLANT_SKILL'),"%%d",""),1,true)~=nil) then GreenThumbFrame_PotInfoFrameTypetext:SetText(GreenThumb.seedTypes[nPotType]..", "..C_LEVEL.." "..string.gsub(string.gsub(getglobal("GreenThumbFrame_InfoTooltipTextLeft"..n):GetText(),"%|c........",""),"[^0-9]","")); break; end; end; GreenThumb_UpdateCareStates(); GreenThumb_PlantCaredTooltip(); end; function GreenThumb_UpdateCareStates() local index=0; for i=1,table.maxn(GreenThumb.FurnitureID) do if (i==GreenThumb.FurnitureID[GreenThumb_GetFocusFurnishingID()]) then if (GreenThumb.Cared[i]~=nil) then SetItemButtonTextureVertexColor(getglobal("GreenThumbFrame_CareState_"..i), 0.7, 1, 0.7 ); else SetItemButtonTextureVertexColor(getglobal("GreenThumbFrame_CareState_"..i), 1, 0.7, 0.7 ); end; else if (GreenThumb.Cared[i]~=nil) then SetItemButtonTextureVertexColor(getglobal("GreenThumbFrame_CareState_"..i), 0, 0.7, 0 ); else SetItemButtonTextureVertexColor(getglobal("GreenThumbFrame_CareState_"..i), 0.7, 0, 0 ); end; end; end; end; function GreenThumb_TimeFormat(seconds) if (seconds > 3600) then local divide = seconds/3600; local hours = math.floor(divide); local minutes = math.floor((divide-hours)*60); local msg = tostring(hours); if (hours ~= 1) then msg=msg.." "..GreenThumb.Strings.Hours..", "..minutes; else msg=msg.." "..GreenThumb.Strings.Hour..", "..minutes; end; if (minutes ~= 1) then msg=msg.." "..GreenThumb.Strings.Minutes; else msg=msg.." "..GreenThumb.Strings.Minute; end; return msg; else local minutes = math.floor(seconds/60); local msg = tostring(minutes); if (minutes ~= 1) then msg=msg.." "..GreenThumb.Strings.Minutes; else msg=msg.." "..GreenThumb.Strings.Minute; end; return msg; end; end; ---------------------------------------------------------------------------------------------------- -------------------- Tooltips ---------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- function GreenThumb_Tooltip(this) GameTooltip:SetOwner(GreenThumbFrame_Label,"ANCHOR_BOTTOM",0,0); GameTooltip:ClearAllAnchors(); GameTooltip:SetAnchor("BOTTOMLEFT","TOPLEFT",GreenThumbFrame_Label,-3,0); GameTooltip:SetText(GreenThumb.Name.." "..GreenThumb.Version,0,0.63,0); GameTooltip:AddLine( GreenThumb.Strings.TooltipHelp1,0.6,1,0.3); GameTooltip:AddLine("\n"..GreenThumb.Strings.TooltipHelp2,0.6,1,0.3); GameTooltip:AddLine("\n"..GreenThumb.Strings.TooltipHelp3,0.6,1,0.3); GameTooltip:AddLine("\n"..GreenThumb.Strings.TooltipHelp4,0.6,1,0.3); end; function GreenThumb_PotInfoTooltip() GameTooltip:SetOwner(GreenThumbFrame_PotInfoFrameButton, "ANCHOR_BOTTOMRIGHT"); GameTooltip:SetHouseItem( -1 , GreenThumb_GetFocusFurnishingID() ); end; function GreenThumb_SeedInfoTooltip() local szState, szPotName, nPotType, szSeedName, szSeedTexture, szSeedLink, fGrowRate, fHealthRate, nReapTime, nFeedPoint, nWaterPoint, nTopdressPoint, nBestWaterPoint, nBestTopdressPoint, fDecWater, fDecTopdress = Plant_GetInfo(); GameTooltip:SetOwner(GreenThumbFrame_Progress, "ANCHOR_BOTTOMRIGHT"); GameTooltip:SetHyperLink(szSeedLink); end; function GreenThumb_StoreFrameTooltip(this) GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT"); if (this:GetName()=="GreenThumbFrame_PlantStoreModifications_StoreWaterButton") then GameTooltip:SetText(GreenThumb.Strings.BuyWater1,0,0.63,0); GameTooltip:AddLine("["..GreenThumb.Name.." "..GreenThumb.Version.."]",0,0.63,0); GameTooltip:AddLine(GreenThumb.Strings.BuyWater2,0.6,1,0.3); elseif (this:GetName()=="GreenThumbFrame_PlantStoreModifications_StoreFertilizerButton") then GameTooltip:SetText(GreenThumb.Strings.BuyFert1,0,0.63,0); GameTooltip:AddLine("["..GreenThumb.Name.." "..GreenThumb.Version.."]",0,0.63,0); GameTooltip:AddLine(GreenThumb.Strings.BuyFert2,0.6,1,0.3); elseif (this:GetName()=="GreenThumbFrame_PlantStoreModifications_MaxLevelMaterial") then GameTooltip:SetText(GreenThumb.Strings.MaxLevel1,0,0.63,0); GameTooltip:AddLine("["..GreenThumb.Name.." "..GreenThumb.Version.."]",0,0.63,0); GameTooltip:AddLine(GreenThumb.Strings.MaxLevel2,0.6,1,0.3); end; end; function GreenThumb_CarePlantTooltip() GameTooltip:SetOwner(GreenThumbFrame_CarePlantButton, "ANCHOR_TOPRIGHT"); GameTooltip:SetText(GreenThumb.Strings.Care, 1, 1, 1 ); end; function GreenThumb_ResetCareStatesTooltip() GameTooltip:SetOwner(GreenThumbFrame_CareState_X, "ANCHOR_TOPRIGHT"); GameTooltip:SetText(GreenThumb.Strings.TooltipReset, 1, 1, 1 ); end; function GreenThumb_PlantCaredTooltip(index) GameTooltip:Hide(); local ID = GreenThumb.FurnitureID[GreenThumb_GetFocusFurnishingID()]; if (index==nil) then index=ID; end; if (GreenThumb.Cared[index]~=nil) then GameTooltip:SetText(string.gsub(GreenThumb.Strings.TooltipPot,"",tostring(index)),0,0.63,0); GameTooltip:AddDoubleLine(GreenThumb.Strings.TooltipWater..":",tostring(GreenThumb.Cared[index][1]).."x",0.6,1,0.3); GameTooltip:AddDoubleLine(GreenThumb.Strings.TooltipFert..":" ,tostring(GreenThumb.Cared[index][2]).."x",0.6,1,0.3); else GameTooltip:SetText(string.gsub(GreenThumb.Strings.TooltipPot,"",tostring(index)),0.63,0,0); GameTooltip:AddLine(GreenThumb.Strings.TooltipUncared,1,0.3,0.3); end; end; ---------------------------------------------------------------------------------------------------- -------------------- Settings ---------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- function GreenThumb_HouseFurnishingsFrame_OnHide(this) Sol.hooks.GetOriginalFn(GreenThumb.Name, "HouseFurnishingsFrame_OnHide")(this); GreenThumb_FindPots(); end; function GreenThumb_StoreFrame_SellUpdate() Sol.hooks.GetOriginalFn(GreenThumb.Name, "StoreFrame_SellUpdate")(); GreenThumb_UpdateMaterialHighlights(); end; -- Only run this function, when furnitures not detected!!! Slows down extremly!!! function GreenThumb_FindPots() GreenThumb.Cared={}; GreenThumb.FurnitureID = {}; local index=0; for i=1,Houses_GetFurnitureItemInfo(-1) do local enable, name, texture , Placed = Houses_GetFurnitureItemInfo(i); GreenThumbFrame_InfoTooltip:SetHouseItem( -1 , i ); -- Only use Furniture, when its a placed pot for n=2,7 do if (Placed and string.find(getglobal("GreenThumbFrame_InfoTooltipTextLeft"..n):GetText(),string.gsub(TEXT('SYS_NEED_PLANT_SKILL'),"%%d",""),1,true)~=nil) then index=index+1; getglobal("GreenThumbFrame_CareState_"..index):Show(); SetItemButtonTexture(getglobal("GreenThumbFrame_CareState_"..index), texture); table.insert(GreenThumb.FurnitureID,i,index); break; end; end; if (index==10) then break; end; -- Stop after tenth pot, no more buttons defined in xml end; for i=(index+1),10 do -- Hide remaining CareStates getglobal("GreenThumbFrame_CareState_"..i):Hide(); end; end; function GreenThumb_GetPlantLevel() local plantlevel=1; local currValue, extraValue, maxValue = GetPlayerSkilled("PLANT"); if (currValue >= GreenThumb.Materials.Water[4][2]) then plantlevel=4; elseif (currValue >= GreenThumb.Materials.Water[3][2]) then plantlevel=3; elseif (currValue >= GreenThumb.Materials.Water[2][2]) then plantlevel=2; end; if (plantlevel > GreenThumb_Settings.MaxLevelMaterial) then plantlevel = GreenThumb_Settings.MaxLevelMaterial; end; return plantlevel; end; function GreenThumb_UpdateMaterialHighlights() local plantlevel=GreenThumb_GetPlantLevel(); GreenThumbFrame_PlantStoreModifications_Highlight_Water:Hide(); GreenThumbFrame_PlantStoreModifications_Highlight_Fertilizer:Hide(); for n=1,10 do if (getglobal("StoreFrameItem"..n.."Name"):GetText() == GreenThumb.Materials.Water[plantlevel][1]) then GreenThumbFrame_PlantStoreModifications_Highlight_Water:ClearAllAnchors(); GreenThumbFrame_PlantStoreModifications_Highlight_Water:SetAnchor("CENTER", "CENTER", getglobal("StoreFrameItem"..n.."Button"), 0, 0); GreenThumbFrame_PlantStoreModifications_Highlight_Water:Show(); end; if (getglobal("StoreFrameItem"..n.."Name"):GetText() == GreenThumb.Materials.Fertilizer[plantlevel][1]) then GreenThumbFrame_PlantStoreModifications_Highlight_Fertilizer:ClearAllAnchors(); GreenThumbFrame_PlantStoreModifications_Highlight_Fertilizer:SetAnchor("CENTER", "CENTER", getglobal("StoreFrameItem"..n.."Button"), 0, 0); GreenThumbFrame_PlantStoreModifications_Highlight_Fertilizer:Show(); end; end; end; function GreenThumb_ChangeMaxLevelMaterials(int) GreenThumb_Settings.MaxLevelMaterial = GreenThumb_Settings.MaxLevelMaterial + int; if (GreenThumb_Settings.MaxLevelMaterial < 1) then GreenThumb_Settings.MaxLevelMaterial = 1; end; if (GreenThumb_Settings.MaxLevelMaterial > table.maxn(GreenThumb.Materials.Water)) then GreenThumb_Settings.MaxLevelMaterial = table.maxn(GreenThumb.Materials.Water); end; GreenThumb_DisplayMaxLevelMaterial(); GreenThumb_UpdateMaterialHighlights(); end; function GreenThumb_DisplayMaxLevelMaterial() GreenThumbFrame_PlantStoreModifications_MaxLevelMaterial_Text:SetText(tostring(GreenThumb.Materials.Water[GreenThumb_Settings.MaxLevelMaterial][2])); if (GreenThumb_Settings.MaxLevelMaterial == 1) then GreenThumbFrame_PlantStoreModifications_MaterialsMinus:Disable(); else GreenThumbFrame_PlantStoreModifications_MaterialsMinus:Enable(); end; if (GreenThumb_Settings.MaxLevelMaterial == table.maxn(GreenThumb.Materials.Water)) then GreenThumbFrame_PlantStoreModifications_MaterialsPlus:Disable(); else GreenThumbFrame_PlantStoreModifications_MaterialsPlus:Enable(); end; end; function GreenThumb_BuyMaterials(item) local plantlevel=GreenThumb_GetPlantLevel(); local BuyWater = 0; local BuyFert = 0; local bagitems, bagsize = GetBagCount(); for i=1,bagsize do local index, texture, name, itemCount, locked, invalid = GetBagItemInfo(i); if ((item == nil or item == "water" ) and string.match(name,GreenThumb.Materials.Water [plantlevel][1])) then BuyWater = BuyWater + 250 - itemCount; end; if ((item == nil or item == "fertilizer") and string.match(name,GreenThumb.Materials.Fertilizer[plantlevel][1])) then BuyFert = BuyFert + 250 - itemCount; end; end; if (item == "water" and BuyWater == 0) then BuyWater = 250; end; if (item == "fertilizer" and BuyFert == 0) then BuyFert = 250; end; local index=1; while true do local icon, name, price, moneyType, count, stock = GetStoreSellItemInfo(index); if (name==nil) then break; end; if (BuyWater > 0 and GreenThumb.Materials.Water[plantlevel][1]==name) then StoreBuyItem(index, BuyWater); end; if (BuyFert > 0 and GreenThumb.Materials.Fertilizer[plantlevel][1]==name) then StoreBuyItem(index, BuyFert); end; index=index+1; end; end; ---------------------------------------------------------------------------------------------------- -------------------- Care for Plants --------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- function GreenThumb_CareForPlants() local szState, szPotName, nPotType, szSeedName, szSeedTexture, szSeedLink, fGrowRate, fHealthRate, nReapTime, nFeedPoint, nWaterPoint, nTopdressPoint, nBestWaterPoint, nBestTopdressPoint, fDecWater, fDecTopdress = Plant_GetInfo(); if (szState == "none" and (IsShiftKeyDown() or IsCtrlKeyDown() or IsAltKeyDown())) then local bagitems, bagsize = GetBagCount(); for i = 1,bagsize do local link = GetBagItemLink(60+i); if (link ~= nil) then GreenThumbFrame_InfoTooltip:SetHyperLink(link); for j = 2,10 do local text = getglobal("GreenThumbFrame_InfoTooltipTextLeft"..j):GetText(); if (string.match(text,TEXT('SYS_ITEMTYPE_09')) ~= nil) then local seedtype = string.gsub(getglobal("GreenThumbFrame_InfoTooltipTextLeft"..(j+1)):GetText(),"^.*: ",""); if (string.find(GreenThumb.seedTypes[nPotType],seedtype) or nPotType==0) then PickupBagItem(60+i); Plant_PickupItem("seed"); Plant_Grow("seed"); GreenThumb.planted = true; return; end; end; end; end; end; elseif (szState == "ripe" and IsShiftKeyDown()) then Plant_GetProduct(); elseif (szState == "death" and (IsShiftKeyDown() or IsCtrlKeyDown() or IsAltKeyDown())) then PlantFrameClearBatton_OnClick(); elseif ((szState == "grow" or szState == "ripe") and (IsCtrlKeyDown() or IsAltKeyDown())) then GreenThumb_IrrigatePlants(); end; end; function GreenThumb_IrrigatePlants() GreenThumb.watered = 0; GreenThumb.fertilized = 0; local watercount = tonumber("0"..PlantWaterInfoFrameButtonCount:GetText()); local ferticount = tonumber("0"..PlantTopdressInfoFrameButtonCount:GetText()); if (watercount == 0) then Sol.timers.ScheduleTimer(GreenThumb.Name, 0.0, GreenThumb_PlaceWater); else GreenThumb_UseWater(); end; if (ferticount == 0) then Sol.timers.ScheduleTimer(GreenThumb.Name, 0.1, GreenThumb_PlaceFert); else GreenThumb_UseFert(); end; end; function GreenThumb_PlaceWater() for n=1, table.maxn(GreenThumb.Materials.Water) do for k,v in pairs(Sol.data.items.GetBagSlots(GreenThumb.Materials.Water[n][1])) do PickupBagItem(v.index) ; Plant_PickupItem("water"); Sol.timers.ScheduleTimer(GreenThumb.Name, 0.2, GreenThumb_UseWater); return; end; end; end; function GreenThumb_UseWater() local szState, szPotName, nPotType, szSeedName, szSeedTexture, szSeedLink, fGrowRate, fHealthRate, nReapTime, nFeedPoint, nWaterPoint, nTopdressPoint, nBestWaterPoint, nBestTopdressPoint, fDecWater, fDecTopdress = Plant_GetInfo(); GreenThumb.watertarget = math.floor((nBestWaterPoint - nWaterPoint + 5)/10); if (IsAltKeyDown()) then GreenThumb.watertarget = GreenThumb.watertarget + 1; end; for i = 1, GreenThumb.watertarget do GreenThumb.watered = GreenThumb.watered + 1; Plant_Grow("water"); end; GreenThumb_CheckCare(); end; function GreenThumb_PlaceFert() for n=1, table.maxn(GreenThumb.Materials.Fertilizer) do for k,v in pairs(Sol.data.items.GetBagSlots(GreenThumb.Materials.Fertilizer[n][1])) do PickupBagItem(v.index); Plant_PickupItem("topdress"); Sol.timers.ScheduleTimer(GreenThumb.Name, 0.1, GreenThumb_UseFert); return; end; end; end; function GreenThumb_UseFert() local szState, szPotName, nPotType, szSeedName, szSeedTexture, szSeedLink, fGrowRate, fHealthRate, nReapTime, nFeedPoint, nWaterPoint, nTopdressPoint, nBestWaterPoint, nBestTopdressPoint, fDecWater, fDecTopdress = Plant_GetInfo(); GreenThumb.fertilizertarget = math.floor((nBestTopdressPoint - nTopdressPoint + 5)/10); if (IsAltKeyDown()) then GreenThumb.fertilizertarget = GreenThumb.fertilizertarget + 1; end; for i = 1, GreenThumb.fertilizertarget do GreenThumb.fertilized = GreenThumb.fertilized + 1; Plant_Grow("topdress"); end; GreenThumb_CheckCare(); end; -- Save caresteps after caring is finished function GreenThumb_CheckCare() local ID = GreenThumb.FurnitureID[GreenThumb_GetFocusFurnishingID()]; if (GreenThumb.watered ~= nil and GreenThumb.watertarget ~= nil and GreenThumb.fertilized ~= nil and GreenThumb.fertilizertarget) then if (GreenThumb.watered >= GreenThumb.watertarget and GreenThumb.fertilized >= GreenThumb.fertilizertarget) then if (GreenThumb.Cared[ID]==nil) then GreenThumb.Cared[ID] = {GreenThumb.watered,GreenThumb.fertilized}; else GreenThumb.Cared[ID][1] = GreenThumb.Cared[ID][1] + GreenThumb.watered; GreenThumb.Cared[ID][2] = GreenThumb.Cared[ID][2] + GreenThumb.fertilized; end; GreenThumb.watertarget = nil; GreenThumb.fertilizertarget = nil; end; GreenThumb_UpdateCareStates(); GreenThumb_PlantCaredTooltip(); end; end; ---------------------------------------------------------------------------------------------------- -------------------- Chatfilter --------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- function GreenThumb_ChatFrame_OnEvent(this, event) if ( event == "CHAT_MSG_SYSTEM" ) then for n=1,table.maxn(GreenThumb.BlockMessages) do if (string.match(arg1, GreenThumb.BlockMessages[n])) then return; end; end; end; Sol.hooks.GetOriginalFn(GreenThumb.Name, "ChatFrame_OnEvent")(this, event); end; ---------------------------------------------------------------------------------------------------- -------------------- Frame Fading ------------------------------------------------------------------ ---------------------------------------------------------------------------------------------------- function GreenThumb_OnUpdate(frame, elapsedTime) GreenThumb_FadeFrames(elapsedTime); end function GreenThumb_FadeFrames(value,force) if (type(value)=="number") then for n=1,table.maxn(GreenThumb.Fade) do if (GreenThumb.Fade[n]~=nil) then -- iterate value GreenThumb.Fade[n][2]=GreenThumb.Fade[n][2]+GreenThumb.Fade[n][3]*value*2; -- declare max/min values local Alpha=1; local Scale=1; if (GreenThumb.Fade[n][1]=="GreenThumbFrame_Config") then Alpha=GreenThumb_Settings.Alpha; Scale=GreenThumb_Settings.Scale; end; -- check for max/min local complete=false; if (GreenThumb.Fade[n][2]>=1 and GreenThumb.Fade[n][3]== 1) then GreenThumb.Fade[n][2]=1; complete=true; end; if (GreenThumb.Fade[n][2]<=0 and GreenThumb.Fade[n][3]==-1) then GreenThumb.Fade[n][2]=0; complete=true; end; -- set scale/alpha getglobal(GreenThumb.Fade[n][1]):SetAlpha((GreenThumb.Fade[n][2] )*Alpha); getglobal(GreenThumb.Fade[n][1]):SetScale((GreenThumb.Fade[n][2]*0.1+0.9)*Scale); -- set visibility if (getglobal(GreenThumb.Fade[n][1]):GetAlpha()>0) then getglobal(GreenThumb.Fade[n][1]):Show(); else getglobal(GreenThumb.Fade[n][1]):Hide(); -- Reset values after hiding window, to prevent showing faded frames through addonmanager getglobal(GreenThumb.Fade[n][1]):SetAlpha(Alpha); getglobal(GreenThumb.Fade[n][1]):SetScale(Scale); end; -- remove completed frame if (complete) then table.remove(GreenThumb.Fade,n); n=n-1; end; end; end; elseif (type(value)=="string") then local i,j; if (getglobal(value):IsVisible()) then i=1; j=-1; else i=0; j= 1; end; for n=1,table.maxn(GreenThumb.Fade) do if (value==GreenThumb.Fade[n][1]) then i= GreenThumb.Fade[n][2]; j=-GreenThumb.Fade[n][3]; table.remove(GreenThumb.Fade,n); break; end; end; if (force~=nil) then j=force; end; table.insert(GreenThumb.Fade,{value,i,j}); end; end;