Announcement

Collapse
No announcement yet.

Selected state call for Event listener?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Selected state call for Event listener?

    How do i get a List Item Renderer's (Button) selected state to call through unreal?

    UScript
    Code:
    // need gamepad button over event to work or selected
    ScrollingList.AddEventListener('CLIK_select', onItemRollOver);
    
    //Only works with mouse over
    ScrollingList.AddEventListener('CLIK_itemRollOver', onItemRollOver);
    Doesn't seem to work

    Only the mouse over state with the mouse works, however, when you have a button selected with the GamePad or Keyboard, it doesn't work at all.

    Any insight into this?

    #2
    Bump........

    Comment


      #3
      Try this:

      Code:
      ScrollingList.AddEventListener('CLIK_change', onListChange);
      
      function onListChange(GFxClikWidget.EventData ev)
      {
          `log("Selected Item's parent: "@ev.target.GetString("_name"));
          `log("index: "@ev.index);
      }

      Comment


        #4
        Thanks Matt! That worked great! Sorry for the late response.


        One Issue though now is that when i attempt to purchase the item, it charges me for the LAST selected item.

        Code:
        function onItemPress(GFxClikWidget.EventData ev)
        {
            `log("Item Selected Index: " @ ItemIndex);
            `log("Item Selected Index: " @(BMSS.ItemInformations[ItemIndex].ItemName));
        		//If the purchase attempt returns false display a popup
            
        		if(!BMSS.PurchaseItem(BMSS.ItemInformations[ev.index].ItemToSell,BMSS.ItemInformations[ev.index].Cost))
        		{
        		}		
        }
        I had the same issue with mouse events.

        Thanks Matt

        Comment


          #5
          I'm not sure why it would be doing that. But what you could try to do is to store the correct index when it is selected in a global variable. Then use that global variable to ensure your purchase system charges you for the correct item.

          Comment


            #6
            Hmm still does it i tried this.

            Code:
            event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
            {    
                switch(WidgetName)
                {                 
            			case ('list2'):
            	    ScrollingList = GFxClikWidget(Widget);
            	    SetUpDataProvider(ScrollingList);
            			
            	    ScrollingList.AddEventListener('CLIK_itemPress', onItemPress);
            			ScrollingList.AddEventListener('CLIK_change', onListChange);
            			//ScrollingList.AddEventListener('CLIK_itemRollOut', onItemRollOut);
            	    break;
                    default:
                        break;
                }
                return true;
            }
            
            function onItemPress(GFxClikWidget.EventData ev)
            {
                `log("Item Selected Index: " @ ItemIndex);
                `log("Item Selected Index: " @(BMSS.ItemInformations[ItemIndex].ItemName));
            		//If the purchase attempt returns false display a popup
                
            		if(!BMSS.PurchaseItem(BMSS.ItemInformations[ItemIndex].ItemToSell,BMSS.ItemInformations[ItemIndex].Cost))
            		{
            		}		
            }
            
            function onListChange(GFxClikWidget.EventData ev)
            {
                `log("Selected Item's parent: "@ev.target.GetString("_name"));
                `log("index: "@ev.index);
            		Description.SetString("text",""@(BMSS.ItemInformations[ev.index].ItemDescription)$"");
            		ItemIndex = ev.index;
            }
            Full Code
            Code:
            //=============================================================================
            // BM_ShopListGFX
            //
            //Shows a list of items and how much of it is in the inventory
            //Keeps track of purchased equip items
            //Ravishing Studios 2012
            
            //=============================================================================
            class BM_ShopListGFX extends GFxMoviePlayer;
            
            
            
            var GFxClikWidget ScrollingList;
            
            var BM_ShopSystem BMSS;
            var BM_PlayerPawn BMPP;
            
            var GFxObject RootPanel;
            var GFxObject Yums;
            var GFxObject Description;
            
            var GFxObject Root;
            
            //Properly position characters
            var int TotalLength;
            var int NameLength;
            var int AmountLength;
            var int RemainingCharacters;
            var int ItemIndex;
            
            var bool bEquips;
            var bool bItems;
            var bool bWeapons;
            var bool bSpecials;
            
            
            var GFxClikWidget PS_Items,PS_Equips,PS_Weapons,PS_Specials;
            
            
            function bool Start(optional bool StartPaused = false)
            {
                Super.Start();
                Advance(0);
            
                //Get a reference to our pawns inventory manager
            		Root = GetVariableObject("_root");
            		Yums = GetVariableObject("_root.yums");
                Description = GetVariableObject("_root.itemdescription");
            		RootPanel = GetVariableObject("_root.listClip");
            		UpdateDescription();
            		UpdateYums();
            		
            		//Tab Buttons
            		PS_Items = GFxClikWidget(Root.GetObject("items", class'GFxClikWidget'));
                PS_Items.AddEventListener('CLIK_press', fliptab_items);
            		
            		PS_Equips = GFxClikWidget(Root.GetObject("equips", class'GFxClikWidget'));
                PS_Equips.AddEventListener('CLIK_press', fliptab_equips);
            		
            		PS_Weapons = GFxClikWidget(Root.GetObject("weapons", class'GFxClikWidget'));
                PS_Weapons.AddEventListener('CLIK_press', fliptab_weapons);
            		
            		PS_Specials = GFxClikWidget(Root.GetObject("specials", class'GFxClikWidget'));
                PS_Specials.AddEventListener('CLIK_press', fliptab_specials);
            		
                return true;
            }
            //Assign shop to this FLA 
            
            
            function Initialize(BM_ShopSystem BMS,BM_PlayerPawn BMP)
            {
            	BMSS = BMS;
            	BMPP = BMP;
            }
            
            function UpdateYums()
            {
            	 Yums.SetString("text",""@(BMPP.BMManager.Yums)$"");
            }
            function UpdateDescription(){}
            
            function fliptab_items(GFxClikWidget.EventData ev)
            {
            	bWeapons = false;
            	bSpecials = false;
            	bEquips = false;
            	bItems = true;
            	
            	SetUpDataProvider(ScrollingList);
            }
            
            function fliptab_equips(GFxClikWidget.EventData ev)
            {
            	bWeapons = false;
            	bSpecials = false;
            	bItems = false;
            	bEquips = true;
            	
            	SetUpDataProvider(ScrollingList);
            } 
            
            function fliptab_weapons(GFxClikWidget.EventData ev)
            {
            	bSpecials = false;
            	bItems = false;
            	bEquips = false;
            	bWeapons = true;
            	
            	SetUpDataProvider(ScrollingList);
            }  
            
            function fliptab_specials(GFxClikWidget.EventData ev)
            {
            	bWeapons = false;
            	bItems = false;
            	bEquips = false;
            	bWeapons = false;
            	bSpecials = true;
            	
            	SetUpDataProvider(ScrollingList);
            } 
            event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
            {    
                switch(WidgetName)
                {                 
            			case ('list2'):
            	    ScrollingList = GFxClikWidget(Widget);
            	    SetUpDataProvider(ScrollingList);
            			
            	    ScrollingList.AddEventListener('CLIK_itemPress', onItemPress);
            			ScrollingList.AddEventListener('CLIK_change', onListChange);
            			//ScrollingList.AddEventListener('CLIK_itemRollOut', onItemRollOut);
            	    break;
                    default:
                        break;
                }
                return true;
            }
            
            function onItemPress(GFxClikWidget.EventData ev)
            {
                `log("Item Selected Index: " @ ItemIndex);
                `log("Item Selected Index: " @(BMSS.ItemInformations[ItemIndex].ItemName));
            		//If the purchase attempt returns false display a popup
                
            		if(!BMSS.PurchaseItem(BMSS.ItemInformations[ItemIndex].ItemToSell,BMSS.ItemInformations[ItemIndex].Cost))
            		{
            		}		
            }
            
            function onListChange(GFxClikWidget.EventData ev)
            {
                `log("Selected Item's parent: "@ev.target.GetString("_name"));
                `log("index: "@ev.index);
            		Description.SetString("text",""@(BMSS.ItemInformations[ev.index].ItemDescription)$"");
            		ItemIndex = ev.index;
            }
            
            
            // function onItemRollOut(GFxClikWidget.EventData ev)
            // { 
            		// ItemIndex = ev.index;
            // }
            //Fill the list with current inventory items inside of inventorymanager
            function SetUpDataProvider(GFxClikWidget Widget)
            {
                local byte i;
                local GFxObject DataProvider;
                local GFxObject TempObj;
                local string FullLabelName;
            		local int Cost;
            
             
                if(bItems)
            		{
            			DataProvider = None;
            			DataProvider = CreateArray();
            
            			switch(Widget)
            			{
            						case (ScrollingList):
            
            						for(i = 0; i < BMSS.ItemInformations.Length; i++)
            						{
            								
            									FullLabelName = BMSS.ItemInformations[i].ItemName;
            									Cost = BMSS.ItemInformations[i].Cost;
            									TempObj = CreateObject("Object");
            									TempObj.SetString("fname",  FullLabelName);
            									TempObj.SetString("fname", FullLabelName); // this will be displayed in the list
            									TempObj.SetString("lAmount", ""@(Cost)$"");
            									DataProvider.SetElementObject(i, TempObj);
            									//Widget.SetFloat("rowCount", TempInv.Length);   // you must specify the row count of scrolling lists manually
            							 
            						 }
            
            						break;
            							default:
            						break;
            			}
                	Widget.SetObject("dataProvider", DataProvider);
            		}
            		else if(bEquips)
            		{
            			DataProvider = None;
            			DataProvider = CreateArray();
            
            			switch(Widget)
            			{
            						case (ScrollingList):
            
            						for(i = 0; i < BMSS.EquipInformations.Length; i++)
            						{
            								
            									FullLabelName = BMSS.EquipInformations[i].ItemName;
            									Cost = BMSS.EquipInformations[i].Cost;
            									TempObj = CreateObject("Object");
            									TempObj.SetString("fname",  FullLabelName);
            									TempObj.SetString("fname", FullLabelName); // this will be displayed in the list
            									TempObj.SetString("lAmount", ""@(Cost)$"");
            									DataProvider.SetElementObject(i, TempObj);
            									//Widget.SetFloat("rowCount", TempInv.Length);   // you must specify the row count of scrolling lists manually
            							 
            						 }
            
            						break;
            							default:
            						break;
            			}
                	Widget.SetObject("dataProvider", DataProvider);
            		}
            		else if(bWeapons)
            		{
            			DataProvider = None;
            			DataProvider = CreateArray();
            
            			switch(Widget)
            			{
            						case (ScrollingList):
            
            						for(i = 0; i < BMSS.WeaponInformations.Length; i++)
            						{
            								
            									FullLabelName = BMSS.WeaponInformations[i].ItemName;
            									Cost = BMSS.WeaponInformations[i].Cost;
            									TempObj = CreateObject("Object");
            									TempObj.SetString("fname",  FullLabelName);
            									TempObj.SetString("fname", FullLabelName); // this will be displayed in the list
            									TempObj.SetString("lAmount", ""@(Cost)$"");
            									DataProvider.SetElementObject(i, TempObj);
            									//Widget.SetFloat("rowCount", TempInv.Length);   // you must specify the row count of scrolling lists manually
            							 
            						 }
            
            						break;
            							default:
            						break;
            			}
                	Widget.SetObject("dataProvider", DataProvider);
            		}
            		else if(bSpecials)
            		{
            			DataProvider = None;
            			DataProvider = CreateArray();
            
            			switch(Widget)
            			{
            						case (ScrollingList):
            
            						for(i = 0; i < BMSS.SpecialsInformations.Length; i++)
            						{
            								
            									FullLabelName = BMSS.SpecialsInformations[i].ItemName;
            									Cost = BMSS.SpecialsInformations[i].Cost;
            									TempObj = CreateObject("Object");
            									TempObj.SetString("fname",  FullLabelName);
            									TempObj.SetString("fname", FullLabelName); // this will be displayed in the list
            									TempObj.SetString("lAmount", ""@(Cost)$"");
            									DataProvider.SetElementObject(i, TempObj);
            									//Widget.SetFloat("rowCount", TempInv.Length);   // you must specify the row count of scrolling lists manually
            							 
            						 }
            
            						break;
            							default:
            						break;
            			}
                	Widget.SetObject("dataProvider", DataProvider);
            		}  	  	  	  	
            }
            
            function PlayCloseAnimation()
            {
            }
            function PlayOpenAnimation()
            {
            }
            
            
            defaultproperties
            {    
                WidgetBindings.Add((WidgetName="list2",WidgetClass=class'GFxClikWidget'))
                TotalLength= 50; // 34 possible characters in the widget
            		bCaptureInput=true
            		bItems = true
            }

            Comment


              #7
              i had the same issue but i just fixed it by having one main Int that would work as the index then assign the index from the GFxClikWidget event data



              [/CODE]

              Comment


                #8
                Wouldnt that be the same as what Matt suggested? It still doesn't work. Ill take another look later to make sure I didn't make a local variable by accident.

                Comment


                  #9
                  I seem to have finally gotten it working through a few circumstances however now im having trouble getting the option stepper to be read.

                  I keep getting accessed none on it. Its in a different frame so I call a function in Unreal to Init it.


                  AS code in frame 19
                  Code:
                  ExternalInterface.call("InitThisButton");
                  Unreal Script

                  Code:
                  var GFxClikWidget PS_Items,PS_Equips,PS_Weapons,PS_Specials,PS_Amount;
                  
                  
                  function InitThisButton()
                  {
                  	        PS_Amount = GFxClikWidget(Root.GetObject("amounttochoose", class'GFxClikWidget'));
                  		PS_Amount.AddEventListener('CLIK_change', UpdateAmount);
                  }
                  Error
                  Code:
                  [0047.18] ScriptWarning: Accessed None 'PS_Amount'
                  	BM_ShopListGFX Transient.BM_ShopListGFX_0
                  	Function BaconMan.BM_ShopListGFX:InitThisButton:0055


                  EDIT:

                  I got it to work, I did it the other way using Widget Initialized instead and it worked.

                  Comment

                  Working...
                  X