示例#1
0
        // This reads the object (from bytes)
        public void Deserialize(DataSerializer s)
        {
            int[] ids = s.ReadInt32Array();

            PropPainterManager.instance.map = new Dictionary <ushort, Color>();

            // Temporary hack. I need to figure out why this for loop repeats forever, I cannot figure out why.
            List <int> repeatedIDs = new List <int>();

            for (ushort i = 0; i < ids.Length; i++)
            {
                Db.l(i);

                int h = ids[i];
                if (repeatedIDs.Contains(i))
                {
                    break;
                }

                if (i == 7000)
                {
                    repeatedIDs.Add(i);
                }

                if (h != 16777216 && !repeatedIDs.Contains(i))
                {
                    repeatedIDs.Add(i);

                    byte r = (byte)((h >> 16) & 0xFF);
                    byte g = (byte)((h >> 8) & 0xFF);
                    byte b = (byte)((h) & 0xFF);
                    PropPainterManager.instance.SetColor(i, new Color32(r, g, b, 255));
                }
            }
        }
        private static void ChangeSelectionColors(Color color)
        {
            if (doNotUpdateColors)
            {
                doNotUpdateColors = false;
                return;
            }
            Db.l("Color of selected objects changed to (" + color.ToString() + ")");
            List <ushort> props = PropPainterManager.instance.ExtractPropsFromMoveItSelection();

            for (int i = 0; i < props.Count; i++)
            {
                PropPainterManager.instance.SetColor(props[i], color);
            }
        }
示例#3
0
        public override void OnSaveData()
        {
            byte[] bytes;

            // Convert the MakeHistoricalData object to bytes
            using (var stream = new MemoryStream())
            {
                DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, PropPainterDataContainer.DataVersion, _data);
                bytes = stream.ToArray();
            }

            // Save bytes in savegame
            serializableDataManager.SaveData(PropPainterDataContainer.DataId, bytes);

            Db.l("Data saved (Size in bytes: { " + bytes.Length + "})");
        }
示例#4
0
        public override void OnLoadData()
        {
            byte[] bytes = serializableDataManager.LoadData(PropPainterDataContainer.DataId);
            if (bytes != null)
            {
                using (var stream = new MemoryStream(bytes))
                {
                    _data = DataSerializer.Deserialize <PropPainterDataContainer>(stream, DataSerializer.Mode.Memory);
                }
                Db.l("Data loaded (Size in bytes: { " + bytes.Length + "})");
            }
            else
            {
                _data = new PropPainterDataContainer();

                Db.w("Data created");
            }
        }
 private static void Postfix(Dictionary <Instance, Instance> ___m_clonedOrigin)
 {
     foreach (KeyValuePair <Instance, Instance> x in ___m_clonedOrigin)
     {
         Instance a = x.Key;
         Instance b = x.Value;
         if (a.id.Type != InstanceType.Prop)
         {
             return;
         }
         if (PropPainterManager.instance.GetColor(a.id.Prop) == null)
         {
             return;
         }
         PropPainterManager.instance.SetColor(b.id.Prop, (Color)PropPainterManager.instance.GetColor(a.id.Prop));
         Db.l("Colors cloned from " + a + " to " + b);
     }
 }
示例#6
0
        public void AfterDeserialize(DataSerializer s)
        {
            // @TODO implement afterdeserialize properly
            Db.l("After deserialize.");

            /*
             * if (!PropManager.exists) return;
             *
             * List<ushort> invalidPropIDs = new List<ushort>();
             *
             * PropInstance[] propInstances = PropManager.instance.m_props.m_buffer;
             *
             * // itertate through all building ids, filter active ids
             * foreach (KeyValuePair<ushort, Color> item in PropPainterManager.instance.map)
             * {
             *  if ((PropInstance.Flags) propInstances[item.Key].m_flags == PropInstance.Flags.None)
             *  {
             *      invalidPropIDs.Add(item.Key);
             *  }
             * }
             *
             * PropPainterManager.instance.map
             */
        }
        // Updated code thanks to TPB- @TODO implement!
        private static void CreateUI(UIComponent parent, string name)
        {
            UIColorField field = UITemplateManager.Get <UIPanel>("LineTemplate").Find <UIColorField>("LineColor");

            field           = UnityEngine.Object.Instantiate <UIColorField>(field);
            field.isVisible = false;
            field.name      = "PropPickerColorField";

            UIColorPicker picker = UnityEngine.Object.Instantiate <UIColorPicker>(field.colorPicker);

            picker.eventColorUpdated += ChangeSelectionColors;
            picker.color              = Color.white;
            picker.component.color    = Color.white;
            picker.name = name;

            UIPanel pickerPanel = picker.component as UIPanel;

            pickerPanel.backgroundSprite = "InfoPanelBack";
            pickerPanel.isVisible        = false;
            picker.component.size        = new Vector2(254f, 226f); // ?/

            parent.AttachUIComponent(picker.gameObject);

            pickerPanel.absolutePosition = UIToolOptionPanel.instance.m_viewOptions.absolutePosition - new Vector3(329, 147);

            Db.l("Prop Picker color picker instantiated");


            FieldInfo f          = typeof(UIToolOptionPanel).GetField("m_alignTools", BindingFlags.Instance | BindingFlags.NonPublic);
            UIButton  AlignTools = f.GetValue(UIToolOptionPanel.instance) as UIButton;

            UIPanel AlignToolsPanel = UIToolOptionPanel.instance.m_alignToolsPanel;

            FieldInfo fa     = typeof(UIToolOptionPanel).GetField("m_single", BindingFlags.Instance | BindingFlags.NonPublic);
            UIButton  Single = fa.GetValue(UIToolOptionPanel.instance) as UIButton;

            FieldInfo fb      = typeof(UIToolOptionPanel).GetField("m_marquee", BindingFlags.Instance | BindingFlags.NonPublic);
            UIButton  Marquee = fb.GetValue(UIToolOptionPanel.instance) as UIButton;

            Single.zOrder  = 7;
            Marquee.zOrder = 7;

            UIToolOptionPanel.instance.m_filtersPanelList.height = 240f;

            // @TODO - Make this modular, please! I need to put more buttons here later and I need to make a single singleton manager for all of my mods.
            UIPanel extraToolBackground = AlignToolsPanel.AddUIComponent <UIPanel>();

            extraToolBackground.size             = new Vector2(26, 70);
            extraToolBackground.clipChildren     = true;
            extraToolBackground.relativePosition = new Vector3(5, -37);
            extraToolBackground.backgroundSprite = "InfoPanelBack";
            extraToolBackground.name             = "ElektrixModsMenu";
            extraToolBackground.zOrder           = 0;

            AlignTools.tooltip = "More Tools";

            UIToolOptionPanel.instance.clipChildren = false;
            UIComponent[] t = UIToolOptionPanel.instance.GetComponentsInChildren <UIPanel>();
            for (int i = 0; i < t.Length; i++)
            {
                t[i].clipChildren = false;
            }


            UIMultiStateButton propPickerButton = AlignToolsPanel.AddUIComponent <UIMultiStateButton>();

            propPickerButton.name            = "PropPickerButton";
            propPickerButton.tooltip         = "Prop Painter";
            propPickerButton.spritePadding   = new RectOffset(2, 2, 2, 2);
            propPickerButton.playAudioEvents = true;

            propPickerButton.relativePosition = new Vector3(0, -45);

            var GetIconsAtlas = typeof(UIToolOptionPanel).GetMethod("GetIconsAtlas", BindingFlags.Instance | BindingFlags.NonPublic);

            propPickerButton.atlas = GetIconsAtlas.Invoke(UIToolOptionPanel.instance, new object[] { }) as UITextureAtlas;

            propPickerButton.backgroundSprites.AddState();
            propPickerButton.foregroundSprites.AddState();

            propPickerButton.backgroundSprites[0].normal   = "OptionBase";
            propPickerButton.backgroundSprites[0].focused  = "OptionBase";
            propPickerButton.backgroundSprites[0].hovered  = "OptionBaseHovered";
            propPickerButton.backgroundSprites[0].pressed  = "OptionBasePressed";
            propPickerButton.backgroundSprites[0].disabled = "OptionBaseDisabled";

            propPickerButton.foregroundSprites[0].normal = "EyeDropper";

            propPickerButton.backgroundSprites[1].normal   = "OptionBaseFocused";
            propPickerButton.backgroundSprites[1].focused  = "OptionBaseFocused";
            propPickerButton.backgroundSprites[1].hovered  = "OptionBaseHovered";
            propPickerButton.backgroundSprites[1].pressed  = "OptionBasePressed";
            propPickerButton.backgroundSprites[1].disabled = "OptionBaseDisabled";

            propPickerButton.foregroundSprites[1].normal = "EyeDropper";

            propPickerButton.size             = new Vector2(36, 36);
            propPickerButton.activeStateIndex = 0;


            propPickerButton.eventClicked += (component, eventParam) => {
                Db.l("Button state " + propPickerButton.activeStateIndex);
                pickerPanel.isVisible = propPickerButton.activeStateIndex == 1;
                UIToolOptionPanel.instance.m_filtersPanelList.height = 240f;
                Db.w("Tried to make color picker visible/invisible");
            };

            Db.l("Prop Picker button instantiated");


            PropPainterManager.instance.colorField        = field;
            PropPainterManager.instance.colorPicker       = picker;
            PropPainterManager.instance.propPainterButton = propPickerButton;
            PropPainterManager.instance.colorPanel        = pickerPanel;
        }