Beispiel #1
0
        public string GetName()
        {
            if (PlayerInput.NumberKeys.Contains(Key))
            {
                return(Key.ToString().Substring(1, 1));
            }
            if (MouseButton != MouseButton.None)
            {
                switch (MouseButton)
                {
                case MouseButton.PrimaryMouse:
                    return(PlayerInput.MouseButtonsSwapped() ? TextManager.Get("input.rightmouse") : TextManager.Get("input.leftmouse"));

                case MouseButton.SecondaryMouse:
                    return(PlayerInput.MouseButtonsSwapped() ? TextManager.Get("input.leftmouse") : TextManager.Get("input.rightmouse"));

                default:
                    return(TextManager.Get("input." + MouseButton.ToString().ToLowerInvariant()));
                }
            }
            else
            {
                return(Key.ToString());
            }
        }
Beispiel #2
0
        private void CreateCharacterFrame(CharacterInfo characterInfo, GUIListBox listBox)
        {
            Skill skill    = null;
            Color?jobColor = null;

            if (characterInfo.Job != null)
            {
                skill    = characterInfo.Job?.PrimarySkill ?? characterInfo.Job.Skills.OrderByDescending(s => s.Level).FirstOrDefault();
                jobColor = characterInfo.Job.Prefab.UIColor;
            }

            GUIFrame frame = new GUIFrame(new RectTransform(new Point(listBox.Content.Rect.Width, (int)(GUI.yScale * 55)), parent: listBox.Content.RectTransform), "ListBoxElement")
            {
                UserData = new Tuple <CharacterInfo, float>(characterInfo, skill?.Level ?? 0.0f)
            };
            GUILayoutGroup mainGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.95f, 0.95f), frame.RectTransform, anchor: Anchor.Center), isHorizontal: true, childAnchor: Anchor.CenterLeft)
            {
                Stretch = true
            };

            float portraitWidth = (0.8f * mainGroup.Rect.Height) / mainGroup.Rect.Width;
            var   icon          = new GUICustomComponent(new RectTransform(new Vector2(portraitWidth, 0.8f), mainGroup.RectTransform),
                                                         onDraw: (sb, component) => characterInfo.DrawIcon(sb, component.Rect.Center.ToVector2(), targetAreaSize: component.Rect.Size.ToVector2()))
            {
                CanBeFocused = false
            };

            GUILayoutGroup nameAndJobGroup = new GUILayoutGroup(new RectTransform(new Vector2(0.4f - portraitWidth, 0.8f), mainGroup.RectTransform))
            {
                CanBeFocused = false
            };
            GUILayoutGroup nameGroup = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.5f), nameAndJobGroup.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft)
            {
                CanBeFocused = false
            };
            GUITextBlock nameBlock = new GUITextBlock(new RectTransform(Vector2.One, nameGroup.RectTransform),
                                                      listBox == hireableList ? characterInfo.OriginalName : characterInfo.Name,
                                                      textColor: jobColor, textAlignment: Alignment.BottomLeft)
            {
                CanBeFocused = false
            };

            nameBlock.Text = ToolBox.LimitString(nameBlock.Text, nameBlock.Font, nameBlock.Rect.Width);

            GUITextBlock jobBlock = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.5f), nameAndJobGroup.RectTransform),
                                                     characterInfo.Job.Name, textColor: Color.White, font: GUI.SmallFont, textAlignment: Alignment.TopLeft)
            {
                CanBeFocused = false
            };

            jobBlock.Text = ToolBox.LimitString(jobBlock.Text, jobBlock.Font, jobBlock.Rect.Width);

            float width = 0.6f / 3;

            if (characterInfo.Job != null && skill != null)
            {
                GUILayoutGroup skillGroup = new GUILayoutGroup(new RectTransform(new Vector2(width, 0.6f), mainGroup.RectTransform), isHorizontal: true);
                float          iconWidth  = (float)skillGroup.Rect.Height / skillGroup.Rect.Width;
                GUIImage       skillIcon  = new GUIImage(new RectTransform(new Vector2(iconWidth, 1.0f), skillGroup.RectTransform), skill.Icon)
                {
                    CanBeFocused = false
                };
                if (jobColor.HasValue)
                {
                    skillIcon.Color = jobColor.Value;
                }
                new GUITextBlock(new RectTransform(new Vector2(1.0f - iconWidth, 1.0f), skillGroup.RectTransform), ((int)skill.Level).ToString(), textAlignment: Alignment.CenterLeft)
                {
                    CanBeFocused = false
                };
            }

            if (listBox != crewList)
            {
                new GUITextBlock(new RectTransform(new Vector2(width, 1.0f), mainGroup.RectTransform),
                                 FormatCurrency(characterInfo.Salary),
                                 textAlignment: Alignment.Center)
                {
                    CanBeFocused = false
                };
            }
            else
            {
                // Just a bit of padding to make list layouts similar
                new GUIFrame(new RectTransform(new Vector2(width, 1.0f), mainGroup.RectTransform), style: null)
                {
                    CanBeFocused = false
                };
            }

            if (listBox == hireableList)
            {
                var hireButton = new GUIButton(new RectTransform(new Vector2(width, 0.9f), mainGroup.RectTransform), style: "CrewManagementAddButton")
                {
                    UserData  = characterInfo,
                    Enabled   = HasPermission,
                    OnClicked = (b, o) => AddPendingHire(o as CharacterInfo)
                };
                hireButton.OnAddedToGUIUpdateList += (GUIComponent btn) =>
                {
                    if (PendingHires.Count + campaign.CrewManager.GetCharacterInfos().Count() >= CrewManager.MaxCrewSize)
                    {
                        if (btn.Enabled)
                        {
                            btn.ToolTip = TextManager.Get("canthiremorecharacters");
                            btn.Enabled = false;
                        }
                    }
                    else if (!btn.Enabled)
                    {
                        btn.ToolTip = string.Empty;
                        btn.Enabled = true;
                    }
                };
            }
            else if (listBox == pendingList)
            {
                new GUIButton(new RectTransform(new Vector2(width, 0.9f), mainGroup.RectTransform), style: "CrewManagementRemoveButton")
                {
                    UserData  = characterInfo,
                    Enabled   = HasPermission,
                    OnClicked = (b, o) => RemovePendingHire(o as CharacterInfo)
                };
            }
            else if (listBox == crewList && campaign != null)
            {
                var currentCrew = GameMain.GameSession.CrewManager.GetCharacterInfos();
                new GUIButton(new RectTransform(new Vector2(width, 0.9f), mainGroup.RectTransform), style: "CrewManagementFireButton")
                {
                    UserData = characterInfo,
                    //can't fire if there's only one character in the crew
                    Enabled   = currentCrew.Contains(characterInfo) && currentCrew.Count() > 1 && HasPermission,
                    OnClicked = (btn, obj) =>
                    {
                        var confirmDialog = new GUIMessageBox(
                            TextManager.Get("FireWarningHeader"),
                            TextManager.GetWithVariable("FireWarningText", "[charactername]", ((CharacterInfo)obj).Name),
                            new string[] { TextManager.Get("Yes"), TextManager.Get("No") });
                        confirmDialog.Buttons[0].UserData   = (CharacterInfo)obj;
                        confirmDialog.Buttons[0].OnClicked  = FireCharacter;
                        confirmDialog.Buttons[0].OnClicked += confirmDialog.Close;
                        confirmDialog.Buttons[1].OnClicked  = confirmDialog.Close;
                        return(true);
                    }
                };
            }

            if (listBox == pendingList || listBox == crewList)
            {
                nameBlock.RectTransform.Resize(new Point(nameBlock.Rect.Width - nameBlock.Rect.Height, nameBlock.Rect.Height));
                nameBlock.Text = ToolBox.LimitString(nameBlock.Text, nameBlock.Font, nameBlock.Rect.Width);
                nameBlock.RectTransform.Resize(new Point((int)(nameBlock.Padding.X + nameBlock.TextSize.X + nameBlock.Padding.Z), nameBlock.Rect.Height));
                Point size = new Point((int)(0.7f * nameBlock.Rect.Height));
                new GUIImage(new RectTransform(size, nameGroup.RectTransform), "EditIcon")
                {
                    CanBeFocused = false
                };
                size = new Point(3 * mainGroup.AbsoluteSpacing + icon.Rect.Width + nameAndJobGroup.Rect.Width, mainGroup.Rect.Height);
                new GUIButton(new RectTransform(size, frame.RectTransform)
                {
                    RelativeOffset = new Vector2(0.025f)
                }, style: null)
                {
                    Enabled   = HasPermission,
                    ToolTip   = TextManager.GetWithVariable("campaigncrew.givenicknametooltip", "[mouseprimary]", TextManager.Get($"input.{(PlayerInput.MouseButtonsSwapped() ? "rightmouse" : "leftmouse")}")),
                    UserData  = characterInfo,
                    OnClicked = CreateRenamingComponent
                };
            }
        }