Advertisement
Guest User

Untitled

a guest
May 24th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class UIChooseSpecializations extends UIInventory dependson(X2EventListener_RPG_StrategyListener);
  2.  
  3. var array<SoldierSpecialization> SpecializationsPool;
  4. var array<Commodity>        CommodityPool;
  5. var int                     SelectedIndexPool;
  6.  
  7. var array<SoldierSpecialization> SpecializationsChosen;
  8. var array<Commodity>        CommoditiesChosen;
  9. var int                     SelectedIndexChosen;
  10.  
  11. var array<int> SelectedItems;
  12.  
  13. var UIX2PanelHeader PoolHeader;
  14. var UIList PoolList;
  15. var UIX2PanelHeader ChosenHeader;
  16. var UIList ChosenList;
  17.  
  18. // var StateObjectReference m_UnitRef;
  19.  
  20. var localized string m_strTitlePool;
  21. var localized string m_strInventoryLabelPool;
  22. var localized string m_strTitleChosen;
  23. var localized string m_strInventoryLabelChosem;
  24. var localized string m_strChoose;
  25. var localized string m_strRemove;
  26.  
  27.  
  28. simulated function InitScreen(XComPlayerController InitController, UIMovie InitMovie, optional name InitName)
  29. {
  30.     `LOG(self.Class.name @ GetFuncName() @ InitController @ InitMovie @ InitName,, 'RPG-UIChooseSpecializations');
  31.  
  32.     super.InitScreen(InitController, InitMovie, InitName);
  33.  
  34.     BuildList(PoolList, PoolHeader, 'PoolList', 'PoolHeader',
  35.         120, m_strTitlePool, m_strInventoryLabelPool);
  36.  
  37.     BuildList(ChosenList, ChosenHeader, 'ChosenList', 'ChosenHeader',
  38.         1200, m_strTitleChosen, m_strInventoryLabelChosem);
  39.  
  40.     PoolList.BG.OnMouseEventDelegate = OnChildMouseEvent;
  41.     ChosenList.BG.OnMouseEventDelegate = OnChildMouseEvent;
  42.  
  43.     PoolList.OnItemDoubleClicked = OnSpecializationsPoolSelected;
  44.     ChosenList.OnItemDoubleClicked = OnSpecializationsChosenSelected;
  45.  
  46.     SpecializationsPool.Length = 0;
  47.     SpecializationsPool = class'X2TemplateHelper_RPGOverhaul'.static.GetSpecializations();
  48.     //SpecializationsPool.Sort(SortSpecializationsByName);
  49.  
  50.     CommodityPool = ConvertToCommodities(SpecializationsPool);
  51.  
  52.     SpecializationsChosen.Length = 0;
  53.     //SpecializationsChosen = class'SoldierSpecializationManager'.static.GetInstance().GetSecondarySpecializationTemplates(true);
  54.     //SpecializationsChosen.Sort(SortSpecializationsByName);
  55.  
  56.     //CommoditiesChosen = ConvertToCommodities(SpecializationsChosen);
  57.  
  58.     PopulateData();
  59.     UpdateNavHelp();
  60.    
  61.     SetBuiltLabel("");
  62.     SetCategory("");
  63.     ListContainer.Hide();
  64.     ItemCard.Hide();
  65.    
  66.     Navigator.SetSelected(List);
  67.     List.SetSelectedIndex(0);
  68. }
  69.  
  70. simulated function BuildList(out UIList CommList, out UIX2PanelHeader Header, name ListName, name HeaderName,
  71.     int PositionX, optional string HeaderTitle = "", optional string HeaderSubtitle = "")
  72. {
  73.     CommList = Spawn(class'UIList', self);
  74.     CommList.BGPaddingTop = 90;
  75.     CommList.BGPaddingRight = 30;
  76.     CommList.bSelectFirstAvailable = false;
  77.     CommList.bAnimateOnInit = false;
  78.     CommList.InitList(ListName,
  79.         PositionX, 230,
  80.         568, 710,
  81.         false, true
  82.     );
  83.     CommList.BG.SetAlpha(75);
  84.     CommList.Show();
  85.  
  86.     Header = Spawn(class'UIX2PanelHeader', self);  
  87.     Header.bAnimateOnInit = false;
  88.     Header.InitPanelHeader(HeaderName, HeaderTitle, HeaderSubtitle);
  89.     Header.SetPosition(PositionX, 150);
  90.     Header.SetHeaderWidth(588);
  91.     Header.Show();
  92.  
  93.     `LOG(self.Class.name @ GetFuncName() @ CommList @ Header,, 'RPG-UIChooseSpecializations');
  94. }
  95.  
  96. simulated function array<Commodity> ConvertToCommodities(array<SoldierSpecialization> Specializations)
  97. {
  98.     local SoldierSpecialization Spec;
  99.     local int i;
  100.     local array<Commodity> Commodities;
  101.     local Commodity Comm;
  102.     local X2UniversalSoldierClassInfo Template;
  103.  
  104.     for (i = 0; i < Specializations.Length; i++)
  105.     {
  106.         Spec = Specializations[i];
  107.        
  108.         Template = new(None, string(Spec.TemplateName))class'X2UniversalSoldierClassInfo';
  109.        
  110.         Comm.Title = Template.ClassSpecializationTitle;
  111.         Comm.Image = Template.ClassSpecializationIcon;
  112.         Comm.Desc = Template.ClassSpecializationSummary;
  113.         //Comm.OrderHours = class'SpecialTrainingUtilities'.static.GetSpecialTrainingDays() * 24;
  114.  
  115.         Commodities.AddItem(Comm);
  116.     }
  117.  
  118.     return Commodities;
  119. }
  120. /*
  121. function int SortSpecializationsByName(SoldierSpecialization a, SoldierSpecialization b)
  122. {  
  123.     if (a.DisplayName < b.DisplayName)
  124.         return 1;
  125.     else if (a.DisplayName > b.DisplayName)
  126.         return -1;
  127.     else
  128.         return 0;
  129. }
  130. */
  131. simulated function PopulateData()
  132. {
  133.     local Commodity Template;
  134.     local int i;
  135.     local UIInventory_ClassListItem Item;
  136.  
  137.     `LOG(self.Class.name @ GetFuncName(),, 'RPG-UIChooseSpecializations');
  138.  
  139.     PoolList.ClearItems()
  140.     for(i = 0; i < CommodityPool.Length; i++)
  141.     {
  142.         Template = CommodityPool[i];
  143.         Item = Spawn(class'UIInventory_ClassListItem', PoolList.itemContainer);
  144.         Item.InitInventoryListCommodity(Template, , m_strChoose, , , 126);
  145.  
  146.         if (IsPicked(i))
  147.         {
  148.             Item.SetDisabled(true, "You already have a chosen this specialization.");
  149.             Item.ShouldShowGoodState(true, "This is your chhosem specialization.");
  150.         }
  151.  
  152.         if (IsRandomSpec(i))
  153.         {
  154.             Item.SetDisabled(true, "Random specialization.");
  155.         }
  156.     }
  157.  
  158.  
  159.     ChosenList.ClearItems();   
  160.     for(i = 0; i < CommoditiesChosen.Length; i++)
  161.     {
  162.         Template = CommoditiesChosen[i];
  163.         Item = Spawn(class'UIInventory_ClassListItem', ChosenList.itemContainer);
  164.         Item.InitInventoryListCommodity(Template, , m_strRemove, , , 126);
  165.        
  166.         if (!IsRandomSpec(i))
  167.             Item.SetDisabled(true, "Random specializations cant be removed.");
  168.     }
  169. }
  170.  
  171. simulated function bool IsPicked(int Index)
  172. {
  173.     return SelectedItems.Find(Index) != INDEX_NONE;
  174. }
  175.  
  176. simulated function bool IsRandomSpec(int Index)
  177. {
  178.     return false;
  179. }
  180.  
  181. simulated function int GetItemIndex(Commodity Item)
  182. {
  183.     local int i;
  184.  
  185.     for(i = 0; i < CommodityPool.Length; i++)
  186.     {
  187.         if(CommodityPool[i] == Item)
  188.         {
  189.             return i;
  190.         }
  191.     }
  192.  
  193.     return -1;
  194. }
  195.  
  196.  
  197. simulated function OnSpecializationsPoolSelected(UIList kList, int itemIndex)
  198. {
  199.     if (itemIndex != SelectedIndexPool)
  200.     {
  201.         SelectedIndexPool = itemIndex;
  202.     }
  203.  
  204.     if (!IsPicked(SelectedIndexPool))
  205.     {
  206.         SelectedItems.AddItem(SelectedIndexPool);
  207.         PopulateData();
  208.     }
  209.     else
  210.     {
  211.         PlayNegativeSound();
  212.     }
  213. }
  214.  
  215. simulated function OnSpecializationsChosenSelected(UIList kList, int itemIndex)
  216. {
  217.     if (itemIndex != SelectedIndexChosen)
  218.     {
  219.         SelectedIndexChosen = itemIndex;
  220.     }
  221.  
  222.     if (!IsRandomSpec(SelectedIndexChosen))
  223.     {
  224.         SelectedItems.AddItem(SelectedIndexChosen);
  225.         PopulateData();
  226.         //Movie.Stack.Pop(self);
  227.     }
  228.     else
  229.     {
  230.         PlayNegativeSound();
  231.     }
  232. }
  233.  
  234. simulated function bool OnUnrealCommand(int cmd, int arg)
  235. {
  236.     local bool bHandled;
  237.  
  238.     if (!CheckInputIsReleaseOrDirectionRepeat(cmd, arg))
  239.         return false;
  240.  
  241.     // Only pay attention to presses or repeats; ignoring other input types
  242.     // NOTE: Ensure repeats only occur with arrow keys
  243.  
  244.     bHandled = super.OnUnrealCommand(cmd, arg);
  245.  
  246.     if (bHandled)
  247.     {
  248.         if (List.GetSelectedItem() != none)
  249.             SelectedIndexPool = List.GetItemIndex(List.GetSelectedItem());
  250.     }
  251.     /* TODO: Fix controller support
  252.     else
  253.     {
  254.         if (`ISCONTROLLERACTIVE && CanTrainSpecialization(SelectedIndexPool))
  255.         {
  256.             switch (cmd)
  257.             {
  258.             case class'UIUtilities_Input'.const.FXS_BUTTON_A :
  259.                 OnSpecializationsPoolSelected(List, SelectedIndexPool);
  260.                 bHandled = true;
  261.                 break;
  262.             }
  263.         }
  264.     }
  265.     */
  266.     return bHandled;
  267. }
  268.  
  269. simulated function UpdateNavHelp()
  270. {
  271.     local UINavigationHelp NavHelp;
  272.  
  273.     NavHelp = `HQPRES.m_kAvengerHUD.NavHelp;
  274.  
  275.     NavHelp.ClearButtonHelp();
  276.     NavHelp.bIsVerticalHelp = `ISCONTROLLERACTIVE;
  277.     NavHelp.AddBackButton(OnCancel);
  278.  
  279.     if(`ISCONTROLLERACTIVE && !IsPicked(SelectedIndexPool))
  280.     {
  281.         NavHelp.AddSelectNavHelp();
  282.     }
  283. }
  284.  
  285. simulated function PlayNegativeSound()
  286. {
  287.     if(!`ISCONTROLLERACTIVE)
  288.         class'UIUtilities_Sound'.static.PlayNegativeSound();
  289. }
  290.  
  291. simulated function RefreshFacility()
  292. {
  293.     local UIScreen QueueScreen;
  294.  
  295.     QueueScreen = Movie.Stack.GetScreen(class'UIFacility_Academy');
  296.     if (QueueScreen != None)
  297.         UIFacility_Academy(QueueScreen).RealizeFacility();
  298. }
  299.  
  300. simulated function OnCancelButton(UIButton kButton) { OnCancel(); }
  301. simulated function OnCancel()
  302. {
  303.     CloseScreen();
  304.     Movie.Stack.PopFirstInstanceOfClass(class'UIArmory');
  305. }
  306.  
  307. simulated function OnChildMouseEvent(UIPanel Control, int Cmd)
  308. {
  309.     switch(Cmd)
  310.     {
  311.         case class'UIUtilities_Input'.const.FXS_L_MOUSE_OUT:
  312.             PoolList.ClearSelection();
  313.             ChosenList.ClearSelection();
  314.             break;
  315.     }
  316. }
  317.  
  318. //==============================================================================
  319.  
  320. simulated function OnLoseFocus()
  321. {
  322.     super.OnLoseFocus();
  323.     `HQPRES.m_kAvengerHUD.NavHelp.ClearButtonHelp();
  324. }
  325.  
  326. simulated function OnReceiveFocus()
  327. {
  328.     super.OnReceiveFocus();
  329.     `HQPRES.m_kAvengerHUD.NavHelp.ClearButtonHelp();
  330.     `HQPRES.m_kAvengerHUD.NavHelp.AddBackButton(OnCancel);
  331. }
  332.  
  333. defaultproperties
  334. {
  335.     bAutoSelectFirstNavigable = false
  336.     bHideOnLoseFocus = true
  337.    
  338.     InputState = eInputState_Consume
  339.    
  340.     DisplayTag="UIDisplay_Academy"
  341.     CameraTag="UIDisplay_Academy"
  342. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement