UI : Close Button in corner of UI window
Moderators: Lavish Software Team, Moderators
UI : Close Button in corner of UI window
I believe that there should be a way to script what the X (Close) button does in the corner of the UI window instead of the default behavior of just hiding the window. Perhaps add a <CloseOption> tag to complement <CloseButton> that would allow us to choose Hide (default) or Unload.
You actually can. Any of the controls used can be a descendant of the required type, but must have the same name. Hannibal demonstrated a close button that performs other operations in one of his UIs (actually I dont know if he posted it or not, but he discussed it with me to figure it out and showed me what he did).
So all you do is make a commandbutton named CloseButton or whatever the name is (it might just be Close, I dont recall without looking), and as the command, put whatever you want.
And either way, the title bar is just a frame and can contain whatever you want. Put a check box in there named whatever you want, it doesnt matter. So you can put your own button in there with the same look as the default Close button, and have it do something else. If you dont name it what the normal one is named, it wont even try to hide the window by default
So all you do is make a commandbutton named CloseButton or whatever the name is (it might just be Close, I dont recall without looking), and as the command, put whatever you want.
And either way, the title bar is just a frame and can contain whatever you want. Put a check box in there named whatever you want, it doesnt matter. So you can put your own button in there with the same look as the default Close button, and have it do something else. If you dont name it what the normal one is named, it wont even try to hide the window by default

Sorry, I should specify since this isnt fully documented yet.
The <CloseButton> toggle in the Window element itself simply controls whether or not the element named "Close" in the Title Bar (which is just a frame), if any, will be available.
The <TitleBar> tag in the Window element is creating a child of the window, which is just a "frame" element. It is allowed to have any properties of a normal frame, and if it has specially named controls within it, they will be specially used. If it does not have those controls, then they will not be specially used. It is not limited to specific controls, or specific placement in the window element.
The default window and title bar appearance and such are set up by the default skin. If you want to override any of the behavior, take a peek at the default skin in DefaultSkin.xml for a better understanding
The <CloseButton> toggle in the Window element itself simply controls whether or not the element named "Close" in the Title Bar (which is just a frame), if any, will be available.
The <TitleBar> tag in the Window element is creating a child of the window, which is just a "frame" element. It is allowed to have any properties of a normal frame, and if it has specially named controls within it, they will be specially used. If it does not have those controls, then they will not be specially used. It is not limited to specific controls, or specific placement in the window element.
The default window and title bar appearance and such are set up by the default skin. If you want to override any of the behavior, take a peek at the default skin in DefaultSkin.xml for a better understanding
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<ISUI>
<Window name='Autofish Config'>
<Visible>1</Visible>
<X>375</X>
<Y>240</Y>
<Width>240</Width>
<Height>240</Height>
<TitleBar>
<checkbox name='Custom Close Button'>
<X>0</X>
<Y>0</Y>
<Width>10</Width>
<Height>10</Height>
<Command>ui -unload .\\Scripts\\miniAutofish\\Interface\\miniAutofish_ConfigUI.xml</Command>
</checkbox>
</TitleBar>
<Children>
<commandcheckbox name='Use AFKAlarm'>
<X>10</X>
<Y>10</Y>
<Width>100</Width>
<Height>20</Height>
<Text> -> Use AFKAlarm</Text>
<Command>RunScript AFKAlarm</Command>
<CommandChecked>EndScript AFKAlarm</CommandChecked>
<Data>${Script[AFKAlarm]}</Data>
</commandcheckbox>
<commandcheckbox name='Show Scoresheet'>
<X>10</X>
<Y>30</Y>
<Width>100</Width>
<Height>20</Height>
<Text> -> Display Scoresheet</Text>
<Command>Script[miniAutofish].Variable[miniAutofish_display_scoresheet]:Toggle</Command>
<CommandChecked>Script[miniAutofish].Variable[miniAutofish_display_scoresheet]:Toggle</CommandChecked>
<Data>${Script[miniAutofish].Variable[miniAutofish_display_scoresheet]}</Data>
</commandcheckbox>
</Children>
</Window>
</ISUI>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<ISUI>
<Window name='Autofish Config'>
<Visible>1</Visible>
<X>375</X>
<Y>240</Y>
<Width>240</Width>
<Height>240</Height>
<TitleBar>
<Height>16</Height>
<Border>1</Border>
<BorderColor>FF000033</BorderColor>
<Width>100%</Width>
<BackgroundColor>FF000066</BackgroundColor>
<Children>
<checkbox name='Custom Close Button' template='window.TitleBar.Close'>
<X>r13</X>
<Y>2</Y>
<Width>11</Width>
<Height>11</Height>
<Command>ui -unload .\\Scripts\\miniAutofish\\Interface\\miniAutofish_ConfigUI.xml</Command>
</checkbox>
</Children>
</TitleBar>
<Children>
<commandcheckbox name='Use AFKAlarm'>
<X>10</X>
<Y>10</Y>
<Width>100</Width>
<Height>20</Height>
<Text> -> Use AFKAlarm</Text>
<Command>RunScript AFKAlarm</Command>
<CommandChecked>EndScript AFKAlarm</CommandChecked>
<Data>${Script[AFKAlarm]}</Data>
</commandcheckbox>
<commandcheckbox name='Show Scoresheet'>
<X>10</X>
<Y>30</Y>
<Width>100</Width>
<Height>20</Height>
<Text> -> Display Scoresheet</Text>
<Command>Script[miniAutofish].Variable[miniAutofish_display_scoresheet]:Toggle</Command>
<CommandChecked>Script[miniAutofish].Variable[miniAutofish_display_scoresheet]:Toggle</CommandChecked>
<Data>${Script[miniAutofish].Variable[miniAutofish_display_scoresheet]}</Data>
</commandcheckbox>
</Children>
</Window>
</ISUI>
Thanks for the info (especially pointing me towards the DefaultSkin.xml file!).
I feel like such an idiot now. The code below is my friend.
Code: Select all
<TitleBar template='window.TitleBar'>
Well, the reason the default skin uses templates is so that you can replace whatever portions you want, and keep the rest of the defaults.
Also, a few additions were made that will help you with what you want. 1: A custom XML entity "&file;" which references the current XML filename. 2: "&filepath;" which references the current XML file's PATH, without the filename or the final slash, used like "&filepath;/someother.XML"
And another suggestion for when you're hardcoding paths: Instead of using \\ for paths, start using / instead. It's a bit less confusing-looking. Additionally, the leading .\\ in your path can just be dropped, and the path will be relative.
Note: The &file; is quoted in the above because the file and path can include spaces, which means it would be interpreted by the UI command as separate parameters. Remove any of the other children you dont want also 
Also, a few additions were made that will help you with what you want. 1: A custom XML entity "&file;" which references the current XML filename. 2: "&filepath;" which references the current XML file's PATH, without the filename or the final slash, used like "&filepath;/someother.XML"
And another suggestion for when you're hardcoding paths: Instead of using \\ for paths, start using / instead. It's a bit less confusing-looking. Additionally, the leading .\\ in your path can just be dropped, and the path will be relative.
Code: Select all
<TitleBar Template="window.TitleBar">
<Children>
<checkbox name='Custom Close Button' template='window.TitleBar.Close'>
<Command>ui -unload "&file;"</Command>
</checkbox>
<text Name='Title' template='window.TitleBar.title' />
<button Name='Minimize' template='window.TitleBar.Minimize' />
<button Name='Maximize' template='window.TitleBar.Maximize' />
</Children>
</TitleBar>

I figured that I would make one more post in this thread detailing my (hopefully) final code for the custom Close Button.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<ISUI>
<Window name='Autofish Config'>
<Visible>1</Visible>
<X>375</X>
<Y>240</Y>
<Width>240</Width>
<Height>240</Height>
<TitleBar template='window.TitleBar'>
<Children>
<text Name='Title' template='window.TitleBar.title' />
<button Name='Minimize' template='window.TitleBar.Minimize' />
<commandbutton name='Custom Close Button' template='window.TitleBar.Close'>
<Command>ui -unload .\\Scripts\\miniAutofish\\Interface\\miniAutofish_ConfigUI.xml</Command>
</commandbutton>
</Children>
</TitleBar>
<Children>
<commandcheckbox name='Use AFKAlarm'>
<X>10</X>
<Y>10</Y>
<Width>100</Width>
<Height>20</Height>
<Text> -> Use AFKAlarm</Text>
<Command>RunScript AFKAlarm</Command>
<CommandChecked>EndScript AFKAlarm</CommandChecked>
<Data>${Script[AFKAlarm]}</Data>
</commandcheckbox>
<commandcheckbox name='Show Scoresheet'>
<X>10</X>
<Y>30</Y>
<Width>100</Width>
<Height>20</Height>
<Text> -> Display Scoresheet</Text>
<Command>Script[miniAutofish].Variable[miniAutofish_display_scoresheet]:Toggle</Command>
<CommandChecked>Script[miniAutofish].Variable[miniAutofish_display_scoresheet]:Toggle</CommandChecked>
<Data>${Script[miniAutofish].Variable[miniAutofish_display_scoresheet]}</Data>
</commandcheckbox>
</Children>
</Window>
</ISUI>
Code: Select all
<Command>ui -unload "&file;"</Command>
Code: Select all
<Command>ui -unload "&filepath;/miniAutofish_ConfigUI.xml"</Command>