Commit 585fec25 authored by Senator John's avatar Senator John 💬

Merge branch 'patch' into 'master'

Patch

See merge request !39
parents 7c15b217 4005b33f
...@@ -56,6 +56,87 @@ namespace MDPro3 ...@@ -56,6 +56,87 @@ namespace MDPro3
manager.GetElement<RawImage>("Card").material = mat; manager.GetElement<RawImage>("Card").material = mat;
} }
private static bool IsPendulumEffectContext(Card data, GPS p)
{
return p != null
&& (((p.location & (uint)CardLocation.PendulumZone) > 0)
|| ((p.location & (uint)CardLocation.SpellZone) > 0
&& !data.HasType(CardType.Equip)
&& !data.HasType(CardType.Continuous)
&& !data.HasType(CardType.Trap)));
}
private static string WrapInactiveText(string text)
{
return string.IsNullOrEmpty(text) ? string.Empty : "<color=#666666>" + text + "</color>";
}
private static string BuildPendulumDescription(Card data, Card origin, GPS p)
{
var inPendulumContext = IsPendulumEffectContext(data, p);
var inMonsterContext = p != null && (p.location & (uint)CardLocation.MonsterZone) > 0;
if (!inPendulumContext && !inMonsterContext)
return data.GetDescription(true);
var setName = data.GetSetNameWithColor();
var pendulumText = origin.GetPendulumDescription()?.Trim('\r', '\n');
var monsterText = origin.GetMonsterDescription()?.Trim('\r', '\n');
if (Language.GetConfig() == Language.Korean)
{
var monsterHeader = InterString.Get("【怪兽效果】");
if (!data.HasType(CardType.Effect))
monsterHeader = InterString.Get("【怪兽描述】");
monsterHeader = Card.NormalizeBracketLabel(monsterHeader);
var pendulumHeader = Card.NormalizeBracketLabel(InterString.Get("【灵摆效果】"));
var pendulumBlock = pendulumHeader + "\n" + (pendulumText ?? string.Empty);
var monsterBlock = monsterHeader + "\n" + (monsterText ?? string.Empty);
if (inPendulumContext)
return setName + pendulumBlock + "\n" + WrapInactiveText(monsterBlock);
if (inMonsterContext)
return setName + monsterBlock + "\n" + WrapInactiveText(pendulumBlock);
return data.GetDescription(true);
}
var pendulumHeaderDefault = Card.NormalizeBracketLabel(InterString.Get("【灵摆效果】"));
var result = setName;
if (!string.IsNullOrEmpty(monsterText))
result += inPendulumContext ? WrapInactiveText(monsterText) : monsterText;
if (!string.IsNullOrEmpty(pendulumText))
{
var pendulumBlock = pendulumHeaderDefault + "\n" + pendulumText;
if (!string.IsNullOrEmpty(monsterText))
{
if (inMonsterContext)
{
result += "\n" + WrapInactiveText(Card.PendulumSeparatorLine + "\n" + pendulumBlock);
}
else if (inPendulumContext)
{
result += WrapInactiveText("\n" + Card.PendulumSeparatorLine) + "\n" + pendulumBlock;
}
else
{
result += "\n" + Card.PendulumSeparatorLine + "\n" + pendulumBlock;
}
}
else
{
if (!string.IsNullOrEmpty(result))
result += "\n";
result += inMonsterContext ? WrapInactiveText(pendulumBlock) : pendulumBlock;
}
}
return result;
}
public void Show(GameCard card, Material mat, int code = -1, GPS gps = null) public void Show(GameCard card, Material mat, int code = -1, GPS gps = null)
{ {
Card data; Card data;
...@@ -124,26 +205,7 @@ namespace MDPro3 ...@@ -124,26 +205,7 @@ namespace MDPro3
manager.GetElement<Text>("TextType").text = data.GetTypeForUI(); manager.GetElement<Text>("TextType").text = data.GetTypeForUI();
if (data.HasType(CardType.Pendulum)) if (data.HasType(CardType.Pendulum))
{ manager.GetElement<TextMeshProUGUI>("TextDescription").text = tails + BuildPendulumDescription(data, origin, p);
var texts = origin.GetDescriptionSplit();
string monster = InterString.Get("【怪兽效果】");
if (!data.HasType(CardType.Effect))
monster = InterString.Get("【怪兽描述】");
if (p != null
&& ((p.location & (uint)CardLocation.PendulumZone) > 0 ||
((p.location & (uint)CardLocation.SpellZone) > 0
&& !data.HasType(CardType.Equip)
&& !data.HasType(CardType.Continuous)
&& !data.HasType(CardType.Trap))))
manager.GetElement<TextMeshProUGUI>("TextDescription").text = tails + data.GetSetNameWithColor() + InterString.Get("【灵摆效果】") + "\n" + texts[0] + "\n"
+ "<color=#666666>" + monster + "\n" + texts[1] + "</color>";
else if (p != null && (p.location & (uint)CardLocation.MonsterZone) > 0)
manager.GetElement<TextMeshProUGUI>("TextDescription").text = tails + data.GetSetNameWithColor() + monster + "\n" + texts[1] + "\n"
+ "<color=#666666>" + InterString.Get("【灵摆效果】") + "\n" + texts[0] + "</color>";
else
manager.GetElement<TextMeshProUGUI>("TextDescription").text = tails + data.GetSetNameWithColor() + InterString.Get("【灵摆效果】") + "\n" + texts[0] + "\n"
+ monster + "\n" + texts[1];
}
else else
manager.GetElement<TextMeshProUGUI>("TextDescription").text = tails + data.GetSetNameWithColor() + data.Desc; manager.GetElement<TextMeshProUGUI>("TextDescription").text = tails + data.GetSetNameWithColor() + data.Desc;
......
...@@ -1607,7 +1607,7 @@ namespace MDPro3 ...@@ -1607,7 +1607,7 @@ namespace MDPro3
if (model == null) if (model == null)
return; return;
var mode = CurrentReplayGodView && p.InLocation(CardLocation.Hand) && !p.InMyControl() var mode = p.InLocation(CardLocation.Hand) && !p.InMyControl()
? ShadowCastingMode.Off ? ShadowCastingMode.Off
: ShadowCastingMode.On; : ShadowCastingMode.On;
var cardModel = manager.GetElement<Transform>("CardModel"); var cardModel = manager.GetElement<Transform>("CardModel");
......
...@@ -84,6 +84,7 @@ namespace MDPro3.Duel ...@@ -84,6 +84,7 @@ namespace MDPro3.Duel
opActivated.Clear(); opActivated.Clear();
Program.instance.ocgcore.GetUI<OcgCoreUI>().CardDescription.Hide(); Program.instance.ocgcore.GetUI<OcgCoreUI>().CardDescription.Hide();
Program.instance.ocgcore.GetUI<OcgCoreUI>().CardList.Hide(); Program.instance.ocgcore.GetUI<OcgCoreUI>().CardList.Hide();
Program.instance.ocgcore.GetUI<OcgCoreUI>().ResetBgDetailState();
surrendered = false; surrendered = false;
tagSurrendered = false; tagSurrendered = false;
deckReserved = false; deckReserved = false;
...@@ -818,6 +819,7 @@ namespace MDPro3.Duel ...@@ -818,6 +819,7 @@ namespace MDPro3.Duel
mySummonCount++; mySummonCount++;
else else
opSummonCount++; opSummonCount++;
Core.GetUI<OcgCoreUI>().RefreshBgDetail();
var se = "SE_LAND_NORMAL"; var se = "SE_LAND_NORMAL";
...@@ -910,6 +912,7 @@ namespace MDPro3.Duel ...@@ -910,6 +912,7 @@ namespace MDPro3.Duel
mySpSummonCount++; mySpSummonCount++;
else else
opSpSummonCount++; opSpSummonCount++;
Core.GetUI<OcgCoreUI>().RefreshBgDetail();
if (card.GetData().HasType(CardType.Token)) if (card.GetData().HasType(CardType.Token))
goto TokenPass; goto TokenPass;
...@@ -1968,6 +1971,7 @@ namespace MDPro3.Duel ...@@ -1968,6 +1971,7 @@ namespace MDPro3.Duel
mySpSummonCount = 0; mySpSummonCount = 0;
opSummonCount = 0; opSummonCount = 0;
opSpSummonCount = 0; opSpSummonCount = 0;
Core.GetUI<OcgCoreUI>().RefreshBgDetail();
turns++; turns++;
myTurn = isFirst ? (turns % 2 != 0) : (turns % 2 == 0); myTurn = isFirst ? (turns % 2 != 0) : (turns % 2 == 0);
duelBGManager.OnNewTurn(myTurn, turns); duelBGManager.OnNewTurn(myTurn, turns);
......
...@@ -156,6 +156,16 @@ namespace MDPro3.Duel ...@@ -156,6 +156,16 @@ namespace MDPro3.Duel
return player; return player;
} }
private static VoicesData GetVoiceSet(bool isHero)
{
return isHero ? heroVoices : rivalVoices;
}
private int GetLeadingState(bool isHero)
{
return isHero ? LeadingStateOfHero() : LeadingStateOfRival();
}
#endregion #endregion
#region Message Process #region Message Process
...@@ -258,8 +268,8 @@ namespace MDPro3.Duel ...@@ -258,8 +268,8 @@ namespace MDPro3.Duel
if (turns == 1) if (turns == 1)
return UniTask.CompletedTask; return UniTask.CompletedTask;
var targetData = myTurn ? heroVoices : rivalVoices; var targetData = GetVoiceSet(myTurn);
var leadingState = myTurn ? LeadingStateOfHero() : LeadingStateOfRival(); var leadingState = GetLeadingState(myTurn);
var data = new VoiceData(); var data = new VoiceData();
data.name = GetVoiceBySituation(targetData.TurnStart, leadingState); data.name = GetVoiceBySituation(targetData.TurnStart, leadingState);
...@@ -277,13 +287,13 @@ namespace MDPro3.Duel ...@@ -277,13 +287,13 @@ namespace MDPro3.Duel
if(duelPhase != DuelPhase.BattleStart && duelPhase != DuelPhase.End) if(duelPhase != DuelPhase.BattleStart && duelPhase != DuelPhase.End)
return UniTask.CompletedTask; return UniTask.CompletedTask;
var targetData = myTurn ? heroVoices : rivalVoices; var targetData = GetVoiceSet(myTurn);
var data = new VoiceData(); var data = new VoiceData();
if(duelPhase == DuelPhase.BattleStart) if(duelPhase == DuelPhase.BattleStart)
data.name = Tools.GetRandomDictionaryElement(targetData.BattleStart.rawKvp).Value.shortName; data.name = Tools.GetRandomDictionaryElement(targetData.BattleStart.rawKvp).Value.shortName;
else if(duelPhase == DuelPhase.End) else if(duelPhase == DuelPhase.End)
{ {
var leadingState = myTurn ? LeadingStateOfHero() : LeadingStateOfRival(); var leadingState = GetLeadingState(myTurn);
data.name = GetVoiceBySituation(targetData.TurnEnd, leadingState); data.name = GetVoiceBySituation(targetData.TurnEnd, leadingState);
} }
data.num = GetVoiceNum(targetData, data.name); data.num = GetVoiceNum(targetData, data.name);
...@@ -417,9 +427,9 @@ namespace MDPro3.Duel ...@@ -417,9 +427,9 @@ namespace MDPro3.Duel
category = (int)Category.Summon; category = (int)Category.Summon;
subCategory = (int)SummonSub.Normal; subCategory = (int)SummonSub.Normal;
isMe = from.controller == 0; isMe = from.InMyControl();
var targetDataT = isMe ? heroVoices : rivalVoices; var targetDataT = GetVoiceSet(isMe);
var data = GetVoiceByCard(isMe ? heroVoices : rivalVoices, targetDataT.MainMonsterSummon, code, 0, isMe); var data = GetVoiceByCard(targetDataT, targetDataT.MainMonsterSummon, code, 0, isMe);
if (data.name != string.Empty) if (data.name != string.Empty)
{ {
voiceData.Add(data); voiceData.Add(data);
...@@ -465,16 +475,16 @@ namespace MDPro3.Duel ...@@ -465,16 +475,16 @@ namespace MDPro3.Duel
isMe = from.InMyControl(); isMe = from.InMyControl();
} }
var targetDataT = isMe ? heroVoices : rivalVoices; var targetDataT = GetVoiceSet(isMe);
if (subCategory != (int)SummonSub.Special) if (subCategory != (int)SummonSub.Special)
{ {
var data = GetVoiceByCard(isMe ? heroVoices : rivalVoices, targetDataT.BeforeMainSummon, code, 0, isMe); var data = GetVoiceByCard(targetDataT, targetDataT.BeforeMainSummon, code, 0, isMe);
if (data.name != string.Empty) if (data.name != string.Empty)
voiceData.Add(data); voiceData.Add(data);
} }
var dataT = GetVoiceByCard(isMe ? heroVoices : rivalVoices, targetDataT.MainMonsterSummon, code, 0, isMe); var dataT = GetVoiceByCard(targetDataT, targetDataT.MainMonsterSummon, code, 0, isMe);
if (dataT.name != string.Empty) if (dataT.name != string.Empty)
{ {
if (subCategory != (int)SummonSub.Special && voiceData.Count == 0) if (subCategory != (int)SummonSub.Special && voiceData.Count == 0)
...@@ -515,7 +525,7 @@ namespace MDPro3.Duel ...@@ -515,7 +525,7 @@ namespace MDPro3.Duel
code = nextPack.Data.reader.ReadInt32(); code = nextPack.Data.reader.ReadInt32();
var gps = nextPack.Data.reader.ReadGPS(); var gps = nextPack.Data.reader.ReadGPS();
var targetDataT = gps.InMyControl() ? heroVoices : rivalVoices; var targetDataT = GetVoiceSet(gps.InMyControl());
var data = GetVoiceByCard(targetDataT, targetDataT.MainMonsterEffect, code, 0, gps.InMyControl()); var data = GetVoiceByCard(targetDataT, targetDataT.MainMonsterEffect, code, 0, gps.InMyControl());
if (data.name != string.Empty) if (data.name != string.Empty)
{ {
...@@ -535,8 +545,8 @@ namespace MDPro3.Duel ...@@ -535,8 +545,8 @@ namespace MDPro3.Duel
isMe = from.InMyControl(); isMe = from.InMyControl();
} }
if (NeedBeforeCardEffect(from.InMyControl())) if (NeedBeforeCardEffect(isMe))
voiceData.Add(GetBeforeCardEffectData(isMe ? heroVoices : rivalVoices, from.InMyControl())); voiceData.Add(GetBeforeCardEffectData(GetVoiceSet(isMe), isMe));
var simple = SimpleVoiceData.GetCardEffectSubCategory(nextPack.Data.reader, fromHand); var simple = SimpleVoiceData.GetCardEffectSubCategory(nextPack.Data.reader, fromHand);
category = simple.category; category = simple.category;
...@@ -546,7 +556,7 @@ namespace MDPro3.Duel ...@@ -546,7 +556,7 @@ namespace MDPro3.Duel
fromHand = false; fromHand = false;
} }
var targetData = isMe ? heroVoices : rivalVoices; var targetData = GetVoiceSet(isMe);
if(category == 0) if(category == 0)
return UniTask.CompletedTask; return UniTask.CompletedTask;
if (fromHand) if (fromHand)
...@@ -554,7 +564,7 @@ namespace MDPro3.Duel ...@@ -554,7 +564,7 @@ namespace MDPro3.Duel
var data = new VoiceData(); var data = new VoiceData();
data.name = GetVoiceBySubCategory(targetData.CardEffect, (int)CardEffectSub.FromHand, (int)CardEffectSub.FromHand, 0); data.name = GetVoiceBySubCategory(targetData.CardEffect, (int)CardEffectSub.FromHand, (int)CardEffectSub.FromHand, 0);
data.num = GetVoiceNum(targetData, data.name); data.num = GetVoiceNum(targetData, data.name);
data.isHero = from.controller == 0; data.isHero = isMe;
data.wait = true; data.wait = true;
data.delay = 0f; data.delay = 0f;
voiceData.Add(data); voiceData.Add(data);
...@@ -562,7 +572,7 @@ namespace MDPro3.Duel ...@@ -562,7 +572,7 @@ namespace MDPro3.Duel
var data2 = new VoiceData(); var data2 = new VoiceData();
data2.name = GetVoiceBySubCategory(targetData.GetCategoryEntry((Category)category), subCategory, subInCase, patternIndex); data2.name = GetVoiceBySubCategory(targetData.GetCategoryEntry((Category)category), subCategory, subInCase, patternIndex);
data2.num = GetVoiceNum(targetData, data2.name); data2.num = GetVoiceNum(targetData, data2.name);
data2.isHero = from.controller == 0; data2.isHero = isMe;
data2.wait = true; data2.wait = true;
data2.delay = 0f; data2.delay = 0f;
voiceData.Add(data2); voiceData.Add(data2);
...@@ -633,13 +643,14 @@ namespace MDPro3.Duel ...@@ -633,13 +643,14 @@ namespace MDPro3.Duel
return UniTask.CompletedTask; return UniTask.CompletedTask;
var player = LocalPlayer(reader.ReadByte()); var player = LocalPlayer(reader.ReadByte());
var targetData = player == 0 ? heroVoices : rivalVoices; var isHero = player == 0;
var leadingState = player == 0 ? LeadingStateOfHero() : LeadingStateOfRival(); var targetData = GetVoiceSet(isHero);
var leadingState = GetLeadingState(isHero);
var data = new VoiceData(); var data = new VoiceData();
data.name = GetVoiceBySituation(targetData.Draw, leadingState); data.name = GetVoiceBySituation(targetData.Draw, leadingState);
data.num = GetVoiceNum(targetData, data.name); data.num = GetVoiceNum(targetData, data.name);
data.isHero = player == 0; data.isHero = isHero;
data.wait = true; data.wait = true;
data.delay = 0f; data.delay = 0f;
voiceData.Add(data); voiceData.Add(data);
...@@ -651,17 +662,18 @@ namespace MDPro3.Duel ...@@ -651,17 +662,18 @@ namespace MDPro3.Duel
{ {
var player = LocalPlayer(reader.ReadByte()); var player = LocalPlayer(reader.ReadByte());
var value = reader.ReadInt32(); var value = reader.ReadInt32();
var targetData = player == 0 ? heroVoices : rivalVoices; var isHero = player == 0;
var cacheLP = player == 0 ? life0 : life1; var targetData = GetVoiceSet(isHero);
var cacheLP = isHero ? life0 : life1;
if (player == 0) if (isHero)
life0 -= value; life0 -= value;
else else
life1 -= value; life1 -= value;
if (value >= cacheLP) if (value >= cacheLP)
{ {
voiceData.Add(GetFinishDamageVoiceData(targetData, player == 0)); voiceData.Add(GetFinishDamageVoiceData(targetData, isHero));
return UniTask.CompletedTask; return UniTask.CompletedTask;
} }
...@@ -671,7 +683,7 @@ namespace MDPro3.Duel ...@@ -671,7 +683,7 @@ namespace MDPro3.Duel
else else
data.name = Tools.GetRandomDictionaryElement(targetData.Damage.rawKvp).Value.shortName; data.name = Tools.GetRandomDictionaryElement(targetData.Damage.rawKvp).Value.shortName;
data.num = GetVoiceNum(targetData, data.name); data.num = GetVoiceNum(targetData, data.name);
data.isHero = player == 0; data.isHero = isHero;
data.wait = false; data.wait = false;
data.delay = 0f; data.delay = 0f;
voiceData.Add(data); voiceData.Add(data);
...@@ -683,23 +695,24 @@ namespace MDPro3.Duel ...@@ -683,23 +695,24 @@ namespace MDPro3.Duel
{ {
var player = LocalPlayer(reader.ReadByte()); var player = LocalPlayer(reader.ReadByte());
var value = reader.ReadInt32(); var value = reader.ReadInt32();
var targetData = player == 0 ? heroVoices : rivalVoices; var isHero = player == 0;
var cacheLP = player == 0 ? life0 : life1; var targetData = GetVoiceSet(isHero);
if (player == 0) var cacheLP = isHero ? life0 : life1;
if (isHero)
life0 -= value; life0 -= value;
else else
life1 -= value; life1 -= value;
if (value >= cacheLP) if (value >= cacheLP)
{ {
voiceData.Add(GetFinishDamageVoiceData(targetData, player == 0)); voiceData.Add(GetFinishDamageVoiceData(targetData, isHero));
return UniTask.CompletedTask; return UniTask.CompletedTask;
} }
var data = new VoiceData(); var data = new VoiceData();
data.name = Tools.GetRandomDictionaryElement(targetData.CostDamage.rawKvp).Value.shortName; data.name = Tools.GetRandomDictionaryElement(targetData.CostDamage.rawKvp).Value.shortName;
data.num = GetVoiceNum(targetData, data.name); data.num = GetVoiceNum(targetData, data.name);
data.isHero = player == 0; data.isHero = isHero;
data.wait = false; data.wait = false;
data.delay = 0f; data.delay = 0f;
voiceData.Add(data); voiceData.Add(data);
...@@ -723,17 +736,18 @@ namespace MDPro3.Duel ...@@ -723,17 +736,18 @@ namespace MDPro3.Duel
{ {
var player = LocalPlayer(reader.ReadByte()); var player = LocalPlayer(reader.ReadByte());
var value = reader.ReadInt32(); var value = reader.ReadInt32();
var targetData = player == 0 ? heroVoices : rivalVoices; var isHero = player == 0;
var targetData = GetVoiceSet(isHero);
var diff = (player == 0 ? life0 : life1) - value; var diff = (isHero ? life0 : life1) - value;
if (player == 0) if (isHero)
life0 = value; life0 = value;
else else
life1 = value; life1 = value;
if (value == 0) if (value == 0)
{ {
voiceData.Add(GetFinishDamageVoiceData(targetData, player == 0)); voiceData.Add(GetFinishDamageVoiceData(targetData, isHero));
return UniTask.CompletedTask; return UniTask.CompletedTask;
} }
...@@ -746,7 +760,7 @@ namespace MDPro3.Duel ...@@ -746,7 +760,7 @@ namespace MDPro3.Duel
else else
data.name = Tools.GetRandomDictionaryElement(targetData.Damage.rawKvp).Value.shortName; data.name = Tools.GetRandomDictionaryElement(targetData.Damage.rawKvp).Value.shortName;
data.num = GetVoiceNum(targetData, data.name); data.num = GetVoiceNum(targetData, data.name);
data.isHero = player == 0; data.isHero = isHero;
data.wait = false; data.wait = false;
data.delay = 0f; data.delay = 0f;
voiceData.Add(data); voiceData.Add(data);
...@@ -780,12 +794,13 @@ namespace MDPro3.Duel ...@@ -780,12 +794,13 @@ namespace MDPro3.Duel
} }
bool finalBlow = value >= (from.InMyControl() ? life1 : life0); bool finalBlow = value >= (from.InMyControl() ? life1 : life0);
var targetData = from.InMyControl() ? heroVoices : rivalVoices; var isHero = from.InMyControl();
var targetData = GetVoiceSet(isHero);
var data = new VoiceData(); var data = new VoiceData();
data.name = Tools.GetRandomDictionaryElement(finalBlow ? targetData.BeforeAttackFinish.rawKvp : targetData.BeforeAttackNormal.rawKvp).Value.shortName; data.name = Tools.GetRandomDictionaryElement(finalBlow ? targetData.BeforeAttackFinish.rawKvp : targetData.BeforeAttackNormal.rawKvp).Value.shortName;
data.num = GetVoiceNum(targetData, data.name); data.num = GetVoiceNum(targetData, data.name);
data.isHero = from.controller == 0; data.isHero = isHero;
data.wait = true; data.wait = true;
data.delay = 0f; data.delay = 0f;
voiceData.Add(data); voiceData.Add(data);
......
...@@ -262,7 +262,7 @@ namespace MDPro3.Duel.YGOSharp ...@@ -262,7 +262,7 @@ namespace MDPro3.Duel.YGOSharp
return normalized == UNKNOWN_BATTLE_VALUE ? "?" : normalized.ToString(); return normalized == UNKNOWN_BATTLE_VALUE ? "?" : normalized.ToString();
} }
private static readonly string PendulumSeparatorLine = new string('─', 14); internal static readonly string PendulumSeparatorLine = new string('─', 14);
public string GetDescription(bool withSetName = false) public string GetDescription(bool withSetName = false)
{ {
...@@ -311,7 +311,7 @@ namespace MDPro3.Duel.YGOSharp ...@@ -311,7 +311,7 @@ namespace MDPro3.Duel.YGOSharp
+ "\n" + monsterHeader + "\n" + (monsterText ?? string.Empty); + "\n" + monsterHeader + "\n" + (monsterText ?? string.Empty);
} }
private static string NormalizeBracketLabel(string label) internal static string NormalizeBracketLabel(string label)
{ {
if (string.IsNullOrEmpty(label)) if (string.IsNullOrEmpty(label))
return string.Empty; return string.Empty;
......
...@@ -7,6 +7,7 @@ using System.IO; ...@@ -7,6 +7,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
...@@ -224,16 +225,19 @@ namespace MDPro3 ...@@ -224,16 +225,19 @@ namespace MDPro3
#region Online #region Online
public static async Task<Texture2D> DownloadImageAsync(string url) public static async Task<Texture2D> DownloadImageAsync(string url, CancellationToken cancellationToken = default)
{ {
using var request = UnityWebRequestTexture.GetTexture(url); using var request = UnityWebRequestTexture.GetTexture(url);
request.SetRequestHeader("User-Agent", "MDPro3/" + Application.version + " (" + System.Environment.OSVersion.ToString() + "); Unity/" + Application.unityVersion); request.SetRequestHeader("User-Agent", "MDPro3/" + Application.version + " (" + System.Environment.OSVersion.ToString() + "); Unity/" + Application.unityVersion);
var send = request.SendWebRequest(); var send = request.SendWebRequest();
await TaskUtility.WaitUntil(() => send.isDone); while (!send.isDone)
await TaskUtility.WaitOneFrame(cancellationToken);
if (!Application.isPlaying) if (!Application.isPlaying)
return null; return null;
cancellationToken.ThrowIfCancellationRequested();
if (request.result == UnityWebRequest.Result.Success) if (request.result == UnityWebRequest.Result.Success)
{ {
return DownloadHandlerTexture.GetContent(request); return DownloadHandlerTexture.GetContent(request);
......
...@@ -144,7 +144,7 @@ namespace MDPro3.Duel ...@@ -144,7 +144,7 @@ namespace MDPro3.Duel
var tempStrings = new List<string>(); var tempStrings = new List<string>();
foreach (var e in entry.rawKvp) foreach (var e in entry.rawKvp)
if (e.Value.situations != null && e.Value.situations.Length > 0) if (e.Value.situations != null && e.Value.situations.Length > 0)
if (Array.IndexOf(e.Value.situations, situation) > 0) if (Array.IndexOf(e.Value.situations, situation) >= 0)
tempStrings.Add(e.Value.shortName); tempStrings.Add(e.Value.shortName);
if (tempStrings.Count > 0) if (tempStrings.Count > 0)
returnValue = tempStrings[UnityEngine.Random.Range(0, tempStrings.Count)]; returnValue = tempStrings[UnityEngine.Random.Range(0, tempStrings.Count)];
...@@ -681,4 +681,4 @@ namespace MDPro3.Duel ...@@ -681,4 +681,4 @@ namespace MDPro3.Duel
return returnValue; return returnValue;
} }
} }
} }
\ No newline at end of file
using System; using System;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
...@@ -113,8 +114,10 @@ namespace MDPro3.Net ...@@ -113,8 +114,10 @@ namespace MDPro3.Net
} }
} }
public static async UniTask<Texture2D> GetAvatarAsync(string userName) public static async UniTask<Texture2D> GetAvatarAsync(string userName, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested();
if(!Directory.Exists(avatarSavePath)) if(!Directory.Exists(avatarSavePath))
Directory.CreateDirectory(avatarSavePath); Directory.CreateDirectory(avatarSavePath);
...@@ -137,6 +140,7 @@ namespace MDPro3.Net ...@@ -137,6 +140,7 @@ namespace MDPro3.Net
return cachedAvatars[avatarName]; return cachedAvatars[avatarName];
var pic = await TextureManager.LoadPicFromFileAsync(fullPath); var pic = await TextureManager.LoadPicFromFileAsync(fullPath);
cancellationToken.ThrowIfCancellationRequested();
lock (cachedAvatars) lock (cachedAvatars)
if (!cachedAvatars.ContainsKey(avatarName)) if (!cachedAvatars.ContainsKey(avatarName))
...@@ -148,7 +152,7 @@ namespace MDPro3.Net ...@@ -148,7 +152,7 @@ namespace MDPro3.Net
using(var request = UnityWebRequest.Get(userUrl.Replace("{username}", userName))) using(var request = UnityWebRequest.Get(userUrl.Replace("{username}", userName)))
{ {
await request.SendWebRequest(); await request.SendWebRequest().WithCancellation(cancellationToken);
if (request.result == UnityWebRequest.Result.Success) if (request.result == UnityWebRequest.Result.Success)
{ {
avatarAddress = JsonUtility.FromJson<MyCardRoomUserInfo>(request.downloadHandler.text).user.avatar; avatarAddress = JsonUtility.FromJson<MyCardRoomUserInfo>(request.downloadHandler.text).user.avatar;
...@@ -160,8 +164,11 @@ namespace MDPro3.Net ...@@ -160,8 +164,11 @@ namespace MDPro3.Net
} }
} }
var requestAvatar = Tools.DownloadImageAsync(avatarAddress); cancellationToken.ThrowIfCancellationRequested();
var requestAvatar = Tools.DownloadImageAsync(avatarAddress, cancellationToken);
await requestAvatar; await requestAvatar;
cancellationToken.ThrowIfCancellationRequested();
Texture2D downloadImage = requestAvatar.Result; Texture2D downloadImage = requestAvatar.Result;
if (downloadImage == null) if (downloadImage == null)
return null; return null;
......
...@@ -22,6 +22,7 @@ namespace MDPro3 ...@@ -22,6 +22,7 @@ namespace MDPro3
public static PlayerInput PlayerInput; public static PlayerInput PlayerInput;
public static string KeyboardSchemeName = "Keyboard&Mouse"; public static string KeyboardSchemeName = "Keyboard&Mouse";
public static string GamepadSchemeName = "Gamepad"; public static string GamepadSchemeName = "Gamepad";
public static string TouchSchemeName = "Touch";
public static bool NextSelectionIsAxis; public static bool NextSelectionIsAxis;
public static GameObject HoverObject; public static GameObject HoverObject;
...@@ -124,6 +125,7 @@ namespace MDPro3 ...@@ -124,6 +125,7 @@ namespace MDPro3
private float downPressingTime; private float downPressingTime;
private const float moveRepeatDelay = 0.4f; private const float moveRepeatDelay = 0.4f;
private const float moveRepeatRate = 0.2f; private const float moveRepeatRate = 0.2f;
private const float moveInputDeadzone = 0.35f;
private void Awake() private void Awake()
{ {
...@@ -157,17 +159,25 @@ namespace MDPro3 ...@@ -157,17 +159,25 @@ namespace MDPro3
private void Update() private void Update()
{ {
MoveInput = moveAction.ReadValue<Vector2>(); var hasTouchInput = TryGetTouchState(out var touchPosition, out var touchPressed, out var touchPressing, out var touchReleased);
MousePos = mouseAction.ReadValue<Vector2>(); if (hasTouchInput)
{
EnsureTouchControlScheme();
if (Cursor.lockState == CursorLockMode.Locked)
ShowCursorForTouch();
}
MoveInput = ApplyMoveDeadzone(moveAction.ReadValue<Vector2>());
MousePos = hasTouchInput ? touchPosition : mouseAction.ReadValue<Vector2>();
LeftScrollWheel = leftScrollAction.ReadValue<Vector2>(); LeftScrollWheel = leftScrollAction.ReadValue<Vector2>();
RightScrollWheel = rightScrollAction.ReadValue<Vector2>(); RightScrollWheel = rightScrollAction.ReadValue<Vector2>();
if (MousePos != lastMousePos) if (MousePos != lastMousePos || touchPressed)
{ {
MouseMovedEvent(); MouseMovedEvent();
} }
if(MoveInput != Vector2.zero && !InputFieldActivating()) if (MoveInput != Vector2.zero && !hasTouchInput && !InputFieldActivating())
{ {
if (Cursor.lockState == CursorLockMode.None) if (Cursor.lockState == CursorLockMode.None)
{ {
...@@ -193,13 +203,13 @@ namespace MDPro3 ...@@ -193,13 +203,13 @@ namespace MDPro3
#region Mouse #region Mouse
MouseLeftDown = leftClickAction.WasPressedThisFrame(); MouseLeftDown = leftClickAction.WasPressedThisFrame() || touchPressed;
MouseRightDown = rightClickAction.WasPressedThisFrame(); MouseRightDown = rightClickAction.WasPressedThisFrame();
MouseMiddleDown = middleClickAction.WasPressedThisFrame(); MouseMiddleDown = middleClickAction.WasPressedThisFrame();
MouseLeftPressing = leftClickAction.IsPressed(); MouseLeftPressing = leftClickAction.IsPressed() || touchPressing;
MouseMiddlePressing = middleClickAction.IsPressed(); MouseMiddlePressing = middleClickAction.IsPressed();
MouseRightPressing = rightClickAction.IsPressed(); MouseRightPressing = rightClickAction.IsPressed();
MouseLeftUp = leftClickAction.WasReleasedThisFrame(); MouseLeftUp = leftClickAction.WasReleasedThisFrame() || touchReleased;
MouseRightUp = rightClickAction.WasReleasedThisFrame(); MouseRightUp = rightClickAction.WasReleasedThisFrame();
MouseMiddleUp = middleClickAction.WasReleasedThisFrame(); MouseMiddleUp = middleClickAction.WasReleasedThisFrame();
...@@ -334,9 +344,70 @@ namespace MDPro3 ...@@ -334,9 +344,70 @@ namespace MDPro3
} }
private static Vector2 ApplyMoveDeadzone(Vector2 input)
{
input.x = ApplyMoveDeadzone(input.x);
input.y = ApplyMoveDeadzone(input.y);
return input;
}
private static float ApplyMoveDeadzone(float input)
{
if (Mathf.Abs(input) < moveInputDeadzone)
return 0f;
return Mathf.Sign(input);
}
private static bool TryGetTouchState(out Vector2 touchPosition, out bool touchPressed, out bool touchPressing, out bool touchReleased)
{
touchPosition = default;
touchPressed = false;
touchPressing = false;
touchReleased = false;
var touchscreen = Touchscreen.current;
if (touchscreen == null)
return false;
var touch = touchscreen.primaryTouch;
touchPressed = touch.press.wasPressedThisFrame;
touchPressing = touch.press.isPressed;
touchReleased = touch.press.wasReleasedThisFrame;
if (!touchPressed && !touchPressing && !touchReleased)
return false;
touchPosition = touch.position.ReadValue();
return true;
}
private static bool TouchInputActive()
{
var touchscreen = Touchscreen.current;
if (touchscreen == null)
return false;
var touch = touchscreen.primaryTouch;
return touch.press.wasPressedThisFrame || touch.press.isPressed || touch.press.wasReleasedThisFrame;
}
private void EnsureTouchControlScheme()
{
if (PlayerInput == null || Touchscreen.current == null || PlayerInput.currentControlScheme == TouchSchemeName)
return;
try
{
PlayerInput.SwitchCurrentControlScheme(TouchSchemeName, Touchscreen.current);
}
catch (InvalidOperationException)
{
}
}
private void MouseMovedEvent() private void MouseMovedEvent()
{ {
if(PlayerInput.currentControlScheme != GamepadSchemeName) if (PlayerInput.currentControlScheme != GamepadSchemeName || TouchInputActive())
OnMouseMovedAction?.Invoke(); OnMouseMovedAction?.Invoke();
} }
...@@ -365,6 +436,8 @@ namespace MDPro3 ...@@ -365,6 +436,8 @@ namespace MDPro3
public static bool NeedDefaultSelect() public static bool NeedDefaultSelect()
{ {
if (TouchInputActive())
return false;
if (PlayerInput.currentControlScheme == GamepadSchemeName) if (PlayerInput.currentControlScheme == GamepadSchemeName)
return true; return true;
else if (Cursor.lockState == CursorLockMode.Locked) else if (Cursor.lockState == CursorLockMode.Locked)
...@@ -449,6 +522,15 @@ namespace MDPro3 ...@@ -449,6 +522,15 @@ namespace MDPro3
ignoreNextCursorMove = true; ignoreNextCursorMove = true;
} }
} }
private void ShowCursorForTouch()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
hasCursorRestorePos = false;
ignoreNextCursorMove = false;
}
private void HideCursor() private void HideCursor()
{ {
cursorRestorePos = MousePos; cursorRestorePos = MousePos;
......
...@@ -2,9 +2,11 @@ using MDPro3.Net; ...@@ -2,9 +2,11 @@ using MDPro3.Net;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Threading;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using MDPro3.Servant; using MDPro3.Servant;
using MDPro3.UI.ServantUI; using MDPro3.UI.ServantUI;
...@@ -62,14 +64,33 @@ namespace MDPro3.UI ...@@ -62,14 +64,33 @@ namespace MDPro3.UI
protected override async UniTask RefreshAsync() protected override async UniTask RefreshAsync()
{ {
refreshed = false; refreshed = false;
var cancellationToken = cts?.Token ?? destroyCancellationToken;
var face0 = Manager.GetElement<RawImage>("Face0");
var face1 = Manager.GetElement<RawImage>("Face1");
Manager.GetElement<RawImage>("Face0").texture = Appearance.defaultFace0.texture; if (face0 != null)
Manager.GetElement<RawImage>("Face1").texture = Appearance.defaultFace1.texture; face0.texture = Appearance.defaultFace0.texture;
if (face1 != null)
face1.texture = Appearance.defaultFace1.texture;
Manager.GetElement<RawImage>("Face0").texture = await MyCard.GetAvatarAsync(player0Name); try
Manager.GetElement<RawImage>("Face1").texture = await MyCard.GetAvatarAsync(player1Name); {
var avatar0 = await MyCard.GetAvatarAsync(player0Name, cancellationToken);
if (!cancellationToken.IsCancellationRequested && face0 != null)
face0.texture = avatar0;
var avatar1 = await MyCard.GetAvatarAsync(player1Name, cancellationToken);
if (!cancellationToken.IsCancellationRequested && face1 != null)
face1.texture = avatar1;
refreshed = true; refreshed = true;
}
catch (OperationCanceledException)
{
}
catch (MissingReferenceException)
{
}
} }
protected override void CallToggleOnEvent() protected override void CallToggleOnEvent()
......
...@@ -621,6 +621,55 @@ namespace MDPro3.UI.ServantUI ...@@ -621,6 +621,55 @@ namespace MDPro3.UI.ServantUI
} }
private bool bgDetailShowing; private bool bgDetailShowing;
public void RefreshBgDetail()
{
var core = Program.instance.ocgcore;
var info = core?.messageDispatcher?.duel?.duelBGManager?.fieldSummonRightInfo;
if (info == null)
return;
var summonInfoManager = info.GetComponent<ElementObjectManager>();
if (summonInfoManager == null)
return;
var nearManager = summonInfoManager.GetElement<ElementObjectManager>("RootNear");
var farManager = summonInfoManager.GetElement<ElementObjectManager>("RootFar");
nearManager.GetElement<TextMeshPro>("TextSummon").text = mySummonCount.ToString();
nearManager.GetElement<TextMeshPro>("TextSpSummon").text = mySpSummonCount.ToString();
farManager.GetElement<TextMeshPro>("TextSummon").text = opSummonCount.ToString();
farManager.GetElement<TextMeshPro>("TextSpSummon").text = opSpSummonCount.ToString();
nearManager.GetElement<TextMeshPro>("TextTotalAtk").text = core.GetAllAtk(true).ToString();
farManager.GetElement<TextMeshPro>("TextTotalAtk").text = core.GetAllAtk(false).ToString();
summonInfoManager.GetElement<TextMeshPro>("GraveNear").text = core.GetLocationCardCount(CardLocation.Grave, 0).ToString();
summonInfoManager.GetElement<TextMeshPro>("GraveFar").text = core.GetLocationCardCount(CardLocation.Grave, 1).ToString();
summonInfoManager.GetElement<TextMeshPro>("ExcludeNear").text = core.GetLocationCardCount(CardLocation.Removed, 0).ToString();
summonInfoManager.GetElement<TextMeshPro>("ExcludeFar").text = core.GetLocationCardCount(CardLocation.Removed, 1).ToString();
summonInfoManager.GetElement<TextMeshPro>("DeckNear").text = core.GetLocationCardCount(CardLocation.Deck, 0).ToString();
summonInfoManager.GetElement<TextMeshPro>("DeckFar").text = core.GetLocationCardCount(CardLocation.Deck, 1).ToString();
summonInfoManager.GetElement<TextMeshPro>("ExtraNear").text = core.GetLocationCardCount(CardLocation.Extra, 0).ToString();
summonInfoManager.GetElement<TextMeshPro>("ExtraFar").text = core.GetLocationCardCount(CardLocation.Extra, 1).ToString();
summonInfoManager.GetElement<TextMeshPro>("HandNear").text = core.GetLocationCardCount(CardLocation.Hand, 0).ToString();
summonInfoManager.GetElement<TextMeshPro>("HandFar").text = core.GetLocationCardCount(CardLocation.Hand, 1).ToString();
}
public void ResetBgDetailState()
{
var wasShowing = bgDetailShowing;
bgDetailShowing = false;
foreach (var card in cards)
card.HideHiddenLabel();
var info = Program.instance.ocgcore?.messageDispatcher?.duel?.duelBGManager?.fieldSummonRightInfo;
if (info != null)
{
if (wasShowing || info.activeSelf)
CameraManager.DuelOverlay3DMinus();
info.SetActive(false);
}
}
public void SwitchBgDetail(bool show) public void SwitchBgDetail(bool show)
{ {
if (show) if (show)
...@@ -631,7 +680,6 @@ namespace MDPro3.UI.ServantUI ...@@ -631,7 +680,6 @@ namespace MDPro3.UI.ServantUI
private void ShowBgDetail() private void ShowBgDetail()
{ {
var core = Program.instance.ocgcore;
var info = Program.instance.ocgcore.messageDispatcher.duel.duelBGManager.fieldSummonRightInfo; var info = Program.instance.ocgcore.messageDispatcher.duel.duelBGManager.fieldSummonRightInfo;
if (bgDetailShowing) if (bgDetailShowing)
...@@ -644,29 +692,7 @@ namespace MDPro3.UI.ServantUI ...@@ -644,29 +692,7 @@ namespace MDPro3.UI.ServantUI
{ {
CameraManager.DuelOverlay3DPlus(); CameraManager.DuelOverlay3DPlus();
info.SetActive(true); info.SetActive(true);
RefreshBgDetail();
var summonInfoManager = info.GetComponent<ElementObjectManager>();
var nearManager = summonInfoManager.GetElement<ElementObjectManager>("RootNear");
var farManager = summonInfoManager.GetElement<ElementObjectManager>("RootFar");
nearManager.GetElement<TextMeshPro>("TextSummon").text = mySummonCount.ToString();
nearManager.GetElement<TextMeshPro>("TextSpSummon").text = mySpSummonCount.ToString();
farManager.GetElement<TextMeshPro>("TextSummon").text = opSummonCount.ToString();
farManager.GetElement<TextMeshPro>("TextSpSummon").text = opSpSummonCount.ToString();
nearManager.GetElement<TextMeshPro>("TextTotalAtk").text = core.GetAllAtk(true).ToString();
farManager.GetElement<TextMeshPro>("TextTotalAtk").text = core.GetAllAtk(false).ToString();
summonInfoManager.GetElement<TextMeshPro>("GraveNear").text = core.GetLocationCardCount(CardLocation.Grave, 0).ToString();
summonInfoManager.GetElement<TextMeshPro>("GraveFar").text = core.GetLocationCardCount(CardLocation.Grave, 1).ToString();
summonInfoManager.GetElement<TextMeshPro>("ExcludeNear").text = core.GetLocationCardCount(CardLocation.Removed, 0).ToString();
summonInfoManager.GetElement<TextMeshPro>("ExcludeFar").text = core.GetLocationCardCount(CardLocation.Removed, 1).ToString();
summonInfoManager.GetElement<TextMeshPro>("DeckNear").text = core.GetLocationCardCount(CardLocation.Deck, 0).ToString();
summonInfoManager.GetElement<TextMeshPro>("DeckFar").text = core.GetLocationCardCount(CardLocation.Deck, 1).ToString();
summonInfoManager.GetElement<TextMeshPro>("ExtraNear").text = core.GetLocationCardCount(CardLocation.Extra, 0).ToString();
summonInfoManager.GetElement<TextMeshPro>("ExtraFar").text = core.GetLocationCardCount(CardLocation.Extra, 1).ToString();
summonInfoManager.GetElement<TextMeshPro>("HandNear").text = core.GetLocationCardCount(CardLocation.Hand, 0).ToString();
summonInfoManager.GetElement<TextMeshPro>("HandFar").text = core.GetLocationCardCount(CardLocation.Hand, 1).ToString();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment