Customizable button functions

User avatar
Mikko Merikivi
Posts: 18
Joined: Fri Sep 13, 2013 9:04 pm

Customizable button functions

Postby Mikko Merikivi » Thu Oct 10, 2013 9:27 pm

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)?
User avatar
Andrettin
Posts: 433
Joined: Sun Jun 30, 2013 9:58 pm
Location: Vienna, Austria
Contact:

Re: Customizable button functions

Postby Andrettin » Fri Oct 11, 2013 1:49 am

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.
User avatar
Kyran
Posts: 499
Joined: Sat Dec 31, 2011 5:19 pm
Location: Australia
Contact:

Re: Customizable button functions

Postby Kyran » Fri Oct 11, 2013 9:34 am

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
User avatar
cybermind
Posts: 110
Joined: Sat Dec 31, 2011 11:43 pm

Re: Customizable button functions

Postby cybermind » Sat Oct 12, 2013 6:11 pm

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
User avatar
Mikko Merikivi
Posts: 18
Joined: Fri Sep 13, 2013 9:04 pm

Re: Customizable button functions

Postby Mikko Merikivi » Sun Oct 13, 2013 12:10 pm

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).
User avatar
DinkyDyeAussie
Posts: 259
Joined: Fri Feb 10, 2012 10:39 am
Location: Australia

Re: Customizable button functions

Postby DinkyDyeAussie » Wed Mar 12, 2014 2:11 am

mainscr.cpp also has a custom function to load in custom button called:

Code: Select all

void DrawUserDefinedButtons()
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! :x 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:

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,
    },	
  },
})
...and yet we have to do things like this in the options.lua and the like:

Code: Select all

 function menu:addHalfButton(caption, hotkey, x, y, callback)
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 :(
User avatar
Kyran
Posts: 499
Joined: Sat Dec 31, 2011 5:19 pm
Location: Australia
Contact:

Re: Customizable button functions

Postby Kyran » Wed Mar 12, 2014 9:08 am

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
User avatar
DinkyDyeAussie
Posts: 259
Joined: Fri Feb 10, 2012 10:39 am
Location: Australia

Re: Customizable button functions

Postby DinkyDyeAussie » Wed Mar 12, 2014 1:34 pm

Hey, you got my pun!!! hahaha!!! Love that add :)

Who is online

Users browsing this forum: No registered users and 2 guests