Esempio n. 1
0
    public static void DisplayCategory(string category)
    {
        if (instance == null)
        {
            return;
        }

        Dictionary <string, BaseSettingsElement[]> option;

        // Optimisation for saving
        if (instance.currentCategory != string.Empty && instance.currentCategory != category && instance.options.TryGetValue(instance.currentCategory, out option))
        {
            foreach (string headingName in option.Keys)
            {
                BaseSettingsElement[] settingsElements = option[headingName];
                for (int i = 0; i < settingsElements.Length; i++)
                {
                    BaseSettingsElement elementCopy = settingsElements[i];

                    if (elementCopy != null && elementCopy.valueChanged)
                    {
                        instance.changesTracker.Add(elementCopy);
                    }
                }
            }

            if (instance.changesTracker.Count > 0)
            {
                instance.Apply();
            }
        }

        instance.categoryHeading.text = LocalizationTable.GetLocalization(category);
        instance.currentCategory      = category;

        // Clear root
        foreach (Transform child in instance.elementRoot.transform)
        {
            child.BroadcastMessage("Despawn", SendMessageOptions.DontRequireReceiver);
            Destroy(child.gameObject);
        }

        foreach (ColorButton button in instance.categoryRoot.GetComponentsInChildren <ColorButton>())
        {
            if (button.gameObject.name != category)
            {
                button.RevertColor();
            }
            else
            {
                button.SelectColor();
            }
        }

        if (instance.currentCategory != string.Empty && instance.options.TryGetValue(category, out option))
        {
            foreach (string headingName in option.Keys)
            {
                // Create heading prefab
                SettingsHeading heading = Instantiate(instance.headingPrefab).GetComponent <SettingsHeading>();
                heading.SetText(headingName);
                heading.transform.SetParent(instance.elementRoot.transform);

                BaseSettingsElement[] settingsElements = option[headingName];
                for (int i = 0; i < settingsElements.Length; i++)
                {
                    if (settingsElements[i] != null)
                    {
                        BaseSettingsElement element = settingsElements[i];
                        GameObject          go      = element.InitializeElement();
                        TooltipComponent    tc      = go.AddComponent <TooltipComponent>();
                        tc.Tooltip          = element.option.tooltip;
                        tc.UseHeavyTextMode = true;

                        heading.AddObjectToRoot(go);
                        element.valueChanged = false;
                    }
                }
            }
        }

        // Update canvases, to allow the normalized position to properly exist.
        Canvas.ForceUpdateCanvases();
        instance.settingsScrollRect.normalizedPosition = new Vector2(0, 1);
    }
    private GameObject CreateButton(GameMenuItem gameMenuItem)
    {
        GameObject gameObject = (GameObject)Instantiate(buttonPrefab, this.gameObject.transform);

        gameObject.name = "Button - " + gameMenuItem.Key;
        gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(gameMenuItem.Key) };

        Button button = gameObject.GetComponent <Button>();

        button.onClick.AddListener(delegate
        {
            if (!GameController.Instance.IsModal)
            {
                DeactivateAll();
                gameMenuItem.Trigger();
            }
        });

        Action localizationFilesChangedHandler = null;

        localizationFilesChangedHandler = delegate
        {
            Transform transform;
            try
            {
                transform = gameObject.transform;
            }
            catch (MissingReferenceException)
            {
                // this sometimes gets called when gameObject doesn't exist
                // if so the gameObject has obviously been destroyed, so deregister
                // the callback
                LocalizationTable.CBLocalizationFilesChanged -= localizationFilesChangedHandler;
                return;
            }

            string menuItemKey = gameObject.name.Replace("Button - ", string.Empty);
            transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[]
            {
                LocalizationTable.GetLocalization(menuItemKey)
            };
        };
        LocalizationTable.CBLocalizationFilesChanged += localizationFilesChangedHandler;

        return(gameObject);
    }
Esempio n. 3
0
    // Use this for initialization.
    private void Start()
    {
        tileTypes = TileType.LoadedTileTypes;
        BuildModeController bmc = WorldController.Instance.buildModeController;

        // For each furniture prototype in our world, create one instance
        // of the button to be clicked!
        foreach (TileType type in tileTypes)
        {
            GameObject go = (GameObject)Instantiate(buildFurnitureButtonPrefab);
            go.transform.SetParent(this.transform);

            TileType tileType = type;

            go.name = "Button - Build " + tileType.Type;

            // TODO: Not a elegant solution! Find a better way.
            if (type == TileType.Empty)
            {
                go.name = "Button - Remove " + tileType.Type;
                go.GetComponentInChildren <TextLocalizer>().defaultText = "remove";
            }

            go.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(tileType.LocalizationCode) };
            Button b = go.GetComponent <Button>();

            b.onClick.AddListener(delegate
            {
                bmc.SetModeBuildTile(tileType);
            });
        }

        lastLanguage = LocalizationTable.currentLanguage;
    }
Esempio n. 4
0
 public DropdownValue(string lang)
 {
     language = lang;
     text     = LocalizationTable.GetLocalization("lang", LocalizationTable.FallbackMode.ReturnKey, lang);
 }
Esempio n. 5
0
 public void SelectLanguage(int lang)
 {
     string[] languages = LocalizationTable.GetLanguages();
     LocalizationTable.currentLanguage = languages[lang];
     Settings.setSetting("localization", languages[lang]);
 }
Esempio n. 6
0
 internal virtual void RaiseTableRemovedFromCollection(LocalizationTableCollection collection, LocalizationTable table) => TableRemovedFromCollection?.Invoke(collection, table);
Esempio n. 7
0
    private void RenderDeconstructButton()
    {
        taskItems = new List <GameObject>();

        UnityEngine.Object buttonPrefab     = Resources.Load("UI/MenuLeft/ConstructionMenu/Button");
        Transform          contentTransform = this.transform.Find("Scroll View").Find("Viewport").Find("Content");

        BuildModeController buildModeController = WorldController.Instance.buildModeController;

        GameObject gameObject = (GameObject)Instantiate(buttonPrefab);

        gameObject.transform.SetParent(contentTransform);
        taskItems.Add(gameObject);

        gameObject.name = "Button - Deconstruct";

        gameObject.transform.GetComponentInChildren <Text>().text = LocalizationDeconstruct;

        Button button = gameObject.GetComponent <Button>();

        button.onClick.AddListener(delegate
        {
            buildModeController.SetMode_Deconstruct();
        });

        LocalizationTable.CBLocalizationFilesChanged += delegate
        {
            gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(LocalizationDeconstruct) };
        };

        Image image = gameObject.transform.GetChild(0).GetComponentsInChildren <Image>().First();

        image.sprite = SpriteManager.GetSprite("UI", "Deconstruct");
    }
Esempio n. 8
0
        private void OnTablesGUI()
        {
            var settings = activeSettings.ActiveSettings;

            if (settings == null)
            {
                return;
            }
            if (!stylesLoaded)
            {
                LoadStyles();
            }

            if (tableQueryChanged)
            {
                UpdateTableFilter();
                tableQueryChanged = false;
            }

            GUILayout.BeginVertical(style_containerNoMarginTop);
            tableSearchScroll = GUILayout.BeginScrollView(tableSearchScroll,
                                                          filteredTables.Count * 40 >= 200 ? new[] { GUILayout.MaxHeight(200), GUILayout.MinHeight(0) } : new GUILayoutOption[0]);
            selectedTable = GUILayoutExtras.Selection(selectedTable, filteredTables, (val, isSelected, index) => {
                var back            = GUI.backgroundColor;
                GUI.backgroundColor = index % 2 == 0 ? new Color(0.8f, 0.8f, 0.8f) : Color.white;
                GUI.enabled         = !isSelected;
                var clicked         = GUILayout.Button("", style_localeSelectionEntryButton, GUILayout.MinHeight(40));
                var lastRect        = GUILayoutUtility.GetLastRect();
                GUI.enabled         = true;
                GUI.Label(lastRect, $"{val.TableName}", style_localeSelectionEntryLabel);
                GUI.backgroundColor = back;
                return(clicked);
            });

            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            GUILayout.BeginHorizontal(style_containerNoMarginTop);

            if (GUILayout.Button("Open Table Editor", GUILayout.Height(30)))
            {
                TableEditorWindow.Display(settings);
            }

            if (selectedTable == null)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Remove Selected", GUILayout.Height(30)))
            {
                if (EditorUtility.DisplayDialog("Confirm table removal", "This action cannot be undone. Are you sure you want to delete the table?", "Yes", "No"))
                {
                    settings.RemoveTable(selectedTable);
                    AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(selectedTable));
                    Utils.SaveChanges();
                    selectedTable = null;
                    Utils.DirtyTables(settings);
                }
            }

            GUI.enabled = true;

            GUILayout.EndHorizontal();
        }
Esempio n. 9
0
 /// <summary>
 /// Builds the interface.
 /// </summary>
 public void BuildInterface()
 {
     text.text = LocalizationTable.GetLocalization(Action.LocalizationKey);
 }
Esempio n. 10
0
 public string GetName()
 {
     return(LocalizationTable.GetLocalization(JobObjectType));
 }
 /// <summary>
 /// Sets the text for the heading.
 /// </summary>
 /// <param name="text"></param>
 public void SetText(string text)
 {
     headingText.text = LocalizationTable.GetLocalization(text);
 }
Esempio n. 12
0
    public void HandleTooltip(Vector2 position, MouseCursor cursor, bool isDragging)
    {
        cursor.Reset();
        Tile t = WorldController.Instance.GetTileAtWorldCoord(position);

        int validPostionCount    = 0;
        int invalidPositionCount = 0;
        List <GameObject> dragPreviewGameObjects = WorldController.Instance.MouseController.DragPreviewGameObjects;

        // Placing furniture object.
        if (BuildMode == BuildMode.FURNITURE)
        {
            cursor.DisplayCursorInfo(TextAnchor.LowerRight, LocalizationTable.GetLocalization(PrototypeManager.Furniture.Get(BuildModeType).GetName()), MouseCursor.TextColor, false);

            // Dragging and placing multiple furniture.
            if (t != null && isDragging == true && dragPreviewGameObjects.Count > 1)
            {
                for (int i = 0; i < dragPreviewGameObjects.Count; i++)
                {
                    Tile t1 = WorldController.Instance.GetTileAtWorldCoord(dragPreviewGameObjects[i].transform.position);
                    if (World.Current.FurnitureManager.IsPlacementValid(BuildModeType, t1) &&
                        (t1.PendingBuildJobs == null || t1.PendingBuildJobs.Count == 0))
                    {
                        validPostionCount++;
                    }
                    else
                    {
                        invalidPositionCount++;
                    }
                }

                string currentBuildRequirements = string.Empty;

                Build buildOrder = PrototypeManager.Furniture.Get(BuildModeType).GetOrderAction <Build>();
                if (buildOrder != null)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (KeyValuePair <string, int> item in buildOrder.Inventory)
                    {
                        sb.Append(string.Format("{0}x {1}", item.Value * validPostionCount, PrototypeManager.Inventory.Get(item.Key).LocalizedName));
                        if (buildOrder.Inventory.Count > 1)
                        {
                            sb.AppendLine();
                        }
                    }

                    currentBuildRequirements = sb.ToString();
                }
                else
                {
                    UnityDebugger.Debugger.LogError("BuildOrder is null");
                }

                cursor.DisplayCursorInfo(TextAnchor.UpperLeft, validPostionCount.ToString(), Color.green, false);
                cursor.DisplayCursorInfo(TextAnchor.UpperRight, invalidPositionCount.ToString(), Color.red, false);
                cursor.DisplayCursorInfo(TextAnchor.LowerLeft, currentBuildRequirements, MouseCursor.TextColor, false);
            }
        }
        else if (BuildMode == BuildMode.FLOOR)
        {
            // Placing tiles and dragging.
            if (t != null && isDragging == true && dragPreviewGameObjects.Count >= 1)
            {
                cursor.DisplayCursorInfo(TextAnchor.UpperLeft, dragPreviewGameObjects.Count.ToString(), MouseCursor.TextColor, false);
                cursor.DisplayCursorInfo(TextAnchor.LowerLeft, LocalizationTable.GetLocalization(GetFloorTile()), MouseCursor.TextColor, false);
            }
        }
    }
    // Use this for initialization
    private void Start()
    {
        BuildModeController bmc = WorldController.Instance.buildModeController;

        // For each furniture prototype in our world, create one instance
        // of the button to be clicked!
        foreach (string s in PrototypeManager.Furniture.Keys)
        {
            GameObject go = (GameObject)Instantiate(buildFurnitureButtonPrefab);
            go.transform.SetParent(this.transform);

            Furniture proto    = PrototypeManager.Furniture.GetPrototype(s);
            string    objectId = s;

            go.name = "Button - Build " + objectId;

            go.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(proto.LocalizationCode) };

            Button b = go.GetComponent <Button>();

            b.onClick.AddListener(delegate
            {
                bmc.SetMode_BuildFurniture(objectId);
                this.gameObject.SetActive(false);
            });

            // http://stackoverflow.com/questions/1757112/anonymous-c-sharp-delegate-within-a-loop
            string furn = s;
            LocalizationTable.CBLocalizationFilesChanged += delegate
            {
                go.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(PrototypeManager.Furniture.GetPrototype(furn).LocalizationCode) };
            };
        }

        lastLanguage = LocalizationTable.currentLanguage;
    }
Esempio n. 14
0
    // Update is called once per frame
    void Update()
    {
        if (mc.mySelection == null)
        {
            canvasGroup.alpha          = 0;
            canvasGroup.interactable   = false;
            canvasGroup.blocksRaycasts = false;
            return;
        }

        canvasGroup.alpha          = 1;
        canvasGroup.interactable   = true;
        canvasGroup.blocksRaycasts = true;

        ISelectable actualSelection = mc.mySelection.stuffInTile[mc.mySelection.subSelection];

        txt.text = LocalizationTable.GetLocalization(actualSelection.GetName()) + "\n" + LocalizationTable.GetLocalization(actualSelection.GetDescription()) + "\n" + actualSelection.GetHitPointString(); //TODO: Change the hitpoint stuff.
    }
Esempio n. 15
0
    private void RenderUtilityButtons()
    {
        utilityItems = new List <GameObject>();

        UnityEngine.Object buttonPrefab     = Resources.Load("UI/MenuLeft/ConstructionMenu/Button");
        Transform          contentTransform = this.transform.FindChild("Scroll View").FindChild("Viewport").FindChild("Content");

        BuildModeController buildModeController = WorldController.Instance.buildModeController;

        // For each furniture prototype in our world, create one instance
        // of the button to be clicked!
        foreach (string utilityKey in PrototypeManager.Utility.Keys)
        {
            if (PrototypeManager.Utility.Get(utilityKey).HasTypeTag("Non-buildable") && showAllFurniture == false)
            {
                continue;
            }

            GameObject gameObject = (GameObject)Instantiate(buttonPrefab);
            gameObject.transform.SetParent(contentTransform);
            furnitureItems.Add(gameObject);

            Utility proto    = PrototypeManager.Utility.Get(utilityKey);
            string  objectId = utilityKey;

            gameObject.name = "Button - Build " + objectId;

            gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(proto.LocalizationCode) };

            Button button = gameObject.GetComponent <Button>();

            button.onClick.AddListener(delegate
            {
                buildModeController.SetMode_BuildUtility(objectId);
                menuLeft.CloseMenu();
            });

            // http://stackoverflow.com/questions/1757112/anonymous-c-sharp-delegate-within-a-loop
            string utility = utilityKey;
            LocalizationTable.CBLocalizationFilesChanged += delegate
            {
                gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(PrototypeManager.Utility.Get(utility).LocalizationCode) };
            };

            Image image = gameObject.transform.GetChild(0).GetComponentsInChildren <Image>().First();
            image.sprite = WorldController.Instance.utilitySpriteController.GetSpriteForUtility(utilityKey);
        }
    }
Esempio n. 16
0
    /// <summary>
    /// Gets the Context Menu Actions.
    /// </summary>
    /// <param name="contextMenu">The context menu to check for actions.</param>
    /// <returns>Context menu actions.</returns>
    public IEnumerable <ContextMenuAction> GetContextMenuActions(ContextMenu contextMenu)
    {
        if (SettingsKeyHolder.DeveloperMode || HasTypeTag("Non-deconstructible") == false)
        {
            yield return(new ContextMenuAction
            {
                LocalizationKey = LocalizationTable.GetLocalization("deconstruct_furniture", LocalizationCode),
                RequireCharacterSelected = false,
                Action = (ca, c) => SetDeconstructJob()
            });
        }

        if (PrototypeManager.Inventory.Has(this.Type))
        {
            yield return(new ContextMenuAction
            {
                LocalizationKey = LocalizationTable.GetLocalization("uninstall_furniture", LocalizationCode),
                RequireCharacterSelected = false,
                Action = (ca, c) => SetUninstallJob()
            });
        }

        for (int i = 0; i < Jobs.Count; i++)
        {
            if (!Jobs[i].IsBeingWorked)
            {
                yield return(new ContextMenuAction
                {
                    LocalizationKey = LocalizationTable.GetLocalization("prioritize_furniture", LocalizationCode),
                    RequireCharacterSelected = true,
                    Action = (ca, c) => c.PrioritizeJob(Jobs[0])
                });
            }
        }

        // check for context menus of components
        foreach (BuildableComponent component in components)
        {
            List <ContextMenuAction> componentContextMenu = component.GetContextMenu();
            if (componentContextMenu != null)
            {
                foreach (ContextMenuAction compContextMenuAction in componentContextMenu)
                {
                    yield return(compContextMenuAction);
                }
            }
        }

        foreach (ContextMenuLuaAction contextMenuLuaAction in contextMenuLuaActions)
        {
            if (!contextMenuLuaAction.DevModeOnly ||
                SettingsKeyHolder.DeveloperMode)
            {
                // TODO The Action could be done via a lambda, but it always uses the same space of memory, thus if 2 actions are performed, the same action will be produced for each.
                yield return(new ContextMenuAction
                {
                    LocalizationKey = contextMenuLuaAction.LocalizationKey,
                    RequireCharacterSelected = contextMenuLuaAction.RequireCharacterSelected,
                    Action = InvokeContextMenuLuaAction,
                    Parameter = contextMenuLuaAction.LuaFunction    // Note that this is only in place because of the problem with the previous statement.
                });
            }
        }
    }
Esempio n. 17
0
    private void RenderTileButtons()
    {
        tileItems = new List <GameObject>();

        UnityEngine.Object buttonPrefab     = Resources.Load("UI/MenuLeft/ConstructionMenu/Button");
        Transform          contentTransform = this.transform.FindChild("Scroll View").FindChild("Viewport").FindChild("Content");

        BuildModeController buildModeController = WorldController.Instance.buildModeController;

        foreach (TileType item in PrototypeManager.TileType.Values)
        {
            TileType tileType = item;

            string key = tileType.LocalizationCode;

            GameObject gameObject = (GameObject)Instantiate(buttonPrefab);
            gameObject.transform.SetParent(contentTransform);
            tileItems.Add(gameObject);

            gameObject.name = "Button - Build Tile " + key;

            gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(key) };

            Button button = gameObject.GetComponent <Button>();
            button.onClick.AddListener(delegate
            {
                buildModeController.SetModeBuildTile(tileType);
            });

            LocalizationTable.CBLocalizationFilesChanged += delegate
            {
                gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(key) };
            };

            Image image = gameObject.transform.GetChild(0).GetComponentsInChildren <Image>().First();
            image.sprite = SpriteManager.GetSprite("Tile", tileType.Type);
        }
    }
Esempio n. 18
0
 internal virtual void RaiseTableAddedToCollection(LocalizationTableCollection collection, LocalizationTable table) => TableAddedToCollection?.Invoke(collection, table);