コード例 #1
0
    public void ToggleToggled(FToggle toggle)
    {
        //if we hit a tab... turn off the others!
        if (toggle.state == "on")
        {
            foreach (FToggle t in toggles)
            {
                if (t != toggle && t.state == "on")
                {
                    t.state = "off";
                }
            }

            if (TabChanged != null)
            {
                TabChanged(toggle);
            }
        }
        else
        {
            //reject the toggle
            toggle.state = "on";
        }

        //refresh state one last time for the one we selected in case any of our siblings turned off shared assets
        toggle.state = toggle.state;
    }
コード例 #2
0
    public void Add(FToggle toggle)
    {
        if (toggles.Count == 0)
        {
            toggle.state = "on";              //on = selected state
        }
        else
        {
            toggle.state = "off";              //off = able to be pressed
        }

        toggles.Add(toggle);
        toggle.SignalToggle += ToggleToggled;
    }
コード例 #3
0
    public static FToggle WrapAndReplace(FStateButton button, List <string> toggle_states)
    {
        FToggle toggle = new FToggle(toggle_states);

        foreach (string key in button.buttons.Keys)
        {
            toggle.addState(key, button.buttons[key]);
        }
        toggle.finalize();

        toggle.x = button.x;
        toggle.y = button.y;

        if (button.container != null)
        {
            button.container.AddChildAtIndex(toggle, button.container.IndexOf(button.container));
            button.RemoveFromContainer();
            button.cleanUp();
        }
        return(toggle);
    }
コード例 #4
0
    internal void processMetadata(string metadata)
    {
        //master list of all name -> coordinates
        positions = new Dictionary <string, Vector2>();

        //lists of our buttons, labels, progress bars, and images
        labels   = new Dictionary <string, FLabel>();
        buttons  = new Dictionary <string, FButton>();
        progress = new Dictionary <string, FSprite>();
        images   = new Dictionary <string, FSprite>();
        toggles  = new Dictionary <string, FToggle>();

        string[] objects = metadata.Split("+"[0]);

        List <string> things_to_toggle = new List <string>();

        foreach (string obj in objects)
        {
            //ignore the empty string
            if (obj == "")
            {
                continue;
            }

            string[] data = obj.Split("|"[0]);
            string   type = data[0].Split("_"[0])[0];

            //these two don't have an x & a y!
            if (data[0] == "root_width")
            {
                rootWidth = System.Int32.Parse(data[1]);
                continue;
            }
            else if (data[0] == "root_height")
            {
                rootHeight = System.Int32.Parse(data[1]);
                continue;
            }

            int x = System.Int32.Parse(data[1]);
            int y = System.Int32.Parse(data[2]);

//			 Debug.Log(data[0] + " - " + x + "," + y);

            if (type == "btn")
            {
                if (data[0].IndexOf("_down") >= 0)
                {
                    //no need to process a button twice!
                    continue;
                }

                string  button_name = data[0].Replace("btn_", "").Replace("_up", "");
                FButton button      = new FButton(data[0], "btn_" + button_name + "_down");

                button.data = button_name;

                if (button_name.Contains("tab_"))
                {
                    things_to_toggle.Add(button_name);
                }

                this.AddChild(button);
                button.x = x;
                button.y = y;

                buttons[button_name]   = button;
                positions[button_name] = new Vector2(x, y);
            }
            else if (type == "text")
            {
                //TODO: font size

                // Debug.Log("ADDING LABEL: " + data[0].Substring(5));

                //might be more later?
                string clean_text = data[9].Replace("/r", "/n");
                FLabel label      = new FLabel(data[4], clean_text);
                this.AddChild(label);

                float text_size = (float)System.Double.Parse(data[6]);
                // Debug.Log ("TEXT SIZE: " + text_size);
                int font_size = LoadedFonts[data[4]];

                float scale_mod = text_size / font_size;
                label.scale = scale_mod;


                if (data[5] == "center")
                {
                    label.anchorX = 0.5f;
                }
                else if (data[5] == "left")
                {
                    label.anchorX = 0.0f;
                }
                else if (data[5] == "right")
                {
                    label.anchorX = 1.0f;
                }

                label.x = x;
                label.y = y;

                label.color = hexToColor(data[3]);

                labels[data[0].Substring(5)]    = label;
                positions[data[0].Substring(5)] = new Vector2(x, y);
            }
            else
            {
                //x,y in this point are assuming y is at the top left...
                positions[data[0]] = new Vector2(x, y);

                FSprite sprite = new FSprite(data[0]);
                this.AddChild(sprite);

                // Debug.Log("   -> anchorX = " + sprite.anchorX);

                sprite.x = x;
                sprite.y = y;

                images[data[0]]    = sprite;
                positions[data[0]] = new Vector2(x, y);
            }
        }

        //CONVERT things with tab_buttonname_state into buttons with state!
        foreach (string button_name in things_to_toggle)
        {
            string[] toggle_data = button_name.Split("_"[0]);
            string   state       = toggle_data[toggle_data.Length - 1];

            //pop off the tab_ and the _state
            string toggle_name = toggle_data[1];
            for (int i = 2; i < toggle_data.Length - 1; i++)
            {
                toggle_name = toggle_name + "_" + toggle_data[i];
            }

            if (!toggles.ContainsKey(toggle_name))
            {
                toggles[toggle_name]      = new FToggle();
                toggles[toggle_name].data = toggle_name;
            }

            toggles[toggle_name].addState(state, buttons[button_name]);
        }

        foreach (FToggle toggle in toggles.Values)
        {
            Debug.Log("ADDED TOGGLE " + toggle.data);
            toggle.finalize();
        }
    }
コード例 #5
0
        protected override void OnPrefabInit()
        {
            base.OnPrefabInit();

            #region set object references
            // This would be handled by Unity normally via Unity magic
            const string path = "ScrollView/Viewport/Content/Panel";

            cancelButton  = transform.Find("CancelButton").gameObject.AddComponent <FButton>();
            confirmButton = transform.Find("OKButton").gameObject.AddComponent <FButton>();
            githubButton  = transform.Find("GithubButton").gameObject.AddComponent <FButton>();
            steamButton   = transform.Find("SteamButton").gameObject.AddComponent <FButton>();

            versionLabel = transform.Find("VersionLabel").gameObject.GetComponent <Text>();
            authorNote   = transform.Find("AuthorNote").gameObject.GetComponent <Text>();

            iceHatchToggle         = transform.Find(path + "/GlassSculptureSettingsPanel/IceHatchToggle/Toggle").gameObject.AddComponent <FToggle>();
            fabulousUnicornsToggle = transform.Find(path + "/GlassSculptureSettingsPanel/FabUnicornsToggle/Toggle").gameObject.AddComponent <FToggle>();
            biscuitToggle          = transform.Find(path + "/FountainSettingsPanel/BiscuitToggle/Toggle").gameObject.AddComponent <FToggle>();

            lanternFuelCycle  = transform.Find(path + "/LanternSettingsPanel/CycleSelectorPanel/CycleSelector").gameObject.AddComponent <FCycle>();
            aquariumPacuCycle = transform.Find(path + "/AquariumSettingsPanel/CycleSelectorPanel/CycleSelector").gameObject.AddComponent <FCycle>();

            stainedGlassSpeedSlider = transform.Find(path + "/GlassTileSettingsPanel/SpeedSlider/Slider").gameObject.AddComponent <FSpeedSlider>();

            #endregion

            // Stained glass tiles speed slider
            stainedGlassSpeedSlider.fSlider.mapValue        = x => x / 20f + 1f;
            stainedGlassSpeedSlider.fSlider.reverseMapValue = x => (x - 1f) * 20f;

            stainedGlassSpeedSlider.AssignRanges(new List <FSpeedSlider.Range> {
                new FSpeedSlider.Range(1f, STAINEDSPEED.NOBONUS, Color.grey),
                new FSpeedSlider.Range(1.05f, STAINEDSPEED.SMALL, Color.grey),
                new FSpeedSlider.Range(1.25f, STAINEDSPEED.REGULAR, Color.white),
                new FSpeedSlider.Range(1.3f, STAINEDSPEED.HASTY, Color.white),
                new FSpeedSlider.Range(1.5f, STAINEDSPEED.METAL, Color.yellow),
                new FSpeedSlider.Range(1.55f, STAINEDSPEED.FAST, Color.red)
            });

            // Lantern options
            lanternFuelCycle.Options = new List <FCycle.CycleOption>()
            {
                new FCycle.CycleOption("Oil", LANTERNCYCLE.OIL, null),
                new FCycle.CycleOption("Petroleum", LANTERNCYCLE.PETROLEUM, null)
            };

            // Aquarium options
            aquariumPacuCycle.Options = new List <FCycle.CycleOption>()
            {
                new FCycle.CycleOption("Stasis", PACUCYLCE.STASIS, PACUCYLCE.STASISDESC),
                new FCycle.CycleOption("Normal", PACUCYLCE.NORMAL, PACUCYLCE.NORMALDESC),
                new FCycle.CycleOption("TenTimes", PACUCYLCE.TENTIMES, PACUCYLCE.TENTIMESDESC)
            };
            aquariumPacuCycle.showDescriptions = true;

            SetSettings(Mod.Settings);

            ConsumeMouseScroll = true;
            activateOnSpawn    = true;
            gameObject.SetActive(false);
        }