Connecting to GUI Objects

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Connecting to GUI Objects

      Hey Guys,
      I have been working on an engine using alot of the concepts from the 4th edition of the book and am having trouble thinking up how to do something.

      I have a Custom GUI that I have been working on and it works well, it uses tinyXML to read in things like

      <GUIButton PosX="300" PosY="400"/>

      So far it works really well, but I do not know how I will go about connecting these controls to anything, here is my current xml file

      <?xml version="1.0" ?>
      <root>
      <Font File="centabel.ttf" Size="16"/>
      <GUIContainer PosX="200" PosY="100" Width="800" Height="400" Colour="30AA45FF">
      <GUITitleBar PosX="0" PosY="0" Width="800" Height="25" Colour="50CC70FF">
      <GUIStaticText PosX="5" PosY="5" Colour="DDFFDDFF" Text="Window Title"/>
      <GUIButton PosX="777" PosY="2" Width="20" Height="20" Colour="AADDDDFF">
      <GUIStaticText PosX="5" Colour="30FF30FF" Text="x"/>
      </GUIButton>
      </GUITitleBar>
      </GUIContainer>
      </root>

      How would I link these controls to either a function or controlling a variable, I can't just read in an attribute and convert it to a variable name, and the same for a function. I could only think of something for buttons, ie, on my button put say

      <GUIButton type="Close" id="button1"/>
      And to close a container say,
      <GUIContainer controller="button1"/>

      Which would allow it to close the GUIContainer through the event manager, but, how would I map these to say, a variable.

      If I have a slider or a check box, I can't just add an id to a boolean. Am I going about this the wrong way, even with fully embedding the initial positioning in XML, do you think I am losing out on too much control doing it this way?
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz

      The post was edited 1 time, last by mholley519 ().

    • Sure you can, as long as you connect them to Lua variables. You can dynamically build a table in Lua with whatever data you want. You can even attach a function by string:

      Source Code

      1. <GUIButton PosX="777" PosY="2" Width="20" Height="20" Colour="AADDDDFF" Command="Dialogs.newPalette:Done()">


      Of course, your command can be whatever you want it to be. If I need the engine to care about it, I have it send an event instead, which is handled on the engine side:

      Source Code

      1. <GUIButton PosX="777" PosY="2" Width="20" Height="20" Colour="AADDDDFF" Command="QueueEvent(EventType.EVENTTYPE_SAVEWORLD, {});">


      In your button code, you just execute this string directly as Lua script.

      But more to your point of GUI architecture and handling updates, there are two main methodologies. You can do a push method, or a pull method. A push method causes the GUI control to push an event every time something changes. Buttons work well with the push method since you just call some callback function or send an event. The pull method is where only the internal state of the object is updated and any system that cares needs to dig into the GUI hierarchy to find out the current value. This works well for text controls, sliders, and things like that. You rarely care what the value is at any given time and more often care about what it is when the player clicks an OK or Apply button.

      For the push model, I would recommend something similar to what I proposed. You map a Lua callback function by string and call it when the button is clicked. If you're doing this all in C++, it gets a but trickier. You can either subclass every button overriding a virtual OnClick() function, or you can set up a generic event where the data contains the ID of the control. Every system that cares about UI events has to respond and run the test, which is ugly. Besides, GUI handling is something that really belongs in script.

      For the pull model, your life is easier. You simply link the object with the GUI control's ID. So if you had a slider to control the allocation of resources in a Civ-like game, the system that cares about the slider would have an ID to it and be able to grab it whenever necessary. It might even maintain a pointer directly to that GUI element. That way, it just reads the value whenever it needs it. In C++, this would be done by casting whatever your generic GUI control class is to the appropriate subclass. In Lua, you wouldn't have to do any of that. You just test to see if the thing you're looking for exists.

      Hopefully this all makes sense. It's late so I may just be rambling. ;)

      -Rez
    • Wow thanks, I have been working through the book randomly as I found I needed to learn the Event Management before anything else, I'll have to read up on the Lua Scripting, thanks again
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • Rez,

      I am having alot of trouble getting LuaPlus set up, it didn't show in the book. I cloned the Git Repo properly, and I got JamPlus which I assume is like C-Make. I have set my Path var's properly, running the Create Visual Studio 2010 batch file comes up with some errors. Is this the only way to go?

      I tried to just use the source files and the library's from the binary pack, I include luastate.h but I get a bunch of missing type specifiers. There seems to be a lack of documentation on the luaplus site.

      Thanks

      *Edit*
      I got JamPlus to run, I was using the wrong version I think. Now running the LuaPlus solution, it comes with a ton of missing file's mostly in reference to #include "LuaLink.h" . Even when adding the proper include directory's that holds LuaLink.h it still refuses to load it up. In the old source code there was a '3rd Party App' Folder, which the Game Code 4 solution refers to, but was not included in my clone of the repo.

      I usually don't have this much trouble with setting up a library thanks again for your help
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz

      The post was edited 1 time, last by mholley519 ().

    • I was really hoping to use LuaPlus. Thanks, but I will keep trying until it works I don't give up easy lol
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • Yeah thats why I wanted to use it, I am having alot of problems getting it to work though. I successfully built a static library, but I had to do it manually, but trying to use the headers only brings on another slew of errors. It looks nice to use, and obviously it's not impossible as this book uses it. I have tried anything, I'll just wait for Rez to get back to me on how he set it up.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • LuaPlus is a nightmare to set up, but once you have it building, everything is fine. That's really the only bad thing about it.

      Why not just use the libs we provide in 3rdParty.zip?

      -Rez
    • I copied both the lib and the dll from LuaPlus and included the directory in my VC++ 2010 project as well as putting the Lib in the Inputs/Additional Dependencies however when I try to run the app in debug mode I get an error that the DLL can not be found. Is there anything else I need to do to make sure the DLL can be read?
    • I am having the exact same errors with the SDK's included in the 3rdParty.zip

      I added src/LuaPlus directory and also the directory for the .lib file's. I have LuaState.h included in my project but when I go to build I get a ton of messages, I almost got it working last time but I had to change a ton of stuff, which I don't think I should be messing with.

      Should I be creating a specific LuaPlus Project inside my solution?
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • Hey mholley519,

      You shouldn't be directly including the LuaPlus files in your project or creating a LuaPlus Project, as they are already built and included with 3rdParty.zip. All you need to do is make sure that your project properly references the .lib file, and that the Includes and Libraries paths are correct so that it can find the header files and the .lib file.

      You could include the LuaPlus headers if you want (for ease of viewing them), but don't include the .cpp's :)

      James
    • That is the first thing I tried, but I get alot of issues.
      I found to get all the header files satisfied I had to include , src/LuaPlus, and src/LuaPlus/src. It isn't showing me any missing header file errors, but now I am getting a ton of missing type specifiers, undefined's etc.

      I have tried it again and again in different ways I don't know what could be causing this.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • Your description is a bit hard to follow. It sounds like you're in a place where you've changed a bunch of things away from the original configuration, so you are likely running into a number of different problems where it's not clear which change caused it.

      I would try this: delete everything. Go to the folder you synched from SVN and hit shift+delete to permanently erase it from your hard drive. Then, sync up to the latest version (this is basically a force-sync to ensure that your revision is at the base value and that there are zero changes). Then open the readme file and go through it step by step as if you were executing a computer program. Don't add or remove any steps, don't jump ahead, just follow it line by line.

      All of the include & lib directories are set up with relative paths, so as long as you follow the instructions exactly, there shouldn't be any issues. Mike and I did this exact thing on several different computers before publishing the source code and got everything to build & link perfectly each time.

      This may seem like a waste of time but trust me, sometimes you just have to revert all your changes and start over. I've certainly done it enough in my time. :)

      -Rez
    • Ok, so these are the steps I have gone through without changing anything in the project options or the source code.

      1. Cloned the Git Repo onto my hard drive
      2. Downloaded JamPlus
      3. Set the PATH variable to include the bin folder
      for Jam
      4. Ran the CreateVS2010.bat file to create the VS Solution
      5. went to the build2010 folder and opened up the
      solution
      6. Pressed build
      7. I get these errors

      LuaPlus Build Errors

      Then when using the headers and lib's included with the 3rdParty.zip I get these
      *Edit* - Sorry didn't link the right one here it is
      Using 3rd Party.zip
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz

      The post was edited 1 time, last by mholley519 ().

    • Why are you building LuaPlus? You shouldn't have to build any of the 3rdParty libs.

      -Rez