Simplify text creation

This commit is contained in:
Andrei Zavatski
2019-08-20 16:11:59 +03:00
parent c4344f3f7c
commit 5c7cb4dc21

View File

@ -50,37 +50,45 @@ namespace osu.Game.Overlays.Profile.Sections.Kudosu
{ {
date.Colour = colours.GreySeafoamLighter; date.Colour = colours.GreySeafoamLighter;
string userLinkTemplate() => $"[{historyItem.Giver?.Url} {historyItem.Giver?.Username}]";
switch (historyItem.Action) switch (historyItem.Action)
{ {
case KudosuAction.VoteGive: case KudosuAction.VoteGive:
linkFlowContainer.AddText(@"Received ");
addKudosuPart();
addMainPart($@" from {userLinkTemplate()} for a post at ");
addPostPart();
break;
case KudosuAction.Give: case KudosuAction.Give:
linkFlowContainer.AddText(@"Received "); linkFlowContainer.AddText(@"Received ");
addKudosuPart(); addKudosuPart();
addMainPart(); addMainPart(@" from obtaining votes in modding post of ");
addPostPart(); addPostPart();
break; break;
case KudosuAction.Reset: case KudosuAction.Reset:
addMainPart(); addMainPart($@"Kudosu reset by {userLinkTemplate()} for the post ");
addPostPart(); addPostPart();
break; break;
case KudosuAction.VoteReset: case KudosuAction.VoteReset:
linkFlowContainer.AddText(@"Lost "); linkFlowContainer.AddText(@"Lost ");
addKudosuPart(); addKudosuPart();
addMainPart(); addMainPart(@" from losing votes in modding post of ");
addPostPart(); addPostPart();
break; break;
case KudosuAction.DenyKudosuReset: case KudosuAction.DenyKudosuReset:
linkFlowContainer.AddText(@"Denied "); linkFlowContainer.AddText(@"Denied ");
addKudosuPart(); addKudosuPart();
addMainPart(); addMainPart(@" from modding post ");
addPostPart(); addPostPart();
break; break;
case KudosuAction.Revoke: case KudosuAction.Revoke:
addMainPart(); addMainPart($@"Denied kudosu by {userLinkTemplate()} for the post ");
addPostPart(); addPostPart();
break; break;
} }
@ -95,53 +103,13 @@ namespace osu.Game.Overlays.Profile.Sections.Kudosu
}); });
} }
private void addMainPart() private void addMainPart(string text)
{ {
var text = createMessage(); var formatted = MessageFormatter.FormatText(text);
linkFlowContainer.AddLinks(text.Text, text.Links); linkFlowContainer.AddLinks(formatted.Text, formatted.Links);
} }
private void addPostPart() => linkFlowContainer.AddLink(historyItem.Post.Title, historyItem.Post.Url); private void addPostPart() => linkFlowContainer.AddLink(historyItem.Post.Title, historyItem.Post.Url);
private MessageFormatter.MessageFormatterResult createMessage()
{
string userLinkTemplate() => $"[{historyItem.Giver?.Url} {historyItem.Giver?.Username}]";
string message;
switch (historyItem.Action)
{
case KudosuAction.Give:
message = $@" from {userLinkTemplate()} for a post at ";
break;
case KudosuAction.VoteGive:
message = @" from obtaining votes in modding post of ";
break;
case KudosuAction.Reset:
message = $@"Kudosu reset by {userLinkTemplate()} for the post ";
break;
case KudosuAction.VoteReset:
message = @" from losing votes in modding post of ";
break;
case KudosuAction.DenyKudosuReset:
message = @" from modding post ";
break;
case KudosuAction.Revoke:
message = $@"Denied kudosu by {userLinkTemplate()} for the post ";
break;
default:
message = string.Empty;
break;
}
return MessageFormatter.FormatText(message);
}
} }
} }