Customizable button functions
- Mikko Merikivi
- Posts: 18
- Joined: Fri Sep 13, 2013 9:04 pm
Customizable button functions
Another thing that I noticed I'll need for a fully functional formation system is that the buttons, when pressed, need to be able to perform LUA functions. Since right now what the buttons can do is highly hard-coded, I thought about an easier solution than rewriting the entire button system. My current thought is that they could also give the name of the LUA function to execute when pressed. Of course, it will require its own argument (it would be preceded by an argument that goes something like "callfunction") or otherwise it will get mixed up with hardcoded button functions. But I don't think that will be too hard to do. So, how does my proposal sound? Would this be actually useful for something (else than the formations)?
Re: Customizable button functions
I think that this is a very good idea, and that it would be useful for a number of things, like adding more complex functions which changed variables, etc.
Re: Customizable button functions
Hell yeah, custom buttons everywhere!
04:27 jim4 why haven't you added wc1 support? this project sucks. i'm only going to use freecraft
05:06 jim4 finished wc1 support yet? i've been waiting for 6 years
05:10 jim4 new things scare me
05:06 jim4 finished wc1 support yet? i've been waiting for 6 years
05:10 jim4 new things scare me
Re: Customizable button functions
Currently you can define a new spell type, and make a custom handler for button using "spell-cast" action. Then, just define a separate block for this spell in unit's animation table using "if-var" command and then use "lua-callback" command. All of this requires trunk version of Stratagus to be implemented
- Mikko Merikivi
- Posts: 18
- Joined: Fri Sep 13, 2013 9:04 pm
Re: Customizable button functions
That sounds like a pretty complicated way but OK. Also, I now noticed that Guichan apparently also supports calling LUA functions. My break from Stratagus has been so long that I remembered the old way of doing things. However, I'm pretty sure that when in the game the only menu-like buttons are sort of hardcoded (in ui/mainscr.cpp the UI.MenuButton, UI.NetworkMenuButton and UI.NetworkDiplomacyButton).
- DinkyDyeAussie
- Posts: 260
- Joined: Fri Feb 10, 2012 10:39 am
- Location: Australia
Re: Customizable button functions
mainscr.cpp also has a custom function to load in custom button called:
Which is basically the same as the UI.MenuButton, UI.NetworkMenuButton and UI.NetworkDiplomacyButton declarations.
I am trying it out now as I want the buttons to behave properly in the game, just like the menu button does. Will let you know how I go
*** EDIT ***
It's not as trivial as I first thought. Man they must've stripped a whole heap of stuff outta the engine!
Not happy jan! Wished the devs could've just left some more of the gui features in so people have the option to customize the interface a bit more and do it a bit easier. The code to make the button text in the game menu "highlight" (i.e. make all the text turn white or yellow depending on what race you play - like the menu button does) is still in the widgets.lua file...like this:
...and yet we have to do things like this in the options.lua and the like:
so we can't have any style to the buttons except for the menu button...Seems a liiiittle cheap, considering every button in freecraft has the text highlight effect going on 
Code: Select all
void DrawUserDefinedButtons()
I am trying it out now as I want the buttons to behave properly in the game, just like the menu button does. Will let you know how I go

*** EDIT ***
It's not as trivial as I first thought. Man they must've stripped a whole heap of stuff outta the engine!

Code: Select all
DefineButtonStyle("gm-half", {
Size = {106, 28},
Font = "large",
TextNormalColor = "yellow",
TextReverseColor = "white",
TextAlign = "Center",
TextPos = {53, 7},
Default = {
File = "ui/buttons_1.png", Size = {300, 144}, Frame = 10,
},
Hover = {
TextNormalColor = "white",
Border = {
Color = {128, 128, 128}, Size = 1,
},
},
Clicked = {
File = "ui/buttons_1.png", Size = {300, 144}, Frame = 11,
TextNormalColor = "white",
TextPos = {55, 9},
Border = {
Color = {255, 255, 0}, Size = 1,
},
},
})
Code: Select all
function menu:addHalfButton(caption, hotkey, x, y, callback)

Re: Customizable button functions
04:27 jim4 why haven't you added wc1 support? this project sucks. i'm only going to use freecraft
05:06 jim4 finished wc1 support yet? i've been waiting for 6 years
05:10 jim4 new things scare me
05:06 jim4 finished wc1 support yet? i've been waiting for 6 years
05:10 jim4 new things scare me
- DinkyDyeAussie
- Posts: 260
- Joined: Fri Feb 10, 2012 10:39 am
- Location: Australia
Re: Customizable button functions
Hey, you got my pun!!! hahaha!!! Love that add 
