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
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)
{
Card data;
......@@ -124,26 +205,7 @@ namespace MDPro3
manager.GetElement<Text>("TextType").text = data.GetTypeForUI();
if (data.HasType(CardType.Pendulum))
{
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];
}
manager.GetElement<TextMeshProUGUI>("TextDescription").text = tails + BuildPendulumDescription(data, origin, p);
else
manager.GetElement<TextMeshProUGUI>("TextDescription").text = tails + data.GetSetNameWithColor() + data.Desc;
......
......@@ -1607,7 +1607,7 @@ namespace MDPro3
if (model == null)
return;
var mode = CurrentReplayGodView && p.InLocation(CardLocation.Hand) && !p.InMyControl()
var mode = p.InLocation(CardLocation.Hand) && !p.InMyControl()
? ShadowCastingMode.Off
: ShadowCastingMode.On;
var cardModel = manager.GetElement<Transform>("CardModel");
......
......@@ -84,6 +84,7 @@ namespace MDPro3.Duel
opActivated.Clear();
Program.instance.ocgcore.GetUI<OcgCoreUI>().CardDescription.Hide();
Program.instance.ocgcore.GetUI<OcgCoreUI>().CardList.Hide();
Program.instance.ocgcore.GetUI<OcgCoreUI>().ResetBgDetailState();
surrendered = false;
tagSurrendered = false;
deckReserved = false;
......@@ -818,6 +819,7 @@ namespace MDPro3.Duel
mySummonCount++;
else
opSummonCount++;
Core.GetUI<OcgCoreUI>().RefreshBgDetail();
var se = "SE_LAND_NORMAL";
......@@ -910,6 +912,7 @@ namespace MDPro3.Duel
mySpSummonCount++;
else
opSpSummonCount++;
Core.GetUI<OcgCoreUI>().RefreshBgDetail();
if (card.GetData().HasType(CardType.Token))
goto TokenPass;
......@@ -1968,6 +1971,7 @@ namespace MDPro3.Duel
mySpSummonCount = 0;
opSummonCount = 0;
opSpSummonCount = 0;
Core.GetUI<OcgCoreUI>().RefreshBgDetail();
turns++;
myTurn = isFirst ? (turns % 2 != 0) : (turns % 2 == 0);
duelBGManager.OnNewTurn(myTurn, turns);
......
......@@ -156,6 +156,16 @@ namespace MDPro3.Duel
return player;
}
private static VoicesData GetVoiceSet(bool isHero)
{
return isHero ? heroVoices : rivalVoices;
}
private int GetLeadingState(bool isHero)
{
return isHero ? LeadingStateOfHero() : LeadingStateOfRival();
}
#endregion
#region Message Process
......@@ -258,8 +268,8 @@ namespace MDPro3.Duel
if (turns == 1)
return UniTask.CompletedTask;
var targetData = myTurn ? heroVoices : rivalVoices;
var leadingState = myTurn ? LeadingStateOfHero() : LeadingStateOfRival();
var targetData = GetVoiceSet(myTurn);
var leadingState = GetLeadingState(myTurn);
var data = new VoiceData();
data.name = GetVoiceBySituation(targetData.TurnStart, leadingState);
......@@ -277,13 +287,13 @@ namespace MDPro3.Duel
if(duelPhase != DuelPhase.BattleStart && duelPhase != DuelPhase.End)
return UniTask.CompletedTask;
var targetData = myTurn ? heroVoices : rivalVoices;
var targetData = GetVoiceSet(myTurn);
var data = new VoiceData();
if(duelPhase == DuelPhase.BattleStart)
data.name = Tools.GetRandomDictionaryElement(targetData.BattleStart.rawKvp).Value.shortName;
else if(duelPhase == DuelPhase.End)
{
var leadingState = myTurn ? LeadingStateOfHero() : LeadingStateOfRival();
var leadingState = GetLeadingState(myTurn);
data.name = GetVoiceBySituation(targetData.TurnEnd, leadingState);
}
data.num = GetVoiceNum(targetData, data.name);
......@@ -417,9 +427,9 @@ namespace MDPro3.Duel
category = (int)Category.Summon;
subCategory = (int)SummonSub.Normal;
isMe = from.controller == 0;
var targetDataT = isMe ? heroVoices : rivalVoices;
var data = GetVoiceByCard(isMe ? heroVoices : rivalVoices, targetDataT.MainMonsterSummon, code, 0, isMe);
isMe = from.InMyControl();
var targetDataT = GetVoiceSet(isMe);
var data = GetVoiceByCard(targetDataT, targetDataT.MainMonsterSummon, code, 0, isMe);
if (data.name != string.Empty)
{
voiceData.Add(data);
......@@ -465,16 +475,16 @@ namespace MDPro3.Duel
isMe = from.InMyControl();
}
var targetDataT = isMe ? heroVoices : rivalVoices;
var targetDataT = GetVoiceSet(isMe);
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)
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 (subCategory != (int)SummonSub.Special && voiceData.Count == 0)
......@@ -515,7 +525,7 @@ namespace MDPro3.Duel
code = nextPack.Data.reader.ReadInt32();
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());
if (data.name != string.Empty)
{
......@@ -535,8 +545,8 @@ namespace MDPro3.Duel
isMe = from.InMyControl();
}
if (NeedBeforeCardEffect(from.InMyControl()))
voiceData.Add(GetBeforeCardEffectData(isMe ? heroVoices : rivalVoices, from.InMyControl()));
if (NeedBeforeCardEffect(isMe))
voiceData.Add(GetBeforeCardEffectData(GetVoiceSet(isMe), isMe));
var simple = SimpleVoiceData.GetCardEffectSubCategory(nextPack.Data.reader, fromHand);
category = simple.category;
......@@ -546,7 +556,7 @@ namespace MDPro3.Duel
fromHand = false;
}
var targetData = isMe ? heroVoices : rivalVoices;
var targetData = GetVoiceSet(isMe);
if(category == 0)
return UniTask.CompletedTask;
if (fromHand)
......@@ -554,7 +564,7 @@ namespace MDPro3.Duel
var data = new VoiceData();
data.name = GetVoiceBySubCategory(targetData.CardEffect, (int)CardEffectSub.FromHand, (int)CardEffectSub.FromHand, 0);
data.num = GetVoiceNum(targetData, data.name);
data.isHero = from.controller == 0;
data.isHero = isMe;
data.wait = true;
data.delay = 0f;
voiceData.Add(data);
......@@ -562,7 +572,7 @@ namespace MDPro3.Duel
var data2 = new VoiceData();
data2.name = GetVoiceBySubCategory(targetData.GetCategoryEntry((Category)category), subCategory, subInCase, patternIndex);
data2.num = GetVoiceNum(targetData, data2.name);
data2.isHero = from.controller == 0;
data2.isHero = isMe;
data2.wait = true;
data2.delay = 0f;
voiceData.Add(data2);
......@@ -633,13 +643,14 @@ namespace MDPro3.Duel
return UniTask.CompletedTask;
var player = LocalPlayer(reader.ReadByte());
var targetData = player == 0 ? heroVoices : rivalVoices;
var leadingState = player == 0 ? LeadingStateOfHero() : LeadingStateOfRival();
var isHero = player == 0;
var targetData = GetVoiceSet(isHero);
var leadingState = GetLeadingState(isHero);
var data = new VoiceData();
data.name = GetVoiceBySituation(targetData.Draw, leadingState);
data.num = GetVoiceNum(targetData, data.name);
data.isHero = player == 0;
data.isHero = isHero;
data.wait = true;
data.delay = 0f;
voiceData.Add(data);
......@@ -651,17 +662,18 @@ namespace MDPro3.Duel
{
var player = LocalPlayer(reader.ReadByte());
var value = reader.ReadInt32();
var targetData = player == 0 ? heroVoices : rivalVoices;
var cacheLP = player == 0 ? life0 : life1;
var isHero = player == 0;
var targetData = GetVoiceSet(isHero);
var cacheLP = isHero ? life0 : life1;
if (player == 0)
if (isHero)
life0 -= value;
else
life1 -= value;
if (value >= cacheLP)
{
voiceData.Add(GetFinishDamageVoiceData(targetData, player == 0));
voiceData.Add(GetFinishDamageVoiceData(targetData, isHero));
return UniTask.CompletedTask;
}
......@@ -671,7 +683,7 @@ namespace MDPro3.Duel
else
data.name = Tools.GetRandomDictionaryElement(targetData.Damage.rawKvp).Value.shortName;
data.num = GetVoiceNum(targetData, data.name);
data.isHero = player == 0;
data.isHero = isHero;
data.wait = false;
data.delay = 0f;
voiceData.Add(data);
......@@ -683,23 +695,24 @@ namespace MDPro3.Duel
{
var player = LocalPlayer(reader.ReadByte());
var value = reader.ReadInt32();
var targetData = player == 0 ? heroVoices : rivalVoices;
var cacheLP = player == 0 ? life0 : life1;
if (player == 0)
var isHero = player == 0;
var targetData = GetVoiceSet(isHero);
var cacheLP = isHero ? life0 : life1;
if (isHero)
life0 -= value;
else
life1 -= value;
if (value >= cacheLP)
{
voiceData.Add(GetFinishDamageVoiceData(targetData, player == 0));
voiceData.Add(GetFinishDamageVoiceData(targetData, isHero));
return UniTask.CompletedTask;
}
var data = new VoiceData();
data.name = Tools.GetRandomDictionaryElement(targetData.CostDamage.rawKvp).Value.shortName;
data.num = GetVoiceNum(targetData, data.name);
data.isHero = player == 0;
data.isHero = isHero;
data.wait = false;
data.delay = 0f;
voiceData.Add(data);
......@@ -723,17 +736,18 @@ namespace MDPro3.Duel
{
var player = LocalPlayer(reader.ReadByte());
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;
if (player == 0)
var diff = (isHero ? life0 : life1) - value;
if (isHero)
life0 = value;
else
life1 = value;
if (value == 0)
{
voiceData.Add(GetFinishDamageVoiceData(targetData, player == 0));
voiceData.Add(GetFinishDamageVoiceData(targetData, isHero));
return UniTask.CompletedTask;
}
......@@ -746,7 +760,7 @@ namespace MDPro3.Duel
else
data.name = Tools.GetRandomDictionaryElement(targetData.Damage.rawKvp).Value.shortName;
data.num = GetVoiceNum(targetData, data.name);
data.isHero = player == 0;
data.isHero = isHero;
data.wait = false;
data.delay = 0f;
voiceData.Add(data);
......@@ -780,12 +794,13 @@ namespace MDPro3.Duel
}
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();
data.name = Tools.GetRandomDictionaryElement(finalBlow ? targetData.BeforeAttackFinish.rawKvp : targetData.BeforeAttackNormal.rawKvp).Value.shortName;
data.num = GetVoiceNum(targetData, data.name);
data.isHero = from.controller == 0;
data.isHero = isHero;
data.wait = true;
data.delay = 0f;
voiceData.Add(data);
......
......@@ -262,7 +262,7 @@ namespace MDPro3.Duel.YGOSharp
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)
{
......@@ -311,7 +311,7 @@ namespace MDPro3.Duel.YGOSharp
+ "\n" + monsterHeader + "\n" + (monsterText ?? string.Empty);
}
private static string NormalizeBracketLabel(string label)
internal static string NormalizeBracketLabel(string label)
{
if (string.IsNullOrEmpty(label))
return string.Empty;
......
......@@ -7,6 +7,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
......@@ -224,16 +225,19 @@ namespace MDPro3
#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);
request.SetRequestHeader("User-Agent", "MDPro3/" + Application.version + " (" + System.Environment.OSVersion.ToString() + "); Unity/" + Application.unityVersion);
var send = request.SendWebRequest();
await TaskUtility.WaitUntil(() => send.isDone);
while (!send.isDone)
await TaskUtility.WaitOneFrame(cancellationToken);
if (!Application.isPlaying)
return null;
cancellationToken.ThrowIfCancellationRequested();
if (request.result == UnityWebRequest.Result.Success)
{
return DownloadHandlerTexture.GetContent(request);
......
......@@ -144,7 +144,7 @@ namespace MDPro3.Duel
var tempStrings = new List<string>();
foreach (var e in entry.rawKvp)
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);
if (tempStrings.Count > 0)
returnValue = tempStrings[UnityEngine.Random.Range(0, tempStrings.Count)];
......@@ -681,4 +681,4 @@ namespace MDPro3.Duel
return returnValue;
}
}
}
\ No newline at end of file
}
using System;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
......@@ -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))
Directory.CreateDirectory(avatarSavePath);
......@@ -137,6 +140,7 @@ namespace MDPro3.Net
return cachedAvatars[avatarName];
var pic = await TextureManager.LoadPicFromFileAsync(fullPath);
cancellationToken.ThrowIfCancellationRequested();
lock (cachedAvatars)
if (!cachedAvatars.ContainsKey(avatarName))
......@@ -148,7 +152,7 @@ namespace MDPro3.Net
using(var request = UnityWebRequest.Get(userUrl.Replace("{username}", userName)))
{
await request.SendWebRequest();
await request.SendWebRequest().WithCancellation(cancellationToken);
if (request.result == UnityWebRequest.Result.Success)
{
avatarAddress = JsonUtility.FromJson<MyCardRoomUserInfo>(request.downloadHandler.text).user.avatar;
......@@ -160,8 +164,11 @@ namespace MDPro3.Net
}
}
var requestAvatar = Tools.DownloadImageAsync(avatarAddress);
cancellationToken.ThrowIfCancellationRequested();
var requestAvatar = Tools.DownloadImageAsync(avatarAddress, cancellationToken);
await requestAvatar;
cancellationToken.ThrowIfCancellationRequested();
Texture2D downloadImage = requestAvatar.Result;
if (downloadImage == null)
return null;
......
......@@ -22,6 +22,7 @@ namespace MDPro3
public static PlayerInput PlayerInput;
public static string KeyboardSchemeName = "Keyboard&Mouse";
public static string GamepadSchemeName = "Gamepad";
public static string TouchSchemeName = "Touch";
public static bool NextSelectionIsAxis;
public static GameObject HoverObject;
......@@ -124,6 +125,7 @@ namespace MDPro3
private float downPressingTime;
private const float moveRepeatDelay = 0.4f;
private const float moveRepeatRate = 0.2f;
private const float moveInputDeadzone = 0.35f;
private void Awake()
{
......@@ -157,17 +159,25 @@ namespace MDPro3
private void Update()
{
MoveInput = moveAction.ReadValue<Vector2>();
MousePos = mouseAction.ReadValue<Vector2>();
var hasTouchInput = TryGetTouchState(out var touchPosition, out var touchPressed, out var touchPressing, out var touchReleased);
if (hasTouchInput)
{
EnsureTouchControlScheme();
if (Cursor.lockState == CursorLockMode.Locked)
ShowCursorForTouch();
}
MoveInput = ApplyMoveDeadzone(moveAction.ReadValue<Vector2>());
MousePos = hasTouchInput ? touchPosition : mouseAction.ReadValue<Vector2>();
LeftScrollWheel = leftScrollAction.ReadValue<Vector2>();
RightScrollWheel = rightScrollAction.ReadValue<Vector2>();
if (MousePos != lastMousePos)
if (MousePos != lastMousePos || touchPressed)
{
MouseMovedEvent();
}
if(MoveInput != Vector2.zero && !InputFieldActivating())
if (MoveInput != Vector2.zero && !hasTouchInput && !InputFieldActivating())
{
if (Cursor.lockState == CursorLockMode.None)
{
......@@ -193,13 +203,13 @@ namespace MDPro3
#region Mouse
MouseLeftDown = leftClickAction.WasPressedThisFrame();
MouseLeftDown = leftClickAction.WasPressedThisFrame() || touchPressed;
MouseRightDown = rightClickAction.WasPressedThisFrame();
MouseMiddleDown = middleClickAction.WasPressedThisFrame();
MouseLeftPressing = leftClickAction.IsPressed();
MouseLeftPressing = leftClickAction.IsPressed() || touchPressing;
MouseMiddlePressing = middleClickAction.IsPressed();
MouseRightPressing = rightClickAction.IsPressed();
MouseLeftUp = leftClickAction.WasReleasedThisFrame();
MouseLeftUp = leftClickAction.WasReleasedThisFrame() || touchReleased;
MouseRightUp = rightClickAction.WasReleasedThisFrame();
MouseMiddleUp = middleClickAction.WasReleasedThisFrame();
......@@ -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()
{
if(PlayerInput.currentControlScheme != GamepadSchemeName)
if (PlayerInput.currentControlScheme != GamepadSchemeName || TouchInputActive())
OnMouseMovedAction?.Invoke();
}
......@@ -365,6 +436,8 @@ namespace MDPro3
public static bool NeedDefaultSelect()
{
if (TouchInputActive())
return false;
if (PlayerInput.currentControlScheme == GamepadSchemeName)
return true;
else if (Cursor.lockState == CursorLockMode.Locked)
......@@ -449,6 +522,15 @@ namespace MDPro3
ignoreNextCursorMove = true;
}
}
private void ShowCursorForTouch()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
hasCursorRestorePos = false;
ignoreNextCursorMove = false;
}
private void HideCursor()
{
cursorRestorePos = MousePos;
......
......@@ -2,9 +2,11 @@ using MDPro3.Net;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using UnityEngine.EventSystems;
using MDPro3.Servant;
using MDPro3.UI.ServantUI;
......@@ -62,14 +64,33 @@ namespace MDPro3.UI
protected override async UniTask RefreshAsync()
{
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;
Manager.GetElement<RawImage>("Face1").texture = Appearance.defaultFace1.texture;
if (face0 != null)
face0.texture = Appearance.defaultFace0.texture;
if (face1 != null)
face1.texture = Appearance.defaultFace1.texture;
Manager.GetElement<RawImage>("Face0").texture = await MyCard.GetAvatarAsync(player0Name);
Manager.GetElement<RawImage>("Face1").texture = await MyCard.GetAvatarAsync(player1Name);
try
{
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()
......
......@@ -621,6 +621,55 @@ namespace MDPro3.UI.ServantUI
}
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)
{
if (show)
......@@ -631,7 +680,6 @@ namespace MDPro3.UI.ServantUI
private void ShowBgDetail()
{
var core = Program.instance.ocgcore;
var info = Program.instance.ocgcore.messageDispatcher.duel.duelBGManager.fieldSummonRightInfo;
if (bgDetailShowing)
......@@ -644,29 +692,7 @@ namespace MDPro3.UI.ServantUI
{
CameraManager.DuelOverlay3DPlus();
info.SetActive(true);
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();
RefreshBgDetail();
}
}
......
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