Skip to content

Commit

Permalink
Finish implementing skillmaster dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 24, 2022
1 parent ea276ef commit a8989cb
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 100 deletions.
13 changes: 11 additions & 2 deletions EndlessClient/Dialogs/Factories/SkillmasterDialogFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AutomaticTypeMapper;
using EndlessClient.Content;
using EndlessClient.Dialogs.Services;
using EndlessClient.HUD;
using EOLib.Domain.Character;
Expand All @@ -19,10 +20,12 @@ public class SkillmasterDialogFactory : ISkillmasterDialogFactory
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly IEOMessageBoxFactory _messageBoxFactory;
private readonly ITextInputDialogFactory _textInputDialogFactory;
private readonly ISkillDataProvider _skillDataProvider;
private readonly ICharacterProvider _characterProvider;
private readonly ICharacterInventoryProvider _characterInventoryProvider;
private readonly IPubFileProvider _pubFileProvider;
private readonly IContentProvider _contentProvider;

public SkillmasterDialogFactory(INativeGraphicsManager nativeGraphicsManager,
ISkillmasterActions skillmasterActions,
Expand All @@ -31,10 +34,12 @@ public SkillmasterDialogFactory(INativeGraphicsManager nativeGraphicsManager,
ILocalizedStringFinder localizedStringFinder,
IStatusLabelSetter statusLabelSetter,
IEOMessageBoxFactory messageBoxFactory,
ITextInputDialogFactory textInputDialogFactory,
ISkillDataProvider skillDataProvider,
ICharacterProvider characterProvider,
ICharacterInventoryProvider characterInventoryProvider,
IPubFileProvider pubFileProvider)
IPubFileProvider pubFileProvider,
IContentProvider contentProvider)
{
_nativeGraphicsManager = nativeGraphicsManager;
_skillmasterActions = skillmasterActions;
Expand All @@ -43,10 +48,12 @@ public SkillmasterDialogFactory(INativeGraphicsManager nativeGraphicsManager,
_localizedStringFinder = localizedStringFinder;
_statusLabelSetter = statusLabelSetter;
_messageBoxFactory = messageBoxFactory;
_textInputDialogFactory = textInputDialogFactory;
_skillDataProvider = skillDataProvider;
_characterProvider = characterProvider;
_characterInventoryProvider = characterInventoryProvider;
_pubFileProvider = pubFileProvider;
_contentProvider = contentProvider;
}

public SkillmasterDialog Create()
Expand All @@ -58,10 +65,12 @@ public SkillmasterDialog Create()
_localizedStringFinder,
_statusLabelSetter,
_messageBoxFactory,
_textInputDialogFactory,
_skillDataProvider,
_characterProvider,
_characterInventoryProvider,
_pubFileProvider);
_pubFileProvider,
_contentProvider);
}
}

Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Dialogs/ListDialogItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ public void SetPrimaryClickAction(EventHandler onClickAction)
Text = oldText.Text,
Underline = true
};
_primaryText.ResizeBasedOnText();

((XNAHyperLink)_primaryText).OnClick += onClickAction;

_primaryText.SetParentControl(this);
_primaryText.Initialize();
_primaryText.ResizeBasedOnText();

oldText.Dispose();

Expand Down
192 changes: 95 additions & 97 deletions EndlessClient/Dialogs/SkillmasterDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EndlessClient.Content;
using EndlessClient.Dialogs.Factories;
using EndlessClient.Dialogs.Services;
using EndlessClient.HUD;
using EOLib;
using EOLib.Domain.Character;
using EOLib.Domain.Interact.Skill;
using EOLib.Graphics;
Expand Down Expand Up @@ -38,10 +40,12 @@ private enum SkillState
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly IEOMessageBoxFactory _messageBoxFactory;
private readonly ITextInputDialogFactory _textInputDialogFactory;
private readonly ISkillDataProvider _skillDataProvider;
private readonly ICharacterProvider _characterProvider;
private readonly ICharacterInventoryProvider _characterInventoryProvider;
private readonly IPubFileProvider _pubFileProvider;
private readonly IContentProvider _contentProvider;

public SkillmasterDialog(INativeGraphicsManager nativeGraphicsManager,
ISkillmasterActions skillmasterActions,
Expand All @@ -50,10 +54,12 @@ public SkillmasterDialog(INativeGraphicsManager nativeGraphicsManager,
ILocalizedStringFinder localizedStringFinder,
IStatusLabelSetter statusLabelSetter,
IEOMessageBoxFactory messageBoxFactory,
ITextInputDialogFactory textInputDialogFactory,
ISkillDataProvider skillDataProvider,
ICharacterProvider characterProvider,
ICharacterInventoryProvider characterInventoryProvider,
IPubFileProvider pubFileProvider)
IPubFileProvider pubFileProvider,
IContentProvider contentProvider)
: base(nativeGraphicsManager, dialogButtonService)
{
Buttons = ScrollingListDialogButtons.Cancel;
Expand All @@ -70,11 +76,12 @@ public SkillmasterDialog(INativeGraphicsManager nativeGraphicsManager,
_localizedStringFinder = localizedStringFinder;
_statusLabelSetter = statusLabelSetter;
_messageBoxFactory = messageBoxFactory;
_textInputDialogFactory = textInputDialogFactory;
_skillDataProvider = skillDataProvider;
_characterProvider = characterProvider;
_characterInventoryProvider = characterInventoryProvider;
_pubFileProvider = pubFileProvider;

_contentProvider = contentProvider;
SetState(SkillState.Initial, regen: true);
}

Expand Down Expand Up @@ -102,9 +109,10 @@ protected override void OnUpdateControl(GameTime gameTime)

private void BackClicked(object sender, EventArgs e)
{
ListItemType = ListDialogItem.ListItemStyle.Large;

if (_state == SkillState.Learn && _showingRequirements)
{
ListItemType = ListDialogItem.ListItemStyle.Large;
SetState(SkillState.Learn, regen: true);
_showingRequirements = false;
}
Expand All @@ -124,15 +132,15 @@ private void SetState(SkillState newState, bool regen = false)
int numToLearn = _cachedSkills.Count(x => !_cachedSpells.Any(si => si.ID == x.Id));
int numToForget = _cachedSpells.Count;

ClearItemList();

if (newState == SkillState.Learn && numToLearn == 0)
{
var dlg = _messageBoxFactory.CreateMessageBox(DialogResourceID.SKILL_NOTHING_MORE_TO_LEARN);
dlg.ShowDialog();
return;
}

ClearItemList();

switch (newState)
{
case SkillState.Initial:
Expand Down Expand Up @@ -213,42 +221,41 @@ private void SetState(SkillState newState, bool regen = false)
}
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[_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[_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;
{
var input = _textInputDialogFactory.Create(_localizedStringFinder.GetString(DialogResourceID.SKILL_PROMPT_TO_FORGET), 32);

input.DialogClosing += (_, args) =>
{
if (args.Result == XNADialogResult.Cancel)
return;

_cachedSpells.SingleOrNone(s => string.Equals(_pubFileProvider.ESFFile[s.ID].Name, input.ResponseText, StringComparison.OrdinalIgnoreCase))
.Match(
some: si =>
{
_skillmasterActions.ForgetSkill(si.ID);
},
none: () =>
{
args.Cancel = true;

var dlg = _messageBoxFactory.CreateMessageBox(DialogResourceID.SKILL_FORGET_ERROR_NOT_LEARNED);
dlg.ShowDialog();
});
};

input.ShowDialog();

//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);
}
{
ShowForgetAllMessage();
Buttons = ScrollingListDialogButtons.BackCancel;
}
break;
}

Expand Down Expand Up @@ -296,21 +303,6 @@ private void Learn(Skill skill)
}
}

//private void _forgetAllAction()
//{
// EOMessageBox.Show(DialogResourceID.SKILL_RESET_CHARACTER_CONFIRMATION, EODialogButtons.OkCancel, EOMessageBoxStyle.SmallDialogSmallHeader,
// (sender, args) =>
// {
// if (args.Result == XNADialogResult.Cancel) return;

// if (!m_api.ResetCharacterStatSkill())
// {
// Close();
// ((EOGame) Game).DoShowLostConnectionDialogAndReturnToMainMenu();
// }
// });
//}

private void ShowRequirements(Skill skill)
{
_showingRequirements = true;
Expand Down Expand Up @@ -379,49 +371,55 @@ private void ShowRequirementsLabel(Skill skill)
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_INFORMATION, full.ToString());
}

//private void _showForgetAllMessage(Action forgetAllAction)
//{
// List<string> drawStrings = new List<string>();

// string[] messages =
// {
// OldWorld.GetString(EOResourceID.SKILLMASTER_FORGET_ALL),
// OldWorld.GetString(EOResourceID.SKILLMASTER_FORGET_ALL_MSG_1),
// OldWorld.GetString(EOResourceID.SKILLMASTER_FORGET_ALL_MSG_2),
// OldWorld.GetString(EOResourceID.SKILLMASTER_FORGET_ALL_MSG_3),
// OldWorld.GetString(EOResourceID.SKILLMASTER_CLICK_HERE_TO_FORGET_ALL)
// };

// TextSplitter ts = new TextSplitter("", Game.Content.Load<SpriteFont>(Constants.FontSize08pt5)) { LineLength = 200 };
// foreach (string s in messages)
// {
// ts.Text = s;
// if (!ts.NeedsProcessing)
// {
// //no text clipping needed
// drawStrings.Add(s);
// drawStrings.Add(" ");
// continue;
// }

// drawStrings.AddRange(ts.SplitIntoLines());
// drawStrings.Add(" ");
// }

// //now need to take the processed draw strings and make an OldListDialogItem for each one
// foreach (string s in drawStrings)
// {
// string next = s;
// bool link = false;
// if (next.Length > 0 && next[0] == '*')
// {
// next = next.Remove(0, 1);
// link = true;
// }
// OldListDialogItem nextItem = new OldListDialogItem(this, OldListDialogItem.ListItemStyle.Small) { Text = next };
// if (link) nextItem.SetPrimaryTextLink(forgetAllAction);
// AddItemToList(nextItem, false);
// }
//}
private void ShowForgetAllMessage()
{
ListItemType = ListDialogItem.ListItemStyle.Small;

var messages = new[]
{
_localizedStringFinder.GetString(EOResourceID.SKILLMASTER_FORGET_ALL),
_localizedStringFinder.GetString(EOResourceID.SKILLMASTER_FORGET_ALL_MSG_1),
_localizedStringFinder.GetString(EOResourceID.SKILLMASTER_FORGET_ALL_MSG_2),
_localizedStringFinder.GetString(EOResourceID.SKILLMASTER_FORGET_ALL_MSG_3),
_localizedStringFinder.GetString(EOResourceID.SKILLMASTER_CLICK_HERE_TO_FORGET_ALL)
};

var drawStrings = new List<string>();
var ts = new TextSplitter(string.Empty, _contentProvider.Fonts[Constants.FontSize09]) { LineLength = 200 };
foreach (string s in messages)
{
ts.Text = s;
drawStrings.AddRange(ts.NeedsProcessing ? ts.SplitIntoLines() : new[] { s });
drawStrings.Add(" ");
}

foreach (string s in drawStrings)
{
var link = s.Length > 0 && s[0] == '*';
var nextItem = new ListDialogItem(this, ListDialogItem.ListItemStyle.Small)
{
PrimaryText = link ? s.Remove(0, 1) : s
};

if (link)
{
nextItem.SetPrimaryClickAction((_, _) =>
{
var dlg = _messageBoxFactory.CreateMessageBox(DialogResourceID.SKILL_RESET_CHARACTER_CONFIRMATION, EODialogButtons.OkCancel);
dlg.DialogClosing += (_, args) =>
{
// todo: test how GameServer handles character reset with paperdoll items still equipped
if (args.Result == XNADialogResult.OK)
{
_skillmasterActions.ResetCharacter();
}
};
dlg.ShowDialog();
});
}

AddItemToList(nextItem, sortList: false);
}
}
}
}

0 comments on commit a8989cb

Please sign in to comment.