Skip to content

Commit

Permalink
Create reclaim value reticle
Browse files Browse the repository at this point in the history
  • Loading branch information
lL1l1 committed Mar 2, 2024
1 parent 6c22f57 commit 74d0c5d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
88 changes: 88 additions & 0 deletions lua/ui/controls/reticles/reclaim.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
--******************************************************************************************************
--** Copyright (c) 2024 IL1I1
--**
--** Permission is hereby granted, free of charge, to any person obtaining a copy
--** of this software and associated documentation files (the "Software"), to deal
--** in the Software without restriction, including without limitation the rights
--** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
--** copies of the Software, and to permit persons to whom the Software is
--** furnished to do so, subject to the following conditions:
--**
--** The above copyright notice and this permission notice shall be included in all
--** copies or substantial portions of the Software.
--**
--** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
--** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
--** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
--** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
--** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
--** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
--** SOFTWARE.
--******************************************************************************************************

local Bitmap = import("/lua/maui/bitmap.lua").Bitmap

local UIUtil = import("/lua/ui/uiutil.lua")
local LayoutHelpers = import("/lua/maui/layouthelpers.lua")
local Reticle = import('/lua/ui/controls/reticle.lua').Reticle

-- Local upvalues for performance
local GetRolloverInfo = GetRolloverInfo

--- Reticle for teleport cost info
---@class UIReclaimReticle : UIReticle
---@field MassValueIcon Bitmap
---@field mText Text
ReclaimReticle = ClassUI(Reticle) {

---@param self UIReclaimReticle
SetLayout = function(self)
self.MassValueIcon = Bitmap(self)
self.MassValueIcon:SetTexture(UIUtil.UIFile('/game/unit_view_icons/mass.dds'))
LayoutHelpers.SetDimensions(self.MassValueIcon, 19, 19)

self.mText = UIUtil.CreateText(self, "mValue", 16, UIUtil.bodyFont, true)
LayoutHelpers.CenteredRightOf(self.MassValueIcon, self, 4)
LayoutHelpers.RightOf(self.mText, self.MassValueIcon, 2)

-- from economy_mini.lua, same color as the mass stored/storage text
self.mText:SetColor('ffb7e75f')
end,

---@param self UIReclaimReticle
UpdateDisplay = function(self)
local rolloverInfo = GetRolloverInfo()
if rolloverInfo then
if self:IsHidden() then
self:SetHidden(false)
end

-- copy the wreck logic from Unit.lua
local bp = __blueprints[rolloverInfo.blueprintId]
local mass = bp.Economy.BuildCostMass

local mass_tech_mult = 0.9
local tech_category = bp.TechCategory

-- We reduce the mass value based on tech category
if tech_category == 'TECH1' then
mass_tech_mult = 0.9
elseif tech_category == 'TECH2' then
mass_tech_mult = 0.8
elseif tech_category == 'TECH3' then
mass_tech_mult = 0.7
elseif tech_category == 'EXPERIMENTAL' then
mass_tech_mult = 0.6
end

mass = mass * mass_tech_mult * bp.Wreckage.MassMult

self.mText:SetText(string.format('%d', mass))
else
if not self:IsHidden() then
self:Hide()
end
end
end,

}
4 changes: 2 additions & 2 deletions lua/ui/controls/reticles/teleport.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ local GetSelectedUnits = GetSelectedUnits

--- Reticle for teleport cost info
---@class UITeleportReticle : UIReticle
---@field ePrefix Text
---@field tPrefix Text
---@field EnergyCostIcon Bitmap
---@field BuildTimeIcon Bitmap
---@field eText Text
---@field tText Text
TeleportReticle = ClassUI(Reticle) {
Expand Down
2 changes: 2 additions & 0 deletions lua/ui/controls/worldview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local OverchargeCanKill = import("/lua/ui/game/unitview.lua").OverchargeCanKill
local CommandMode = import("/lua/ui/game/commandmode.lua")

local TeleportReticle = import("/lua/ui/controls/reticles/teleport.lua").TeleportReticle
local ReclaimReticle = import("/lua/ui/controls/reticles/reclaim.lua").ReclaimReticle

WorldViewParams = {
ui_SelectTolerance = 7.0,
Expand Down Expand Up @@ -703,6 +704,7 @@ WorldView = ClassUI(moho.UIWorldView, Control) {
self.CanIssueReclaimOrdersOld = canIssueReclaimOrders
self.ViaRightMouseButtonOld = viaRightMouseButton
self:ApplyReclaimCursor(identifier, canIssueReclaimOrders, viaCommandMode, true)
ReclaimReticle(self)
else
if (canIssueReclaimOrders ~= self.CanIssueReclaimOrdersOld) or (viaRightMouseButton ~= self.ViaRightMouseButtonOld) then
self:ApplyReclaimCursor(identifier, canIssueReclaimOrders, viaCommandMode, true)
Expand Down

0 comments on commit 74d0c5d

Please sign in to comment.