Ejemplo n.º 1
0
		private void _setState(SkillState newState)
		{
			SkillState old = m_state;

			if (old == newState) return;

			int numToLearn = m_skills.Count(_skill => !World.Instance.MainPlayer.ActiveCharacter.Spells.Exists(_spell => _spell.id == _skill.ID));
			int numToForget = World.Instance.MainPlayer.ActiveCharacter.Spells.Count;

			if (newState == SkillState.Learn && numToLearn == 0)
			{
				EOMessageBox.Show(DATCONST1.SKILL_NOTHING_MORE_TO_LEARN, XNADialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
				return;
			}

			ClearItemList();
			switch (newState)
			{
				case SkillState.Initial:
				{
					string learnNum = string.Format("{0}{1}", numToLearn, World.GetString(DATCONST2.SKILLMASTER_ITEMS_TO_LEARN));
					string forgetNum = string.Format("{0}{1}", numToForget, World.GetString(DATCONST2.SKILLMASTER_ITEMS_LEARNED));

					ListDialogItem learn = new ListDialogItem(this, ListDialogItem.ListItemStyle.Large, 0)
					{
						Text = World.GetString(DATCONST2.SKILLMASTER_WORD_LEARN),
						SubText = learnNum,
						IconGraphic = LearnIcon,
						ShowItemBackGround = false,
						OffsetY = 45
					};
					learn.OnLeftClick += (o, e) => _setState(SkillState.Learn);
					learn.OnRightClick += (o, e) => _setState(SkillState.Learn);
					AddItemToList(learn, false);

					ListDialogItem forget = new ListDialogItem(this, ListDialogItem.ListItemStyle.Large, 1)
					{
						Text = World.GetString(DATCONST2.SKILLMASTER_WORD_FORGET),
						SubText = forgetNum,
						IconGraphic = ForgetIcon,
						ShowItemBackGround = false,
						OffsetY = 45
					};
					forget.OnLeftClick += (o, e) => _setState(SkillState.Forget);
					forget.OnRightClick += (o, e) => _setState(SkillState.Forget);
					AddItemToList(forget, false);

					ListDialogItem forgetAll = new ListDialogItem(this, ListDialogItem.ListItemStyle.Large, 2)
					{
						Text = World.GetString(DATCONST2.SKILLMASTER_FORGET_ALL),
						SubText = World.GetString(DATCONST2.SKILLMASTER_RESET_YOUR_CHARACTER),
						IconGraphic = ForgetIcon,
						ShowItemBackGround = false,
						OffsetY = 45
					};
					forgetAll.OnLeftClick += (o, e) => _setState(SkillState.ForgetAll);
					forgetAll.OnRightClick += (o, e) => _setState(SkillState.ForgetAll);
					AddItemToList(forgetAll, false);

					_setButtons(ScrollingListDialogButtons.Cancel);
				}
					break;
				case SkillState.Learn:
				{
					int index = 0;
					for (int i = 0; i < m_skills.Count; ++i)
					{
						if (World.Instance.MainPlayer.ActiveCharacter.Spells.FindIndex(_sp => m_skills[i].ID == _sp.id) >= 0)
							continue;
						int localI = i;

						SpellRecord spellData = (SpellRecord) World.Instance.ESF.Data[m_skills[localI].ID];

						ListDialogItem nextListItem = new ListDialogItem(this, ListDialogItem.ListItemStyle.Large, index++)
						{
							Visible = false,
							Text = spellData.Name,
							SubText = World.GetString(DATCONST2.SKILLMASTER_WORD_REQUIREMENTS),
							IconGraphic = World.GetSpellIcon(spellData.Icon, false),
							ShowItemBackGround = false,
							OffsetY = 45,
							ID = m_skills[localI].ID
						};
						nextListItem.OnLeftClick += (o, e) => _learn(m_skills[localI]);
						nextListItem.OnRightClick += (o, e) => _learn(m_skills[localI]);
						nextListItem.OnMouseEnter += (o, e) => _showRequirementsLabel(m_skills[localI]);
						nextListItem.SetSubtextLink(() => _showRequirements(m_skills[localI]));
						AddItemToList(nextListItem, false);
					}

					_setButtons(ScrollingListDialogButtons.BackCancel);
				}
					break;
				case SkillState.Forget:
				{
					TextInputDialog input = new TextInputDialog(World.GetString(DATCONST1.SKILL_PROMPT_TO_FORGET, false), 32);
					input.SetAsKeyboardSubscriber();
					input.DialogClosing += (sender, args) =>
					{
						if (args.Result == XNADialogResult.Cancel) return;
						bool found =
							World.Instance.MainPlayer.ActiveCharacter.Spells.Any(
								_spell => ((SpellRecord) World.Instance.ESF.Data[_spell.id]).Name.ToLower() == input.ResponseText.ToLower());

						if (!found)
						{
							args.CancelClose = true;
							EOMessageBox.Show(DATCONST1.SKILL_FORGET_ERROR_NOT_LEARNED, XNADialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
							input.SetAsKeyboardSubscriber();
						}

						if (!m_api.ForgetSpell(
								World.Instance.MainPlayer.ActiveCharacter.Spells.Find(
									_spell => ((SpellRecord) World.Instance.ESF.Data[_spell.id]).Name.ToLower() == input.ResponseText.ToLower()).id))
						{
							Close();
							((EOGame)Game).DoShowLostConnectionDialogAndReturnToMainMenu();
						}
					};

					//should show initial info in the actual dialog since this uses a pop-up input box
					//	to select a skill to remove
					newState = SkillState.Initial;
					goto case SkillState.Initial;
				}
				case SkillState.ForgetAll:
				{
					_showForgetAllMessage(_forgetAllAction);
					_setButtons(ScrollingListDialogButtons.BackCancel);
				}
					break;
			}

			m_state = newState;
		}
Ejemplo n.º 2
0
        private void _setState(SkillState newState)
        {
            SkillState old = m_state;

            if (old == newState)
            {
                return;
            }

            int numToLearn  = m_skills.Count(_skill => !OldWorld.Instance.MainPlayer.ActiveCharacter.Spells.Exists(_spell => _spell.ID == _skill.ID));
            int numToForget = OldWorld.Instance.MainPlayer.ActiveCharacter.Spells.Count;

            if (newState == SkillState.Learn && numToLearn == 0)
            {
                EOMessageBox.Show(DialogResourceID.SKILL_NOTHING_MORE_TO_LEARN, EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
                return;
            }

            ClearItemList();
            switch (newState)
            {
            case SkillState.Initial:
            {
                string learnNum  = $"{numToLearn}{OldWorld.GetString(EOResourceID.SKILLMASTER_ITEMS_TO_LEARN)}";
                string forgetNum = $"{numToForget}{OldWorld.GetString(EOResourceID.SKILLMASTER_ITEMS_LEARNED)}";

                ListDialogItem learn = new ListDialogItem(this, ListDialogItem.ListItemStyle.Large, 0)
                {
                    Text               = OldWorld.GetString(EOResourceID.SKILLMASTER_WORD_LEARN),
                    SubText            = learnNum,
                    IconGraphic        = LearnIcon,
                    ShowItemBackGround = false,
                    OffsetY            = 45
                };
                learn.OnLeftClick  += (o, e) => _setState(SkillState.Learn);
                learn.OnRightClick += (o, e) => _setState(SkillState.Learn);
                AddItemToList(learn, false);

                ListDialogItem forget = new ListDialogItem(this, ListDialogItem.ListItemStyle.Large, 1)
                {
                    Text               = OldWorld.GetString(EOResourceID.SKILLMASTER_WORD_FORGET),
                    SubText            = forgetNum,
                    IconGraphic        = ForgetIcon,
                    ShowItemBackGround = false,
                    OffsetY            = 45
                };
                forget.OnLeftClick  += (o, e) => _setState(SkillState.Forget);
                forget.OnRightClick += (o, e) => _setState(SkillState.Forget);
                AddItemToList(forget, false);

                ListDialogItem forgetAll = new ListDialogItem(this, ListDialogItem.ListItemStyle.Large, 2)
                {
                    Text               = OldWorld.GetString(EOResourceID.SKILLMASTER_FORGET_ALL),
                    SubText            = OldWorld.GetString(EOResourceID.SKILLMASTER_RESET_YOUR_CHARACTER),
                    IconGraphic        = ForgetIcon,
                    ShowItemBackGround = false,
                    OffsetY            = 45
                };
                forgetAll.OnLeftClick  += (o, e) => _setState(SkillState.ForgetAll);
                forgetAll.OnRightClick += (o, e) => _setState(SkillState.ForgetAll);
                AddItemToList(forgetAll, false);

                _setButtons(ScrollingListDialogButtons.Cancel);
            }
            break;

            case SkillState.Learn:
            {
                int index = 0;
                for (int i = 0; i < m_skills.Count; ++i)
                {
                    if (OldWorld.Instance.MainPlayer.ActiveCharacter.Spells.FindIndex(_sp => m_skills[i].ID == _sp.ID) >= 0)
                    {
                        continue;
                    }
                    int localI = i;

                    var spellData = OldWorld.Instance.ESF.Data[m_skills[localI].ID];

                    ListDialogItem nextListItem = new ListDialogItem(this, ListDialogItem.ListItemStyle.Large, index++)
                    {
                        Visible            = false,
                        Text               = spellData.Name,
                        SubText            = OldWorld.GetString(EOResourceID.SKILLMASTER_WORD_REQUIREMENTS),
                        IconGraphic        = OldWorld.GetSpellIcon(spellData.Icon, false),
                        ShowItemBackGround = false,
                        OffsetY            = 45,
                        ID = m_skills[localI].ID
                    };
                    nextListItem.OnLeftClick  += (o, e) => _learn(m_skills[localI]);
                    nextListItem.OnRightClick += (o, e) => _learn(m_skills[localI]);
                    nextListItem.OnMouseEnter += (o, e) => _showRequirementsLabel(m_skills[localI]);
                    nextListItem.SetSubtextLink(() => _showRequirements(m_skills[localI]));
                    AddItemToList(nextListItem, false);
                }

                _setButtons(ScrollingListDialogButtons.BackCancel);
            }
            break;

            case SkillState.Forget:
            {
                TextInputDialog input = new TextInputDialog(OldWorld.GetString(DialogResourceID.SKILL_PROMPT_TO_FORGET, false), 32);
                input.SetAsKeyboardSubscriber();
                input.DialogClosing += (sender, args) =>
                {
                    if (args.Result == XNADialogResult.Cancel)
                    {
                        return;
                    }
                    bool found =
                        OldWorld.Instance.MainPlayer.ActiveCharacter.Spells.Any(
                            _spell => OldWorld.Instance.ESF.Data[_spell.ID].Name.ToLower() == input.ResponseText.ToLower());

                    if (!found)
                    {
                        args.CancelClose = true;
                        EOMessageBox.Show(DialogResourceID.SKILL_FORGET_ERROR_NOT_LEARNED, EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
                        input.SetAsKeyboardSubscriber();
                    }

                    if (!m_api.ForgetSpell(
                            OldWorld.Instance.MainPlayer.ActiveCharacter.Spells.Find(
                                _spell => OldWorld.Instance.ESF.Data[_spell.ID].Name.ToLower() == input.ResponseText.ToLower()).ID))
                    {
                        Close();
                        ((EOGame)Game).DoShowLostConnectionDialogAndReturnToMainMenu();
                    }
                };

                //should show initial info in the actual dialog since this uses a pop-up input box
                //    to select a skill to remove
                newState = SkillState.Initial;
                goto case SkillState.Initial;
            }

            case SkillState.ForgetAll:
            {
                _showForgetAllMessage(_forgetAllAction);
                _setButtons(ScrollingListDialogButtons.BackCancel);
            }
            break;
            }

            m_state = newState;
        }