Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local land_up = UIUtil.UIFile('/icons/units/land_up.dds')
- local land_down = UIUtil.UIFile('/icons/units/land_down.dds')
- local land_over = UIUtil.UIFile('/icons/units/land_over.dds')
- local divider_horizontal_bmp = UIUtil.UIFile('/game/c-q-e-panel/divider_horizontal_bmp.dds')
- local divider_bmp = UIUtil.UIFile('/game/c-q-e-panel/divider_bmp.dds')
- local arrow_vert_bmp = UIUtil.UIFile('/game/c-q-e-panel/arrow_vert_bmp.dds')
- local arrow_bmp = UIUtil.UIFile('/game/c-q-e-panel/arrow_bmp.dds')
- local selection_brackets_player_highlighted = UIUtil.UIFile('/game/selection/selection_brackets_player_highlighted.dds')
- local fuel = UIUtil.UIFile('/game/unit_view_icons/fuel.dds')
- local default_icon = UIUtil.UIFile('/icons/units/default_icon.dds')
- local glow = UIUtil.UIFile('/game/units_bmp/glow.dds')
- local OldFormatData = FormatData
- local techCats = {
- [1] = "TECH1",
- [2] = "TECH2",
- [3] = "TECH3",
- [4] = "EXPERIMENTAL",
- }
- function FormatData(unitData, type)
- if type == 'selection' then
- local retData = {}
- local sortedUnits = {
- [1] = {cat = "ALLUNITS", units = {}},
- [2] = {cat = "LAND", units = {}},
- [3] = {cat = "AIR", units = {}},
- [4] = {cat = "NAVAL", units = {}},
- [5] = {cat = "STRUCTURE", units = {}},
- [6] = {cat = "SORTCONSTRUCTION", units = {}},
- }
- local lowFuelUnits = {}
- local idleConsUnits = {}
- for _, unit in unitData do
- local id = unit:GetBlueprint().BlueprintId
- if unit:IsInCategory('AIR') and unit:GetFuelRatio() < .2 and unit:GetFuelRatio() > -1 then
- if not lowFuelUnits[id] then
- lowFuelUnits[id] = {}
- end
- table.insert(lowFuelUnits[id], unit)
- elseif options.gui_seperate_idle_builders ~= 0 and unit:IsInCategory('CONSTRUCTION') and unit:IsIdle() then
- if not idleConsUnits[id] then
- idleConsUnits[id] = {}
- end
- table.insert(idleConsUnits[id], unit)
- else
- local cat = 0
- for i, t in sortedUnits do
- if unit:IsInCategory(t.cat) then
- cat = i
- end
- end
- if not sortedUnits[cat].units[id] then
- sortedUnits[cat].units[id] = {}
- end
- table.insert(sortedUnits[cat].units[id], unit)
- end
- end
- local didPutUnits = false
- for _, t in sortedUnits do
- if didPutUnits then
- table.insert(retData, { type = 'spacer' })
- didPutUnits = false
- end
- retData, didPutUnits = insertIntoTableLowestTechFirst(t.units, retData, false, false)
- end
- if didPutUnits then
- table.insert(retData, { type = 'spacer' })
- didPutUnits = false
- end
- retData, didPutUnits = insertIntoTableLowestTechFirst(lowFuelUnits, retData, true, false)
- if didPutUnits then
- table.insert(retData, { type = 'spacer' })
- didPutUnits = false
- end
- retData, didPutUnits = insertIntoTableLowestTechFirst(idleConsUnits, retData, false, true)
- if retData[table.getn(retData)].type == 'spacer' then
- table.remove(retData, table.getn(retData))
- end
- CreateExtraControls('selection')
- SetSecondaryDisplay('attached')
- import(UIUtil.GetLayoutFilename('construction')).OnTabChangeLayout(type)
- return retData
- end
- return OldFormatData(unitData, type)
- end
- function insertIntoTableLowestTechFirst(units, t, isLowFuel, isIdleCon)
- local didInsert = false
- local isPut = false
- for _, tech in techCats do
- for i, v in units do
- if v[1]:IsInCategory(tech) then
- table.insert(t, { type = 'unitstack', id = i, units = v, lowFuel = isLowFuel, idleCon = isIdleCon })
- units[i] = nil
- isPut = true
- didInsert = true
- end
- end
- end
- --adding units without TECH category
- for i, v in units do
- table.insert(t, { type = 'unitstack', id = i, units = v, lowFuel = isLowFuel, idleCon = isIdleCon })
- end
- return t, didInsert
- end
- function CommonLogic()
- controls.choices:SetupScrollControls(controls.scrollMin, controls.scrollMax, controls.pageMin, controls.pageMax)
- controls.secondaryChoices:SetupScrollControls(controls.secondaryScrollMin, controls.secondaryScrollMax, controls.secondaryPageMin, controls.secondaryPageMax)
- controls.secondaryProgress:SetNeedsFrameUpdate(true)
- controls.secondaryProgress.OnFrame = function(self, delta)
- local frontOfQueue = sortedOptions.selection[1]
- if not frontOfQueue or frontOfQueue:IsDead() then
- return
- end
- controls.secondaryProgress:SetValue(frontOfQueue:GetWorkProgress() or 0)
- if controls.secondaryChoices.top == 1 and not controls.selectionTab:IsChecked() and not controls.constructionGroup:IsHidden() then
- self:SetAlpha(1, true)
- else
- self:SetAlpha(0, true)
- end
- end
- controls.secondaryChoices.SetControlToType = function(control, type)
- local function SetIconTextures(control)
- if DiskGetFileInfo(UIUtil.UIFile('/icons/units/' .. control.Data.id .. '_icon.dds', true)) then
- control.Icon:SetTexture(UIUtil.UIFile('/icons/units/' .. control.Data.id .. '_icon.dds', true))
- else
- control.Icon:SetTexture(UIUtil.UIFile('/icons/units/default_icon.dds'))
- end
- if __blueprints[control.Data.id].StrategicIconName then
- local iconName = __blueprints[control.Data.id].StrategicIconName
- if DiskGetFileInfo('/textures/ui/common/game/strategicicons/' .. iconName .. '_rest.dds') then
- control.StratIcon:SetTexture('/textures/ui/common/game/strategicicons/' .. iconName .. '_rest.dds')
- control.StratIcon.Height:Set(control.StratIcon.BitmapHeight)
- control.StratIcon.Width:Set(control.StratIcon.BitmapWidth)
- else
- control.StratIcon:SetSolidColor('ff00ff00')
- end
- else
- control.StratIcon:SetSolidColor('00000000')
- end
- end
- if type == 'spacer' then
- if controls.secondaryChoices._vertical then
- control.Icon:SetTexture(UIUtil.UIFile('/game/c-q-e-panel/divider_horizontal_bmp.dds'))
- control.Width:Set(48)
- control.Height:Set(20)
- else
- control.Icon:SetTexture(UIUtil.UIFile('/game/c-q-e-panel/divider_bmp.dds'))
- control.Width:Set(20)
- control.Height:Set(48)
- end
- control.Icon.Width:Set(control.Icon.BitmapWidth)
- control.Icon.Height:Set(control.Icon.BitmapHeight)
- control.Count:SetText('')
- control:Disable()
- control.StratIcon:SetSolidColor('00000000')
- control:SetSolidColor('00000000')
- control.BuildKey = nil
- elseif type == 'queuestack' or type == 'attachedunit' then
- SetIconTextures(control)
- local up, down, over, dis = GetBackgroundTextures(control.Data.id)
- control:SetNewTextures(up, down, over, dis)
- control:SetOverrideTexture(down)
- control.tooltipID = LOC(__blueprints[control.Data.id].Description) or 'no description'
- control:DisableOverride()
- control.Height:Set(48)
- control.Width:Set(48)
- control.Icon.Height:Set(48)
- control.Icon.Width:Set(48)
- control.BuildKey = nil
- if control.Data.count > 1 then
- control.Count:SetText(control.Data.count)
- control.Count:SetColor('ffffffff')
- else
- control.Count:SetText('')
- end
- control.Icon:Show()
- control:Enable()
- end
- end
- controls.secondaryChoices.CreateElement = function()
- local btn = FixableButton(controls.choices)
- btn.Icon = Bitmap(btn)
- btn.Icon:DisableHitTest()
- LayoutHelpers.AtCenterIn(btn.Icon, btn)
- btn.StratIcon = Bitmap(btn.Icon)
- btn.StratIcon:DisableHitTest()
- LayoutHelpers.AtTopIn(btn.StratIcon, btn.Icon, 4)
- LayoutHelpers.AtLeftIn(btn.StratIcon, btn.Icon, 4)
- btn.Count = UIUtil.CreateText(btn.Icon, '', 20, UIUtil.bodyFont)
- btn.Count:SetColor('ffffffff')
- btn.Count:SetDropShadow(true)
- btn.Count:DisableHitTest()
- LayoutHelpers.AtBottomIn(btn.Count, btn, 4)
- LayoutHelpers.AtRightIn(btn.Count, btn, 3)
- btn.Count.Depth:Set(function() return btn.Icon.Depth() + 10 end)
- btn.HandleEvent = function(self, event)
- if event.Type == 'MouseEnter' then
- Tooltip.CreateMouseoverDisplay(self, self.tooltipID, nil, false)
- elseif event.Type == 'MouseExit' then
- Tooltip.DestroyMouseoverDisplay()
- end
- return CustomHandleEvent(self, event)
- end
- btn.OnRolloverEvent = OnRolloverHandler
- btn.OnClick = OnClickHandler
- return btn
- end
- controls.choices.CreateElement = function()
- local btn = FixableButton(controls.choices)
- btn.Icon = Bitmap(btn)
- btn.Icon:DisableHitTest()
- LayoutHelpers.AtCenterIn(btn.Icon, btn)
- btn.StratIcon = Bitmap(btn.Icon)
- btn.StratIcon:DisableHitTest()
- LayoutHelpers.AtTopIn(btn.StratIcon, btn.Icon, 4)
- LayoutHelpers.AtLeftIn(btn.StratIcon, btn.Icon, 4)
- btn.Count = UIUtil.CreateText(btn.Icon, '', 20, UIUtil.bodyFont)
- btn.Count:SetColor('ffffffff')
- btn.Count:SetDropShadow(true)
- btn.Count:DisableHitTest()
- LayoutHelpers.AtBottomIn(btn.Count, btn)
- LayoutHelpers.AtRightIn(btn.Count, btn)
- btn.LowFuel = Bitmap(btn)
- btn.LowFuel:SetSolidColor('ffff0000')
- btn.LowFuel:DisableHitTest()
- LayoutHelpers.FillParent(btn.LowFuel, btn)
- btn.LowFuel:SetAlpha(0)
- btn.LowFuel:DisableHitTest()
- btn.LowFuel.Incrementing = 1
- btn.LowFuelIcon = Bitmap(btn.LowFuel, UIUtil.UIFile('/game/unit_view_icons/fuel.dds'))
- LayoutHelpers.AtLeftIn(btn.LowFuelIcon, btn, 4)
- LayoutHelpers.AtBottomIn(btn.LowFuelIcon, btn, 4)
- btn.LowFuelIcon:DisableHitTest()
- btn.LowFuel.OnFrame = function(glow, elapsedTime)
- local curAlpha = glow:GetAlpha()
- curAlpha = curAlpha + (elapsedTime * glow.Incrementing)
- if curAlpha > .4 then
- curAlpha = .4
- glow.Incrementing = -1
- elseif curAlpha < 0 then
- curAlpha = 0
- glow.Incrementing = 1
- end
- glow:SetAlpha(curAlpha)
- end
- btn.HandleEvent = function(self, event)
- if event.Type == 'MouseEnter' then
- Tooltip.CreateMouseoverDisplay(self, self.tooltipID, nil, false)
- elseif event.Type == 'MouseExit' then
- Tooltip.DestroyMouseoverDisplay()
- end
- return CustomHandleEvent(self, event)
- end
- btn.OnRolloverEvent = OnRolloverHandler
- btn.OnClick = OnClickHandler
- return btn
- end
- controls.choices.SetControlToType = function(control, type)
- local function SetIconTextures(control, optID)
- local id = optID or control.Data.id
- if DiskGetFileInfo(UIUtil.UIFile('/icons/units/' .. id .. '_icon.dds', true)) then
- control.Icon:SetTexture(UIUtil.UIFile('/icons/units/' .. id .. '_icon.dds', true))
- else
- control.Icon:SetTexture(UIUtil.UIFile('/icons/units/default_icon.dds'))
- end
- if __blueprints[id].StrategicIconName then
- local iconName = __blueprints[id].StrategicIconName
- if DiskGetFileInfo('/textures/ui/common/game/strategicicons/' .. iconName .. '_rest.dds') then
- control.StratIcon:SetTexture('/textures/ui/common/game/strategicicons/' .. iconName .. '_rest.dds')
- control.StratIcon.Height:Set(control.StratIcon.BitmapHeight)
- control.StratIcon.Width:Set(control.StratIcon.BitmapWidth)
- else
- control.StratIcon:SetSolidColor('ff00ff00')
- end
- else
- control.StratIcon:SetSolidColor('00000000')
- end
- end
- if type == 'arrow' then
- control.Count:SetText('')
- control:Disable()
- control:SetSolidColor('00000000')
- if controls.choices._vertical then
- control.Icon:SetTexture(UIUtil.UIFile('/game/c-q-e-panel/arrow_vert_bmp.dds'))
- control.Width:Set(48)
- control.Height:Set(20)
- else
- control.Icon:SetTexture(UIUtil.UIFile('/game/c-q-e-panel/arrow_bmp.dds'))
- control.Width:Set(20)
- control.Height:Set(48)
- end
- control.Icon.Depth:Set(function() return control.Depth() + 5 end)
- control.Icon.Height:Set(control.Icon.BitmapHeight)
- control.Icon.Width:Set(30)
- control.Icon:Show()
- control.StratIcon:SetSolidColor('00000000')
- control.StratIcon:Hide()
- control.LowFuel:SetAlpha(0, true)
- control.LowFuel:SetNeedsFrameUpdate(false)
- control.BuildKey = nil
- elseif type == 'spacer' then
- if controls.choices._vertical then
- control.Icon:SetTexture(UIUtil.UIFile('/game/c-q-e-panel/divider_horizontal_bmp.dds'))
- control.Width:Set(48)
- control.Height:Set(20)
- else
- control.Icon:SetTexture(UIUtil.UIFile('/game/c-q-e-panel/divider_bmp.dds'))
- control.Width:Set(20)
- control.Height:Set(48)
- end
- control.Icon.Width:Set(control.Icon.BitmapWidth)
- control.Icon.Height:Set(control.Icon.BitmapHeight)
- control.Count:SetText('')
- control:Disable()
- control.StratIcon:SetSolidColor('00000000')
- control:SetSolidColor('00000000')
- control.LowFuel:SetAlpha(0, true)
- control.LowFuel:SetNeedsFrameUpdate(false)
- control.BuildKey = nil
- elseif type == 'enhancement' then
- control.Icon:SetSolidColor('00000000')
- local up, down, over, _, selected = GetEnhancementTextures(control.Data.unitID, control.Data.icon)
- control:SetNewTextures(up, down, over, up)
- control:SetOverrideTexture(selected)
- control.tooltipID = LOC(control.Data.enhTable.Name) or 'no description'
- control:SetOverrideEnabled(control.Data.Selected)
- control.Height:Set(48)
- control.Width:Set(48)
- control.Icon.Height:Set(48)
- control.Icon.Width:Set(48)
- control.Icon.Depth:Set(function() return control.Depth() + 1 end)
- control.Count:SetText('')
- control.StratIcon:SetSolidColor('00000000')
- control.LowFuel:SetAlpha(0, true)
- control.LowFuel:SetNeedsFrameUpdate(false)
- control.BuildKey = nil
- if control.Data.Disabled then
- control:Enable()
- control.Data.TooltipOnly = true
- if not control.Data.Selected then
- control.Icon:SetSolidColor('aa000000')
- end
- else
- control.Data.TooltipOnly = false
- control:Enable()
- end
- elseif type == 'templates' then
- control:DisableOverride()
- SetIconTextures(control, control.Data.template.icon)
- control:SetNewTextures(GetBackgroundTextures(control.Data.template.icon))
- control.Height:Set(48)
- control.Width:Set(48)
- if control.Data.template.icon then
- control.Icon:SetTexture(UIUtil.UIFile('/icons/units/' .. control.Data.template.icon .. '_icon.dds', true))
- else
- control.Icon:SetTexture('/textures/ui/common/icons/units/default_icon.dds')
- end
- control.Icon.Height:Set(48)
- control.Icon.Width:Set(48)
- control.Icon.Depth:Set(function() return control.Depth() + 1 end)
- control.StratIcon:SetSolidColor('00000000')
- control.tooltipID = control.Data.template.name or 'no description'
- control.BuildKey = control.Data.template.key
- if showBuildIcons and control.Data.template.key then
- control.Count:SetText(string.char(control.Data.template.key) or '')
- control.Count:SetColor('ffff9000')
- else
- control.Count:SetText('')
- end
- control.Icon:Show()
- control:Enable()
- control.LowFuel:SetAlpha(0, true)
- control.LowFuel:SetNeedsFrameUpdate(false)
- elseif type == 'item' then
- SetIconTextures(control)
- control:SetNewTextures(GetBackgroundTextures(control.Data.id))
- local _, down = GetBackgroundTextures(control.Data.id)
- control.tooltipID = LOC(__blueprints[control.Data.id].Description) or 'no description'
- control:SetOverrideTexture(down)
- control:DisableOverride()
- control.Height:Set(48)
- control.Width:Set(48)
- control.Icon.Height:Set(48)
- control.Icon.Width:Set(48)
- control.Icon.Depth:Set(function() return control.Depth() + 1 end)
- control.BuildKey = nil
- if showBuildIcons then
- local unitBuildKeys = BuildMode.GetUnitKeys(sortedOptions.selection[1]:GetBlueprint().BlueprintId, GetCurrentTechTab())
- control.Count:SetText(unitBuildKeys[control.Data.id] or '')
- control.Count:SetColor('ffff9000')
- else
- control.Count:SetText('')
- end
- control.Icon:Show()
- control:Enable()
- control.LowFuel:SetAlpha(0, true)
- control.LowFuel:SetNeedsFrameUpdate(false)
- elseif type == 'unitstack' then
- SetIconTextures(control)
- control:SetNewTextures(GetBackgroundTextures(control.Data.id))
- control.tooltipID = LOC(__blueprints[control.Data.id].Description) or 'no description'
- control:DisableOverride()
- control.Height:Set(48)
- control.Width:Set(48)
- control.Icon.Height:Set(48)
- control.Icon.Width:Set(48)
- control.LowFuel:SetAlpha(0, true)
- control.BuildKey = nil
- if control.Data.lowFuel then
- control.LowFuel:SetNeedsFrameUpdate(true)
- control.LowFuelIcon:SetAlpha(1)
- else
- control.LowFuel:SetNeedsFrameUpdate(false)
- end
- if table.getn(control.Data.units) > 1 then
- control.Count:SetText(table.getn(control.Data.units))
- control.Count:SetColor('ffffffff')
- else
- control.Count:SetText('')
- end
- control.Icon:Show()
- control:Enable()
- end
- end
- if options.gui_bigger_strat_build_icons ~= 0 then
- local oldSecondary = controls.secondaryChoices.SetControlToType
- local oldPrimary = controls.choices.SetControlToType
- -- norem add idle icon to buttons
- local oldPrimaryCreate = controls.choices.CreateElement
- controls.choices.CreateElement = function()
- local btn = oldPrimaryCreate()
- btn.IdleIcon = Bitmap(btn.Icon, UIUtil.SkinnableFile('/game/idle_mini_icon/idle_icon.dds'))
- LayoutHelpers.AtBottomIn(btn.IdleIcon, btn)
- LayoutHelpers.AtLeftIn(btn.IdleIcon, btn)
- btn.IdleIcon:DisableHitTest()
- btn.IdleIcon:SetAlpha(0)
- return btn
- end
- controls.secondaryChoices.SetControlToType = function(control, type)
- oldSecondary(control, type)
- if control.StratIcon.Underlay then
- control.StratIcon.Underlay:Hide()
- end
- StratIconReplacement(control)
- end
- controls.choices.SetControlToType = function(control, type)
- oldPrimary(control, type)
- if control.StratIcon.Underlay then
- control.StratIcon.Underlay:Hide()
- end
- StratIconReplacement(control)
- -- AZ improved selection code
- if type == 'unitstack' and control.Data.idleCon then
- control.IdleIcon:SetAlpha(1)
- end
- end
- else -- If we dont have bigger strat icons selected, just do the idle icon
- local oldSecondary = controls.secondaryChoices.SetControlToType
- local oldPrimary = controls.choices.SetControlToType
- -- norem add idle icon to buttons
- local oldPrimaryCreate = controls.choices.CreateElement
- controls.choices.CreateElement = function()
- local btn = oldPrimaryCreate()
- btn.IdleIcon = Bitmap(btn.Icon, UIUtil.SkinnableFile('/game/idle_mini_icon/idle_icon.dds'))
- LayoutHelpers.AtBottomIn(btn.IdleIcon, btn)
- LayoutHelpers.AtLeftIn(btn.IdleIcon, btn)
- btn.IdleIcon:DisableHitTest()
- btn.IdleIcon:SetAlpha(0)
- return btn
- end
- controls.secondaryChoices.SetControlToType = function(control, type)
- oldSecondary(control, type)
- end
- controls.choices.SetControlToType = function(control, type)
- oldPrimary(control, type)
- -- AZ improved selection code
- if type == 'unitstack' and control.Data.idleCon then
- control.IdleIcon:SetAlpha(1)
- end
- end
- end
- if options.gui_visible_template_names ~= 0 then
- local oldSecondary = controls.secondaryChoices.SetControlToType
- local oldPrimary = controls.choices.SetControlToType
- local oldPrimaryCreate = controls.choices.CreateElement
- controls.choices.CreateElement = function()
- local btn = oldPrimaryCreate()
- -- creating the display area
- btn.Tmplnm = UIUtil.CreateText(btn.Icon, '', 11, UIUtil.bodyFont)
- btn.Tmplnm:SetColor('ffffff00')
- btn.Tmplnm:DisableHitTest()
- btn.Tmplnm:SetDropShadow(true)
- btn.Tmplnm:SetCenteredHorizontally(true)
- LayoutHelpers.CenteredBelow(btn.Tmplnm, btn, 0)
- btn.Tmplnm.Depth:Set(function() return btn.Icon.Depth() + 10 end)
- return btn
- end
- controls.secondaryChoices.SetControlToType = function(control, type)
- oldSecondary(control, type)
- end
- controls.choices.SetControlToType = function(control, type)
- oldPrimary(control, type)
- -- the text
- if type == 'templates' and 'templates' then
- control.Tmplnm.Width:Set(48)
- control.Tmplnm:SetText(string.sub(control.Data.template.name, cutA, cutB))
- end
- end
- end
- end
- function CustomHandleEvent(self, event)
- local eventHandled = false
- if event.Type == 'MouseEnter' then
- if self.mAltToggledFlag then
- self:SetTexture(self.mAltHighlight)
- else
- self:SetTexture(self.mHighlight)
- end
- self:OnRolloverEvent('enter')
- self:Play()
- self.mMouseOver = true
- eventHandled = true
- elseif event.Type == 'MouseExit' then
- if self.mAltToggledFlag then
- self:SetTexture(self.mAltNormal)
- else
- self:SetTexture(self.mNormal)
- end
- self:OnRolloverEvent('exit')
- self:Play()
- self.mMouseOver = false
- eventHandled = true
- elseif event.Type == 'ButtonPress' or event.Type == 'ButtonDClick' then
- self:OnClick(event.Modifiers)
- self:Play()
- eventHandled = true
- end
- return eventHandled
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement