Example #1
0
        private void CheckAndAddChange(List <SourceUpdate> updates, Dom.Element item, string itemsrc, string ObjectRelativeUrl)
        {
            if (string.IsNullOrEmpty(itemsrc))
            {
                return;
            }

            if (DomUrlService.IsExternalLink(itemsrc))
            {
                return;
            }

            string RelativeUrl = Kooboo.Lib.Helper.UrlHelper.Combine(ObjectRelativeUrl, itemsrc);

            if (RelativeUrl != null)
            {
                RelativeUrl = System.Net.WebUtility.UrlDecode(RelativeUrl);
            }

            if (itemsrc != RelativeUrl)
            {
                string oldstring = Kooboo.Sites.Service.DomService.GetOpenTag(item);
                string newstring = oldstring.Replace(itemsrc, RelativeUrl);

                updates.Add(new SourceUpdate()
                {
                    StartIndex = item.location.openTokenStartIndex,
                    EndIndex   = item.location.openTokenEndIndex,
                    NewValue   = newstring
                });
            }
        }
Example #2
0
        /// <summary>Starts indexing the given attribute right now.</summary>
        public void StartAttributeIndex(string attrib)
        {
            // Create the lookup:
            AttributeLookup lookup = new AttributeLookup();

            // Index the document:
            for (int i = 0; i < childNodes_.length; i++)
            {
                Dom.Element e = childNodes_[i] as Dom.Element;

                if (e == null)
                {
                    continue;
                }

                e.AddToAttributeLookup(attrib, lookup);
            }

            if (lookup.Count == 0)
            {
                // Well.. that was pointless! Nothing to actually index!
                return;
            }

            if (AttributeIndex == null)
            {
                // Create the index now:
                AttributeIndex = new Dictionary <string, AttributeLookup>();
            }

            AttributeIndex[attrib] = lookup;
        }
        /// <summary>Adds this element to the given attribute lookup.</summary>
        public void AddToAttributeLookup(string attrib, AttributeLookup lookup)
        {
            // Got the attribute?
            string value;

            if (Properties.TryGetValue(attrib, out value))
            {
                lookup.Add(value, this);
            }

            // Any kids got it?
            if (childNodes_ == null)
            {
                return;
            }

            // Add each one..
            for (int i = 0; i < childNodes_.length; i++)
            {
                // Add child elements too:
                Dom.Element el = (childNodes_[i] as Dom.Element);

                if (el == null)
                {
                    // E.g. text node.
                    continue;
                }

                // Add:
                el.AddToAttributeLookup(attrib, lookup);
            }
        }
Example #4
0
        public static void Update(ComputedStyle style)
        {
            // Get the ordinal:
            string ordinal = PowerUI.HtmlOListElement.GetOrdinal(style, true);

            if (ordinal == "")
            {
                // (None). Remove the marker:
                style.RemoveVirtual(MarkerSelector.Priority);
            }
            else
            {
                // Require marker:
                Dom.Element node = style.GetOrCreateVirtual(MarkerSelector.Priority, "span", true) as Dom.Element;

                node.style.display   = "inline-block";
                node.style.width     = "40px";
                node.style.left      = "-40px";
                node.style.textAlign = "right";
                node.style.position  = "-spark-absolute";

                // Write its content now:
                node.innerHTML = ordinal;
            }
        }
Example #5
0
        public static bool RequireRenderLink(Dom.Element hrefElement, Repository.SiteDb SiteDb = null)
        {
            if (hrefElement.hasAttribute(Kooboo.Sites.ConstTALAttributes.href))
            {
                return(true);
            }
            var href = Service.DomUrlService.GetLinkOrSrc(hrefElement);

            if (string.IsNullOrEmpty(href))
            {
                return(false);
            }
            if (href.Contains("{") && href.Contains("}"))
            {
                return(true);
            }

            if (href.StartsWith("/__kb"))
            {
                return(true);
            }

            if (SiteDb == null)
            {
                return(false);
            }

            if (SiteDb.WebSite != null && SiteDb.WebSite.EnableSitePath && SiteDb.WebSite.SitePath != null && SiteDb.WebSite.HasSitePath())
            {
                return(true);
            }

            if (Service.DomUrlService.IsExternalLink(href))
            {
                return(false);
            }

            var route = Routing.ObjectRoute.GetRoute(SiteDb, href);

            if (route == null)
            {
                return(false);
            }

            if (route.Parameters.Count > 0)
            {
                return(true);
            }

            if (route.DestinationConstType == ConstObjectType.Page)
            {
                var page = SiteDb.Pages.Get(route.objectId);
                if (page != null && page.Parameters.Count > 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #6
0
        public void DisplayDetailInfo(GameObject unit)
        {
            UnityEngine.Profiling.Profiler.BeginSample("p DisplayDetailInfo"); // Profiler
            if (unit == null)
            {
                return;
            }

            unitBaseBehaviorComponent = unit.GetComponent <BaseBehavior>();

            // Set health
            foreach (var element in UI.document.getElementsByClassName("unitHealth"))
            {
                element.style.width = new StringBuilder(16).AppendFormat("{0:F0}%", unitBaseBehaviorComponent.health / unitBaseBehaviorComponent.maxHealth * 100).ToString();
            }

            foreach (var element in UI.document.getElementsByClassName("dinamicInfo"))
            {
                element.innerHTML = "";

                BaseBehavior.ResourceType resourseDisplayType = BaseBehavior.ResourceType.None;
                string gatgherInfo = "";
                float  resources   = 0.0f;
                if (unitBaseBehaviorComponent != null && unitBaseBehaviorComponent.resourceHold > 0)
                {
                    resources           = unitBaseBehaviorComponent.resourceHold;
                    resourseDisplayType = unitBaseBehaviorComponent.resourceType;

                    UnitBehavior.ResourceGatherInfo resourceGatherInfo = unit.GetComponent <UnitBehavior>().GetResourceFarmByType(unitBaseBehaviorComponent.interactType, resourseDisplayType);
                    gatgherInfo = new StringBuilder(30).AppendFormat(" ({0:F2} per second. Maximum: {1:F1})", resourceGatherInfo.gatherPerSecond, resourceGatherInfo.maximumCapacity).ToString();
                }
                else if (unitBaseBehaviorComponent.resourceCapacity > 0)
                {
                    resources           = unitBaseBehaviorComponent.resourceCapacity;
                    resourseDisplayType = unitBaseBehaviorComponent.resourceCapacityType;
                }
                if (resourseDisplayType != BaseBehavior.ResourceType.None)
                {
                    Dom.Element statusticDiv = UI.document.createElement("p");
                    if (resourseDisplayType == BaseBehavior.ResourceType.Food)
                    {
                        statusticDiv.innerHTML = new StringBuilder(50).AppendFormat("Food: {0:F0} {1}", resources, gatgherInfo).ToString();
                    }
                    else if (resourseDisplayType == BaseBehavior.ResourceType.Gold)
                    {
                        statusticDiv.innerHTML = new StringBuilder(50).AppendFormat("Gold: {0:F0} {1}", resources, gatgherInfo).ToString();
                    }
                    else if (resourseDisplayType == BaseBehavior.ResourceType.Wood)
                    {
                        statusticDiv.innerHTML = new StringBuilder(50).AppendFormat("Wood: {0:F0} {1}", resources, gatgherInfo).ToString();
                    }
                    element.appendChild(statusticDiv);
                }
            }
            UnityEngine.Profiling.Profiler.EndSample(); // Profiler
        }
Example #7
0
        public override bool TryMatch(Dom.Node context)
        {
            // Tag match?
            Dom.Element el = context as Dom.Element;

            if (el == null)
            {
                return(false);
            }

            return(el.Tag == Text || (el.Tag == null && Text == "span"));
        }
Example #8
0
        public void UpdateQueue(GameObject unit = null)
        {
            UnityEngine.Profiling.Profiler.BeginSample("p UpdateQueue"); // Profiler
            if (unit != null)
            {
                unitBaseBehaviorComponent = unit.GetComponent <BaseBehavior>();
            }

            DeleteQueue();

            if (unit != null && unitBaseBehaviorComponent.productionQuery.Count > 0)
            {
                var info = UI.document.getElementsByClassName("infoBlock")[0];

                Dom.Element infoDiv = UI.document.createElement("div");
                infoDiv.className = "query clckable";
                info.appendChild(infoDiv);

                var index = 0;
                foreach (var unitQueue in unitBaseBehaviorComponent.productionQuery)
                {
                    BaseBehavior    skillBaseBehaviorComponent = unitQueue.GetComponent <BaseBehavior>();
                    BaseSkillScript skillScript = unitQueue.GetComponent <BaseSkillScript>();

                    string imagePath   = "";
                    float  timeToBuild = 0.0f;
                    if (skillBaseBehaviorComponent != null)
                    {
                        imagePath   = skillBaseBehaviorComponent.skillInfo.imagePath;
                        timeToBuild = skillBaseBehaviorComponent.skillInfo.timeToBuild;
                    }
                    if (skillScript != null)
                    {
                        imagePath   = skillScript.skillInfo.imagePath;
                        timeToBuild = skillScript.skillInfo.timeToBuild;
                    }

                    object createdObject = UI.document.Run("CreateQueueElement", imagePath, index, timeToBuild, unitBaseBehaviorComponent.buildTimer);
                    index += 1;
                    HtmlElement createdQueue = (HtmlElement)((Jint.Native.JsValue)createdObject).ToObject();
                    createdQueue.onmousedown = RemoveQueueElementFromSelected;
                }
            }
            UnityEngine.Profiling.Profiler.EndSample(); // Profiler
        }
Example #9
0
        public static void CreateOrUpdateCameraOnMap(Dom.Element mapBlock, Dom.Element mapImage)
        {
            //var blindFog = (HtmlElement)mapBlock.getElementsByClassName("blindFog")[0];
            TerrainGenerator terrainGenerator = Terrain.activeTerrain.GetComponent <TerrainGenerator>();

            //((HtmlElement)blindFog).image = terrainGenerator.blindTexture2D;

            UnityEngine.Profiling.Profiler.BeginSample("p CreateOrUpdateCameraOnMap"); // Profiler
            Vector3 vameraLookAt        = Camera.main.transform.position - new Vector3(Camera.main.transform.forward.normalized.x, 0, Camera.main.transform.forward.normalized.z) * CameraController.GetCameraOffset();
            bool    isCameraInTerrain   = IsInTerrainRange(vameraLookAt);
            float   cameraScale         = 20.0f / (Terrain.activeTerrain.terrainData.size.x / 50.0f / 4.0f);
            float   cameraHeight        = cameraScale / 1.2f;
            float   cameraWidtht        = cameraScale;
            Vector2 positionCameraOnMap = GetPositionOnMap(vameraLookAt);

            cameraDiv = null;
            if (isCameraInTerrain)
            {
                if (mapBlock.getElementsByClassName("mapCamera").length <= 0)
                {
                    cameraDiv              = UI.document.createElement("div");
                    cameraDiv.className    = "mapCamera clckable";
                    cameraDiv.style.height = new StringBuilder(7).AppendFormat("{0}%", cameraHeight).ToString();
                    cameraDiv.style.width  = new StringBuilder(7).AppendFormat("{0}%", cameraWidtht).ToString();
                    mapBlock.appendChild(cameraDiv);
                }
                else
                {
                    cameraDiv = mapBlock.getElementsByClassName("mapCamera")[0];
                }

                if (cameraDiv != null)
                {
                    cameraDiv.style.left      = new StringBuilder(7).AppendFormat("{0}%", positionCameraOnMap.x * 100.0f).ToString();
                    cameraDiv.style.bottom    = new StringBuilder(7).AppendFormat("{0}%", positionCameraOnMap.y * 100.0f).ToString();
                    cameraDiv.style.transform = new StringBuilder(30).AppendFormat("rotate({0}deg) translate(-50%,-50%)", Camera.main.transform.rotation.eulerAngles.y).ToString();
                }
            }
            else if (mapBlock.getElementsByClassName("mapCamera").length <= 0)
            {
                cameraDiv = mapBlock.getElementsByClassName("mapCamera")[0];
                cameraDiv.remove();
            }
            UnityEngine.Profiling.Profiler.EndSample(); // Profiler
        }
Example #10
0
        /// <summary>
        /// Tidies up any event handlers added by cue nodes.
        /// </summary>
        public void clearCues()
        {
            if (cueElements == null)
            {
                return;
            }

            foreach (CueElementData ced in cueElements)
            {
                Dom.Element node = ced.target;

                // Remove it:
                node.removeEventListener(ced.eventName, ced.eventListener);
            }

            // Ok!
            cueElements = null;
        }
Example #11
0
        private void GetPosition(Dom.Element element, ref List <string> positions)
        {
            foreach (var item in element.attributes)
            {
                var lower = item.name.ToLower();
                if (lower == "tal-placeholder" || lower == "position" || lower == "placeholder" || lower == "k-placeholder")
                {
                    string value = item.value;
                    if (!positions.Contains(value))
                    {
                        positions.Add(value);
                    }
                }
            }

            foreach (var item in element.childNodes.item)
            {
                if (item is Dom.Element)
                {
                    GetPosition(item as Dom.Element, ref positions);
                }
            }
        }
Example #12
0
        public bool DisplayDescription(string className, List <SkillInfo> skillUIImages = null)
        {
            UnityEngine.Profiling.Profiler.BeginSample("p DisplayDescription"); // Profiler
            foreach (SkillInfo skillUIImage in checkedUIImages)
            {
                if (className.Contains(skillUIImage.uniqueName))
                {
                    if (descriptionActiveClass == skillUIImage.uniqueName)
                    {
                        return(true);
                    }

                    if (descriptionActiveClass != "" && descriptionActiveClass != skillUIImage.uniqueName)
                    {
                        DestroyDescription();
                    }

                    var         containerDescription = UI.document.getElementsByClassName("containerDescription")[0];
                    Dom.Element altInfo = UI.document.createElement("div");
                    altInfo.className = new StringBuilder(30).AppendFormat("content altInfo {0}", skillUIImage.uniqueName).ToString();
                    containerDescription.appendChild(altInfo);
                    DrawInfo("altInfo", skillUIImage, drawImage: false, detailInfo: true);
                    descriptionActiveClass = skillUIImage.uniqueName;
                    return(true);
                }
            }
            foreach (var skillElement in skillsCache)
            {
                unitBaseBehaviorComponent = skillElement.Key.GetComponent <BaseBehavior>();
                skillScript = skillElement.Key.GetComponent <BaseSkillScript>();

                SkillInfo skillInfo = null;
                if (unitBaseBehaviorComponent != null)
                {
                    skillInfo       = unitBaseBehaviorComponent.skillInfo;
                    costInfo        = unitBaseBehaviorComponent.GetCostInformation().ToArray();
                    tableStatistics = unitBaseBehaviorComponent.GetStatistics().ToArray();
                }
                if (skillScript != null)
                {
                    skillInfo       = skillScript.skillInfo;
                    costInfo        = skillScript.GetCostInformation().ToArray();
                    tableStatistics = skillScript.GetStatistics().ToArray();
                }

                if (className.Contains(skillInfo.uniqueName))
                {
                    if (descriptionActiveClass == skillInfo.uniqueName)
                    {
                        return(true);
                    }

                    if (descriptionActiveClass != "" && descriptionActiveClass != skillInfo.uniqueName)
                    {
                        DestroyDescription();
                    }

                    skillErrorInfo = BaseSkillScript.GetSkillErrorInfo(skillElement.Value, skillElement.Key);

                    var         containerDescription = UI.document.getElementsByClassName("containerDescription")[0];
                    Dom.Element altInfo = UI.document.createElement("div");
                    altInfo.className = "content altInfo";
                    containerDescription.appendChild(altInfo);

                    DrawInfo("altInfo", skillInfo, drawImage: false, detailInfo: true,
                             errorMessage: skillErrorInfo.errorMessage,
                             tableStatistics: tableStatistics,
                             costInfo: costInfo);

                    displayedNames.Add(skillInfo.uniqueName);
                    descriptionActiveClass = skillInfo.uniqueName;
                    return(true);
                }
            }
            UnityEngine.Profiling.Profiler.EndSample(); // Profiler
            return(false);
        }
Example #13
0
 /// <summary>Creates a new element style for the given element.</summary>
 /// <param name="element">The element that this will be the style for.</param>
 public ElementStyle(Dom.Element element) : base(element)
 {
     Computed = new ComputedStyle(element);
 }
Example #14
0
        public static void CreateOrUpdateMaps(ref Dictionary <HtmlElement, HtmlElement> mapCache, bool update = false)
        {
            if (update)
            {
                UpdateMaps();

                cacheUnitDivs.Clear();
            }
            mapCache.Clear();

            CameraController cameraController = Camera.main.GetComponent <CameraController>();
            int index = 0;

            foreach (var mapBlock in mapBlocks)
            {
                // Draw map
                if (cameraController.terrainGenerator != null)
                {
                    if (((HtmlElement)mapBlock).image == null && cameraController.terrainGenerator.mapTexture != null)
                    {
                        ((HtmlElement)mapBlock).image = cameraController.terrainGenerator.mapTexture;
                        mapBlock.style.height         = "100%";
                        mapBlock.style.width          = "100%";
                    }
                }
                else
                {
                    mapBlock.style.backgroundImage = String.Format("{0}.png", SceneManager.GetActiveScene().name);
                }

                mapImage = (HtmlElement)mapBlock.getElementsByClassName("mapVision")[0];
                mapCache.Add((HtmlElement)mapBlock, mapImage);

                if (mapImage.image == null && cameraController.terrainGenerator.mapTexture != null && cameraController.mapTexture.height > 0)
                {
                    mapImage.image        = cameraController.mapTexture;
                    mapImage.style.height = "100%";
                    mapImage.style.width  = "100%";
                }

                blindFog = (HtmlElement)mapBlock.getElementsByClassName("blindFog")[0];
                if (blindFog.image == null && cameraController.terrainGenerator.blindTexture2D != null && cameraController.terrainGenerator.blindTexture2D.height > 0)
                {
                    blindFog.image        = cameraController.terrainGenerator.blindTexture;
                    blindFog.style.height = "100%";
                    blindFog.style.width  = "100%";
                }

                unitsBlock = (HtmlElement)mapBlock.getElementsByClassName("units")[0];
                if (update)
                {
                    unitsBlock.innerHTML = "";
                }

                // Draw units + calculate statistic
                foreach (GameObject unit in GameObject.FindGameObjectsWithTag("Unit"))
                {
                    if (unit.GetComponent <BaseBehavior>().IsDisplayOnMap() && IsInTerrainRange(unit.transform.position))
                    {
                        if (!update && cacheUnitDivs.ContainsKey(unit) && cacheUnitDivs[unit].Count > index)
                        {
                            unitDiv = cacheUnitDivs[unit][index];
                        }
                        else
                        {
                            unitDiv           = UI.document.createElement("div");
                            unitDiv.className = "unit clckable";
                            // unitDiv.id = unit.GetComponent<PhotonView>().ViewID.ToString();
                            unitsBlock.appendChild(unitDiv);

                            if (!cacheUnitDivs.ContainsKey(unit))
                            {
                                cacheUnitDivs[unit] = new List <Dom.Element>();
                            }

                            cacheUnitDivs[unit].Add(unitDiv);
                        }

                        Vector2 positionOnMap = GetPositionOnMap(unit.transform.position);
                        unitDiv.style.left            = new StringBuilder(5).AppendFormat("{0}%", positionOnMap.x * 100.0f - 1.5).ToString();
                        unitDiv.style.bottom          = new StringBuilder(5).AppendFormat("{0}%", positionOnMap.y * 100.0f - 1.5).ToString();
                        unitDiv.style.backgroundColor = unit.GetComponent <BaseBehavior>().GetDisplayColor();
                    }
                    else if (cacheUnitDivs.ContainsKey(unit) && cacheUnitDivs[unit].Count > index)
                    {
                        unitDiv = cacheUnitDivs[unit][index];
                        unitsBlock.removeChild(unitDiv);
                    }
                }
                index++;
            }
        }
 public AttributeLookupLink(Element element)
 {
     Element = element;
 }