Blazephlozard

HP2 code button

Feb 8th, 2021 (edited)
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.13 KB | None | 0 0
  1. using System;
  2. using DG.Tweening;
  3. using DG.Tweening.Core;
  4. using DG.Tweening.Plugins.Options;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7.  
  8. // Token: 0x02000135 RID: 309
  9. public class UiCellphoneAppCode : UiCellphoneApp
  10. {
  11.     // Token: 0x0600065D RID: 1629 RVA: 0x0003321C File Offset: 0x0003141C
  12.     private void Start()
  13.     {
  14.         this.titleBar.Populate(null, this.titleLabelText);
  15.         this.resultsRectTransform.localScale = Vector3.one * 0.25f;
  16.         this.resultsCanvasGroup.alpha = 0f;
  17.         this._currentFieldText = (this.inputField.text = "");
  18.         this.submitButton.ButtonPressedEvent += this.OnSubmitButtonPressed;
  19.         this.inputField.Select();
  20.         this.Refresh();
  21.     }
  22.  
  23.     // Token: 0x0600065E RID: 1630 RVA: 0x000332A6 File Offset: 0x000314A6
  24.     private void Update()
  25.     {
  26.         if (this._currentFieldText != this.inputField.text)
  27.         {
  28.             this.Refresh();
  29.         }
  30.     }
  31.  
  32.     // Token: 0x0600065F RID: 1631 RVA: 0x000332C8 File Offset: 0x000314C8
  33.     public override void Refresh()
  34.     {
  35.         this._currentFieldText = (this.inputField.text = this.inputField.text.ToUpper());
  36.         if (!StringUtils.IsEmpty(this.inputField.text))
  37.         {
  38.             this.submitButton.Enable();
  39.             return;
  40.         }
  41.         this.submitButton.Disable();
  42.     }
  43.  
  44.     // Token: 0x06000660 RID: 1632 RVA: 0x00033324 File Offset: 0x00031524
  45.     private void OnSubmitButtonPressed(ButtonBehavior buttonBehavior)
  46.     {
  47.         string input = this.inputField.text.ToUpper().Trim();
  48.         this._currentFieldText = (this.inputField.text = "");
  49.         this.inputField.Select();
  50.         this.Refresh();
  51.         string key = StringUtils.MD5(input);
  52.         if (Game.Manager.Settings.unlockCodes.ContainsKey(key))
  53.         {
  54.             CodeDefinition codeDefinition = Game.Manager.Settings.unlockCodes[key];
  55.             CodeType codeType = codeDefinition.codeType;
  56.             if (codeType != CodeType.TOGGLE)
  57.             {
  58.                 if (codeType == CodeType.UNLOCK)
  59.                 {
  60.                     if (!Game.Persistence.playerData.unlockedCodes.Contains(codeDefinition))
  61.                     {
  62.                         Game.Persistence.playerData.unlockedCodes.Add(codeDefinition);
  63.                         this.ShowCodeResult(codeDefinition.onMessage, false);
  64.                     }
  65.                     else
  66.                     {
  67.                         this.ShowCodeResult(this.resultMsgRepeat, true);
  68.                     }
  69.                 }
  70.             }
  71.             else if (!Game.Persistence.playerData.unlockedCodes.Contains(codeDefinition))
  72.             {
  73.                 Game.Persistence.playerData.unlockedCodes.Add(codeDefinition);
  74.                 this.ShowCodeResult(codeDefinition.onMessage, false);
  75.             }
  76.             else
  77.             {
  78.                 Game.Persistence.playerData.unlockedCodes.Remove(codeDefinition);
  79.                 this.ShowCodeResult(codeDefinition.offMessage, false);
  80.             }
  81.         }
  82.         else
  83.         {
  84.             this.ShowCodeResult(this.resultMsgInvalid, true);
  85.         }
  86.         if (Game.Manager.Ui.currentCanvas.titleCanvas)
  87.         {
  88.             Game.Manager.Ui.currentCanvas.GetComponent<UiTitleCanvas>().coverArt.Refresh();
  89.         }
  90.     }
  91.  
  92.     // Token: 0x06000661 RID: 1633 RVA: 0x000334A4 File Offset: 0x000316A4
  93.     private void ShowCodeResult(string resultMessage, bool error = false)
  94.     {
  95.         Game.Manager.Time.KillTween(this._resultSequence, false, true);
  96.         this.resultsRectTransform.localScale = Vector3.one * 0.25f;
  97.         this.resultsCanvasGroup.alpha = 0f;
  98.         this.resultsLabel.text = resultMessage;
  99.         this.resultsBackground.sizeDelta = new Vector2(Mathf.Min(this.resultsLabel.preferredWidth + 80f, this.resultsLabel.rectTransform.sizeDelta.x + 80f), this.resultsLabel.preferredHeight + 40f);
  100.         this._resultSequence = DOTween.Sequence();
  101.         this._resultSequence.Insert(0f, this.resultsRectTransform.DOScale(Vector3.one, 0.25f).SetEase(Ease.OutBack));
  102.         this._resultSequence.Insert(0f, this.resultsCanvasGroup.DOFade(1f, 0.25f).SetEase(Ease.Linear));
  103.         Game.Manager.Time.Play(this._resultSequence, this.pauseBehavior.pauseDefinition, 0f);
  104.         if (!error)
  105.         {
  106.             Game.Manager.Audio.Play(AudioCategory.SOUND, Game.Manager.Ui.sfxCellphoneNotification, base.cellphone.pauseBehavior.pauseDefinition);
  107.         }
  108.         else
  109.         {
  110.             Game.Manager.Audio.Play(AudioCategory.SOUND, Game.Manager.Ui.sfxReject, base.cellphone.pauseBehavior.pauseDefinition);
  111.         }
  112.         if (!error)
  113.         {
  114.             this._codeUnlocked = true;
  115.         }
  116.     }
  117.  
  118.     // Token: 0x06000662 RID: 1634 RVA: 0x00033648 File Offset: 0x00031848
  119.     private void OnDestroy()
  120.     {
  121.         Game.Manager.Time.KillTween(this._resultSequence, false, true);
  122.         this.submitButton.ButtonPressedEvent -= this.OnSubmitButtonPressed;
  123.         if (this._codeUnlocked)
  124.         {
  125.             Game.Manager.Settings.SaveSettings();
  126.         }
  127.     }
  128.  
  129.     // Token: 0x04000AD0 RID: 2768
  130.     public UiAppTitleBar titleBar;
  131.  
  132.     // Token: 0x04000AD1 RID: 2769
  133.     public InputField inputField;
  134.  
  135.     // Token: 0x04000AD2 RID: 2770
  136.     public ButtonBehavior submitButton;
  137.  
  138.     // Token: 0x04000AD3 RID: 2771
  139.     public RectTransform resultsRectTransform;
  140.  
  141.     // Token: 0x04000AD4 RID: 2772
  142.     public CanvasGroup resultsCanvasGroup;
  143.  
  144.     // Token: 0x04000AD5 RID: 2773
  145.     public RectTransform resultsBackground;
  146.  
  147.     // Token: 0x04000AD6 RID: 2774
  148.     public Text resultsLabel;
  149.  
  150.     // Token: 0x04000AD7 RID: 2775
  151.     public string titleLabelText;
  152.  
  153.     // Token: 0x04000AD8 RID: 2776
  154.     public string resultMsgInvalid;
  155.  
  156.     // Token: 0x04000AD9 RID: 2777
  157.     public string resultMsgRepeat;
  158.  
  159.     // Token: 0x04000ADA RID: 2778
  160.     private string _currentFieldText;
  161.  
  162.     // Token: 0x04000ADB RID: 2779
  163.     private bool _codeUnlocked;
  164.  
  165.     // Token: 0x04000ADC RID: 2780
  166.     private Sequence _resultSequence;
  167. }
  168.  
Add Comment
Please, Sign In to add comment