Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.43 KB | None | 0 0
  1. using Aquiris.Ballistic.Presentation.Adapter;
  2. using Aquiris.Ballistic.Presentation.View;
  3. using com.aquiris.ballistic.factory;
  4. using com.aquiris.ballistic.filter;
  5. using com.aquiris.ballistic.model.item.game.boost;
  6. using com.aquiris.ballistic.model.item.game.hero;
  7. using com.aquiris.ballistic.model.item.game.lockbox;
  8. using com.aquiris.platform;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using UnityEngine;
  13.  
  14. namespace Aquiris.Ballistic.Presentation.Controller
  15. {
  16.     public class SpecialOffersController : BallisticScreenController
  17.     {
  18.         //
  19.         // Properties
  20.         //
  21.         protected new SpecialOffersView m_view {
  22.             get {
  23.                 return base.m_view as SpecialOffersView;
  24.             }
  25.         }
  26.  
  27.         protected override string Path {
  28.             get {
  29.                 return "special_offers_menu_main";
  30.             }
  31.         }
  32.  
  33.         //
  34.         // Methods
  35.         //
  36.         private void AddRangeBecauseProBuilderIsStupid<T, U> (List<T> p_list, IEnumerable<U> p_range) where U : T
  37.         {
  38.             foreach (U current in p_range) {
  39.                 p_list.Add ((T)((object)current));
  40.             }
  41.         }
  42.  
  43.         public void BuyItem (IItemAdapter p_item)
  44.         {
  45.             QCApplication.Instance.UI.Modal.UnifiedPurchase.DisplayGameItem (p_item);
  46.         }
  47.  
  48.         protected override void OnDestroy ()
  49.         {
  50.             base.OnDestroy ();
  51.             Singleton<PlatformManager>.Instance.onPlayerProfileAndInventoryUpdate -= new Action (this.OnPlayerProfileAndInventoryUpdate);
  52.         }
  53.  
  54.         public void OnInfoButtonClick (IItemAdapter p_gameItem)
  55.         {
  56.             Debug.Log ("OnInfoButtonClick: " + p_gameItem.GetModel ());
  57.             if (p_gameItem is IWeaponAdapter) {
  58.                 QCApplication.Instance.UI.DetailedWeapon.DisplayWeapon (p_gameItem as IWeaponAdapter);
  59.             }
  60.         }
  61.  
  62.         private void OnPlayerProfileAndInventoryUpdate ()
  63.         {
  64.             this.m_profileWasUpdated = true;
  65.         }
  66.  
  67.         public override void OnViewEnabled ()
  68.         {
  69.             base.OnViewEnabled ();
  70.             if (this.m_initted) {
  71.                 return;
  72.             }
  73.             this.m_initted = true;
  74.             Singleton<PlatformManager>.Instance.onPlayerProfileAndInventoryUpdate += new Action (this.OnPlayerProfileAndInventoryUpdate);
  75.             this.RefreshItems ();
  76.         }
  77.  
  78.         private void RefreshItems ()
  79.         {
  80.             this.m_view.ClearItems ();
  81.             List<IItemAdapter> list = new List<IItemAdapter> ();
  82.             LockBoxFilter lockBoxFilter = FilterFactory.GetLockBoxFilter ();
  83.             lockBoxFilter.FilterAvailableByValue (true);
  84.             lockBoxFilter.FilterOwnedSpecificWeaponsByValue (false);
  85.             lockBoxFilter.FilterByState (this.m_view.UIStateToConsider);
  86.             lockBoxFilter.FilterSpecificWeapons (true);
  87.             this.AddRangeBecauseProBuilderIsStupid<IItemAdapter, IWeaponAdapter> (list, lockBoxFilter.GetResultAsWeaponAdapter ());
  88.             lockBoxFilter.Clear ();
  89.             lockBoxFilter.FilterAvailableByValue (true);
  90.             lockBoxFilter.FilterByState (this.m_view.UIStateToConsider);
  91.             lockBoxFilter.FilterSpecificWeapons (false);
  92.             this.AddRangeBecauseProBuilderIsStupid<IItemAdapter, IItemAdapter> (list, ItemAdapterFactory.Get<LockboxGameItem> (lockBoxFilter.GetResult ()));
  93.             WeaponFilter weaponFilter = FilterFactory.GetWeaponFilter ();
  94.             weaponFilter.FilterAvailableWeaponsByValue (true);
  95.             weaponFilter.FilterOwnedWeaponsByValue (false);
  96.             weaponFilter.FilterByState (this.m_view.UIStateToConsider);
  97.             this.AddRangeBecauseProBuilderIsStupid<IItemAdapter, IWeaponAdapter> (list, weaponFilter.GetResultAsWeaponAdapter ());
  98.             List<HeroSkin> itemsOfType = GameItemContainer.Instance.GetItemsOfType<HeroSkin> ();
  99.             this.AddRangeBecauseProBuilderIsStupid<IItemAdapter, IItemAdapter> (list, from item in ItemAdapterFactory.Get<HeroSkin> (itemsOfType)
  100.             where item.IsUIStateSet (this.m_view.UIStateToConsider)
  101.             select item);
  102.             IOrderedEnumerable<IItemAdapter> source = from item in list
  103.             orderby item.GetFeatureScreenSortPriority () descending
  104.             select item;
  105.             List<Boost> itemsOfType2 = GameItemContainer.Instance.GetItemsOfType<Boost> ();
  106.             IOrderedEnumerable<IItemAdapter> source2 = from item in ItemAdapterFactory.Get<Boost> (itemsOfType2)
  107.             orderby item.GetSortPriority () descending
  108.             select item;
  109.             for (int i = 0; i < Mathf.Min (this.m_view.TopCardsToShow, source.Count<IItemAdapter> ()); i++) {
  110.                 this.m_view.AddItem (source.ElementAt (i));
  111.             }
  112.             for (int j = 0; j < Mathf.Min (this.m_view.BottomCardsToShow, itemsOfType2.Count<Boost> ()); j++) {
  113.                 this.m_view.AddItem (source2.ElementAt (j));
  114.             }
  115.         }
  116.  
  117.         private void Update ()
  118.         {
  119.             if (this.m_profileWasUpdated && !QCApplication.Instance.UI.LockboxPopup.IsVisible) {
  120.                 this.m_profileWasUpdated = false;
  121.                 this.RefreshItems ();
  122.             }
  123.         }
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement