Hello guys!
I've created this mini mod called "music changer" a few years ago, but I think it's now time to add more features to it.
I've recently realized that the music playing in your game is defined by a XML element called "<SoundtrackTag>", referring to your civ. So my idea was to take my mod, which was basically only a single button that skipped the current song, and add an extra menu avaible trough RIGHT clicking the button, to change <SoundtrackTag> so the player could choose between Europen, Asian, etc etc, music.
Problem is I have no clue about lua and coding languages. I just barely got the XML (buttons, texts, dialogs) right and now I need some help making it work
So far, I have 4 elements on my mod. MusicButton.xml, MusicButton.lua and Select.xml, Select.lua.
The MusicButton is permanent little button on top of the screen. Left-click skips songs, and now I want to add a right-click feature. The Select would be the new pop-up with various buttons to select a new "continent" for your music.
The problem is, one function in the lua must refer to another file (musicbutton -> select). I know the function is Controls.OK:RegisterCallback(Mouse.eRClick, function() , but I can't figure out the right action. I've tried ContextPtr.Select:SetHide(false) but that doesn't work.
The second problem is, how can I change the <SoundtrackTag> at the click of a button (in the selection menu)? Is there a lua code to do that?
I know it's part of the civilazion's attributes.
Any help would be greatly appreciated, since it's becoming too tricky doing this by myself.
Code in my "MusicButton.lua"
Controls.OK:RegisterCallback(Mouse.eLClick, function()
Events.AudioDebugChangeMusic(true,false,false);
print("Music changer: current song skipped")
end);
Controls.OK:RegisterCallback(Mouse.eRClick, function()
ContextPtr.Select:SetHide(false)
end);
Current "MusicButton.xml"
<Context>
<Container Size="80,30" Anchor="R,T" Offset ="290,28" ConsumeMouse="1" Font="TWCenMT18">
<GridButton ID="OK" Size="70,20" Anchor="C,T" Offset="0,0" Style="BaseButton"
ToolTip="Skips the current music playing.">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,26"
TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce"
Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16"
TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32"
TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce"
Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16"
TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Music" Font="TwCenMT16"
FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
</Container>
</Context>
The current "Select.xml"
<Context>
<Box Style="BGBlock_ClearTopBar" />
<Grid Size="300,500" Anchor="C,C" Style="Grid9DetailFive140" ConsumeMouse="1">
<Image Anchor="C,T" AnchorSide="I,O" Offset="0,-27" Size="256,64" Texture="DecTop256x64.dds">
<Image Anchor="C,C" Offset="0,-6" Size="80,80" Texture="NotificationFrameBase.dds">
<Image ID="DialogTopIcon" Anchor="C,C" Offset="0,0" Size="80,80" Texture="NotificationGeneric.dds" />
</Image>
</Image>
<Label ID="Select" Anchor="C,T" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" Offset="0,60" String="Select your music ethnicity:"/>
<Image Anchor="L,C" AnchorSide="O,I" Offset="-17,0" Size="32,64" Texture="Dec32x64Left.dds" />
<Image Anchor="R,C" AnchorSide="O,I" Offset="-17,0" Size="32,64" Texture="Dec32x64Right.dds" />
<AlphaAnim ID="BgImage" Anchor="L,T" Offset="17,43" Size="266,414" TextureOffset="200,55" Texture="ERA_Classical.dds" Cycle="Once" Stopped="1" AlphaStart="0.3" AlphaEnd="0.3" Speed="1"/>
<GridButton ID="CANCEL" Size="180,36" Anchor="C,B" Offset="0,50" Style="BaseButton" ToolTip="Exit">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Cancel" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
<GridButton ID="EUROPE" Size="180,36" Anchor="C,B" Offset="0,130" Style="BaseButton" ToolTip="TXT_KEY_EUROPE">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Europe" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
<GridButton ID="ASIA" Size="180,36" Anchor="C,B" Offset="0,180" Style="BaseButton" ToolTip="TXT_KEY_ASIA">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Asia" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
<GridButton ID="AFRICA" Size="180,36" Anchor="C,B" Offset="0,230" Style="BaseButton" ToolTip="TXT_KEY_AFRICA">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Africa" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
<GridButton ID="AMERICA" Size="180,36" Anchor="C,B" Offset="0,280" Style="BaseButton" ToolTip="TXT_KEY_AMERICA">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="America" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
<GridButton ID="MIDEASTERN" Size="180,36" Anchor="C,B" Offset="0,330" Style="BaseButton" ToolTip="TXT_KEY_MIDEASTERN">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Middle Eastern" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
</Grid>
</Context>
*edit: I just wanted to note that I have searched for this in all threads I could find, and read and downloaded the basic and the UI tutorials, but couldn't find one that could do a cross-reference, I mean, the lua from one xml making another xml dialog unhide.. it's always "example A" lua acting upon "example A" xml.
I have though maybe I could include everything in the same xml somehow.. but that would require two different contexts... so one of them could remain hidden and the other not. I am not sure it would work
I've created this mini mod called "music changer" a few years ago, but I think it's now time to add more features to it.
I've recently realized that the music playing in your game is defined by a XML element called "<SoundtrackTag>", referring to your civ. So my idea was to take my mod, which was basically only a single button that skipped the current song, and add an extra menu avaible trough RIGHT clicking the button, to change <SoundtrackTag> so the player could choose between Europen, Asian, etc etc, music.
Problem is I have no clue about lua and coding languages. I just barely got the XML (buttons, texts, dialogs) right and now I need some help making it work
So far, I have 4 elements on my mod. MusicButton.xml, MusicButton.lua and Select.xml, Select.lua.
The MusicButton is permanent little button on top of the screen. Left-click skips songs, and now I want to add a right-click feature. The Select would be the new pop-up with various buttons to select a new "continent" for your music.
The problem is, one function in the lua must refer to another file (musicbutton -> select). I know the function is Controls.OK:RegisterCallback(Mouse.eRClick, function() , but I can't figure out the right action. I've tried ContextPtr.Select:SetHide(false) but that doesn't work.
The second problem is, how can I change the <SoundtrackTag> at the click of a button (in the selection menu)? Is there a lua code to do that?
I know it's part of the civilazion's attributes.
Any help would be greatly appreciated, since it's becoming too tricky doing this by myself.
Code in my "MusicButton.lua"
Spoiler :
Controls.OK:RegisterCallback(Mouse.eLClick, function()
Events.AudioDebugChangeMusic(true,false,false);
print("Music changer: current song skipped")
end);
Controls.OK:RegisterCallback(Mouse.eRClick, function()
ContextPtr.Select:SetHide(false)
end);
Current "MusicButton.xml"
Spoiler :
<Context>
<Container Size="80,30" Anchor="R,T" Offset ="290,28" ConsumeMouse="1" Font="TWCenMT18">
<GridButton ID="OK" Size="70,20" Anchor="C,T" Offset="0,0" Style="BaseButton"
ToolTip="Skips the current music playing.">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,26"
TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce"
Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16"
TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32"
TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce"
Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16"
TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Music" Font="TwCenMT16"
FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
</Container>
</Context>
The current "Select.xml"
Spoiler :
<Context>
<Box Style="BGBlock_ClearTopBar" />
<Grid Size="300,500" Anchor="C,C" Style="Grid9DetailFive140" ConsumeMouse="1">
<Image Anchor="C,T" AnchorSide="I,O" Offset="0,-27" Size="256,64" Texture="DecTop256x64.dds">
<Image Anchor="C,C" Offset="0,-6" Size="80,80" Texture="NotificationFrameBase.dds">
<Image ID="DialogTopIcon" Anchor="C,C" Offset="0,0" Size="80,80" Texture="NotificationGeneric.dds" />
</Image>
</Image>
<Label ID="Select" Anchor="C,T" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" Offset="0,60" String="Select your music ethnicity:"/>
<Image Anchor="L,C" AnchorSide="O,I" Offset="-17,0" Size="32,64" Texture="Dec32x64Left.dds" />
<Image Anchor="R,C" AnchorSide="O,I" Offset="-17,0" Size="32,64" Texture="Dec32x64Right.dds" />
<AlphaAnim ID="BgImage" Anchor="L,T" Offset="17,43" Size="266,414" TextureOffset="200,55" Texture="ERA_Classical.dds" Cycle="Once" Stopped="1" AlphaStart="0.3" AlphaEnd="0.3" Speed="1"/>
<GridButton ID="CANCEL" Size="180,36" Anchor="C,B" Offset="0,50" Style="BaseButton" ToolTip="Exit">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Cancel" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
<GridButton ID="EUROPE" Size="180,36" Anchor="C,B" Offset="0,130" Style="BaseButton" ToolTip="TXT_KEY_EUROPE">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Europe" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
<GridButton ID="ASIA" Size="180,36" Anchor="C,B" Offset="0,180" Style="BaseButton" ToolTip="TXT_KEY_ASIA">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Asia" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
<GridButton ID="AFRICA" Size="180,36" Anchor="C,B" Offset="0,230" Style="BaseButton" ToolTip="TXT_KEY_AFRICA">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Africa" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
<GridButton ID="AMERICA" Size="180,36" Anchor="C,B" Offset="0,280" Style="BaseButton" ToolTip="TXT_KEY_AMERICA">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="America" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
<GridButton ID="MIDEASTERN" Size="180,36" Anchor="C,B" Offset="0,330" Style="BaseButton" ToolTip="TXT_KEY_MIDEASTERN">
<ShowOnMouseOver>
<AlphaAnim Anchor="L,C" AnchorSide="O,O" Size="16,32" TextureOffset="0,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="L,C" AnchorSide="O,O" Size="8,16" TextureOffset="0,0" Texture="buttonsides.dds" />
<AlphaAnim Anchor="R,C" AnchorSide="O,O" Size="16,32" TextureOffset="16,0" Texture="buttonsidesglow.dds" Cycle="Bounce" Speed="1" AlphaStart=".99" AlphaEnd=".25"/>
<Image Anchor="R,C" AnchorSide="O,O" Size="8,16" TextureOffset="8,0" Texture="buttonsides.dds" />
</ShowOnMouseOver>
<Label Anchor="C,C" Offset="0,-2" String="Middle Eastern" Font="TwCenMT24" FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
</Grid>
</Context>
*edit: I just wanted to note that I have searched for this in all threads I could find, and read and downloaded the basic and the UI tutorials, but couldn't find one that could do a cross-reference, I mean, the lua from one xml making another xml dialog unhide.. it's always "example A" lua acting upon "example A" xml.
I have though maybe I could include everything in the same xml somehow.. but that would require two different contexts... so one of them could remain hidden and the other not. I am not sure it would work