GamePanels.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. namespace DiamondArrow
  8. {
  9. public sealed partial class DiamondArrowGame
  10. {
  11. RectTransform Sheet(string title,float height=740,bool dismiss=true,string id=null)
  12. {
  13. CloseModal();CurrentModal=id??title;modal=Node(root,"Modal "+CurrentModal,0,0,750,1334);
  14. var shade=modal.gameObject.AddComponent<Image>();shade.color=new Color(.01f,0,.025f,.88f);shade.raycastTarget=true;
  15. if(dismiss){var b=modal.gameObject.AddComponent<Button>();b.transition=Selectable.Transition.None;b.onClick.AddListener(()=>{if(!chestBusy)CloseAndRefresh();});}
  16. var panel=Panel(modal,title,35,(1334-height)/2,680,height);panel.GetComponent<NeonPanel>().raycastTarget=true;panel.gameObject.AddComponent<Button>().transition=Selectable.Transition.None;
  17. Label(panel,title,30,24,530,52,30,Color.white,TextAnchor.MiddleLeft);Rule(panel,30,104,620,Neon.Purple);
  18. if(dismiss)CloseImageButton(panel);
  19. return panel;
  20. }
  21. void CloseImageButton(RectTransform panel)
  22. {
  23. var r=Node(panel,"Close",576,10,88,88);var hit=r.gameObject.AddComponent<Image>();hit.color=Color.clear;hit.raycastTarget=true;
  24. var face=Node(r,"Close artwork",0,0,88,88).gameObject.AddComponent<Image>();face.sprite=theme.closeButton;face.preserveAspect=true;face.raycastTarget=false;
  25. var button=r.gameObject.AddComponent<Button>();button.targetGraphic=face;var colors=button.colors;colors.pressedColor=new Color(.6f,.45f,.7f);button.colors=colors;r.gameObject.AddComponent<ButtonDepth>();button.onClick.AddListener(()=>{Sound(SoundCue.Tap);if(!chestBusy)CloseAndRefresh();});
  26. }
  27. RectTransform FooterButton(RectTransform panel,string name,float x,float width,string title,Action action,bool primary=true)
  28. {return Button(panel,name,x,panel.rect.height-128,width,96,title,action,primary);}
  29. void CloseModal()
  30. {
  31. if(modal){modal.gameObject.SetActive(false);Destroy(modal.gameObject);modal=null;}
  32. CurrentModal=null;if(gemsText)gemsText.text=Save.gems.ToString();
  33. }
  34. void CloseAndRefresh(){CloseModal();if(CurrentScreen=="Lobby")ShowLobby();}
  35. public void ShowQuit()
  36. {
  37. if(Run==null||CurrentScreen!="Game")return;if(Run.Status!=RunStatus.Playing)return;
  38. var p=Sheet("LEAVE THIS LEVEL?",420);Label(p,"Your progress in this attempt will be lost.\nYour diamonds and cleared levels are safe.",35,110,610,112,24,Neon.Muted);
  39. FooterButton(p,"Stay",32,290,"STAY",CloseModal,false);FooterButton(p,"Leave",352,295,"LEAVE",ShowMap,true);
  40. }
  41. public void ShowFail()
  42. {
  43. if(Run==null)return;if(CurrentModal!="Fail")Sound(SoundCue.Fail);bool time=Run.Status==RunStatus.FailedTime;var p=Sheet(time?"TIME UP":"OUT OF HEARTS",650,false,"Fail");
  44. Icon(p,time?10:12,273,88,130);Label(p,"Level "+Run.Level.number+" · "+Run.Remaining+" arrows left",30,235,620,40,26,Neon.Ice);
  45. Label(p,time?"A little more time. One more chance.":"Find a clear path and try again.",30,286,620,56,22,Neon.Muted);
  46. if(Save.gems>=40)Button(p,"Revive",70,382,540,96,time?"+30 SECONDS · 40":"REVIVE · 40",()=>{if(!Run.Revive(Save))return;Sound(SoundCue.Heart);Persist();CloseModal();resultScheduled=false;readyAt=Time.unscaledTime+.35f;UpdateGameHud();},true);
  47. else Label(p,"40 diamonds needed to revive",30,392,620,44,22,Neon.Muted);
  48. FooterButton(p,"Map",30,295,"MAP",ShowMap,false);FooterButton(p,"Retry",355,295,"RETRY",()=>StartLevel(Run.Level.number),true);
  49. }
  50. public void ShowResult()
  51. {
  52. if(Run==null||Run.Status!=RunStatus.Cleared)return;var reward=Economy.Clear(Run,Save);Persist();Sound(SoundCue.Clear);var p=Sheet("LEVEL CLEAR",880,false,"Result");
  53. for(int i=0;i<3;i++)Icon(p,2,216+i*86,112,78,new Color(1,1,1,i<Run.Stars?1:.2f));
  54. Label(p,"LEVEL "+Run.Level.number+" · "+Run.Mistakes+" MISTAKES · "+Clock(Run.TimeLeft)+" LEFT",20,196,640,35,20,Neon.Ice);
  55. var rewards=Panel(p,"Rewards",32,245,616,125,false);Icon(rewards,1,15,23,76);Label(rewards,"+"+reward.Total+" DIAMONDS",105,8,485,47,29,Color.white,TextAnchor.MiddleLeft);
  56. Label(rewards,"Clear "+reward.basic+" First clear "+reward.first+" Time "+reward.time+(reward.keys>0?"\nMilestone: +1 chest key":""),105,57,485,60,19,Neon.Muted,TextAnchor.MiddleLeft);
  57. Label(p,"FASTEST CLEARS · OFFLINE BENCHMARK",32,388,616,32,19,Neon.Ice,TextAnchor.MiddleLeft);if(reward.newBest)Label(p,"NEW BEST",444,420,204,29,18,Neon.Gold);
  58. var rivals=new List<KeyValuePair<string,float>>();var seeded=new System.Random(Run.Level.number*7919+104729);var names=new List<string>{"Nova","Kito","Vega","Rin","Onyx","Sable","Mika","Juno","Zed","Lyra","Ace","Iris","Kai","Nyx","Rex","Yuna"};
  59. for(int i=0;i<12;i++){int k=seeded.Next(names.Count);rivals.Add(new KeyValuePair<string,float>(names[k],Run.Level.seconds*(.34f+Mathf.Pow((float)seeded.NextDouble(),.85f)*.66f)));names.RemoveAt(k);}
  60. const string playerKey="__player__";rivals.Add(new KeyValuePair<string,float>(playerKey,Save.best[Run.Level.number-1]));rivals=rivals.OrderBy(x=>x.Value).ToList();int rank=rivals.FindIndex(x=>x.Key==playerKey);
  61. var shown=new List<int>{0,1,2,3,rank<4?4:rank};for(int j=0;j<5;j++){int ix=shown[j];var row=rivals[ix];bool me=row.Key==playerKey;var box=Panel(p,"Score "+j,32,456+j*43,616,38,false);if(me){box.GetComponent<NeonPanel>().top=Neon.Hex("#67124F");}Label(box,(ix+1).ToString(),10,0,50,38,20,ix==0?Neon.Gold:Neon.Muted);Label(box,me?Save.name+" (You)":row.Key,70,0,365,38,21,me?Neon.Pink:Color.white,TextAnchor.MiddleLeft);Label(box,row.Value.ToString("0.0")+"s",450,0,150,38,22,Neon.Ice);}
  62. Label(p,"Your best: #"+(rank+1)+" / 13 · opponents are simulated",20,680,640,27,17,Neon.Muted);
  63. FooterButton(p,"Result map",32,280,"MAP",ShowMap,false);FooterButton(p,"Next level",337,310,Run.Level.number==30?"REPLAY":"NEXT LEVEL",()=>StartLevel(Mathf.Min(30,Run.Level.number+1)),true);
  64. }
  65. public void ShowCheckin()
  66. {
  67. var p=Sheet("DAILY CHECK-IN",860);Label(p,"A little sparkle, every day.",30,122,620,40,23,Neon.Ice);
  68. for(int i=0;i<7;i++){int day=i+1;var row=Panel(p,"Day "+day,30,182+i*65,620,56,false);if(day==Save.checkinDay)row.GetComponent<NeonPanel>().top=Neon.Hex("#571054");Label(row,"DAY "+day,14,4,110,48,21,day==Save.checkinDay?Neon.Gold:Neon.Muted);Label(row,Economy.CheckinLabels[i],140,4,455,48,22,Color.white,TextAnchor.MiddleLeft);}
  69. bool claimed=Save.checkinDate==Today;Label(p,"Missed days never reset your rewards.",25,656,630,36,19,Neon.Muted);FooterButton(p,"Claim",100,480,claimed?"CLAIMED TODAY":"CLAIM DAY "+Save.checkinDay,()=>{if(Economy.CheckIn(Save,Today)){Persist();Sound(SoundCue.Reward);ShowCheckin();Toast("Daily reward claimed");}else Toast("Come back tomorrow");},!claimed);
  70. }
  71. public void ShowShop()
  72. {
  73. var p=Sheet("SHOP",960);Icon(p,1,34,120,40);Label(p,Save.gems+" DIAMONDS",80,118,500,42,25,Neon.Ice,TextAnchor.MiddleLeft);int[] art={10,12,11,2,13,13,13};
  74. for(int i=0;i<7;i++){int product=i;float y=184+i*100;var row=Panel(p,"Product "+i,27,y,626,92,false);Icon(row,art[i],8,18,56);Label(row,Economy.Products[i],78,17,322,58,23,Color.white,TextAnchor.MiddleLeft);Button(row,"Buy "+Economy.Products[i],410,2,202,88,Economy.Prices[i]+" BUY",()=>{if(Economy.Buy(Save,product)){Persist();Sound(SoundCue.Reward);ShowShop();Toast("Added to your inventory");}else {Sound(SoundCue.Blocked);Toast("Not enough diamonds");}},Save.gems>=Economy.Prices[i]);}
  75. Label(p,"Inventory Spotlight "+Save.spotlight+" Hammer "+Save.hammer+" Hearts "+Save.heart,25,900,630,40,18,Neon.Muted);
  76. }
  77. public void ShowChest()
  78. {
  79. var p=Sheet("LUCKY CHEST",780);var chest=Icon(p,8,211,98,258);Label(p,"ONE CHEST. A LITTLE MORE SPARKLE.",24,375,632,32,19,Neon.Ice);Label(p,"20–300 diamonds, keys or power-ups\nEvery opening contains a reward.",45,425,590,80,23,Neon.Muted);
  80. Label(p,"CHEST KEYS: "+Save.keys+" DIAMONDS: "+Save.gems,25,525,630,36,21,Neon.Gold);
  81. string cost=Save.chestDate!=Today?"OPEN FREE":Save.keys>0?"OPEN · 1 KEY":"OPEN · 60";
  82. FooterButton(p,"Open chest",80,520,cost,()=>{if(chestBusy)return;if(!Economy.CanOpen(Save,Today)){Toast("No keys or diamonds");return;}string prize=Economy.OpenChest(Save,Today,random.NextDouble());Persist();chestBusy=true;Sound(SoundCue.ChestOpen);StartCoroutine(RevealChest(chest.rectTransform,prize));},true);
  83. }
  84. IEnumerator RevealChest(RectTransform chest,string prize)
  85. {
  86. for(float t=0;t<.9f;t+=Time.unscaledDeltaTime){if(!chest)yield break;chest.localScale=Vector3.one*(1+.08f*Mathf.Sin(t*45));chest.localRotation=Quaternion.Euler(0,0,Mathf.Sin(t*55)*4);yield return null;}
  87. chestBusy=false;Sound(SoundCue.Reward);Buzz();var p=Sheet("VAULT UNLOCKED",600);Icon(p,prize.Contains("KEY")?13:prize.Contains("HAMMER")?11:1,243,100,194);Label(p,prize,25,324,630,68,29,Neon.Gold);FooterButton(p,"Collect",100,480,"COLLECT",ShowChest,true);
  88. }
  89. public void ShowDiamonds()
  90. {
  91. var p=Sheet("DIAMONDS",690);Icon(p,1,250,100,180);Label(p,Save.gems.ToString(),25,296,630,75,54,Color.white);Label(p,"Earn diamonds by clearing levels,\nchecking in and opening your daily chest.\nSpend them on power-ups, keys and revives.",45,389,590,135,23,Neon.Muted);FooterButton(p,"Open shop",140,400,"VISIT SHOP",ShowShop,true);
  92. }
  93. public void ShowProfile()
  94. {
  95. var p=Sheet("PLAYER PROFILE",760);Avatar(p,250,94,180);Label(p,Save.name,30,295,620,48,33,Color.white);Label(p,"LEVELS CLEARED "+Save.Cleared+" / 30\nSTARS COLLECTED "+Save.TotalStars+" / 90\nDIAMONDS EARNED "+Save.earned+"\nCHECK-INS "+Save.checkinTotal,75,370,530,200,25,Neon.Ice,TextAnchor.MiddleLeft);FooterButton(p,"Edit identity",125,430,"EDIT IDENTITY",ShowStart,true);
  96. }
  97. public void ShowHelp()
  98. {
  99. var p=Sheet("HOW TO PLAY",800);string[] titles={"01 FIND A CLEAR PATH","02 WATCH YOUR HEARTS","03 BEAT THE CLOCK","04 USE A LITTLE HELP"};string[] bodies={"Tap an arrow. It slides in the direction of its tip.\nAnother arrow in front blocks the way.","Blocked taps cost a heart. Three mistakes end\nthe attempt. No mistakes earns three stars.","Clear every arrow before time runs out.\nSpare time earns extra diamonds.","Spotlight finds a free arrow. Hammer breaks one.\nHeart refill restores one heart, up to five."};for(int i=0;i<4;i++){Label(p,titles[i],35,122+i*133,610,36,23,Neon.Ice,TextAnchor.MiddleLeft);Label(p,bodies[i],35,163+i*133,610,74,21,Neon.Muted,TextAnchor.MiddleLeft);}FooterButton(p,"Got it",150,380,"GOT IT",CloseAndRefresh,true);
  100. }
  101. public void ShowSettings()
  102. {
  103. var p=Sheet("SETTINGS",720);string[] names={"Sound effects","Music","Haptics"};bool[] flags={Save.sfx,Save.music,Save.haptics};
  104. for(int i=0;i<3;i++){int k=i;Label(p,names[i],38,120+i*108,400,88,27,Color.white,TextAnchor.MiddleLeft);Button(p,"Toggle "+names[i],476,120+i*108,160,88,flags[i]?"ON":"OFF",()=>{if(k==0)Save.sfx=!Save.sfx;if(k==1)Save.music=!Save.music;if(k==2)Save.haptics=!Save.haptics;ApplyAudioPreferences();Persist();ShowSettings();},flags[i]);}
  105. Label(p,"All progress is saved on this device.\nDiamond Arrow Slide · 1.0",35,470,610,75,21,Neon.Muted);FooterButton(p,"Reset progress",100,480,"RESET LOCAL PROGRESS",ShowReset,false);
  106. }
  107. void ShowReset()
  108. {
  109. var p=Sheet("RESET PROGRESS?",430);Label(p,"This erases this game's levels, diamonds,\nitems, check-in and profile on this device.",35,115,610,110,24,Neon.Muted);FooterButton(p,"Cancel reset",30,295,"CANCEL",ShowSettings,false);FooterButton(p,"Confirm reset",355,295,"RESET",()=>{store.Reset();Save=new PlayerSave();ApplyAudioPreferences();Persist();ShowStart();},true);
  110. }
  111. void CreateAudio()
  112. {
  113. gameAudio=gameObject.AddComponent<GameAudio>();
  114. gameAudio.Initialize(theme,Save.music,Save.sfx);
  115. }
  116. void ApplyAudioPreferences(){if(gameAudio)gameAudio.ApplyPreferences(Save.music,Save.sfx);}
  117. void Sound(SoundCue cue){if(Save!=null&&Save.sfx&&gameAudio)gameAudio.Play(cue);}
  118. void CountdownAudio()
  119. {
  120. int second=Mathf.CeilToInt(Run.TimeLeft);
  121. if(Run.Status==RunStatus.Playing&&second>=1&&second<=5&&second!=lastCountdownSecond)
  122. {lastCountdownSecond=second;Sound(SoundCue.Countdown);}
  123. }
  124. void Buzz(){
  125. #if UNITY_IOS && !UNITY_EDITOR
  126. if(Save.haptics)Handheld.Vibrate();
  127. #endif
  128. }
  129. }
  130. }