protected override Material[] GenerateMasks(GraphicRequestRGB req, PatternDef pattern)
        {
            Texture2D mainTex = ContentFinder <Texture2D> .Get(req.path);

            Texture2D maskTex = ContentFinder <Texture2D> .Get(req.path + MaskSuffix, false);

            masks = Enumerable.Repeat(maskTex, MatCount).ToArray();
            var mats = new Material[MatCount];
            MaterialRequestRGB mReq = new MaterialRequestRGB()
            {
                mainTex          = mainTex,
                shader           = req.shader,
                properties       = pattern.properties,
                color            = pattern.properties.colorOne ?? req.color,
                colorTwo         = pattern.properties.colorTwo ?? req.colorTwo,
                colorThree       = pattern.properties.colorThree ?? req.colorThree,
                tiles            = req.tiles,
                isSkin           = pattern is SkinDef,
                maskTex          = maskTex,
                patternTex       = pattern?[Rot8.North],
                shaderParameters = req.shaderParameters
            };

            mats[0] = MaterialPoolExpanded.MatFrom(mReq);
            return(mats);
        }
 public Material SubMaterialCycle(PatternDef pattern, int index)
 {
     if (index > (subGraphics.Length - 1))
     {
         Log.Warning($"Graphic Retrieval for Graphic_CannonAnimate indexed past maximum length of {subGraphics.Length}. Self correcting.");
         while (index > (subGraphics.Length - 1))
         {
             index -= (subGraphics.Length - 1);
         }
     }
     return(subGraphics[index].maskMatPatterns.TryGetValue(pattern, subGraphics[index].maskMatPatterns[PatternDefOf.Default]).Second[0]);
 }
示例#3
0
        private void DrawPaintSelection(Rect paintRect)
        {
            paintRect = paintRect.ContractedBy(1);
            Widgets.DrawBoxSolid(paintRect, Greyist);

            Rect outRect = paintRect;

            outRect = outRect.ContractedBy(10f);
            float sqrGridSize = outRect.width / GridDimensionSqr;
            float gridSizeX   = sqrGridSize;
            float gridSizeY   = sqrGridSize;

            /* Scale down if dimensions are not equal */
            if (vehicleTex.width < vehicleTex.height)
            {
                gridSizeX *= (float)vehicleTex.width / vehicleTex.height;
                outRect.x += (sqrGridSize - gridSizeX) / 2;
            }
            /* -------------------------------------- */

            float num            = 0f;
            int   startingIndex  = (pageNumber - 1) * (GridDimensionSqr * GridDimensionSqr);
            int   maxIndex       = Ext_Numeric.Clamp((pageNumber * (GridDimensionSqr * GridDimensionSqr)), 0, availableMasks.Count);
            int   iteration      = 0;
            Rect  displayRect    = new Rect(0, 0, gridSizeX, gridSizeY);
            Rect  paginationRect = new Rect(paintRect.x + 5, paintRect.y + paintRect.height - ButtonHeight, paintRect.width - 10, ButtonHeight * 0.75f);

            if (pageCount > 1)
            {
                UIHelper.DrawPagination(paginationRect, ref pageNumber, pageCount);
            }
            for (int i = startingIndex; i < maxIndex; i++, iteration++)
            {
                displayRect.x = outRect.x + (iteration % GridDimensionSqr) * sqrGridSize;
                displayRect.y = outRect.y + (Mathf.FloorToInt(iteration / GridDimensionSqr)) * gridSizeY;

                RenderHelper.DrawVehicleTexTiled(displayRect, vehicleTex, vehicle, availableMasks[i], true, CurrentColorOne.ToColor, CurrentColorTwo.ToColor, CurrentColorThree.ToColor);
                Rect imageRect = new Rect(displayRect.x, displayRect.y, gridSizeX, gridSizeY);
                if (iteration % GridDimensionSqr == 0)
                {
                    num += imageRect.height;
                }
                TooltipHandler.TipRegion(imageRect, availableMasks[i].LabelCap);
                if (Widgets.ButtonInvisible(imageRect))
                {
                    selectedPattern  = availableMasks[i];
                    displacementX    = 0;
                    displacementY    = 0;
                    additionalTiling = 1;
                }
            }
        }
示例#4
0
        private static VehiclePawn GenerateVehicleInternal(VehicleGenerationRequest request)
        {
            VehiclePawn result = (VehiclePawn)ThingMaker.MakeThing(request.VehicleDef);

            PawnComponentsUtility.CreateInitialComponents(result);

            result.kindDef = request.VehicleDef.VehicleKindDef;
            result.SetFactionDirect(request.Faction);

            string     defaultMask = VehicleMod.settings.vehicles.defaultMasks.TryGetValue(result.VehicleDef.defName, "Default");
            PatternDef pattern     = DefDatabase <PatternDef> .GetNamed(defaultMask);

            if (pattern is null)
            {
                Log.Error($"Unable to retrieve saved default pattern {defaultMask}. Defaulting to original Default mask.");
                pattern = PatternDefOf.Default;
            }

            result.pattern = request.RandomizeMask ? result.VehicleGraphic.maskMatPatterns.RandomElement().Key : pattern;
            if (result.VehicleGraphic.MatSingle.shader.SupportsRGBMaskTex())
            {
                result.DrawColor      = request.ColorOne;
                result.DrawColorTwo   = request.ColorTwo;
                result.DrawColorThree = request.ColorThree;
            }

            result.PostGenerationSetup();
            foreach (VehicleComp comp in result.AllComps.Where(c => c is VehicleComp))
            {
                comp.PostGenerationSetup();
            }

            //REDO - Allow other modders to add setup for non clean-slate items
            if (!request.CleanSlate)
            {
                UpgradeAtRandom(result, request.Upgrades);
                DistributeAmmunition(result);
            }

            float num = Rand.ByCurve(DefaultAgeGenerationCurve);

            result.ageTracker.AgeBiologicalTicks = (long)(num * BiologicalAgeTicksMultiplier) + Rand.Range(0, 3600000);
            result.needs.SetInitialLevels();
            if (Find.Scenario != null)
            {
                Find.Scenario.Notify_NewPawnGenerating(result, PawnGenerationContext.NonPlayer);
            }
            return(result);
        }
示例#5
0
 public virtual Material MatAt(PatternDef pattern, int index = 0)
 {
     if (pattern != null && maskMatPatterns.TryGetValue(pattern, out var values))
     {
         return(values.Second[index]);
     }
     else
     {
         Log.Error($"{VehicleHarmony.LogLabel} Key {pattern?.defName ?? "[Null]"} not found in {GetType()}.");
         string folders = string.Empty;
         foreach (var item in maskMatPatterns)
         {
             folders += $"Item: {item.Key} Destination: {item.Value.First}\n";
         }
         Debug.Message($"{VehicleHarmony.LogLabel} Additional Information:\n" +
                       $"MatCount: {maskMatPatterns.Count}\n" +
                       $"{folders}");
     }
     return(BaseContent.BadMat);
 }
示例#6
0
        public Material MatAt(Rot8 rot, PatternDef pattern)
        {
            if (pattern is null)
            {
                return(MatAt(rot));
            }
            if (maskMatPatterns.TryGetValue(pattern, out var values))
            {
                return(values.Second[rot.AsInt]);
            }
            Log.Error($"[{VehicleHarmony.LogLabel}] Key {pattern.defName} not found in {GetType()}.");
            string folders = string.Empty;

            foreach (var item in maskMatPatterns)
            {
                folders += $"Item: {item.Key} Destination: {item.Value.First}\n";
            }
            Debug.Warning($"{VehicleHarmony.LogLabel} Additional Information:\n" +
                          $"MatCount: {maskMatPatterns.Count}\n" +
                          $"{folders}");
            return(BaseContent.BadMat);
        }
示例#7
0
        public Dialog_ColorPicker(VehiclePawn vehicle)
        {
            Instance     = this;
            this.vehicle = vehicle;
            vehicleTex   = vehicle.VehicleGraphic.TexAt(Rot8.North);

            SetColors(vehicle.DrawColor, vehicle.DrawColorTwo, vehicle.DrawColorThree);
            CurrentSelectedPalette = -1;

            for (int i = 0; i < 255; i++)
            {
                HueChart.SetPixel(0, i, Color.HSVToRGB(Mathf.InverseLerp(0f, 255f, i), 1f, 1f));
            }
            HueChart.Apply(false);
            for (int j = 0; j < 255; j++)
            {
                for (int k = 0; k < 255; k++)
                {
                    Color color = Color.clear;
                    Color c     = Color.Lerp(color, Color.white, Mathf.InverseLerp(0f, 255f, j));
                    color = Color32.Lerp(Color.black, c, Mathf.InverseLerp(0f, 255f, k));
                    ColorChart.SetPixel(j, k, color);
                }
            }

            pageNumber     = 1;
            availableMasks = DefDatabase <PatternDef> .AllDefs.Where(p => p.ValidFor(vehicle.VehicleDef)).ToList();

            RecacheMaterials();
            float ratio = (float)availableMasks.Count / (GridDimensionSqr * GridDimensionSqr);

            pageCount = Mathf.CeilToInt(ratio);

            ColorChart.Apply(false);
            doCloseX   = true;
            forcePause = true;
            absorbInputAroundWindow = true;
            selectedPattern         = vehicle.pattern;
        }
示例#8
0
 private void DoBottomButtons(Rect buttonRect)
 {
     if (Widgets.ButtonText(buttonRect, "Apply".Translate()))
     {
         vehicle.DrawColor      = CurrentColorOne.ToColor;
         vehicle.DrawColorTwo   = CurrentColorTwo.ToColor;
         vehicle.DrawColorThree = CurrentColorThree.ToColor;
         vehicle.pattern        = selectedPattern;
         vehicle.tiles          = additionalTiling;
         vehicle.displacement   = new Vector2(displacementX, displacementY);
         vehicle.Notify_ColorChanged();
         vehicle.CompCannons?.Cannons.ForEach(c => c.ResolveCannonGraphics(vehicle, true));
         Close(true);
     }
     buttonRect.x += ButtonWidth;
     if (Widgets.ButtonText(buttonRect, "CancelAssigning".Translate()))
     {
         Close(true);
     }
     buttonRect.x += ButtonWidth;
     if (Widgets.ButtonText(buttonRect, "VehiclesReset".Translate()))
     {
         SoundDefOf.Click.PlayOneShotOnCamera(null);
         selectedPattern  = vehicle.pattern;
         additionalTiling = vehicle.tiles;
         displacementX    = vehicle.displacement.x;
         displacementY    = vehicle.displacement.y;
         if (CurrentSelectedPalette >= 0)
         {
             var palette = VehicleMod.settings.colorStorage.colorPalette[CurrentSelectedPalette];
             SetColors(palette.Item1, palette.Item2, palette.Item3);
         }
         else
         {
             SetColors(vehicle.DrawColor, vehicle.DrawColorTwo, vehicle.DrawColorThree);
         }
     }
 }
示例#9
0
        private void DrawVehicleOptions(Rect menuRect)
        {
            listingSplit = new Listing_Settings()
            {
                maxOneColumn       = true,
                shiftRectScrollbar = true
            };

            Rect vehicleIconContainer = menuRect.ContractedBy(10);

            vehicleIconContainer.width /= 4;
            vehicleIconContainer.height = vehicleIconContainer.width;
            vehicleIconContainer.x     += vehicleIconContainer.width;

            Rect vehicleDetailsContainer = menuRect.ContractedBy(10);

            vehicleDetailsContainer.x     += vehicleIconContainer.width - 1;
            vehicleDetailsContainer.width -= vehicleIconContainer.width;

            Widgets.DrawBoxSolid(vehicleDetailsContainer, Color.grey);
            Rect vehicleDetailsRect = vehicleDetailsContainer.ContractedBy(1);

            Widgets.DrawBoxSolid(vehicleDetailsRect, ListingExtension.MenuSectionBGFillColor);

            listingStandard = new Listing_Standard();
            listingStandard.Begin(vehicleDetailsContainer.ContractedBy(1));
            listingStandard.Header($"{VehicleMod.selectedDef?.LabelCap ?? string.Empty}", ListingExtension.BannerColor, GameFont.Medium, TextAnchor.MiddleCenter);
            listingStandard.End();

            if (VehicleMod.selectedDef != null)
            {
                try
                {
                    Rect iconRect = menuRect.ContractedBy(10);
                    iconRect.width /= 5;
                    iconRect.height = iconRect.width;
                    iconRect.x     += menuRect.width / 4;
                    iconRect.y     += 30;

                    if (VehicleMod.selectedPatterns.Count > 1)
                    {
                        Rect paintBrushRect = new Rect(iconRect.x + iconRect.width, iconRect.y, 24, 24);
                        Widgets.DrawTextureFitted(paintBrushRect, VehicleTex.Recolor, 1);
                        if (Mouse.IsOver(paintBrushRect))
                        {
                            TooltipHandler.TipRegion(paintBrushRect, "VehiclesRecolorDefaultMaskTooltip".Translate());
                        }
                        if (Widgets.ButtonInvisible(paintBrushRect))
                        {
                            List <FloatMenuOption> list = new List <FloatMenuOption>();
                            foreach (PatternDef pattern in VehicleMod.selectedPatterns)
                            {
                                list.Add(new FloatMenuOption(pattern.LabelCap, () => defaultMasks[VehicleMod.selectedDef.defName] = pattern.defName));
                            }
                            FloatMenu floatMenu = new FloatMenu(list)
                            {
                                vanishIfMouseDistant = true
                            };
                            //floatMenu.onCloseCallback...
                            Find.WindowStack.Add(floatMenu);
                        }
                    }
                    PatternDef curPattern = DefDatabase <PatternDef> .GetNamed(defaultMasks[VehicleMod.selectedDef.defName]);

                    RenderHelper.DrawVehicleTexInSettings(iconRect, VehicleMod.selectedDef, VehicleMod.graphicInt, VehicleMod.selectedVehicleTex, curPattern, Rot8.North);

                    Rect enableButtonRect = menuRect.ContractedBy(10);
                    enableButtonRect.x += enableButtonRect.width / 4 + 5;
                    EnableButton(enableButtonRect);

                    Rect compVehicleRect = menuRect.ContractedBy(10);
                    compVehicleRect.x      += vehicleIconContainer.width * 2 - 10;
                    compVehicleRect.y      += 30;
                    compVehicleRect.width  -= vehicleIconContainer.width * 2;
                    compVehicleRect.height -= (30 + menuRect.height * 0.45f);

                    listingSplit.Begin(compVehicleRect, 2);

                    listingSplit.Header("CompVehicleStats".Translate(), Color.clear, GameFont.Small, TextAnchor.MiddleCenter);

                    foreach (FieldInfo field in VehicleMod.vehicleDefFields)
                    {
                        if (field.TryGetAttribute(out PostToSettingsAttribute post))
                        {
                            post.DrawLister(listingSplit, VehicleMod.selectedDef, field);
                        }
                    }

                    listingSplit.End();

                    float scrollableFieldY     = menuRect.height * 0.4f;
                    Rect  scrollableFieldsRect = new Rect(vehicleDetailsContainer.x + 1, menuRect.y + scrollableFieldY, vehicleDetailsContainer.width - 2, menuRect.height - scrollableFieldY - 10);

                    Rect scrollableFieldsViewRect = new Rect(scrollableFieldsRect.x, scrollableFieldsRect.y, scrollableFieldsRect.width - 20, VehicleMod.scrollableViewHeight);
                    UIElements.DrawLineHorizontalGrey(scrollableFieldsRect.x, scrollableFieldsRect.y - 1, scrollableFieldsRect.width);
                    listingSplit.BeginScrollView(scrollableFieldsRect, ref VehicleMod.saveableFieldsScrollPosition, ref scrollableFieldsViewRect, 3);
                    foreach (var saveableObject in VehicleMod.VehicleCompFields)
                    {
                        if (saveableObject.Value.NullOrEmpty() || saveableObject.Value.All(f => f.TryGetAttribute <PostToSettingsAttribute>(out var settings) &&
                                                                                           settings.VehicleType != VehicleType.Undefined && settings.VehicleType != VehicleMod.selectedDef.vehicleType))
                        {
                            continue;
                        }
                        string header = string.Empty;
                        if (saveableObject.Key.TryGetAttribute(out HeaderTitleAttribute title))
                        {
                            header = title.Translate ? title.Label.Translate().ToString() : title.Label;
                        }
                        listingSplit.Header(header, ListingExtension.BannerColor, GameFont.Small, TextAnchor.MiddleCenter);
                        foreach (FieldInfo field in saveableObject.Value)
                        {
                            if (field.TryGetAttribute(out PostToSettingsAttribute post))
                            {
                                post.DrawLister(listingSplit, VehicleMod.selectedDef, field);
                            }
                        }
                    }
                    listingSplit.EndScrollView(ref scrollableFieldsViewRect);
                }
                catch (Exception ex)
                {
                    Log.Error($"Exception thrown while trying to select {VehicleMod.selectedDef.defName}. Disabling vehicle to preserve mod settings.\nException={ex.Message}");
                    VehicleMod.settingsDisabledFor.Add(VehicleMod.selectedDef.defName);
                    VehicleMod.selectedDef = null;
                    VehicleMod.selectedPatterns.Clear();
                    VehicleMod.selectedDefUpgradeComp = null;
                    VehicleMod.selectedNode           = null;
                    VehicleMod.SetVehicleTex(null);
                }
            }
        }
示例#10
0
 public virtual void CopyFrom(GraphicData graphicData, PatternDef pattern, Color colorThree)
 {
     CopyFrom(graphicData);
     this.colorThree = colorThree;
     this.pattern    = pattern ?? PatternDefOf.Default;
 }
示例#11
0
 public virtual void CopyFrom(GraphicDataRGB graphicData)
 {
     base.CopyFrom(graphicData);
     colorThree = graphicData.colorThree;
     pattern    = graphicData.pattern ?? PatternDefOf.Default;
 }