Example #1
0
    public static ICollection <UIStylesheet> GetCustomStylesheets(this UIResource resource, Options options)
    {
        List <UIStylesheet> styleSheets = new List <UIStylesheet>();

        if (!options.CustomStylesheets.Any())
        {
            resource.Content = resource.Content.Replace("#customstylesheets#", string.Empty);
            return(styleSheets);
        }

        foreach (var stylesheet in options.CustomStylesheets)
        {
            styleSheets.Add(UIStylesheet.Create(options, stylesheet));
        }

        var htmlStyles = styleSheets
                         .Select(s =>
        {
            var linkHref = options.UseRelativeResourcesPath ? s.ResourcePath.AsRelativeResource() : s.ResourcePath;
            return($"<link rel='stylesheet' href='{linkHref}'/>");
        });

        resource.Content = resource.Content.Replace(
            "#customstylesheets#",
            string.Join("\n", htmlStyles)
            );

        return(styleSheets);
    }
Example #2
0
        internal IngameMenuWindow(Race setRace)
        {
            curRace = setRace;
            LevelGameScreen.Game.GamePaused = true;

            BackgroundColor = new Microsoft.Xna.Framework.Color(0.3f, 0.0f, 0.0f, 0.5f);

            //Width = background.Width;
            //Height = background.Height;

            UIResource res = WarFile.GetUIResource(setRace == Race.Humans ? 368 : 369);

            background = new UIImage(WWTexture.FromImageResource(WarFile.GetImageResource(res.BackgroundImageResourceIndex)));
            background.InitWithUIResource(res);
            AddComponent(background);

            background.X = 120;
            background.Y = 20;

            continueButton = (UIButton)background.Components [6];
            continueButton.OnMouseUpInside += closeButton_OnMouseUpInside;

            quitButton = (UIButton)background.Components [5];
            quitButton.OnMouseUpInside += quitButton_OnMouseUpInside;

            MouseCursor.State = MouseCursorState.Pointer;
        }
Example #3
0
        internal static UIWindow FromUIResource(UIResource resource)
        {
            UIWindow wnd = new UIWindow();

            wnd.InitWithUIResource(resource);

            return(wnd);
        }
 private static void AddItem(UIResource resources, Type t, int maxUnnamedIndex)
 {
     UIResourceComponentItem[] res = new UIResourceComponentItem[resources.componentItems.Length + 1];
     Array.ConstrainedCopy(resources.componentItems, 0, res, 0, resources.componentItems.Length);
     res [res.Length - 1]          = new UIResourceComponentItem();
     res [res.Length - 1].typeName = t.FullName;
     res [res.Length - 1].key      = DefaultItemName + maxUnnamedIndex;
     resources.componentItems      = res;
 }
    public UIResourceImage GetResourceImage(string resourceLocator)
    {
        if (!UIResourceDBCache.Contains(resourceLocator))
        {
            Debug.Log("Rersource with locator '" + resourceLocator + "' not found!");
            return(null);
        }

        UIResource resource = UIResourceDBCache[resourceLocator] as UIResource;

        return(new UIResourceImage(resource));
    }
Example #6
0
        internal static UIWindow FromUIResource(string name)
        {
            int idx = WarFile.KnowledgeBase.IndexByName(name);

            if (idx == -1)
            {
                return(null);
            }

            UIResource tr = WarFile.GetUIResource(idx);

            return(FromUIResource(tr));
        }
Example #7
0
        internal void InitWithUIResource(string name)
        {
            int idx = WarFile.KnowledgeBase.IndexByName(name);

            if (idx == -1)
            {
                return;
            }

            UIResource tr = WarFile.GetUIResource(idx);

            InitWithUIResource(tr);
        }
Example #8
0
    void InitInventory()
    {
        foreach (ResourceInfo resourceInfo in tm.resourceInfos)
        {
            inventory.Add(0f);

            GameObject newUIResourceObj = (GameObject)Instantiate(uiResourcePrefab, inventoryParent);
            UIResource newUIResource    = newUIResourceObj.GetComponent <UIResource> ();
            newUIResource.Init(resourceInfo);

            inventoryUI.Add(newUIResource);
        }

        ResetInventory();
    }
Example #9
0
 public string this[int idx]
 {
     get
     {
         UIResource value = null;
         _diction.TryGetValue(idx, out value);
         if (value == null)
         {
             return(DefaultDiction.Item(idx));
         }
         else
         {
             return(value.Resource);
         }
     }
 }
    public bool GetBoolContent(string resourceLocator)
    {
        if (!UIResourceDBCache.Contains(resourceLocator))
        {
            Debug.Log("Rersource with locator '" + resourceLocator + "' not found!");
            return(false);
        }

        UIResource resource = UIResourceDBCache[resourceLocator] as UIResource;

        if (resource.contentType != UIContentType.OnOffCommand)
        {
            Debug.Log("Rersource content type '" + resourceLocator + "' not matched!");
            return(false);
        }
        return(resource.onOffCommand);
    }
    public Texture2D GetTextureContent(string resourceLocator)
    {
        if (!UIResourceDBCache.Contains(resourceLocator))
        {
            Debug.Log("Rersource with locator '" + resourceLocator + "' not found!");
            return(null);
        }

        UIResource resource = UIResourceDBCache[resourceLocator] as UIResource;

        if (resource.contentType != UIContentType.Texture2D)
        {
            Debug.Log("Rersource content type '" + resourceLocator + "' not matched!");
            return(null);
        }
        return(resource.texture);
    }
Example #12
0
    void UpdateInventoryUI()
    {
        float leftAnchor = 0f;

        for (int i = 0; i < inventory.Count; i++)
        {
            UIResource uiResource = inventoryUI [i];
            uiResource.amount = inventory[i];
            uiResource.UpdateVisual();

            uiResource.gameObject.GetComponent <RectTransform> ().offsetMin = new Vector2(leftAnchor, 0f);

            if (uiResource.totalWidth > 0)
            {
                leftAnchor += (uiResource.totalWidth + inventoryPadding);
            }
        }
    }
    public void SetContent(string resourceLocator, string par)
    {
        if (!UIResourceDBCache.Contains(resourceLocator))
        {
            Debug.Log("Rersource with locator '" + resourceLocator + "' not found!");
            return;
        }

        UIResource resource = UIResourceDBCache[resourceLocator] as UIResource;

        if (resource.contentType != UIContentType.Text)
        {
            Debug.Log("Rersource content type '" + resourceLocator + "' not matched!");
            return;
        }

        resource.text = par;
    }
Example #14
0
        void BuildDelta()
        {
            if (_delta == null)
            {
                _delta = new List <UIResource>();
            }
            UIResource resource = null;

            foreach (TranslationItem ti in _list)
            {
                resource = null;
                if (ti.ModifiedFrom && _fromLanguageId != -1)
                {
                    _fromUIResources.TryGetValue(ti.ResourceID, out resource);

                    if (resource == null)
                    {
                        resource            = new UIResource();
                        resource.ResourceID = ti.ResourceID;
                        resource.LanguageID = _fromLanguageId;
                    }
                    resource.Resource = ti.NameFrom;
                    _delta.Add(resource);
                }
                resource = null;
                if (ti.ModifiedTo && _toLanguageId != -1)
                {
                    _toUIResources.TryGetValue(ti.ResourceID, out resource);

                    if (resource == null)
                    {
                        resource            = new UIResource();
                        resource.ResourceID = ti.ResourceID;
                        resource.LanguageID = _toLanguageId;
                    }

                    resource.Resource = ti.NameTo;
                    _delta.Add(resource);
                }
            }

            ResetModifyFlag();
        }
        private UIResource UpdateMonitoringToolsTimeLeft(UIResource resourceGroup)
        {
            if (resourceGroup.AppService == AppService.MonitoringTools)
            {
                TimeSpan timeUsed = DateTime.UtcNow - BackgroundQueueManager.MonitoringResourceGroupCheckoutTimes.GetOrAdd(HttpContext.Current.User.Identity.Name, DateTime.UtcNow);
                TimeSpan timeLeft;
                TimeSpan LifeTime = TimeSpan.FromMinutes(int.Parse(SimpleSettings.MonitoringToolsExpiryMinutes));

                if (timeUsed > LifeTime)
                {
                    timeLeft = TimeSpan.FromMinutes(0);
                }
                else
                {
                    timeLeft = LifeTime - timeUsed;
                }

                resourceGroup.TimeLeftInSeconds = (int)timeLeft.TotalSeconds;
            }
            return(resourceGroup);
        }
Example #16
0
        internal IngameQuitMenuWindow(Race setRace)
        {
            UIResource res = WarFile.GetUIResource(setRace == Race.Humans ? 391 : 392);

            background = new UIImage(WWTexture.FromImageResource(WarFile.GetImageResource(res.BackgroundImageResourceIndex)));
            background.InitWithUIResource(res);
            AddComponent(background);

            background.CenterOnScreen();

            cancelButton = (UIButton)background.Components [3];
            cancelButton.OnMouseUpInside += cancelButton_OnMouseUpInside;

            menuButton = (UIButton)background.Components [2];
            menuButton.OnMouseUpInside += menuButton_OnMouseUpInside;

            quitButton = (UIButton)background.Components [1];
            quitButton.OnMouseUpInside += quitButton_OnMouseUpInside;

            MouseCursor.State = MouseCursorState.Pointer;
        }
Example #17
0
        private void BuildEnglishLanguage()
        {
            if (!ReadOnly)
            {
                ItemResource[] ress =
                    Baumax.Localization.DefaultDiction.GetEnglishResource();

                Domain.Language ll = ClientEnvironment.LanguageService.CreateEntity();

                ll.Name         = "English";
                ll.LanguageCode = "EN-US";

                ll = ClientEnvironment.LanguageService.Save(ll);

                List <UIResource> _lst  = new List <UIResource>();
                UIResource        uires = null;
                foreach (ItemResource res in ress)
                {
                    _lst.Add(new UIResource(res.Key, ll.ID, res.Value));
                }

                ClientEnvironment.LanguageService.UpdateResources(_lst);
            }
        }
Example #18
0
        internal void InitWithUIResource(UIResource resource)
        {
            ClearComponents();

            for (int i = 0; i < resource.Labels.Count; i++)
            {
                WinWarCS.Data.Resources.UIResource.UIEntry me = resource.Labels[i];

                UILabel label = new UILabel(me.Text);
                label.X         = (int)me.X;
                label.Y         = (int)me.Y;
                label.TextAlign = (TextAlignHorizontal)me.Alignment;
                AddComponent(label);
            }

            for (int i = 0; i < resource.Elements.Count; i++)
            {
                WinWarCS.Data.Resources.UIResource.UIEntry me = resource.Elements[i];

                if (me.Type == UIResource.UIEntryType.ValueList)
                {
                    UILabel lbl = new UILabel(me.Values[0]);
                    lbl.X         = (int)(me.X);
                    lbl.Y         = (int)(me.Y);
                    lbl.TextAlign = (TextAlignHorizontal)me.Alignment;
                    AddComponent(lbl);
                }
                else
                {
                    UIButton btn = new UIButton(me.Text, me.ButtonReleasedResourceIndex, me.ButtonPressedResourceIndex);
                    btn.X = (int)(me.X);
                    btn.Y = (int)(me.Y);
                    AddComponent(btn);
                }
            }
        }
    public override void OnInspectorGUI()
    {
        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button(listFolded ? "+" : "-", GUILayout.Height(15f), GUILayout.Width(18f)))
        {
            listFolded = !listFolded;
        }
        EditorGUILayout.LabelField("UIResourceDataBase");
        EditorGUILayout.EndHorizontal();

        List <UIResource> removeList = new List <UIResource>();

        if (!listFolded)
        {
            foreach (var r in Target.UIResourceDatabase)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("->", GUILayout.Width(20f));
                if (GUILayout.Button(r.editorFolded ? "+" : "-", GUILayout.Height(15f), GUILayout.Width(18f)))
                {
                    r.editorFolded = !r.editorFolded;
                }
                EditorGUILayout.LabelField(r.resourceLocator + "-------------------------------------------------------------------------------------------------------------");
                if (r.editorFolded)
                {
                    switch (r.contentType)
                    {
                    case UIContentType.Text:
                        r.text = EditorGUILayout.TextField(r.text);
                        break;

                    case UIContentType.Image:
                        r.image = (Sprite)EditorGUILayout.ObjectField(r.image, typeof(Sprite));
                        break;

                    case UIContentType.Texture2D:
                        r.texture = (Texture2D)EditorGUILayout.ObjectField(r.texture, typeof(Texture2D));
                        break;

                    case UIContentType.OnOffCommand:
                        r.onOffCommand = EditorGUILayout.Toggle(r.onOffCommand);
                        break;

                    default: break;
                    }
                }
                else
                {
                    if (GUILayout.Button("del", GUILayout.Height(15f), GUILayout.Width(48f)))
                    {
                        removeList.Add(r);
                    }
                }
                EditorGUILayout.EndHorizontal();

                if (!r.editorFolded)
                {
                    r.resourceLocator = EditorGUILayout.TextField("Locator", r.resourceLocator);
                    r.contentType     = (UIContentType)EditorGUILayout.EnumPopup("Content Type", r.contentType);
                    switch (r.contentType)
                    {
                    case UIContentType.Text:
                        r.text = EditorGUILayout.TextField("Text", r.text);
                        break;

                    case UIContentType.Image:
                        r.image = (Sprite)EditorGUILayout.ObjectField("Image", r.image, typeof(Sprite));
                        break;

                    case UIContentType.Texture2D:
                        r.texture = (Texture2D)EditorGUILayout.ObjectField(r.texture, typeof(Texture2D));
                        break;

                    case UIContentType.OnOffCommand:
                        r.onOffCommand = EditorGUILayout.Toggle("OnOff Cmd", r.onOffCommand);
                        break;

                    default: break;
                    }


                    EditorGUILayout.Space();
                }
            }
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Add"))
            {
                var r = new UIResource();
                r.resourceLocator = "www...";
                r.contentType     = UIContentType.Text;
                Target.UIResourceDatabase.Add(r);
            }
            EditorGUILayout.EndHorizontal();
        }

        foreach (var r in removeList)
        {
            Target.UIResourceDatabase.Remove(r);
        }
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Example #20
0
 /// <summary>
 /// Add resource to manifest.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="resource"></param>
 /// <returns></returns>
 public static IRazorComponentClientModuleManifestBuilder WithResource(this IRazorComponentClientModuleManifestBuilder builder, UIResource resource)
 {
     builder.Resources.Add(resource);
     return(builder);
 }
Example #21
0
        private void MergeResourceListWithSavedResources(ICollection <UIResource> list)
        {
            if ((list == null) || (list.Count == 0))
            {
                return;
            }

            // prepare dictionary for selecting from DB
            Dictionary <long, List <int> > curResDictionary = new Dictionary <long, List <int> >(2);

            foreach (UIResource entity in list)
            {
                if (curResDictionary.ContainsKey(entity.LanguageID))
                {
                    long langId = entity.LanguageID;
                    if (curResDictionary[langId] == null)
                    {
                        curResDictionary[langId] = new List <int>();
                    }
                    curResDictionary[langId].Add(entity.ResourceID);
                }
                else
                {
                    curResDictionary.Add(entity.LanguageID, new List <int>(new int[] { entity.ResourceID }));
                }
            }

            // select current resources for merge
            // 2think: should we implement reading in the one "SELECT" with big condition string and many parameters?
            StringBuilder     condition      = new StringBuilder();
            List <string>     pNames         = new List <string>();
            List <object>     pValues        = new List <object>();
            List <UIResource> savedResources = new List <UIResource>();

            foreach (long langId in curResDictionary.Keys)
            {
                condition.Length = 0;
                pNames.Clear();
                pValues.Clear();
                pNames.Add("langid");
                pValues.Add(langId);
                condition.AppendFormat("entity.LanguageID = :langid AND entity.ResourceID IN ({0})",
                                       QueryUtils.GenIDList(
                                           curResDictionary[langId].ConvertAll <long>(
                                               delegate(int value) { return(value); }), pNames, pValues));
                List <UIResource> curLanguageResources =
                    TypedListConverter <UIResource> .ToTypedList(
                        _resDao.FindByNamedParam(condition.ToString(), pNames.ToArray(), pValues.ToArray()));

                if ((curLanguageResources != null) && (curLanguageResources.Count > 0))
                {
                    savedResources.AddRange(curLanguageResources);
                }
            }

            // merge IDs
            if (savedResources.Count > 0)
            {
                foreach (UIResource entity in list)
                {
                    if (entity.ID <= 0)
                    {
                        if (curResDictionary.ContainsKey(entity.LanguageID))
                        {
                            long       langId        = entity.LanguageID;
                            UIResource savedResource =
                                savedResources.Find(
                                    delegate(UIResource res)
                            {
                                return((res.LanguageID == langId) &&
                                       (res.ResourceID == entity.ResourceID));
                            });
                            if (savedResource != null)
                            {
                                entity.ID = savedResource.ID;
                            }
                        }
                    }
                }
            }
        }
    protected static void DrawResources(UIResource resources)
    {
        int delete = -1;

        if (resources.componentItems == null)
        {
            resources.componentItems = new UIResourceComponentItem[] { }
        }
        ;
        UIResourceComponentItem[] items = resources.componentItems;

        int maxUnnamedIndex = 1;
        int moveFrom = 0, moveTo = 0;

        for (int i = 0; i < items.Length; i++)
        {
            if (items [i] == null)
            {
                items [i] = new UIResourceComponentItem();
            }
            if (!string.IsNullOrEmpty(items [i].key) && items [i].key.StartsWith(DefaultItemName))
            {
                int unnamedIndex = int.Parse(items [i].key.Substring(DefaultItemName.Length));
                if (unnamedIndex > 0)
                {
                    maxUnnamedIndex = Mathf.Max(unnamedIndex + 1, maxUnnamedIndex);
                }
            }
            int index = i;
            if (DrawResource(items[i], ref index))
            {
                delete = i;
            }
            if (index != i)
            {
                moveFrom = i;
                moveTo   = index;
            }
        }

        if (moveFrom != moveTo && moveFrom >= 0 && moveFrom < items.Length)
        {
            moveTo = Math.Max(0, Math.Min(items.Length, moveTo));
            List <UIResourceComponentItem> list = new List <UIResourceComponentItem> (items);
            var src = list [moveFrom];
            list.RemoveAt(moveFrom);
            if (moveTo < moveFrom)
            {
                list.Insert(moveTo, src);
            }
            else
            {
                list.Insert(moveTo - 1, src);
            }
            items = resources.componentItems = list.ToArray();
        }
        if (delete >= 0)
        {
            UIResourceComponentItem[] newItems = new UIResourceComponentItem[items.Length - 1];
            if (delete > 0)
            {
                Array.ConstrainedCopy(items, 0, newItems, 0, delete);
            }
            if (items.Length - delete - 1 > 0)
            {
                Array.ConstrainedCopy(items, delete + 1, newItems, delete, items.Length - delete - 1);
            }
            resources.componentItems = newItems;
        }

        GUILayout.Space(10);
        if (GUILayout.Button("Add"))
        {
            GenericMenu menu = new GenericMenu();
            for (int i = 0; i < allowedTypes.Length; i++)
            {
                Type t = allowedTypes [i];
                menu.AddItem(new GUIContent(t.Name), false, () => AddItem(resources, t, maxUnnamedIndex));
            }
            menu.ShowAsContext();
        }

        if (!CheckKeys(items))
        {
            EditorGUILayout.HelpBox("关键字不能重复或留空", MessageType.Warning);
        }
    }
 public UIResourceImage(UIResource resource)
 {
     this.resource = resource;
 }