When you subscribe to a button press like
Button.OnClick().Subscribe(SomeFunction)
That should pass a widget_message
So you can subscribe to a function that takes a widget message and then define the player who clicked it like this.
SomeFunction(Message:widget_message):void=
Player := Message.Player
DoSomething(Player)
DoSomething(Player:player):void=
ItemGranter.GrantItem(Player)
if you have multiple buttons in your UI Code you can use this nifty function and class to pass extra parameters to tell exactly which button has been pressed as well
(Listenable : listenable(widget_message)).SubscribeMessage(OutputFunc : tuple(widget_message, t)->void, ExtraData : t where t:type) : cancelable =
Wrapper := wrapper_message(t){ExtraData := ExtraData, OutputFunc := OutputFunc}
Listenable.Subscribe(Wrapper.InputFunc)
wrapper_message(t : type) := class():
ExtraData : t;
OutputFunc : tuple(widget_message, t) -> void
InputFunc(Message : widget_message):void = OutputFunc(Message, ExtraData)
So if you had a few buttons like
button_1: button_quiet = button_quiet{}
button_2 : button_quiet = button_quiet{}
you could use the wrapper function SubscribeMessage to pass which button has been clicked like this
button_1.OnClick().SubscribeMessage(SomeFunction, 0)
button_2.OnClick().SubscribeMessage(SomeFunction, 1)
#then SomeFunction can figure out what to do based on the integer passed into it
SomeFunction(Message:widget_message, button_index:int):void=
Player := Message.Player
if(button_index = 0):
Item_Granter_0.GrantItem(Player)
else if(button_index = 1):
Item_Granter_1.GrantItem(Player)
#or you can have an array of item granters and grab them that way
@editable Granter_Array :[]item_granter_device = array{}
SomeFunction(Message:widget_message, button_index:int):void=
Player := Message.Player
if(Granter := Granter_Array[button_index]):
Granter.GrantItem(Player)