//Handle network command function - Must be registered with the UIManager in order to be called properly //Registering it with the UIManager is best done in the FortressCraftMod class' Register method //The static function calls are designed to work equivalently on the server and client so that the two remain in sync public static NetworkInterfaceResponse HandleNetworkCommand(Player player, NetworkInterfaceCommand nic) { MyModMachine machine = nic.target as MyModMachine; string key = nic.command; if (key != null) { if (key == InterfaceMyFunctionItem) { MyModMachineWindow.MyFunctionItem(player, machine, nic.itemContext); } else if (key == InterfaceMyFunctionString) { int data; //Parse the string data (safely) and send to the appropriate function if (int.TryParse(nic.payload ?? "0", out data)) { MyModMachineWindow.MyFunctionString(player, machine, data); } } } return(new NetworkInterfaceResponse() { entity = machine, inventory = player.mInventory }); }
//Called when a UI panel button is clicked public override bool ButtonClicked(string name, SegmentEntity targetEntity) { if (name == "buttonidentifier") { //Perform actions in response and set dirty if required MyModMachineWindow.MyFunctionString(WorldScript.mLocalPlayer, targetEntity as MyModMachine, 5); dirty = true; return(true); } else if (name == "itemicon") { //You can trigger on clicking icons too (you can pass an item reference associated with the slow instead) MyModMachineWindow.MyFunctionItem(WorldScript.mLocalPlayer, targetEntity as MyModMachine, ItemManager.SpawnItem(100)); return(true); } return(false); }