Author Topic: Messing with the UI (Pilchard123!)  (Read 17483 times)

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Messing with the UI (Pilchard123!)
« on: January 03, 2011, 05:46:50 AM »
Been experimenting with doing UI from lua the last twenty minutes. Seeing what it's possible to achieve.

luanet guide (see section on subtypes) http://luainterface.googlecode.com/svn/trunk/luainterface/doc/guide.pdf

Here's some stuff to go on.

LUA:
Code: [Select]
Game = luanet.import_type("Eufloria.Game")
luanet.load_assembly("System.Drawing")
luanet.load_assembly("Wuwei")
Rectangle = luanet.import_type("System.Drawing.Rectangle")
Window = luanet.import_type("Wuwei.UI.Window")
myWindow = Window(Game.UI, nil, Rectangle(0,0,300,300))
Game.UI.AddWindow(myWindow)

myWindow.Title="My window"
myWindow.CentreTitle=true
myWindow.TitleTextSize=2
myWindow.AlwaysOnTop = true
myWindow.Moveable = false
myWindow.HasCloseButton=false
myWindow.HasHideButton=true
myWindow.Resizeable=false

Here is c# code for the dialog boxes used in the game, should be possible to sort out something like this using luanet
(click to show/hide)

« Last Edit: January 03, 2011, 05:49:54 AM by Alex »

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Messing with the UI (Pilchard123!)
« Reply #1 on: January 03, 2011, 05:54:24 AM »
So if you

- import the types Wuwei.UI.UiEventArgs, Wuwei.UI.Button, Wuwei.UI.Window and probably a bunch of other stuff
- create your own uieventargs subtypes
- create your own window subtype
- add some buttons
- ? override some of the methods with your own lua code ? - this would be ideal , if not i guess you could somehow make the buttons create results you could peek like in the dialog example

you should be able to have a somewhat functioning UI...

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Messing with the UI (Pilchard123!)
« Reply #2 on: January 03, 2011, 05:55:40 AM »
Worth messing with all this stuff in the console btw to speed up turnaround, until you're ready to stick it into a level. I found it quicker anyway.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #3 on: January 03, 2011, 06:25:16 AM »
This looks excellent :>


I will let Pilchard have first shout with this stuff, seeing as he is likely to get the most benefit.  I've anyway got enough on my plate already.  :p

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Messing with the UI (Pilchard123!)
« Reply #4 on: January 03, 2011, 07:03:33 AM »
I wonder what else I have exposed that can be exploited for fun and profit...

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #5 on: January 03, 2011, 07:05:17 AM »
Empire colour?
(i'm so predictable..)

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Messing with the UI (Pilchard123!)
« Reply #6 on: January 03, 2011, 07:19:33 AM »
Empire colour?
(i'm so predictable..)
Ah... nope. Sorry! :( I'll make a note to add this next time.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #7 on: January 03, 2011, 07:24:51 AM »
hehe, no worries.  :>

I might still manage to hack something together to change the empire number until a desired colour is reached, when I get finished with my current project.  I recall you showed me some commands in another thread that might let you read the RGB values of an existing empire...
So really there is no rush on it.  :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #8 on: January 03, 2011, 07:33:20 AM »
Is it possible to make the DrawSprite() function draw things so that they are behind asteroids using this new stuff?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #9 on: January 03, 2011, 08:16:44 AM »
(this would solve all my efficiency problems instantly..)

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Messing with the UI (Pilchard123!)
« Reply #10 on: January 03, 2011, 06:12:22 PM »
My head hurts. I know nothing about any version of C, but I'll have a look at it.

Annikk, don't hold back on my account, I probably won't be able to do anthing with this for quite a while.


EDIT: The stuff in the code box up the top goes where, exactly? LevelSetup? LevelLogic? Before LS? Anywhere?

Also, what is it supposed to do?


EDIT 2: I can't find anything related to luanet on my computer except in the PDF that you linked up top. Problem or not?
« Last Edit: January 03, 2011, 06:40:11 PM by Pilchard123 »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #11 on: January 03, 2011, 06:39:00 PM »
Try LevelSetup :>
By the looks of it, it just makes a blank box or window.

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Messing with the UI (Pilchard123!)
« Reply #12 on: January 03, 2011, 06:48:59 PM »
That's what I thought it did, but if I put it in LS or before it, it complains about [string "chunk"]:1:invalid arguments to method: UI.Addwindow. If I put it in LL, it loads my basic map (the same as for all my demo/test maps) with no problems, but also no window...

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #13 on: January 03, 2011, 06:57:21 PM »
Did you definitely copy this line in?
Code: [Select]
Game = luanet.import_type("Eufloria.Game")


If you did, hmm, I'm not sure...
Try moving the line "Game.UI.AddWindow(myWindow)" below the rest of the new code mayhaps.

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Messing with the UI (Pilchard123!)
« Reply #14 on: January 03, 2011, 07:04:47 PM »
Yes, I did copy that in, and moving the AddWindow line doesn't help, either.

Using DrawBox(2,6,8,3) leads to the error [string "chunk"]:1:invalid arguments to method call, which leads me to believe that there are either too many/few arguments to Game.UI.AddWindow() or it hasn't been made properly, I think most likely the former.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #15 on: January 03, 2011, 07:19:13 PM »
Using DrawBox(2,6,8,3) leads to the error [string "chunk"]:1:invalid arguments to method call

Maybe we should stop arguing with the method.  :D

Oh, man... I should sleep..

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Messing with the UI (Pilchard123!)
« Reply #16 on: January 03, 2011, 07:31:56 PM »
Advice: Do sleep.



My real-world productivity is shot for today. I can just imagine Alex/Rudolph saying this...\/\/\/\/\/\/\/\/\/\/

Now that you are in control of the UI, this next code could take a very, very long time. If you become lightheaded from thirst, feel free to pass out.
An intubation associate will be dispatched to revive you with peptic salve and adrenaline.



EDIT: Would I need LuaInterface installed/whatever to make this all work? If so, how would I go about doing so?

EDIT 2: What's Wuwei? Do I need that as well? Stopping for a while until I get some answers/advice.
« Last Edit: January 03, 2011, 08:00:02 PM by Pilchard123 »

Alex

  • Administrator
  • Ent
  • *****
  • Thank You
  • -Given: 3
  • -Receive: 14
  • Posts: 1,035
Re: Messing with the UI (Pilchard123!)
« Reply #17 on: January 03, 2011, 08:08:26 PM »
My head hurts. I know nothing about any version of C, but I'll have a look at it.

Annikk, don't hold back on my account, I probably won't be able to do anthing with this for quite a while.


EDIT: The stuff in the code box up the top goes where, exactly? LevelSetup? LevelLogic? Before LS? Anywhere?

Also, what is it supposed to do?


EDIT 2: I can't find anything related to luanet on my computer except in the PDF that you linked up top. Problem or not?

luanet is already there in the game, the guide I linked to is instructions on how to use it to do stuff like create sub-classes of existing classes (say you wanted to create your own window type, I think you can actually do that with the info in this thread, but I haven't tried yet).

The lua code at the top, much of that would probably go in the level setup yeah. That code should create a window on the screen.

If you don't know any C#, that's okay - I'll eventually work out some lua. I might do a little more on it today.

That's what I thought it did, but if I put it in LS or before it, it complains about [string "chunk"]:1:invalid arguments to method: UI.Addwindow. If I put it in LL, it loads my basic map (the same as for all my demo/test maps) with no problems, but also no window...

I'll look into it - until then, probably worth typing each line into the console to get a feel of what it does.

Advice: Do sleep.



My real-world productivity is shot for today. I can just imagine Alex/Rudolph saying this...\/\/\/\/\/\/\/\/\/\/

Now that you are in control of the UI, this next code could take a very, very long time. If you become lightheaded from thirst, feel free to pass out.
An intubation associate will be dispatched to revive you with peptic salve and adrenaline.



EDIT: Would I need LuaInterface installed/whatever to make this all work? If so, how would I go about doing so?

EDIT 2: What's Wuwei? Do I need that as well? Stopping for a while until I get some answers/advice.

You won't need to install anything - the commands that import assemblies are there just to let luanet know about types it can import.
so e.g. without:
Code: [Select]
luanet.load_assembly("Wuwei")
this:
Code: [Select]
luanet.import_type("Wuwei.UI.Button")
would do nothing.
similarly with System.Drawing and System.Drawing.Rectangle (which you need to create a window as it takes in a Rectangle that tells it its dimensions).

Back with more later.

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Messing with the UI (Pilchard123!)
« Reply #18 on: January 03, 2011, 08:13:28 PM »
Okay. Here's my (unfinished) ideas for how to use popups/windows in LUA:

Code: [Select]
New info about my ideas in the first post. Sorry for the delay.

[hr][hr]
So, popups...

[color=purple]Anyone know HTML? Good, because that's what I (very) loosely based this on. Other languages might do it the same, but I don't (think I) know any.[/color]

[color=red]WARNING:This is confusing. I'm not entirely sure I understand it either, and it could probably be streamlined/simplified a lot. I'll try to keep this simple.[/color] Okay, now no-one can sue me for causing their head to implode. Text in [color=green]green[/color] denotes an attribute that MUST be set for this to work. These are the only ones I will use in basic examples. The more difficult to understand attributes will have their own examples later.

Popups are essentially tables. A popup is created by the function [b]CreatePopup([color=green]name[/color], width, height, buttons, posX, posY)[/b], and opened using [b]OpenPopup(name)[/b].
NAME is how the popup is referenced in code
WIDTH and HEIGHT are the dimensions of the popup
BUTTONS is a number that dictates what buttons to have along the bottom of the popup. I'll explain further down.
POSX and POSY are the position of the popup relative to the screen, not the world.

Rows are added by using [b]AddRow([color=green]rownumber[/color], height)[/b]
ROWNUMBER is a number given to identify this row, in this table, in code. It also dictates what order they appear in. It'll become clear later.
HEIGHT is the height of the row. They are all just less wide than the popup containing then.

Cells are added by using [b]AddCell([color=green]rownumber, cellnumber[/color], width)[/b]
CELLNUMBER is a number given to identify this cell, in this row, in this table, in code. It also dictates what order they appear in. Again, it'll become clear later.
ROWNUMBER dictates which row to add the cell to.
WIDTH is the width of the row. They are all as tall than the row containing then.

To add a row to a popup, you use (assuming the popup's NAME is 'henry')
[b]henry:AddRow(X)[/b], where X is an integer starting from 1 (or 0).

To add a cell to a row, you use

[b]henry:AddCell(X, Y)[/b], where X and an integer starting from 1 (or 0).

..........



If you want me to finish it, I probably could.

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Messing with the UI (Pilchard123!)
« Reply #19 on: January 04, 2011, 01:38:02 AM »
Hm. Typing Game into the console gives a list of things that look like functions (in purple), subdirectories (for want of a better word, in blue) or variables/attributes (in green).

Game.UI gives MessageEventHandler in green.

Will explore further. Any help by anyone would be appreciated. Am I right about what these things are so far, someone who knows?

EDIT: Should say that I'd typed in the stuff at the start of the thread first. When I got to the AddWindow line, there was a lot of purple text saying compare, concat, and more stuff. But no window. List though, as above.

EDIT AGAIN: I've just realised I never thanked you two for letting this out. So, yeah, thanks.
« Last Edit: January 04, 2011, 02:02:48 AM by Pilchard123 »

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Messing with the UI (Pilchard123!)
« Reply #20 on: January 04, 2011, 04:20:10 AM »
More news.

Typing foo = Game.GetNumLanguages will set foo() to be a function equal to Game.GetNumLanguages. It can then be used as any other function. Typing MessageBox(foo()) will open a messagebox with the number 8 in it, which is presumably the number of languages that the game has been translated into. If only I could do that with other stuff, like UI windows. I continue...

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #21 on: January 04, 2011, 04:54:59 AM »
This is really exciting guys!  Thanks for keeping us updated on your progress Pilchard.

C is very similar in syntax to lua, I believe.  You might say (somewhat inaccurately, but nevertheless) that Lua is a sort of training language ahead of learning C.
I don't think Lua has classes though, so we're being thrown into the deep end a bit here.
Classes are like a more advanced version of functions, I believe.  They are the thing that allows full object-oriented programming according to my cousin Tristen (also leet hax coder, and who uses them all the time).


If anyone can provide a hard and fast description of what classes are, to set us all straight, that would be super helpful ! :>

dragoonreas

  • Seedling
  • **
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 37
  • Eufloria: Yes
Re: Messing with the UI (Pilchard123!)
« Reply #22 on: January 04, 2011, 09:25:08 AM »
I don't think Lua has classes though, so we're being thrown into the deep end a bit here.
Classes are like a more advanced version of functions, I believe.  They are the thing that allows full object-oriented programming according to my cousin Tristen (also leet hax coder, and who uses them all the time).


If anyone can provide a hard and fast description of what classes are, to set us all straight, that would be super helpful ! :>

Clearly you didn't see my mod of your gravity engine where I put it into a 'class' here (or at least the Lua equivalent of one anyway).

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #23 on: January 04, 2011, 09:33:36 AM »
I did not!  Wow, I had no idea anyone else had been doing work on it. :>

Dynamically assignable gravity behaviours is incredibly cool, especially the new types (antigravity - sweet!!).

I've since added to my original design - now asteroids can bounce off one another.  It looks pretty realistic and hardly ever screws up.  I'll be posting my new design soon, along with the other engines I've been developing.  :>

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #24 on: January 04, 2011, 09:37:25 AM »
PS - it's awesome fun, isn't it?  :>  Playing with gravity, I mean.  It's hard to believe so many unusual behaviours fall out of the formulas so naturally!  And being able to effectively tamper with the laws of physics to make things like your antigravity asteroids, is so awesome...  it appeals to my creativity a LOT.

dragoonreas

  • Seedling
  • **
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 37
  • Eufloria: Yes
Re: Messing with the UI (Pilchard123!)
« Reply #25 on: January 04, 2011, 10:55:34 AM »
Yeah, it's basically the same reason I've been playing with tree fractals with my Recursion map (although I didn't have nearly enough time to work on that last semester than I'd hoped… really need to get back to that more).

BTW, here is the resource I used when converting your gravity engine into a 'class'. Putting the engine in a class also opens up some other interesting possibilities, like being able to run multiple instances at once. Now that I think about it, it may even be possible to have an asteroid under the influence of more than one gravity engine with my mod too.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Messing with the UI (Pilchard123!)
« Reply #26 on: January 04, 2011, 10:57:51 AM »
Not sure what the implications of more than one gravity engine affecting the same asteroid would be.
Probably lots of overhead! :p

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Messing with the UI (Pilchard123!)
« Reply #27 on: January 05, 2011, 02:39:16 AM »
Could the code described in these posts
http://failboat.me/2010/lua-get-a-table-of-function-arguments/

http://failboat.me/2010/lua-get-number-of-parameters-in-a-function/

be incorporated into the game somehow? It would be really useful. Don't put it in as a high priority, though, I'm probably the only one that wants it. Don't even put it in at all if you don't want to.

EDIT: What assemblies and types are there importable? If you gave us a list of them, that could be useful and...interesting. Or really, really boring, one of the two. If I'm making too many requests/demands, just tell me to shut up.

EDIT AGAIN: It seems from reading the link that dragoonreas posted that trees, asteroids and empires are classes or the LUA equivalent. Hm.

EDIT X3: Am playing with debug.getinfo(). If all goes according to plan, it should give me a few clues as to what AddWindow actually wants/is.
« Last Edit: January 05, 2011, 03:43:25 AM by Pilchard123 »