赛事loading页面按钮可用性调整

This commit is contained in:
lishuo 2021-07-27 13:29:41 +08:00
parent d4ae01cd32
commit c9b5520331
8 changed files with 1043 additions and 113 deletions

File diff suppressed because it is too large Load Diff

View File

@ -33,6 +33,7 @@ namespace Assets.Scenes.Ride.Scripts
cyclingController = controller;
//渲染比赛界面
panel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CompetitonPanel"), transform);
panel.transform.SetAsFirstSibling();
PFUIPanel mainPanel = panel.GetComponent<PFUIPanel>();
PFUIPanel modelPanel = transform.Find("ModalPanel").GetComponent<PFUIPanel>();
CompetitionDesc = panel.transform.Find("CompetitionDesc").GetComponent<RawImage>();
@ -62,6 +63,18 @@ namespace Assets.Scenes.Ride.Scripts
GetReadyTitle.gameObject.SetActive(false);
GetReady.gameObject.SetActive(false);
}
//1.报名按钮
Apply.SetActive(_canJoin);
//2.观看按钮
var showWatch = !_canJoin && !_canStart && !_canCancelApply && _raceStart;
Watch.SetActive(showWatch);
//3.开始按钮
rideNow.gameObject.SetActive(_canStart);
//4.详情按钮
Detail.SetActive(!_canStart);
//5.取消报名按钮 (比赛开始前可以取消报名)
CancelJoin.SetActive(_canCancelApply && count > 0);
}
#endregion
}
@ -76,6 +89,8 @@ namespace Assets.Scenes.Ride.Scripts
InitGameObject();
InitGameObjectData();
}
GameObject Detail { get; set; }
GameObject Apply { get; set; }
//构建赛事界面
protected override void InitGameObject()
{
@ -85,6 +100,8 @@ namespace Assets.Scenes.Ride.Scripts
Contestant = panel.transform.Find("Contestant").GetComponent<Text>();
Watch = panel.transform.Find("Watch").gameObject;
CancelJoin = panel.transform.Find("CancelJoin").gameObject;
Detail = panel.transform.Find("Detail").gameObject;
Apply = panel.transform.Find("Apply").gameObject;
PlayersPanel = panel.transform.Find("PlayersPanel/List/Viewport/Content");
LeftBack = panel.transform.Find("LeftBack").gameObject;
MiddleBack = panel.transform.Find("MiddleBack").gameObject;
@ -95,10 +112,13 @@ namespace Assets.Scenes.Ride.Scripts
UIManager.AddEvent(ReadMore, EventTriggerType.PointerClick, ReadCompetitionPreview);
UIManager.AddEvent(Watch, EventTriggerType.PointerClick, StartWatch);
UIManager.AddEvent(Apply, EventTriggerType.PointerClick, ApplyRace);
UIManager.AddEvent(CancelJoin, EventTriggerType.PointerClick, CancelReserve);
UIManager.AddEvent(Detail, EventTriggerType.PointerClick, GoDetail);
}
private bool _canCancelApply = false;
private bool _canCancelApply = false;
private bool _raceStart = false;
//查询赛事相关数据
protected override void InitGameObjectData()
{
@ -108,22 +128,7 @@ namespace Assets.Scenes.Ride.Scripts
_canJoin = competition.CanJoin;
_canStart = competition.CanStart;
_canCancelApply = competition.applyed;//可以取消预约
//报名或者开始比赛
rideNowText.text = _canJoin ? "Apply" : "RideNow";
//观战
var showWatch = !_canJoin && !_canStart && !_canCancelApply;
Watch.SetActive(showWatch);
rideNow.gameObject.SetActive(!showWatch);
//取消预约
CancelJoin.SetActive(_canCancelApply);
//比赛结束
if (competition.Status == 4)
{
rideNow.gameObject.SetActive(false);
Watch.SetActive(false);
CancelJoin.SetActive(false);
}
_raceStart = competition.Status == 3;
#region
//赛事名称
mapName.text = competition.Title;
@ -186,12 +191,6 @@ namespace Assets.Scenes.Ride.Scripts
}
}
}
//显示比赛详情图片:如果没有比赛详情图则显示地图
private void ShowCompetitionDescImage()
{
}
private string GetENStatus(string status)
{
switch (status)
@ -204,40 +203,6 @@ namespace Assets.Scenes.Ride.Scripts
return "";
}
#region
//先报名后开始
protected override void StartRide(BaseEventData baseEvent)
{
try
{
//先报名
if (_canJoin)
{
MapCompetitionApi s = new MapCompetitionApi();
var rrr = s.ApplyMapCompetition(cyclingController.competitionId);
if (rrr.result)
{
//var competition = s.GetById(cyclingController.competitionId).data;
//_canStart = competition.CanStart;
_canJoin = false;
//取消预约
CancelJoin.SetActive(true);
}
//if (_canStart)
{
rideNowText.text = "RideNow";
}
}
else
{
base.StartRide(baseEvent);
}
}
catch (Exception e)
{
Debug.LogError(e);
}
}
//查看赛事详情
protected void ReadCompetitionPreview(BaseEventData baseEvent)
@ -252,32 +217,100 @@ namespace Assets.Scenes.Ride.Scripts
cyclingController.player.SetActive(false);
base.StartRide(baseEvent);
}
protected void GoDetail(BaseEventData baseEvent)
{
Application.OpenURL(App.CurrentUser.WebHost + $"#/Mine/MatchPreview?id={cyclingController.competitionId}&Token={App.CurrentUser.cookie}");
}
protected void ApplyRace(BaseEventData baseEvent)
{
UIManager.ShowConfirm("Apply", "Are your want to Apply this race?", async () =>
{
MapCompetitionApi s = ConfigHelper.mapCompetitionApi;
var rrr = s.ApplyMapCompetition(cyclingController.competitionId);
if (rrr.result)
{
var result = s.GetById(cyclingController.competitionId);
if (result.result == false || result.data == null)
{
Utils.showToast(gameObject, "error when get competition information");
return;
}
else
{
competition = result.data;
_canStart = competition.CanStart;
_canJoin = competition.CanJoin;
_canCancelApply = competition.applyed;
UIManager.UpdateJoinCompetition();
Utils.showToast(gameObject, "success", 2, 1);
}
}
else
{
Utils.showToast(gameObject, rrr.errMsg);
}
rideNow.gameObject.SetActive(_canStart);
Detail.SetActive(!_canStart);
UIManager.CloseConfirm();
});
}
//取消预约
protected void CancelReserve(BaseEventData baseEvent)
{
try
{
MapCompetitionApi api = new MapCompetitionApi();
var result = api.CancelMapCompetition(cyclingController.competition.Id);
if (result.result)
UIManager.ShowConfirm("Canel Application", "Are you want to cancel this application?", async () =>
{
rideNowText.text = "Apply";
CancelJoin.SetActive(false);
_canJoin = true;
Debug.Log(result);
//SHOW Alert
}
else
{
Debug.Log(result);
//SHOW Alert
}
MapCompetitionApi api = ConfigHelper.mapCompetitionApi;
var data = api.CancelMapCompetition(cyclingController.competition.Id);
if (data.result)
{
var result = api.GetById(cyclingController.competitionId);
if (result.result == false || result.data == null)
{
Utils.showToast(gameObject, "error when get competition information");
return;
}
else
{
competition = result.data;
_canStart = competition.CanStart;
_canJoin = competition.CanJoin;
_canCancelApply = competition.applyed;
UIManager.UpdateJoinCompetition();
Utils.showToast(gameObject, "success", 2, 1);
}
}
else
{
Utils.showToast(gameObject, data.errMsg);
}
UIManager.CloseConfirm();
});
}
catch (Exception ex)
{
Debug.Log(ex);
}
}
protected override void Cancel(BaseEventData baseEvent)
{
if (App.MainSceneParam.ContainsKey("Name"))
{
App.MainSceneParam["Name"] = "RaceHomePanel";
}
else
{
App.MainSceneParam.Add("Name", "RaceHomePanel");
}
base.Cancel(baseEvent);
}
#endregion
}
}

View File

@ -129,7 +129,8 @@ namespace Assets.Scenes.Ride.Scripts
competitionRankingItem.setRatio(item.KGWeight + "W/KG");
competitionRankingItem.setSpeed(item.Speed.ToString() + "KM/H");
competitionRankingItem.setHead(item.Headimage);
competitionRankingItem.setCountry(item.CountryImg);
var countryTexture = cyclingController.GetCountryImageByName(item.CountryImg);
competitionRankingItem.setCountry(countryTexture);
competitionRankingItem.setDistance(currentPlayer.UserId == item.UserId?"0KM": item.Near.ToString() + "KM");
competitionRankingItem.transform.SetSiblingIndex(item.Index);
}

View File

@ -96,9 +96,9 @@ namespace Assets.Scenes.Ride.Scripts
}
}
public void setCountry(string url)
public void setCountry(Texture texture)
{
Utils.DisplayImage(Country, url, true);
Country.texture = texture;
}
public void setName(string name)
{

View File

@ -164,19 +164,26 @@ namespace Assets.Scenes.Ride.Scripts
protected override void StopRide(BaseEventData baseEventData)
{
//观察者
if (!App.MainSceneParam.ContainsKey("Name"))
{
App.MainSceneParam.Add("Name", "RaceHomePanel");
}
else
{
App.MainSceneParam["Name"] = "RaceHomePanel";
}
if (mainController.isWatch)
{
quitPanel.SetActive(true);
var content=quitPanel.transform.Find("Content").GetComponent<Text>();
content.text = "Do you want to quit?";
quitPanel.transform.Find("AbandonButton").gameObject.SetActive(false);
quitPanel.transform.Find("SaveButton/Text").GetComponent<Text>().text = "OK";
UIManager.ShowConfirm("Quit", "Are you want to quit?", async () =>
{
SceneManager.LoadScene("MainScene");
UIManager.CloseConfirm();
});
}
//参赛者:提醒是否退出并保存赛事结果
else
{
quitPanel.SetActive(true);
base.StopRide(baseEventData);
}
}
}

View File

@ -153,7 +153,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
Near = near,
KGWeight = Math.Round(item.WeightKg, 2).ToString(),
Speed = Math.Round(item.Speed, 1),
CountryImg = ConfigHelper.Host + $"User/GetCountryImg?userid={ item.Id }",
CountryImg = item.Country,//ConfigHelper.Host + $"User/GetCountryImg?userid={ item.Id }",
UserId = item.Id,
IsSelf = item.IsSelf,
Headimage =item.HeadImage

View File

@ -187,7 +187,7 @@ namespace Assets.Scenes.Ride.Scripts
depressFlag = true;
}
}
protected void Cancel(BaseEventData baseEvent)
protected virtual void Cancel(BaseEventData baseEvent)
{
SceneManager.LoadScene("MainScene");
}

View File

@ -42,6 +42,7 @@ public class RaceButtonGroupScript : MonoBehaviour
parent.GetComponent<RaceItemScript>().Join();
}
App.RouteIdParam = map.RouteId;
UIManager.UpdateJoinCompetition();
UIManager.CloseConfirm();
});
}
@ -58,6 +59,7 @@ public class RaceButtonGroupScript : MonoBehaviour
if (map.HasJoin)
{
parent.GetComponent<RaceItemScript>().CancelJoin();
UIManager.UpdateJoinCompetition();
}
UIManager.CloseConfirm();
});