private static Vector2 ExtractBounds(Graphic graphic, GraphicType type) { int vWidth; int vHeight; IntRange vBounds; try { vBounds = Def_Extensions.CropVertical((graphic.MatEast.mainTexture as Texture2D).GetColorSafe(out vWidth, out vHeight), vWidth, vHeight); } catch (Exception ex) { throw new Exception("CombatExtended :: CropVertical error while cropping Textures/" + graphic.path + "_east", ex); } //Plants only care for verts //This is assuming PLANTS TAKE UP A FULL TILE!! // TODO : Refactor if (type == GraphicType.Plant) { return(new Vector2( 1f, (float)(vBounds.max - vBounds.min) / (float)vHeight)); } int hWidth; int hHeight; IntRange hBounds; try { hBounds = Def_Extensions.CropHorizontal((graphic.MatSouth.mainTexture as Texture2D).GetColorSafe(out hWidth, out hHeight), hWidth, hHeight); } catch (Exception ex) { throw new Exception("CombatExtended :: CropHorizontal error while cropping Textures/" + graphic.path + "_south", ex); } return(new Vector2( (float)(hBounds.max - hBounds.min) / (float)hWidth, (float)(vBounds.max - vBounds.min) / (float)vHeight)); }
private static Vector2 ExtractBounds(Graphic graphic, GraphicType type, Graphic headGraphic, Vector2 headOffset) { int vWidth; int vHeight; IntRange vBounds; try { vBounds = Def_Extensions.CropVertical((graphic.MatEast.mainTexture as Texture2D).GetColorSafe(out vWidth, out vHeight), vWidth, vHeight); } catch (Exception ex) { throw new Exception("CombatExtended :: CropVertical error while cropping Textures/" + graphic.path + "_east", ex); } int hWidth; int hHeight; IntRange hBounds; try { hBounds = Def_Extensions.CropHorizontal((graphic.MatSouth.mainTexture as Texture2D).GetColorSafe(out hWidth, out hHeight), hWidth, hHeight); } catch (Exception ex) { throw new Exception("CombatExtended :: CropHorizontal error while cropping Textures/" + graphic.path + "_south", ex); } int vWidthHead; int vHeightHead; IntRange vBoundsHead; try { vBoundsHead = Def_Extensions.CropVertical((headGraphic.MatEast.mainTexture as Texture2D).GetColorSafe(out vWidthHead, out vHeightHead), vWidthHead, vHeightHead); } catch (Exception ex) { throw new Exception("CombatExtended :: CropVertical error while cropping Textures/" + headGraphic.path + "_east", ex); } vBoundsHead.min -= (int)(headOffset.y * (float)vHeightHead); vBoundsHead.max -= (int)(headOffset.y * (float)vHeightHead); vBounds.min = Math.Min(vBounds.min, (int)((float)vBoundsHead.min * (float)vHeight / (float)vHeightHead)); vBounds.max = Math.Max(vBounds.max, (int)((float)vBoundsHead.max * (float)vHeight / (float)vHeightHead)); int hWidthHead; int hHeightHead; IntRange hBoundsHead; try { hBoundsHead = Def_Extensions.CropHorizontal((headGraphic.MatSouth.mainTexture as Texture2D).GetColorSafe(out hWidthHead, out hHeightHead), hWidthHead, hHeightHead); } catch (Exception ex) { throw new Exception("CombatExtended :: CropHorizontal error while cropping Textures/" + headGraphic.path + "_south", ex); } hBoundsHead.min += (int)(headOffset.x * (float)hWidthHead); hBoundsHead.max += (int)(headOffset.x * (float)hWidthHead); hBounds.max = Math.Max(hBounds.max, (int)((float)hBoundsHead.max * (float)hWidth / (float)hWidthHead)); hBounds.min = Math.Min(hBounds.min, (int)((float)hBoundsHead.min * (float)hWidth / (float)hWidthHead)); return(new Vector2( (float)(hBounds.max - hBounds.min) / (float)hWidth, (float)(vBounds.max - vBounds.min) / (float)vHeight)); }
private static Vector2 ExtractBounds(Graphic graphic, GraphicType type) { int vWidth; int vHeight; var vBounds = Def_Extensions.CropVertical((graphic.MatSide.mainTexture as Texture2D).GetColorSafe(out vWidth, out vHeight), vWidth, vHeight); //Plants only care for verts //This is assuming PLANTS TAKE UP A FULL TILE!! // TODO : Refactor if (type == GraphicType.Plant) { return(new Vector2( 1f, (float)(vBounds.max - vBounds.min) / (float)vHeight)); } int hWidth; int hHeight; var hBounds = Def_Extensions.CropHorizontal((graphic.MatFront.mainTexture as Texture2D).GetColorSafe(out hWidth, out hHeight), hWidth, hHeight); return(new Vector2( (float)(hBounds.max - hBounds.min) / (float)hWidth, (float)(vBounds.max - vBounds.min) / (float)vHeight)); }
private static Vector2 ExtractBounds(Graphic graphic, GraphicType type, Graphic headGraphic, Vector2 headOffset) { int vWidth; int vHeight; var vBounds = Def_Extensions.CropVertical((graphic.MatSide.mainTexture as Texture2D).GetColorSafe(out vWidth, out vHeight), vWidth, vHeight); int hWidth; int hHeight; var hBounds = Def_Extensions.CropHorizontal((graphic.MatFront.mainTexture as Texture2D).GetColorSafe(out hWidth, out hHeight), hWidth, hHeight); int vWidthHead; int vHeightHead; var vTexHead = headGraphic.MatSide.mainTexture as Texture2D; var vBoundsHead = Def_Extensions.CropVertical(vTexHead.GetColorSafe(out vWidthHead, out vHeightHead), vWidthHead, vHeightHead); vBoundsHead.min += (int)(headOffset.y * (float)vHeightHead); vBoundsHead.max += (int)(headOffset.y * (float)vHeightHead); vBounds.max = Math.Max(vBounds.max, (int)((float)vBoundsHead.max * (float)vHeight / (float)vHeightHead)); vBounds.min = Math.Min(vBounds.min, (int)((float)vBoundsHead.min * (float)vHeight / (float)vHeightHead)); int hWidthHead; int hHeightHead; var hTexHead = headGraphic.MatFront.mainTexture as Texture2D; var hBoundsHead = Def_Extensions.CropVertical(hTexHead.GetColorSafe(out hWidthHead, out hHeightHead), hWidthHead, hHeightHead); hBoundsHead.min += (int)(headOffset.x * (float)hWidthHead); hBoundsHead.max += (int)(headOffset.x * (float)hWidthHead); hBounds.max = Math.Max(hBounds.max, (int)((float)hBoundsHead.max * (float)hWidth / (float)hWidthHead)); hBounds.min = Math.Min(hBounds.min, (int)((float)hBoundsHead.min * (float)hWidth / (float)hWidthHead)); return(new Vector2( (float)(hBounds.max - hBounds.min) / (float)hWidth, (float)(vBounds.max - vBounds.min) / (float)vHeight)); }
public override IEnumerable <Gizmo> CompGetGizmosExtra() { GizmoAmmoStatus ammoStatusGizmo = new GizmoAmmoStatus { compAmmo = this }; yield return(ammoStatusGizmo); if ((Wielder != null && Wielder.Faction == Faction.OfPlayer) || (turret != null && turret.Faction == Faction.OfPlayer && (turret.MannableComp != null || UseAmmo))) { Action action = null; if (Wielder != null) { action = delegate { TryStartReload(); } } ; else if (turret != null && turret.MannableComp != null) { action = turret.TryOrderReload; } // Check for teaching opportunities string tag; if (turret == null) { if (HasMagazine) { tag = "CE_Reload"; // Teach reloading weapons with magazines } else { tag = "CE_ReloadNoMag"; // Teach about mag-less weapons } } else { if (turret.MannableComp == null) { tag = "CE_ReloadAuto"; // Teach about auto-turrets } else { tag = "CE_ReloadManned"; // Teach about reloading manned turrets } } LessonAutoActivator.TeachOpportunity(ConceptDef.Named(tag), turret, OpportunityType.GoodToKnow); Command_Reload reloadCommandGizmo = new Command_Reload { compAmmo = this, action = action, defaultLabel = HasMagazine ? "CE_ReloadLabel".Translate() : "", defaultDesc = "CE_ReloadDesc".Translate(), icon = CurrentAmmo == null ? ContentFinder <Texture2D> .Get("UI/Buttons/Reload", true) : Def_Extensions.IconTexture(selectedAmmo), tutorTag = tag }; yield return(reloadCommandGizmo); } }
public override IEnumerable <Gizmo> CompGetGizmosExtra() { GizmoAmmoStatus ammoStatusGizmo = new GizmoAmmoStatus { compAmmo = this }; yield return(ammoStatusGizmo); if ((wielder != null && wielder.Faction == Faction.OfPlayer) || (turret != null && turret.Faction == Faction.OfPlayer)) { Action action = null; if (wielder != null) { action = TryStartReload; } else if (turret != null && turret.GetMannableComp() != null) { action = turret.OrderReload; } Command_Reload reloadCommandGizmo = new Command_Reload { compAmmo = this, action = action, defaultLabel = hasMagazine ? "CE_ReloadLabel".Translate() : "", defaultDesc = "CE_ReloadDesc".Translate(), icon = currentAmmo == null ? ContentFinder <Texture2D> .Get("UI/Buttons/Reload", true) : Def_Extensions.IconTexture(selectedAmmo) }; yield return(reloadCommandGizmo); } }