Hello!
I am currently playing around some with "STUB" and it seems great.
The thing is I require custom UI buttons for what I am doing, that are fixed in the UI panel. I can´t seem to figure out how to do it.
They need to be activated when clicked on(not like "bonus" buttons that bring up where to execute). I read in some thread here that this would be possible, but it´s not covered in the documentation and I can´t find a mod where anyone else has done it.
Please let me know how to do this(if possible).
Cheers!
Custom UI objects - Static button
Moderators: Slitherine Core, BA Moderators
-
pipfromslitherine
- Site Admin

- Posts: 9937
- Joined: Wed Mar 23, 2005 10:35 pm
Re: Custom UI objects - Static button
It's certainly an interesting thing to attempt! 
Firstly, you need to create the UI screen that you want to show. You can check out any of the files in DATA\UI or CORE\UI for examples. A simple on to start with is DATA\UI\BattlePop0.txt which is a simple textbox and OK button. You can ignore and omit the animation chunks (anything with a # as the first symbol) for now.
I would recommend using layer 7 for your custom UI control. Each layer is used by different controls, 7 is free in battle.
Once you have your screen, placed in the DATA\UI folder of your custom campaign, you can add a script line to show it in battle. This would be called at the very start, and one way to do this would be to add something of the form:
if( GetTurn() == -1 )
{
ShowUIScreen("MyUIScreenObject", "", "") ;
}
in the StartTurn function of the mission script.
You now can show your UI control. But how to get the button actions etc? You will need a script connected to the UI control. First add a line of the form
SCRIPT MyUIControlScript.bsf
to the root object of your UI control in the UI TXT file. Then create the bsf file in the same folder as your UI file. You will need to add a function called
FUNCTION UI_OBJ_HANDLE(data, event, id)
to catch button presses etc. You can check out the BSF files in the PLUGIN folder for examples on how to do so, but you will be using the IsUIObject function to determine the button pressed. You can also add a UI_OBJ_INIT function to the script if you wish, this is called when the UI object is loaded.
Hope that gets you started! Any more questions, let me know. I will add this to the wiki I think
.
Cheers
Pip
Firstly, you need to create the UI screen that you want to show. You can check out any of the files in DATA\UI or CORE\UI for examples. A simple on to start with is DATA\UI\BattlePop0.txt which is a simple textbox and OK button. You can ignore and omit the animation chunks (anything with a # as the first symbol) for now.
I would recommend using layer 7 for your custom UI control. Each layer is used by different controls, 7 is free in battle.
Once you have your screen, placed in the DATA\UI folder of your custom campaign, you can add a script line to show it in battle. This would be called at the very start, and one way to do this would be to add something of the form:
if( GetTurn() == -1 )
{
ShowUIScreen("MyUIScreenObject", "", "") ;
}
in the StartTurn function of the mission script.
You now can show your UI control. But how to get the button actions etc? You will need a script connected to the UI control. First add a line of the form
SCRIPT MyUIControlScript.bsf
to the root object of your UI control in the UI TXT file. Then create the bsf file in the same folder as your UI file. You will need to add a function called
FUNCTION UI_OBJ_HANDLE(data, event, id)
to catch button presses etc. You can check out the BSF files in the PLUGIN folder for examples on how to do so, but you will be using the IsUIObject function to determine the button pressed. You can also add a UI_OBJ_INIT function to the script if you wish, this is called when the UI object is loaded.
Hope that gets you started! Any more questions, let me know. I will add this to the wiki I think
Cheers
Pip
Re: Custom UI objects - Static button
Wow! Really quick reply and extensive too:D. Thanks allot!
I got the button working with the script right away, made it so it would not pause the game and played around some.
I only have two problems now, before I think I know how to deal with everything else I want to do.
1. How do i bind my button script to the /battle/scripts? - I can´t include them or get them to communicate.
2. I want to hide my own buttons when the existing UI is hidden(like when no units are selected). I know I can use the "ShowUIScreen" and "HideUIScreen" commands, but as far as I know there is no way to tell if the existing UI is showing or not? I tried constructing a TICK function that hides/shows my buttons depending on if a unit is selected - but with no success.
Thanks again for the help - looking forward to your next reply!:)
Cheers
I got the button working with the script right away, made it so it would not pause the game and played around some.
I only have two problems now, before I think I know how to deal with everything else I want to do.
1. How do i bind my button script to the /battle/scripts? - I can´t include them or get them to communicate.
2. I want to hide my own buttons when the existing UI is hidden(like when no units are selected). I know I can use the "ShowUIScreen" and "HideUIScreen" commands, but as far as I know there is no way to tell if the existing UI is showing or not? I tried constructing a TICK function that hides/shows my buttons depending on if a unit is selected - but with no success.
Thanks again for the help - looking forward to your next reply!:)
Cheers
-
pipfromslitherine
- Site Admin

- Posts: 9937
- Joined: Wed Mar 23, 2005 10:35 pm
Re: Custom UI objects - Static button
1 - what exactly do you want to do? I'm not sure what you mean in terms of communicating with the scripts.
2 - hmmm - trickier. You could use GetCurrentSelectedUnit() and check it periodically in your mission script and hide/show the UI panel depending on its value.
Cheers
Pip
2 - hmmm - trickier. You could use GetCurrentSelectedUnit() and check it periodically in your mission script and hide/show the UI panel depending on its value.
Cheers
Pip
Re: Custom UI objects - Static button
The GetCurrentSelectedUnit() worked great! I now have some custom buttons mounted to the original UI, that shows/hides depending on if a unit is selected!:).
Regarding question 1 - What i wanted to do was connect MyUIControlScript.bsf to the /Battle/Scripts so that I could call functions and share values between them. However I have solved this by using a couple of campaign variables and everything works for now.
So as for now I don´t need any more help! Thanks again, I will probably make another thread if I get problems in a different area later on.
Cheers!
Regarding question 1 - What i wanted to do was connect MyUIControlScript.bsf to the /Battle/Scripts so that I could call functions and share values between them. However I have solved this by using a couple of campaign variables and everything works for now.
So as for now I don´t need any more help! Thanks again, I will probably make another thread if I get problems in a different area later on.
Cheers!
-
pipfromslitherine
- Site Admin

- Posts: 9937
- Joined: Wed Mar 23, 2005 10:35 pm
Re: Custom UI objects - Static button
Glad you are up and running - although Universal Variables might be more appropriate for what you are doing (Campaign variables get saved across missions, so you could get wierd side effects?).
Any questions, let me know
Cheers
Pip
Any questions, let me know
Cheers
Pip
