Example #1
0
 public BuildingPaintMenu(Building target_building)
     : base(Game1.uiViewport.Width / 2 - WINDOW_WIDTH / 2, Game1.uiViewport.Height / 2 - WINDOW_HEIGHT / 2, WINDOW_WIDTH, WINDOW_HEIGHT)
 {
     InitializeSavedColors();
     _paintData = Game1.content.Load <Dictionary <string, string> >("Data\\PaintData");
     Game1.player.Halt();
     building     = target_building;
     colorTarget  = target_building.netBuildingPaintColor.Value;
     buildingType = building.buildingType.Value;
     SetRegion(0);
     populateClickableComponentList();
     if (Game1.options.SnappyMenus)
     {
         snapToDefaultClickableComponent();
     }
 }
Example #2
0
 public BuildingPaintMenu(string building_type, Func <Texture2D> get_non_building_texture, Rectangle non_building_source_rect, BuildingPaintColor target)
     : base(Game1.uiViewport.Width / 2 - WINDOW_WIDTH / 2, Game1.uiViewport.Height / 2 - WINDOW_HEIGHT / 2, WINDOW_WIDTH, WINDOW_HEIGHT)
 {
     InitializeSavedColors();
     _paintData = Game1.content.Load <Dictionary <string, string> >("Data\\PaintData");
     Game1.player.Halt();
     building              = null;
     buildingType          = building_type;
     nonBuildingSourceRect = non_building_source_rect;
     getNonBuildingTexture = get_non_building_texture;
     colorTarget           = target;
     SetRegion(0);
     populateClickableComponentList();
     if (Game1.options.SnappyMenus)
     {
         snapToDefaultClickableComponent();
     }
 }
        internal static Texture2D GetPaintedOverlay(Building building, Texture2D base_texture, Texture2D paint_mask_texture, BuildingPaintColor color)
        {
            List <List <int> > paint_indices = null;

            try
            {
                Color[] mask_pixels = new Color[paint_mask_texture.Width * paint_mask_texture.Height];
                paint_mask_texture.GetData(mask_pixels);
                paint_indices = new List <List <int> >();
                for (int j = 0; j < 3; j++)
                {
                    paint_indices.Add(new List <int>());
                }
                for (int i = 0; i < mask_pixels.Length; i++)
                {
                    if (mask_pixels[i] == Color.Red)
                    {
                        paint_indices[0].Add(i);
                    }
                    else if (mask_pixels[i] == Color.Lime)
                    {
                        paint_indices[1].Add(i);
                    }
                    else if (mask_pixels[i] == Color.Blue)
                    {
                        paint_indices[2].Add(i);
                    }
                }
            }
            catch (Exception)
            {
                //_monitor.Log($"Unhandled error occured while getting paint overlay for buildings: {ex}", LogLevel.Debug);
                return(null);
            }

            if (paint_indices == null)
            {
                return(null);
            }
            if (!color.RequiresRecolor())
            {
                return(null);
            }
            Color[] painted_pixels = new Color[base_texture.Width * base_texture.Height];
            base_texture.GetData(painted_pixels);
            Texture2D texture2D = new Texture2D(Game1.graphics.GraphicsDevice, base_texture.Width, base_texture.Height);

            if (!color.Color1Default.Value)
            {
                ApplyPaint(0, -100, 0, ref painted_pixels, paint_indices[0]);
                ApplyPaint(color.Color1Hue.Value, color.Color1Saturation.Value, color.Color1Lightness.Value, ref painted_pixels, paint_indices[0]);
            }
            if (!color.Color2Default.Value)
            {
                ApplyPaint(0, -100, 0, ref painted_pixels, paint_indices[1]);
                ApplyPaint(color.Color2Hue.Value, color.Color2Saturation.Value, color.Color2Lightness.Value, ref painted_pixels, paint_indices[1]);
            }
            if (!color.Color3Default.Value)
            {
                ApplyPaint(0, -100, 0, ref painted_pixels, paint_indices[2]);
                ApplyPaint(color.Color3Hue.Value, color.Color3Saturation.Value, color.Color3Lightness.Value, ref painted_pixels, paint_indices[2]);
            }

            texture2D.SetData(painted_pixels);
            return(texture2D);
        }