private static GameObject CreateToggle(DefaultControls.Resources resources)
        {
            // Set up hierarchy
            GameObject toggleRoot = CreateUIElementRoot("Toggle 2.0", s_ThinElementSize);

            GameObject background = CreateUIObject("Background", toggleRoot);
            GameObject checkmark  = CreateUIObject("Checkmark", background);
            GameObject childLabel = CreateUIObject("Label", toggleRoot);

            // Set up components
            Toggle2 toggle = toggleRoot.AddComponent <Toggle2>();

            toggle.isOn = true;

            Image bgImage = background.AddComponent <Image>();

            bgImage.sprite = resources.standard;
            bgImage.type   = Image.Type.Sliced;
            bgImage.color  = s_DefaultSelectableColor;

            Image checkmarkImage = checkmark.AddComponent <Image>();

            checkmarkImage.sprite = resources.checkmark;

            Text label = childLabel.AddComponent <Text>();

            label.text = "Toggle 2.0";
            SetDefaultTextValues(label);

            toggle.graphic       = checkmarkImage;
            toggle.targetGraphic = bgImage;
            SetDefaultColorTransitionValues(toggle);

            RectTransform bgRect = background.GetComponent <RectTransform>();

            bgRect.anchorMin        = new Vector2(0f, 1f);
            bgRect.anchorMax        = new Vector2(0f, 1f);
            bgRect.anchoredPosition = new Vector2(10f, -10f);
            bgRect.sizeDelta        = new Vector2(kThinHeight, kThinHeight);

            RectTransform checkmarkRect = checkmark.GetComponent <RectTransform>();

            checkmarkRect.anchorMin        = new Vector2(0.5f, 0.5f);
            checkmarkRect.anchorMax        = new Vector2(0.5f, 0.5f);
            checkmarkRect.anchoredPosition = Vector2.zero;
            checkmarkRect.sizeDelta        = new Vector2(20f, 20f);

            RectTransform labelRect = childLabel.GetComponent <RectTransform>();

            labelRect.anchorMin = new Vector2(0f, 0f);
            labelRect.anchorMax = new Vector2(1f, 1f);
            labelRect.offsetMin = new Vector2(23f, 1f);
            labelRect.offsetMax = new Vector2(-5f, -2f);

            return(toggleRoot);
        }
示例#2
0
        /// <summary>
        /// Toggle fullscreen/GUI
        /// </summary>
        public async Task <bool> SetFullscreen(Toggle2 fullscreen)
        {
            var jArgs = new JObject();

            if (fullscreen != null)
            {
                var jpropfullscreen = JToken.FromObject(fullscreen, _client.Serializer);
                jArgs.Add(new JProperty("fullscreen", jpropfullscreen));
            }
            return(await _client.GetData <bool>("GUI.SetFullscreen", jArgs));
        }
示例#3
0
        /// <summary>
        /// Toggle mute/unmute
        /// </summary>
        public async Task <bool> SetMute(Toggle2 mute)
        {
            var jArgs = new JObject();

            if (mute != null)
            {
                var jpropmute = JToken.FromObject(mute, _client.Serializer);
                jArgs.Add(new JProperty("mute", jpropmute));
            }
            return(await _client.GetData <bool>("Application.SetMute", jArgs));
        }
示例#4
0
        /// <summary>
        /// Shuffle/Unshuffle items in the player
        /// </summary>
        public async Task <string> SetShuffle(Toggle2 shuffle, int playerid = 0)
        {
            var jArgs = new JObject();

            if (playerid != null)
            {
                var jpropplayerid = JToken.FromObject(playerid, _client.Serializer);
                jArgs.Add(new JProperty("playerid", jpropplayerid));
            }
            if (shuffle != null)
            {
                var jpropshuffle = JToken.FromObject(shuffle, _client.Serializer);
                jArgs.Add(new JProperty("shuffle", jpropshuffle));
            }
            return(await _client.GetData <string>("Player.SetShuffle", jArgs));
        }
示例#5
0
        /// <summary>
        /// Pauses or unpause playback and returns the new state
        /// </summary>
        public async Task <Speed> PlayPause(Toggle2 play, int playerid = 0)
        {
            var jArgs = new JObject();

            if (playerid != null)
            {
                var jpropplayerid = JToken.FromObject(playerid, _client.Serializer);
                jArgs.Add(new JProperty("playerid", jpropplayerid));
            }
            if (play != null)
            {
                var jpropplay = JToken.FromObject(play, _client.Serializer);
                jArgs.Add(new JProperty("play", jpropplay));
            }
            return(await _client.GetData <Speed>("Player.PlayPause", jArgs));
        }
示例#6
0
        /// <summary>
        /// Toggle recording of a channel
        /// </summary>
        public async Task <string> Record(Toggle2 record, object channel = null)
        {
            var jArgs = new JObject();

            if (record != null)
            {
                var jproprecord = JToken.FromObject(record, _client.Serializer);
                jArgs.Add(new JProperty("record", jproprecord));
            }
            if (channel != null)
            {
                var jpropchannel = JToken.FromObject(channel, _client.Serializer);
                jArgs.Add(new JProperty("channel", jpropchannel));
            }
            return(await _client.GetData <string>("PVR.Record", jArgs));
        }
示例#7
0
        /// <summary>
        /// Enables/Disables a specific addon
        /// </summary>
        public async Task <string> SetAddonEnabled(Toggle2 enabled, string addonid = null)
        {
            var jArgs = new JObject();

            if (addonid != null)
            {
                var jpropaddonid = JToken.FromObject(addonid, _client.Serializer);
                jArgs.Add(new JProperty("addonid", jpropaddonid));
            }
            if (enabled != null)
            {
                var jpropenabled = JToken.FromObject(enabled, _client.Serializer);
                jArgs.Add(new JProperty("enabled", jpropenabled));
            }
            return(await _client.GetData <string>("Addons.SetAddonEnabled", jArgs));
        }
        public override void Update(GameTime gameTime, List <Component> GameComponents)
        {
            //toggle knapp
            Toggle1 = Toggle2;
            Toggle2 = Keyboard.GetState();

            //player speed höger vänster med keys
            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                Position.X -= 7;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                Position.X += 7;
            }

            //delay på hur många skott jag kan skuta, den räknar skotten sen ifall sätter en delay efter 3 skott
            if (CountDelay >= 3)
            {
                Delay++;
                if (Delay >= 60)
                {
                    CountDelay = 0;
                    Delay      = 0;
                }
            }

            //toggle knap med skott delay (reloud time)
            if (Toggle1.IsKeyDown(Keys.Space) && Toggle2.IsKeyUp(Keys.Space) && CountDelay < 3)
            {
                AddProjectileLeft(GameComponents);
                AddProjectileRight(GameComponents);
                CountDelay++;
            }

            //så player inte kan åka ut ur banan
            if (Position.X > 1366 + 20)
            {
                Position.X = 1366 + 20;
            }
            else if (Position.X < 135)
            {
                Position.X = 135;
            }


            //ifall component är en spelare så fortsätter, ifall rectangle(spelar ingen roll vilken men pga att skeppets skott är så långt ut kan bara..
            //metioriterna(enemy) interacta med skeppet) så är är bool Dead = true.
            foreach (var componet in GameComponents)
            {
                if (componet is Player)
                {
                    continue;
                }

                if (componet.Rectangle.Intersects(this.Rectangle))
                {
                    //dead = true för så att jag kan reseta med reset metoden i game1. this är där för att det fungerade efter många tester
                    this.Dead = true;
                }
            }
        }
        private static GameObject CreateDropdown(DefaultControls.Resources resources)
        {
            GameObject root = CreateUIElementRoot("Dropdown 2.0", s_ThickElementSize);

            GameObject label          = CreateUIObject("Label", root);
            GameObject arrow          = CreateUIObject("Arrow", root);
            GameObject template       = CreateUIObject("Template", root);
            GameObject viewport       = CreateUIObject("Viewport", template);
            GameObject content        = CreateUIObject("Content", viewport);
            GameObject item           = CreateUIObject("Item", content);
            GameObject itemBackground = CreateUIObject("Item Background", item);
            GameObject itemCheckmark  = CreateUIObject("Item Checkmark", item);
            GameObject itemLabel      = CreateUIObject("Item Label", item);

            // Sub controls.

            GameObject scrollbar = CreateScrollbar(resources);

            scrollbar.name = "Scrollbar";
            GameObjectUtility.SetParentAndAlign(scrollbar, template);

            Scrollbar2 scrollbarScrollbar = scrollbar.GetComponent <Scrollbar2>();

            scrollbarScrollbar.SetDirection(Scrollbar.Direction.BottomToTop, true);

            RectTransform vScrollbarRT = scrollbar.GetComponent <RectTransform>();

            vScrollbarRT.anchorMin = Vector2.right;
            vScrollbarRT.anchorMax = Vector2.one;
            vScrollbarRT.pivot     = Vector2.one;
            vScrollbarRT.sizeDelta = new Vector2(vScrollbarRT.sizeDelta.x, 0);

            // Setup item UI components.

            Text itemLabelText = itemLabel.AddComponent <Text>();

            SetDefaultTextValues(itemLabelText);
            itemLabelText.alignment = TextAnchor.MiddleLeft;

            Image itemBackgroundImage = itemBackground.AddComponent <Image>();

            itemBackgroundImage.color = new Color32(245, 245, 245, 255);

            Image itemCheckmarkImage = itemCheckmark.AddComponent <Image>();

            itemCheckmarkImage.sprite = resources.checkmark;

            Toggle2 itemToggle = item.AddComponent <Toggle2>();

            itemToggle.targetGraphic = itemBackgroundImage;
            itemToggle.graphic       = itemCheckmarkImage;
            itemToggle.isOn          = true;

            // Setup template UI components.

            Image templateImage = template.AddComponent <Image>();

            templateImage.sprite = resources.standard;
            templateImage.type   = Image.Type.Sliced;

            ScrollRect2 templateScrollRect = template.AddComponent <ScrollRect2>();

            templateScrollRect.content                     = (RectTransform)content.transform;
            templateScrollRect.viewport                    = (RectTransform)viewport.transform;
            templateScrollRect.horizontal                  = false;
            templateScrollRect.movementType                = ScrollRect.MovementType.Clamped;
            templateScrollRect.verticalScrollbar           = scrollbarScrollbar;
            templateScrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
            templateScrollRect.verticalScrollbarSpacing    = -3;

            Mask scrollRectMask = viewport.AddComponent <Mask>();

            scrollRectMask.showMaskGraphic = false;

            Image viewportImage = viewport.AddComponent <Image>();

            viewportImage.sprite = resources.mask;
            viewportImage.type   = Image.Type.Sliced;

            // Setup dropdown UI components.

            Text labelText = label.AddComponent <Text>();

            SetDefaultTextValues(labelText);
            labelText.alignment = TextAnchor.MiddleLeft;

            Image arrowImage = arrow.AddComponent <Image>();

            arrowImage.sprite = resources.dropdown;

            Image backgroundImage = root.AddComponent <Image>();

            backgroundImage.sprite = resources.standard;
            backgroundImage.color  = s_DefaultSelectableColor;
            backgroundImage.type   = Image.Type.Sliced;

            Dropdown2 dropdown = root.AddComponent <Dropdown2>();

            dropdown.targetGraphic = backgroundImage;
            SetDefaultColorTransitionValues(dropdown);
            dropdown.template    = template.GetComponent <RectTransform>();
            dropdown.captionText = labelText;
            dropdown.itemText    = itemLabelText;

            // Setting default Item list.
            itemLabelText.text = "Option A";
            dropdown.options.Add(new Dropdown.OptionData {
                text = "Option A"
            });
            dropdown.options.Add(new Dropdown.OptionData {
                text = "Option B"
            });
            dropdown.options.Add(new Dropdown.OptionData {
                text = "Option C"
            });
            dropdown.RefreshShownValue();

            // Set up RectTransforms.

            RectTransform labelRT = label.GetComponent <RectTransform>();

            labelRT.anchorMin = Vector2.zero;
            labelRT.anchorMax = Vector2.one;
            labelRT.offsetMin = new Vector2(10, 6);
            labelRT.offsetMax = new Vector2(-25, -7);

            RectTransform arrowRT = arrow.GetComponent <RectTransform>();

            arrowRT.anchorMin        = new Vector2(1, 0.5f);
            arrowRT.anchorMax        = new Vector2(1, 0.5f);
            arrowRT.sizeDelta        = new Vector2(20, 20);
            arrowRT.anchoredPosition = new Vector2(-15, 0);

            RectTransform templateRT = template.GetComponent <RectTransform>();

            templateRT.anchorMin        = new Vector2(0, 0);
            templateRT.anchorMax        = new Vector2(1, 0);
            templateRT.pivot            = new Vector2(0.5f, 1);
            templateRT.anchoredPosition = new Vector2(0, 2);
            templateRT.sizeDelta        = new Vector2(0, 150);

            RectTransform viewportRT = viewport.GetComponent <RectTransform>();

            viewportRT.anchorMin = new Vector2(0, 0);
            viewportRT.anchorMax = new Vector2(1, 1);
            viewportRT.sizeDelta = new Vector2(-18, 0);
            viewportRT.pivot     = new Vector2(0, 1);

            RectTransform contentRT = content.GetComponent <RectTransform>();

            contentRT.anchorMin        = new Vector2(0f, 1);
            contentRT.anchorMax        = new Vector2(1f, 1);
            contentRT.pivot            = new Vector2(0.5f, 1);
            contentRT.anchoredPosition = new Vector2(0, 0);
            contentRT.sizeDelta        = new Vector2(0, 28);

            RectTransform itemRT = item.GetComponent <RectTransform>();

            itemRT.anchorMin = new Vector2(0, 0.5f);
            itemRT.anchorMax = new Vector2(1, 0.5f);
            itemRT.sizeDelta = new Vector2(0, 20);

            RectTransform itemBackgroundRT = itemBackground.GetComponent <RectTransform>();

            itemBackgroundRT.anchorMin = Vector2.zero;
            itemBackgroundRT.anchorMax = Vector2.one;
            itemBackgroundRT.sizeDelta = Vector2.zero;

            RectTransform itemCheckmarkRT = itemCheckmark.GetComponent <RectTransform>();

            itemCheckmarkRT.anchorMin        = new Vector2(0, 0.5f);
            itemCheckmarkRT.anchorMax        = new Vector2(0, 0.5f);
            itemCheckmarkRT.sizeDelta        = new Vector2(20, 20);
            itemCheckmarkRT.anchoredPosition = new Vector2(10, 0);

            RectTransform itemLabelRT = itemLabel.GetComponent <RectTransform>();

            itemLabelRT.anchorMin = Vector2.zero;
            itemLabelRT.anchorMax = Vector2.one;
            itemLabelRT.offsetMin = new Vector2(20, 1);
            itemLabelRT.offsetMax = new Vector2(-10, -2);

            template.SetActive(false);

            return(root);
        }