Exemplo n.º 1
0
        /// <summary>Shortens the text of the specified <paramref name="component"/> to fit the component's parent width.</summary>
        /// <param name="component">The component to process.</param>
        /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
        /// <remarks>This method is copied from the original game and is slightly modified.</remarks>
        public static void ShortenTextToFitParent(UITextComponent component)
        {
            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            if (component.parent == null)
            {
                return;
            }

            float parentWidth = component.parent.width;
            float targetWidth = parentWidth - component.relativePosition.x;

            if (component.width > targetWidth && component.text != null)
            {
                component.tooltip = component.text;
                string text = component.text;
                while (component.width > targetWidth && text.Length > 5)
                {
                    text           = text.Remove(text.Length - 4).Trim() + "...";
                    component.text = text;
                }
            }
            else
            {
                component.tooltip = string.Empty;
            }
        }
Exemplo n.º 2
0
        public static void CreateMenuScene(Game game)
        {
            var jouer_entity = new Entity(true);

            jouer_entity.Name        = "jouer";
            jouer_entity.Transform.x = 300;
            jouer_entity.Transform.y = 200;
            var jouer_cmp       = new Engine.System.UI.ImageButtonComponent(jouer_entity);
            var jouer_img_asset = new Engine.System.UI.ImageAsset();

            jouer_img_asset.ContentName = "bouton_jouer";
            jouer_cmp.onclick.action    = (entity, context) => { Embed.LoadScene("game_scene", Engine.Core.Game.Instance); };

            jouer_cmp.AddAsset(jouer_img_asset);
            jouer_entity.AddComponent(jouer_cmp);

            var quitter_entity = new Entity(true);

            quitter_entity.Name        = "quitter";
            quitter_entity.Transform.x = 288;
            quitter_entity.Transform.y = 275;
            var quitter_cmp       = new ImageButtonComponent(quitter_entity);
            var quitter_img_asset = new ImageAsset();

            quitter_img_asset.ContentName = "bouton_quitter";
            quitter_cmp.AddAsset(quitter_img_asset);
            jouer_cmp.onclick.contextRefs = null;
            quitter_cmp.onclick.action    = (entity, context) => { Game.Instance.Exit(); };
            quitter_entity.AddComponent(quitter_cmp);

            var text_entity = new Entity(true);

            text_entity.Name        = "text";
            text_entity.Transform.x = 230;
            text_entity.Transform.y = 100;
            var text_cmp = new UITextComponent(text_entity);

            text_cmp.Text     = "Makers² : le jeu démo !";
            text_cmp.Color    = new Vector4(0, 0, 0, 1);
            text_cmp.FontSize = 36;


            var font_asset = new FontAsset();

            font_asset.ContentName = "coolvetica";
            text_cmp.AddAsset(font_asset);
            text_entity.AddComponent(text_cmp);

            var save_manager = new SavedFilesManager(Manager.Instance);
            var PreSave      = new List <Entity> {
                jouer_entity, quitter_entity, text_entity
            };
            var scene = new SavedScene();

            scene.entities = PreSave;
            save_manager.SaveScene(scene, "menu_scene");
        }
Exemplo n.º 3
0
 public static void SetLineNumberCircleOnRef(ushort lineID, UITextComponent reference, float ratio = 1f)
 {
     GetLineNumberCircleOnRefParams(lineID, ratio, out string text, out Color textColor, out float textScale, out Vector3 relativePosition);
     reference.text             = text;
     reference.textScale        = textScale;
     reference.relativePosition = relativePosition;
     reference.textColor        = textColor;
     reference.useOutline       = true;
     reference.outlineColor     = Color.black;
 }
Exemplo n.º 4
0
 private void RefreshKeyMapping()
 {
     foreach (UIComponent current in component.GetComponentsInChildren <UIComponent>())
     {
         UITextComponent uITextComponent = current.Find <UITextComponent>("Binding");
         SavedInputKey   savedInputKey   = (SavedInputKey)uITextComponent.objectUserData;
         if (this.m_EditingBinding != savedInputKey)
         {
             uITextComponent.text = savedInputKey.ToLocalizedString("KEYNAME");
         }
     }
 }
Exemplo n.º 5
0
 private void RefreshKeyMapping()
 {
     UIComponent[] componentsInChildren = base.component.GetComponentsInChildren <UIComponent>();
     for (int i = 0; i < componentsInChildren.Length; i++)
     {
         UITextComponent uitextComponent = componentsInChildren[i].Find <UITextComponent>("Binding");
         SavedInputKey   savedInputKey   = (SavedInputKey)uitextComponent.objectUserData;
         if (m_EditingBinding != savedInputKey)
         {
             uitextComponent.text = savedInputKey.ToLocalizedString("KEYNAME");
         }
     }
 }
        private static void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
        {
            if (m_EditingBinding != null && !IsModifierKey(p.keycode))
            {
                p.Use();
                UIView.PopModal();
                KeyCode  keycode  = p.keycode;
                InputKey inputKey = (p.keycode == KeyCode.Escape) ? (InputKey)m_EditingBinding.inputKey : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
                if (p.keycode == KeyCode.Backspace)
                {
                    inputKey = 0;
                }
                List <Shortcut> currentAssigned;
                if (!IsAlreadyBound(m_EditingBinding, inputKey, out currentAssigned))
                {
                    if (m_EditingBinding.inputKey != inputKey)
                    {
                        m_EditingBinding.inputKey = inputKey;
                        Shortcut.SaveShorcuts();
                    }

                    UITextComponent uITextComponent = p.source as UITextComponent;
                    uITextComponent.text = SavedInputKey.ToLocalizedString("KEYNAME", inputKey);
                    m_EditingBinding     = null;
                }
                else
                {
                    string arg     = (currentAssigned.Count <= 1) ? currentAssigned[0].name : Locale.Get("KEYMAPPING_MULTIPLE");
                    string message = string.Format(Locale.Get("CONFIRM_REBINDKEY", "Message"), SavedInputKey.ToLocalizedString("KEYNAME", inputKey), arg);
                    ConfirmPanel.ShowModal(Locale.Get("CONFIRM_REBINDKEY", "Title"), message, delegate(UIComponent c, int ret)
                    {
                        if (ret == 1)
                        {
                            for (int i = 0; i < currentAssigned.Count; i++)
                            {
                                currentAssigned[i].inputKey = 0;
                            }
                        }

                        m_EditingBinding.inputKey = inputKey;
                        Shortcut.SaveShorcuts();
                        RefreshKeyMapping();

                        UITextComponent uITextComponent = p.source as UITextComponent;
                        uITextComponent.text            = SavedInputKey.ToLocalizedString("KEYNAME", m_EditingBinding.inputKey);
                        m_EditingBinding = null;
                    });
                }
            }
        }
Exemplo n.º 7
0
 private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (this.m_EditingBinding != null && !this.IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         KeyCode  keycode  = p.keycode;
         InputKey inputKey = (p.keycode == KeyCode.Escape) ? this.m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             inputKey = SavedInputKey.Empty;
         }
         List <SavedInputKey> currentAssigned;
         if (!this.IsAlreadyBound(this.m_EditingBinding, inputKey, this.m_EditingBindingCategory, out currentAssigned))
         {
             this.m_EditingBinding.value = inputKey;
             UITextComponent uITextComponent = p.source as UITextComponent;
             uITextComponent.text          = this.m_EditingBinding.ToLocalizedString("KEYNAME");
             this.m_EditingBinding         = null;
             this.m_EditingBindingCategory = string.Empty;
         }
         else
         {
             string arg     = (currentAssigned.Count <= 1) ? Locale.Get("KEYMAPPING", currentAssigned[0].name) : Locale.Get("KEYMAPPING_MULTIPLE");
             string message = string.Format(Locale.Get("CONFIRM_REBINDKEY", "Message"), SavedInputKey.ToLocalizedString("KEYNAME", inputKey), arg);
             ConfirmPanel.ShowModal(Locale.Get("CONFIRM_REBINDKEY", "Title"), message, delegate(UIComponent c, int ret)
             {
                 if (ret == 1)
                 {
                     this.m_EditingBinding.value = inputKey;
                     for (int i = 0; i < currentAssigned.Count; i++)
                     {
                         currentAssigned[i].value = SavedInputKey.Empty;
                     }
                     this.RefreshKeyMapping();
                 }
                 UITextComponent uITextComponent2 = p.source as UITextComponent;
                 uITextComponent2.text            = this.m_EditingBinding.ToLocalizedString("KEYNAME");
                 this.m_EditingBinding            = null;
                 this.m_EditingBindingCategory    = string.Empty;
             });
         }
     }
 }
Exemplo n.º 8
0
 private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (this.m_EditingBinding != null && !this.IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         KeyCode  keycode  = p.keycode;
         InputKey inputKey = (p.keycode == KeyCode.Escape) ? this.m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             inputKey = SavedInputKey.Empty;
         }
         this.m_EditingBinding.value = inputKey;
         UITextComponent uITextComponent = p.source as UITextComponent;
         uITextComponent.text          = this.m_EditingBinding.ToLocalizedString("KEYNAME");
         this.m_EditingBinding         = null;
         this.m_EditingBindingCategory = string.Empty;
     }
 }
Exemplo n.º 9
0
        public UserInterface(int Score) : base(true)
        {
            Name = "Score";

            var text_cmp = new UITextComponent(this);

            Transform.x       = 550;
            Transform.y       = 10;
            text_cmp.Text     = "Score " + Score.ToString();
            text_cmp.Color    = new Vector4(75, 75, 0, 1);
            text_cmp.FontSize = 26;
            var font_asset = new FontAsset();

            font_asset.ContentName = "coolvetica rg.ttf";

            text_cmp.AddAsset(font_asset);
            AddComponent(text_cmp);
            Debug.WriteLine("User Interface constructor called");
        }
Exemplo n.º 10
0
 private void RefreshBindableInputs()
 {
     foreach (UIComponent current in component.GetComponentsInChildren <UIComponent>())
     {
         UITextComponent uITextComponent = current.Find <UITextComponent>("Binding");
         if (uITextComponent != null)
         {
             SavedInputKey savedInputKey = uITextComponent.objectUserData as SavedInputKey;
             if (savedInputKey != null)
             {
                 uITextComponent.text = savedInputKey.ToLocalizedString("KEYNAME");
             }
         }
         UILabel uILabel = current.Find <UILabel>("Name");
         if (uILabel != null)
         {
             uILabel.text = Locale.Get("KEYMAPPING", uILabel.stringUserData);
         }
     }
 }
Exemplo n.º 11
0
 private void RefreshBindableInputs()
 {
     foreach (UIComponent uicomponent in base.component.GetComponentsInChildren <UIComponent>())
     {
         UITextComponent uitextComponent = uicomponent.Find <UITextComponent>("Binding");
         if (uitextComponent != null)
         {
             SavedInputKey savedInputKey = uitextComponent.objectUserData as SavedInputKey;
             if (savedInputKey != null)
             {
                 uitextComponent.text = savedInputKey.ToLocalizedString("KEYNAME");
             }
         }
         UILabel uilabel = uicomponent.Find <UILabel>("Name");
         if (uilabel != null)
         {
             uilabel.text = uilabel.stringUserData;
         }
     }
 }
Exemplo n.º 12
0
 private void RefreshBindableInputs()
 {
     foreach (UIComponent componentsInChild in this.component.GetComponentsInChildren <UIComponent>())
     {
         UITextComponent uiTextComponent = componentsInChild.Find <UITextComponent>("Binding");
         if (uiTextComponent != null)
         {
             SavedInputKey objectUserData = uiTextComponent.objectUserData as SavedInputKey;
             if ((SavedValue)objectUserData != (SavedValue)null)
             {
                 uiTextComponent.text = objectUserData.ToLocalizedString("KEYNAME");
             }
         }
         UILabel uiLabel = componentsInChild.Find <UILabel>("Name");
         if (uiLabel != null)
         {
             uiLabel.text = ColossalFramework.Globalization.Locale.Get("KEYMAPPING", uiLabel.stringUserData);
         }
     }
 }
Exemplo n.º 13
0
        public Shortcut(UIComponent component)
        {
            UITextComponent textComponent = component as UITextComponent;

            if (textComponent != null && !textComponent.text.IsNullOrWhiteSpace())
            {
                this.name = GetUniqueName(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(textComponent.text.ToLower()));
            }
            else
            {
                this.name = GetUniqueName(component.name);
            }
            this.component = component.name;
            this.path      = GetUIComponentPath(component);

            if (component.parent != null)
            {
                foreach (UIComponent child in component.parent.components)
                {
                    if (child != component && child.name == component.name)
                    {
                        this.usePath     = true;
                        this.onlyVisible = false;
                        return;
                    }
                }
            }

            UIComponent[] components = GameObject.FindObjectsOfType <UIComponent>();
            for (int i = 0; i < components.Length; i++)
            {
                if (components[i] != component && components[i].name == component.name)
                {
                    this.usePath     = false;
                    this.onlyVisible = true;
                    return;
                }
            }
        }
 protected void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter p)
 {
     if (this.m_EditingBinding != null && !this.IsModifierKey(p.keycode))
     {
         p.Use();
         UIView.PopModal();
         KeyCode  keycode  = p.keycode;
         InputKey inputKey = (p.keycode == KeyCode.Escape) ? this.m_EditingBinding.value : SavedInputKey.Encode(keycode, p.control, p.shift, p.alt);
         if (p.keycode == KeyCode.Backspace)
         {
             KeyBindingsManager.instance.GetBindingFromName(comp.parent.name).SetEmpty();
             inputKey = SavedInputKey.Empty;
         }
         else
         {
             KeyBindingsManager.instance.GetBindingFromName(comp.parent.name).ApplySavedInput(keycode, p.control, p.shift, p.alt);
         }
         this.m_EditingBinding.value = inputKey;
         UITextComponent uITextComponent = p.source as UITextComponent;
         uITextComponent.text          = this.m_EditingBinding.ToLocalizedString("KEYNAME");
         this.m_EditingBinding         = null;
         this.m_EditingBindingCategory = string.Empty;
     }
 }
 public void SetCounter(UITextComponent counterLabel)
 {
     counter = counterLabel;
 }
Exemplo n.º 16
0
 public ColossalTextControl(UITextComponent component, bool subscribeEvents = false)
     : base(component, subscribeEvents)
 {
 }