public void AddToMultiList()
        {
            string existingValue = "Pre;Post";
            string fxToAdd       = "One";
            string postValue     = "Pre;Post;One";

            string newValue = FXUtils.AddFXToList(existingValue, fxToAdd);

            Assert.AreEqual(postValue, newValue);

            // make sure the cache returns the same value
            newValue = FXUtils.AddFXToList(existingValue, fxToAdd);
            Assert.AreEqual(postValue, newValue);
        }
        public void RemoveFromMultiList()
        {
            string existingValue = "Pre;One;Post";
            string fxToRemove    = "One";
            string postValue     = "Pre;Post";

            string newValue = FXUtils.RemoveFXFromList(existingValue, fxToRemove);

            Assert.AreEqual(postValue, newValue);

            // make sure the cache returns the same value
            newValue = FXUtils.RemoveFXFromList(existingValue, fxToRemove);
            Assert.AreEqual(postValue, newValue);
        }
Exemplo n.º 3
0
        public void CreateAndAttachFXToEntity(Entity entity, string assetName, string attachmentKey, FXManager.AttachedFXLoadedCallback callback, bool pinToCenterOfMass, Vector3 offset, bool applyRotation)
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            dictionary["assetName"]     = assetName;
            dictionary["entity"]        = entity;
            dictionary["attachmentKey"] = attachmentKey;
            dictionary["assetKey"]      = FXUtils.MakeAssetKey(attachmentKey, entity);
            dictionary["callback"]      = callback;
            dictionary["centerOfMass"]  = pinToCenterOfMass;
            dictionary["coords"]        = offset;
            dictionary["rotation"]      = applyRotation;
            this.CreateAndAttachFXEntityInternal(assetName, dictionary);
        }
Exemplo n.º 4
0
        public void StopParticlesAndRemoveAttachedFXFromEntity(Entity entity, string attachmentKey)
        {
            if (entity == null)
            {
                return;
            }
            GameObjectViewComponent gameObjectViewComponent = entity.Get <GameObjectViewComponent>();

            if (gameObjectViewComponent == null)
            {
                return;
            }
            string     text = FXUtils.MakeAssetKey(attachmentKey, entity);
            GameObject attachedGameObject = gameObjectViewComponent.GetAttachedGameObject(attachmentKey);

            if (attachedGameObject != null)
            {
                float            delay = 0f;
                ParticleSystem[] componentsInChildren = attachedGameObject.GetComponentsInChildren <ParticleSystem>(true);
                if (componentsInChildren != null && componentsInChildren.Length > 0)
                {
                    delay = 5f;
                    int i   = 0;
                    int num = componentsInChildren.Length;
                    while (i < num)
                    {
                        componentsInChildren[i].Stop(false);
                        i++;
                    }
                }
                Dictionary <string, object> dictionary = new Dictionary <string, object>();
                dictionary["entity"]        = entity;
                dictionary["attachmentKey"] = attachmentKey;
                dictionary["assetKey"]      = text;
                dictionary["gameObject"]    = attachedGameObject;
                if (this.activeTimers.ContainsKey(text))
                {
                    Service.ViewTimerManager.KillViewTimer(this.activeTimers[text]);
                    this.activeTimers.Remove(text);
                }
                uint value = Service.ViewTimerManager.CreateViewTimer(delay, false, new TimerDelegate(this.RemoveAttachedFXFromEntityAfterDelay), dictionary);
                this.activeTimers.Add(text, value);
            }
            else
            {
                this.UnloadByAssetKey(text);
            }
        }
Exemplo n.º 5
0
        public override Color GetCurrentLightingColor(LightingColorType type)
        {
            if (this.planetVO == null)
            {
                return(this.defaultColor);
            }
            DefaultLightingVO defaultLightingVO = Service.Get <IDataController>().Get <DefaultLightingVO>(this.planetVO.PlanetaryLighting);
            string            hexColor          = "";

            switch (type)
            {
            case LightingColorType.BuildingColorDark:
                hexColor = defaultLightingVO.LightingColorDark;
                break;

            case LightingColorType.BuildingColorLight:
                hexColor = defaultLightingVO.LightingColorLight;
                break;

            case LightingColorType.UnitColor:
                hexColor = defaultLightingVO.LightingColorMedian;
                break;

            case LightingColorType.ShadowColor:
                hexColor = defaultLightingVO.LightingColorShadow;
                break;

            case LightingColorType.GroundColor:
                hexColor = defaultLightingVO.LightingColorGround;
                break;

            case LightingColorType.GroundColorLight:
                hexColor = defaultLightingVO.LightingColorGroundLight;
                break;

            case LightingColorType.GridColor:
                hexColor = defaultLightingVO.LightingColorGrid;
                break;

            case LightingColorType.WallGridColor:
                hexColor = defaultLightingVO.LightingColorWallGrid;
                break;
            }
            return(FXUtils.ConvertHexStringToColorObject(hexColor));
        }
Exemplo n.º 6
0
        public void CreateFXAtPosition(string assetName, Vector3 worldPos, Quaternion rotation)
        {
            string text = FXUtils.MakeAssetKey(assetName, worldPos);

            if (!this.EnsureUniqueFX(text, assetName, worldPos))
            {
                return;
            }
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            dictionary["assetName"] = assetName;
            dictionary["coords"]    = worldPos;
            dictionary["rotation"]  = rotation;
            AssetHandle value = AssetHandle.Invalid;

            Service.Get <AssetManager>().Load(ref value, assetName, new AssetSuccessDelegate(this.OnFXWithPositionLoaded), null, dictionary);
            this.assetHandles.Add(text, value);
        }
Exemplo n.º 7
0
        public void RemoveAttachedFXFromEntity(Entity entity, string attachmentKey)
        {
            GameObjectViewComponent gameObjectViewComponent = null;

            if (entity != null)
            {
                gameObjectViewComponent = entity.Get <GameObjectViewComponent>();
            }
            if (gameObjectViewComponent != null)
            {
                GameObject attachedGameObject = gameObjectViewComponent.GetAttachedGameObject(attachmentKey);
                if (attachedGameObject != null)
                {
                    gameObjectViewComponent.DetachGameObject(attachmentKey);
                    this.fxInstances.Remove(attachedGameObject);
                    UnityEngine.Object.Destroy(attachedGameObject);
                }
            }
            string assetKey = FXUtils.MakeAssetKey(attachmentKey, entity);

            this.UnloadByAssetKey(assetKey);
        }
Exemplo n.º 8
0
        public void CreateDestructionFX(SmartEntity entity, bool isBuilding)
        {
            string debrisAssetNameForEntity = FXUtils.GetDebrisAssetNameForEntity(entity, isBuilding);

            if (debrisAssetNameForEntity != null)
            {
                GameObjectViewComponent gameObjectViewComp = entity.GameObjectViewComp;
                if (gameObjectViewComp == null)
                {
                    return;
                }
                Vector3 position = gameObjectViewComp.MainTransform.position;
                Vector3 vector   = new Vector3(position.x, 0f, position.z);
                if (!isBuilding)
                {
                    GameObject centerOfMass = gameObjectViewComp.CenterOfMass;
                    if (centerOfMass != null)
                    {
                        Vector3 position2 = centerOfMass.transform.position;
                        vector = new Vector3(position2.x, position2.y, position2.z);
                    }
                }
                string text = FXUtils.MakeAssetKey(debrisAssetNameForEntity, vector);
                if (!this.EnsureUniqueFX(text, debrisAssetNameForEntity, vector))
                {
                    return;
                }
                Dictionary <string, object> dictionary = new Dictionary <string, object>();
                dictionary["assetName"] = debrisAssetNameForEntity;
                dictionary["coords"]    = vector;
                dictionary["assetKey"]  = text;
                AssetHandle value = AssetHandle.Invalid;
                Service.Get <AssetManager>().Load(ref value, debrisAssetNameForEntity, new AssetSuccessDelegate(this.OnDestructionFXLoaded), null, dictionary);
                this.assetHandles.Add(text, value);
            }
        }
Exemplo n.º 9
0
        public static void AddFrameworkToElement(this XmlElement element, FrameworkEntry framework)
        {
            var fxaValue = FXUtils.AddFXToList(element.GetAttribute(Consts.FrameworkAlternate), framework.Name);

            element.SetAttribute(Consts.FrameworkAlternate, fxaValue);
        }
Exemplo n.º 10
0
        public static void MakeParameters(XmlElement root, MemberReference member, IList <ParameterDefinition> parameters, FrameworkTypeEntry typeEntry, ref bool fxAlternateTriggered)
        {
            XmlElement e = DocUtils.WriteElement(root, "Parameters");

            /// addParameter does the work of adding the actual parameter to the XML
            Action <ParameterDefinition, XmlElement, string, int, bool, string, bool> addParameter = (ParameterDefinition param, XmlElement nextTo, string paramType, int index, bool addIndex, string fx, bool addfx) =>
            {
                var pe = root.OwnerDocument.CreateElement("Parameter");

                if (nextTo == null)
                {
                    e.AppendChild(pe);
                }
                else
                {
                    e.InsertAfter(pe, nextTo);
                }

                pe.SetAttribute("Name", param.Name);
                pe.SetAttribute("Type", paramType);
                if (param.ParameterType is ByReferenceType)
                {
                    if (param.IsOut)
                    {
                        pe.SetAttribute("RefType", "out");
                    }
                    else
                    {
                        pe.SetAttribute("RefType", "ref");
                    }
                }
                if (addIndex)
                {
                    pe.SetAttribute("Index", index.ToString());
                }
                if (addfx)
                {
                    pe.SetAttribute(Consts.FrameworkAlternate, fx);
                }

                MakeAttributes(pe, GetCustomAttributes(param.CustomAttributes, ""));
            };

            /// addFXAttributes, adds the index attribute to all existing elements.
            /// Used when we first detect the scenario which requires this.
            Action <XmlNodeList> addFXAttributes = nodes =>
            {
                var i = 0;
                foreach (var node in nodes.Cast <XmlElement> ())
                {
                    node.SetAttribute("Index", i.ToString());
                    i++;
                }
            };

            int parameterIndex       = 0;
            int parameterIndexOffset = 0;

            var  paramNodes = e.GetElementsByTagName("Parameter");
            bool inFXMode   = frameworksCache.Frameworks.Count() > 1;

            foreach (ParameterDefinition p in parameters)
            {
                var ptype = GetDocParameterType(p.ParameterType);
                if (parameterIndex >= paramNodes.Count)
                {
                    // this parameter hasn't been added yet
                    bool hasParameterName = string.IsNullOrWhiteSpace(p.Name);
                    addParameter(p, null, ptype, parameterIndex, false, "", false);
                }
                else // there's enough nodes, see if it truly exists
                {
                    //look for < parameter > that matches position
                    XmlElement parameterNode = e.ChildNodes[parameterIndex + parameterIndexOffset] as XmlElement;


                    if (parameterNode != null)
                    {
                        //Assert Type Matches (if not, throw?)
                        if (parameterNode.HasAttribute("Name") && parameterNode.Attributes["Name"].Value == p.Name)
                        {
                            // we're good, continue on.
                        }
                        else
                        { // name doesn't match
                            if (parameterNode.HasAttribute("Index"))
                            {
                                // TODO: add a FrameworkAlternate check, and set offset correctly
                                int pindex;
                                if (int.TryParse(parameterNode.GetAttribute("Index"), out pindex) && pindex < parameterIndex)
                                {
                                    parameterIndexOffset++;

                                    continue;
                                }
                            }
                            else
                            {
                                if (!inFXMode)
                                {
                                    throw new Exception("shit");
                                }
                                addFXAttributes(paramNodes);
                                //-find type in previous frameworks


                                string fxList = FXUtils.PreviouslyProcessedFXString(typeEntry);

                                //-find < parameter where index = currentIndex >
                                var currentNode = paramNodes[parameterIndex] as XmlElement;
                                currentNode.SetAttribute(Consts.FrameworkAlternate, fxList);

                                addParameter(p, parameterNode, ptype, parameterIndex - parameterIndexOffset, true, typeEntry.Framework.Name, true);
                                parameterIndexOffset++;
                                fxAlternateTriggered = true;
                            }
                        }
                    }
                    else
                    { // no element at this index
                        // TODO: does this ever happen?
                        throw new Exception("This wasn't supposed to happen");
                        //addParameter (p);
                    }

                    /*
                     * - If found
                     * - Assert Type Matches (if not, throw?)
                     *  -If Name Matches …
                     *      - if “FrameworkAlternate”
                     *          -Add typeEntry.Framework.Name to list
                     *     - done!
                     * -Else (exists, but name doesn’t match … FrameworkAlternate path)
                     *     - check if inFXMode if not, throw
                     *     -AddFXParameters
                     *         - adds Index to all existing<parameters
                     *          -find type in previous frameworks
                     *          -find < parameter where index = currentIndex >
                     *          -Add FrameworkAlternate = allPreviousFrameworks and Index = currentIndex
                     *     - Add new node with Index = currentIndex
                     * - else not found
                     *  -add
                     */
                }
                parameterIndex++;
            }
            //-purge `typeEntry.Framework` from any<parameter> that
            // has FrameworkAlternate, and “name” doesn’t match any
            // `parameters`
            var alternates = paramNodes
                             .Cast <XmlElement> ()
                             .Select(p => new
            {
                Element            = p,
                Name               = p.GetAttribute("Name"),
                FrameworkAlternate = p.GetAttribute(Consts.FrameworkAlternate)
            })
                             .Where(p =>
                                    !string.IsNullOrWhiteSpace(p.FrameworkAlternate) &&
                                    p.FrameworkAlternate.Contains(typeEntry.Framework.Name) &&
                                    !parameters.Any(param => param.Name == p.Name))
                             .ToArray();

            if (alternates.Any())
            {
                foreach (var a in alternates)
                {
                    string newValue = FXUtils.RemoveFXFromList(a.FrameworkAlternate, typeEntry.Framework.Name);
                    if (string.IsNullOrWhiteSpace(newValue))
                    {
                        a.Element.RemoveAttribute(Consts.FrameworkAlternate);
                    }
                    else
                    {
                        a.Element.SetAttribute(Consts.FrameworkAlternate, newValue);
                    }
                }
            }

            return;

            /*
             * // old code
             * foreach (ParameterDefinition p in parameters)
             * {
             *  XmlElement pe;
             *
             *  // param info
             *  var ptype = GetDocParameterType (p.ParameterType);
             *  var newPType = ptype;
             *
             *  if (MDocUpdater.SwitchingToMagicTypes)
             *  {
             *      newPType = NativeTypeManager.ConvertFromNativeType (ptype);
             *  }
             *
             *  // now find the existing node, if it's there so we can reuse it.
             *  var nodes = root.SelectSingleNode ("Parameters").SelectNodes ("Parameter")
             *      .Cast<XmlElement> ().Where (x => x.GetAttribute ("Name") == p.Name)
             *      .ToArray ();
             *
             *  // FYI: Exists? No?
             *  if (nodes.Count () == 0)
             *  {
             *      // TODO: instead of this. Needs to be replaced with a better
             *      // check for Parameter index ... should I add parameter index?
             *
             *      // are we in frameworks mode?
             *      // add Index to all existing parameter nodes if they don't have them
             *      // match existing to position and type
             *      bool _inFXMode = typeEntry.Framework.Frameworks.Count () > 1;
             *
             *      // when I find the one, name won't match ...
             *
             *      //  find all "previous" frameworks
             *      //  Add FrameworkAlternate with previous frameworks to found/pre-existing node
             *      var allPreviousTypes_ = typeEntry.Framework.Frameworks
             *                              .Where (f => f.index < typeEntry.Framework.index)
             *                              .Select (f => f.FindTypeEntry (typeEntry))
             *                              .ToArray ();
             *
             *      var allPreviousFrameworks = allPreviousTypes.Value.Select (previous => previous.Framework.Name).ToArray ();
             *      string fxList = string.Join (";", allPreviousFrameworks);
             *
             *      // find the parameters in `root` that have an index == this parameter's index
             *      // if they don't match, then we need to make a new one for this
             *
             *      // Create new "Parameter" node, with FrameworkAlternate = this
             *
             *      // Legacy: wasn't found, let's make sure it wasn't just cause the param name was changed
             *      nodes = root.SelectSingleNode ("Parameters").SelectNodes ("Parameter")
             *          .Cast<XmlElement> ()
             *          .Skip (parameterIndex) // this makes sure we don't inadvertently "reuse" nodes when adding new ones
             *          .Where (x => x.GetAttribute ("Name") != p.Name && (x.GetAttribute ("Type") == ptype || x.GetAttribute ("Type") == newPType))
             *          .Take (1) // there might be more than one that meets this parameter ... only take the first.
             *          .ToArray ();
             *  }
             *
             *  AddXmlNode (nodes,
             *      x => x.GetAttribute ("Type") == ptype,
             *      x => x.SetAttribute ("Type", ptype),
             *      () =>
             *      {
             *          pe = root.OwnerDocument.CreateElement ("Parameter");
             *          e.AppendChild (pe);
             *
             *          pe.SetAttribute ("Name", p.Name);
             *          pe.SetAttribute ("Type", ptype);
             *          if (p.ParameterType is ByReferenceType)
             *          {
             *              if (p.IsOut)
             *                  pe.SetAttribute ("RefType", "out");
             *              else
             *                  pe.SetAttribute ("RefType", "ref");
             *          }
             *
             *          MakeAttributes (pe, GetCustomAttributes (p.CustomAttributes, ""));
             *          return pe;
             *      },
             *      member);
             *
             *  parameterIndex++;
             * }
             *
             * // TODO: was there a `Parameter` that we didn't process that has FrameworkAlternate?
             * // if yes, remove this framework from that FrameworkAlternate
             * // if that makes the list empty, remove the node and corresponding /Docs/parameter node
             */
        }
Exemplo n.º 11
0
        public void RemoveFromList()
        {
            string newValue = FXUtils.RemoveFXFromList("One", "One");

            Assert.AreEqual("", newValue);
        }
Exemplo n.º 12
0
        public void AddToEmptyList()
        {
            string newValue = FXUtils.AddFXToList("", "One");

            Assert.AreEqual("One", newValue);
        }
        public void AddDupeToExistingList()
        {
            string newValue = FXUtils.AddFXToList("One", "One");

            Assert.AreEqual("One", newValue);
        }
Exemplo n.º 14
0
        private void SetupStickerVisuals(StoreTab tab, StickerVO vo)
        {
            string      text            = string.Format("Texture{0}Icon", tab.ToString());
            string      name            = string.Format("Widget{0}Special", tab.ToString());
            string      text2           = string.Format("SpriteBannerGradient{0}Special", tab.ToString());
            string      text3           = string.Format("SpriteBanner{0}Special", tab.ToString());
            string      text4           = string.Format("LabelSee{0}Deals", tab.ToString());
            string      text5           = string.Format("SpriteSee{0}DealsStroke", tab.ToString());
            string      text6           = string.Format("SpriteSee{0}DealsIcon", tab.ToString());
            string      text7           = string.Format("SpriteBkgStrokeTab{0}", tab.ToString());
            string      text8           = string.Format("SpriteBkgDetailRightTab{0}", tab.ToString());
            string      text9           = string.Format("SpriteBkgDetailLeftTab{0}", tab.ToString());
            string      text10          = string.Format("SpriteBkgInnerGlowTab{0}", tab.ToString());
            UXTexture   optionalElement = this.parentStoreScreen.GetOptionalElement <UXTexture>(text);
            FactionType faction         = Service.CurrentPlayer.Faction;

            if (optionalElement != null)
            {
                string text11 = string.Empty;
                if (faction == FactionType.Rebel)
                {
                    text11 = vo.TextureOverrideAssetNameRebel;
                }
                else
                {
                    text11 = vo.TextureOverrideAssetNameEmpire;
                }
                if (!string.IsNullOrEmpty(text11))
                {
                    string assetName = optionalElement.AssetName;
                    this.orginalTextureNames.Add(text, assetName);
                    optionalElement.LoadTexture(text11);
                }
            }
            UXElement optionalElement2 = this.parentStoreScreen.GetOptionalElement <UXElement>(name);

            if (optionalElement2 != null)
            {
                optionalElement2.Visible = true;
            }
            UXSprite optionalElement3 = this.parentStoreScreen.GetOptionalElement <UXSprite>(text2);

            if (optionalElement3 != null && !string.IsNullOrEmpty(vo.GradientColor))
            {
                this.AddOriginalUIColor(text2, optionalElement3.Color);
                optionalElement3.Color = FXUtils.ConvertHexStringToColorObject(vo.GradientColor);
            }
            if (string.IsNullOrEmpty(vo.MainColor))
            {
                return;
            }
            Color    color            = FXUtils.ConvertHexStringToColorObject(vo.MainColor);
            UXSprite optionalElement4 = this.parentStoreScreen.GetOptionalElement <UXSprite>(text3);

            if (optionalElement4 != null)
            {
                this.AddOriginalUIColor(text3, optionalElement4.Color);
                optionalElement4.Color = color;
            }
            UXLabel optionalElement5 = this.parentStoreScreen.GetOptionalElement <UXLabel>(text4);

            if (optionalElement5 != null)
            {
                this.AddOriginalUIColor(text4, optionalElement5.TextColor);
                optionalElement5.TextColor = color;
            }
            UXSprite optionalElement6 = this.parentStoreScreen.GetOptionalElement <UXSprite>(text5);

            if (optionalElement6 != null)
            {
                this.AddOriginalUIColor(text5, optionalElement6.Color);
                optionalElement6.Color = color;
            }
            UXSprite optionalElement7 = this.parentStoreScreen.GetOptionalElement <UXSprite>(text6);

            if (optionalElement7 != null)
            {
                this.AddOriginalUIColor(text6, optionalElement7.Color);
                optionalElement7.Color = color;
            }
            UXSprite optionalElement8 = this.parentStoreScreen.GetOptionalElement <UXSprite>(text7);

            if (optionalElement8 != null)
            {
                this.AddOriginalUIColor(text7, optionalElement8.Color);
                optionalElement8.Color = color;
            }
            Color    color2           = new Color(color.r, color.g, color.b, 0.5f);
            UXSprite optionalElement9 = this.parentStoreScreen.GetOptionalElement <UXSprite>(text8);

            if (optionalElement9 != null)
            {
                this.AddOriginalUIColor(text8, optionalElement9.Color);
                optionalElement9.Color = color2;
            }
            UXSprite optionalElement10 = this.parentStoreScreen.GetOptionalElement <UXSprite>(text9);

            if (optionalElement10 != null)
            {
                this.AddOriginalUIColor(text9, optionalElement10.Color);
                optionalElement10.Color = color2;
            }
            UXSprite optionalElement11 = this.parentStoreScreen.GetOptionalElement <UXSprite>(text10);

            if (optionalElement11 != null)
            {
                this.AddOriginalUIColor(text10, optionalElement11.Color);
                optionalElement11.Color = new Color(color.r, color.g, color.b, 0.4f);
            }
        }