local versionNumber = "v2.2" function widget:GetInfo() return { name = "Take Reminder" .. versionNumber, desc = "Reminds you to /take if a player is gone", author = "Evil4Zerggin - fixed by Adonai_Jr", date = "31 March 2007", license = "GNU GPL, v2 or later", layer = 0, enabled = true -- loaded by default? } end ------------------------------------------------ -- modified by: ------------------------------------------------ -- jK: only get mouse owner in MousePress() if there are teams to take -- and some smaller speed ups ------------------------------------------------ ------------------------------------------------ --config ------------------------------------------------ local autoTake = false ------------------------------------------------ --local variables ------------------------------------------------ local updatePeriod = 0.5 local lastUpdate local vsx, vsy, posx, posy local count local myAllyTeamID local colorBool local trueColor = "\255\255\255\1" local falseColor = "\255\127\127\1" local buttonX = 240 local buttonY = 36 ------------------------------------------------ --speedups ------------------------------------------------ local GetTeamList = Spring.GetTeamList local GetMyAllyTeamID = Spring.GetMyAllyTeamID local GetTeamUnitCount = Spring.GetTeamUnitCount local GetPlayerList = Spring.GetPlayerList local GetPlayerInfo = Spring.GetPlayerInfo local GetGameSeconds = Spring.GetGameSeconds local GetSpectatingState = Spring.GetSpectatingState ------------------------------------------------ --helper functions ------------------------------------------------ function GetTeamIsTakeable(team) local players = GetPlayerList(true) for _, player in ipairs(players) do local _, _, _, playerTeam = GetPlayerInfo(player) if (playerTeam == team) then return false end end return true end function UpdateUnitsToTake() local teamList = GetTeamList(myAllyTeamID) count = 0 for _, team in ipairs(teamList) do local unitsOwned = GetTeamUnitCount(team) if (unitsOwned > 0 and GetTeamIsTakeable(team)) then count = count + unitsOwned end end end function IsOnButton(x, y) return x >= posx - buttonX and x <= posx + buttonX and y >= posy and y <= posy + buttonY end function Take() Spring.SendCommands{"take"} return end ------------------------------------------------ --call-ins ------------------------------------------------ function widget:Initialize() if GetSpectatingState() or Spring.IsReplay() then widgetHandler:RemoveWidget() return true end colorBool = false lastUpdate = 0 vsx, vsy = widgetHandler:GetViewSizes() posx = vsx * 0.75 posy = vsy * 0.75 count = 0 end function widget:ViewResize(viewSizeX, viewSizeY) vsx = viewSizeX vsy = viewSizeY posx = vsx * 0.75 posy = vsy * 0.75 end function widget:DrawScreen() if (count > 0) then gl.Color( 1.0, 1.0, 0 ) gl.Shape(GL.LINE_LOOP, {{ v = { posx + buttonX, posy} }, { v = { posx + buttonX, posy + buttonY } }, { v = { posx - buttonX, posy + buttonY } }, { v = { posx - buttonX, posy} } }) local colorStr if (colorBool) then colorStr = trueColor else colorStr = falseColor end gl.Text(colorStr .. "Click here to take " .. count .. " unit(s)!", posx, posy, 24, "oc") end end function widget:Update() local now = GetGameSeconds() if (now < lastUpdate + updatePeriod) then return end if GetSpectatingState() then Spring.Echo(" Spectator mode. Widget removed.") widgetHandler:RemoveWidget() return end lastUpdate = now myAllyTeamID = GetMyAllyTeamID() colorBool = not colorBool UpdateUnitsToTake() if (count > 0 and autoTake) then Take() end end function widget:MousePress(x, y, button) return (count > 0)and(IsOnButton(x, y)) end function widget:MouseRelease(x, y, button) if (count > 0 and IsOnButton(x, y)) then UpdateUnitsToTake() if (count > 0) then Take() end return -1 end return false end