private void HasHeat(Weapon weapon, StackedWeaponInfo stackedInfo, ref Vector2D currWeaponDisplayPos, bool reset) { int heatBarIndex; if (weapon.State.Overheated) { var index = _session.SCount < 30 ? 1 : 2; heatBarIndex = HeatBarTexture.Length - 2; } else { heatBarIndex = (int)MathHelper.Clamp(weapon.HeatPerc * 10, 0, HeatBarTexture.Length - 1); } stackedInfo.CachedHeatTexture.Material = HeatBarTexture[heatBarIndex].Material; stackedInfo.CachedHeatTexture.Color = Vector4.Zero; stackedInfo.CachedHeatTexture.Position.X = currWeaponDisplayPos.X - _heatOffsetX; stackedInfo.CachedHeatTexture.Position.Y = currWeaponDisplayPos.Y - _heatOffsetY; stackedInfo.CachedHeatTexture.Width = _heatWidth; stackedInfo.CachedHeatTexture.Height = _heatHeight; stackedInfo.CachedHeatTexture.P0 = HeatBarTexture[heatBarIndex].P0; stackedInfo.CachedHeatTexture.P1 = HeatBarTexture[heatBarIndex].P1; stackedInfo.CachedHeatTexture.P2 = HeatBarTexture[heatBarIndex].P2; stackedInfo.CachedHeatTexture.P3 = HeatBarTexture[heatBarIndex].P3; if (reset) { stackedInfo.CachedHeatTexture.Persistant = false; } _textureAddList.Add(stackedInfo.CachedHeatTexture); }
private void HasHeat(Weapon weapon, StackedWeaponInfo stackedInfo, ref Vector2D currWeaponDisplayPos, bool reset) { int heatBarIndex; if (weapon.State.Overheated) { heatBarIndex = _heatBarTexture.Length - 1; } else { heatBarIndex = (int)MathHelper.Clamp(weapon.HeatPerc * 10, 0, _heatBarTexture.Length - 1); } stackedInfo.CachedHeatTexture.Material = _heatBarTexture[heatBarIndex].Material; stackedInfo.CachedHeatTexture.Color = Color.Transparent; stackedInfo.CachedHeatTexture.Position.X = currWeaponDisplayPos.X - _heatOffsetX; stackedInfo.CachedHeatTexture.Position.Y = currWeaponDisplayPos.Y - _heatOffsetY - _paddingHeat; stackedInfo.CachedHeatTexture.Width = _heatWidth; stackedInfo.CachedHeatTexture.Height = _heatHeight; stackedInfo.CachedHeatTexture.P0 = _heatBarTexture[heatBarIndex].P0; stackedInfo.CachedHeatTexture.P1 = _heatBarTexture[heatBarIndex].P1; stackedInfo.CachedHeatTexture.P2 = _heatBarTexture[heatBarIndex].P2; stackedInfo.CachedHeatTexture.P3 = _heatBarTexture[heatBarIndex].P3; if (reset) { stackedInfo.CachedHeatTexture.Persistant = false; } _textureAddList.Add(stackedInfo.CachedHeatTexture); }
private void ShowReloadIcon(Weapon weapon, StackedWeaponInfo stackedInfo, ref Vector2D currWeaponDisplayPos, double textOffset, bool reset) { var mustCharge = weapon.ActiveAmmoDef.ConsumableDef.Const.MustCharge; var texture = mustCharge ? _chargingTexture : _reloadingTexture; if (texture.Length > 0) { if (mustCharge) { stackedInfo.ReloadIndex = MathHelper.Clamp((int)(MathHelper.Lerp(0, texture.Length - 1, weapon.Ammo.CurrentCharge / weapon.MaxCharge)), 0, texture.Length - 1); } stackedInfo.CachedReloadTexture.Material = texture[stackedInfo.ReloadIndex].Material; stackedInfo.CachedReloadTexture.Color = Color.GhostWhite * _session.UiOpacity; stackedInfo.CachedReloadTexture.Position.X = (textOffset - _paddingReload) - _reloadOffset; stackedInfo.CachedReloadTexture.Position.Y = currWeaponDisplayPos.Y; stackedInfo.CachedReloadTexture.Width = _reloadWidth; stackedInfo.CachedReloadTexture.Height = _reloadHeight; stackedInfo.CachedReloadTexture.P0 = texture[stackedInfo.ReloadIndex].P0; stackedInfo.CachedReloadTexture.P1 = texture[stackedInfo.ReloadIndex].P1; stackedInfo.CachedReloadTexture.P2 = texture[stackedInfo.ReloadIndex].P2; stackedInfo.CachedReloadTexture.P3 = texture[stackedInfo.ReloadIndex].P3; if (!mustCharge && _session.Tick10 && ++stackedInfo.ReloadIndex > texture.Length - 1) { stackedInfo.ReloadIndex = 0; } if (reset) { stackedInfo.CachedReloadTexture.Persistant = false; } _textureAddList.Add(stackedInfo.CachedReloadTexture); } }
internal List <StackedWeaponInfo> SortDisplayedWeapons(List <Weapon> list) { int length = list.Count; int finalCount = 0; List <StackedWeaponInfo> finalList; if (!_weaponInfoListPool.TryDequeue(out finalList)) { finalList = new List <StackedWeaponInfo>(); } for (int h = length / 2; h > 0; h /= 2) { for (int i = h; i < length; i += 1) { var tempValue = list[i]; var temp = list[i].State.Heat; int j; for (j = i; j >= h && list[j - h].State.Heat < temp; j -= h) { list[j] = list[j - h]; } list[j] = tempValue; } } if (list.Count > 50) //limit to top 50 based on heat { list.RemoveRange(50, list.Count - 50); } else if (list.Count <= 12) { for (int i = 0; i < list.Count; i++) { var w = list[i]; if (w.System.WeaponName.Length > _currentLargestName) { _currentLargestName = w.System.WeaponName.Length; } StackedWeaponInfo swi; if (!_weaponStackedInfoPool.TryDequeue(out swi)) { swi = new StackedWeaponInfo(); } if (!_textureDrawPool.TryDequeue(out swi.CachedReloadTexture)) { swi.CachedReloadTexture = new TextureDrawData(); } if (!_textureDrawPool.TryDequeue(out swi.CachedHeatTexture)) { swi.CachedHeatTexture = new TextureDrawData(); } swi.CachedHeatTexture.Persistant = true; swi.CachedReloadTexture.Persistant = true; swi.ReloadIndex = 0; swi.HighestValueWeapon = w; swi.WeaponStack = 1; finalList.Add(swi); } return(finalList); } Dictionary <int, List <Weapon> > weaponTypes = new Dictionary <int, List <Weapon> >(); for (int i = 0; i < list.Count; i++) //sort list into groups of same weapon type { var w = list[i]; if (!weaponTypes.ContainsKey(w.System.WeaponIdHash)) { List <Weapon> tmp; if (!_weaponSortingListPool.TryDequeue(out tmp)) { tmp = new List <Weapon>(); } weaponTypes[w.System.WeaponIdHash] = tmp; } weaponTypes[w.System.WeaponIdHash].Add(w); } foreach (var weaponType in weaponTypes) { var weapons = weaponType.Value; if (weapons[0].System.WeaponName.Length > _currentLargestName) { _currentLargestName = weapons[0].System.WeaponName.Length; } if (weapons.Count > 1) { List <List <Weapon> > subLists; List <Weapon> subList; var last = weapons[0]; if (!_weaponSubListsPool.TryDequeue(out subLists)) { subLists = new List <List <Weapon> >(); } if (!_weaponSortingListPool.TryDequeue(out subList)) { subList = new List <Weapon>(); } for (int i = 0; i < weapons.Count; i++) { var w = weapons[i]; if (i == 0) { subList.Add(w); } else { if (last.HeatPerc - w.HeatPerc > .05f || last.Reloading != w.Reloading || last.State.Overheated != w.State.Overheated) { subLists.Add(subList); if (!_weaponSortingListPool.TryDequeue(out subList)) { subList = new List <Weapon>(); } } last = w; subList.Add(w); if (i == weapons.Count - 1) { subLists.Add(subList); } } } weapons.Clear(); _weaponSortingListPool.Enqueue(weapons); for (int i = 0; i < subLists.Count; i++) { var subL = subLists[i]; if (finalCount < 12) { StackedWeaponInfo swi; if (!_weaponStackedInfoPool.TryDequeue(out swi)) { swi = new StackedWeaponInfo(); } if (!_textureDrawPool.TryDequeue(out swi.CachedReloadTexture)) { swi.CachedReloadTexture = new TextureDrawData(); } if (!_textureDrawPool.TryDequeue(out swi.CachedHeatTexture)) { swi.CachedHeatTexture = new TextureDrawData(); } swi.CachedHeatTexture.Persistant = true; swi.CachedReloadTexture.Persistant = true; swi.ReloadIndex = 0; swi.HighestValueWeapon = subL[0]; swi.WeaponStack = subL.Count; finalList.Add(swi); finalCount++; } subL.Clear(); _weaponSortingListPool.Enqueue(subL); } subLists.Clear(); _weaponSubListsPool.Enqueue(subLists); } else { if (finalCount < 12) { StackedWeaponInfo swi; if (!_weaponStackedInfoPool.TryDequeue(out swi)) { swi = new StackedWeaponInfo(); } if (!_textureDrawPool.TryDequeue(out swi.CachedReloadTexture)) { swi.CachedReloadTexture = new TextureDrawData(); } if (!_textureDrawPool.TryDequeue(out swi.CachedHeatTexture)) { swi.CachedHeatTexture = new TextureDrawData(); } swi.CachedHeatTexture.Persistant = true; swi.CachedReloadTexture.Persistant = true; swi.ReloadIndex = 0; swi.HighestValueWeapon = weapons[0]; swi.WeaponStack = 1; finalList.Add(swi); finalCount++; } weapons.Clear(); _weaponSortingListPool.Enqueue(weapons); } } return(finalList); }