Computer Science Canada

GUI's making my head hurt

Author:  rcbhs [ Wed Dec 03, 2008 3:30 pm ]
Post subject:  GUI's making my head hurt

Ok so I am working on making some simple GUI's and I'm soooo confused already. I'llpost the code I have then tell you what I am having trouble with.


code:
import GUI

View.Set ("graphics:800;600")

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%NAME CHARACTER SCREEN%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%VARIABLES%%%%%%%%

var name : int

%%%%%%%%%%PROCEDURES%%%%%%%%%%%

GUI.SetBackgroundColour (grey)

procedure NameEntered (text : string)
    GUI.SetSelection (name, 0, 0)
    GUI.SetActive (name)
end NameEntered

%%%%%%%%%CREATE GUI%%%%%%%%%%%%%

var nameLabel := GUI.CreateLabelFull (maxx div 3, maxy div 2 + 40, "Enter Your Name", 300, 0,
    GUI.CENTER, 0)

name := GUI.CreateTextFieldFull (maxx div 3, maxy div 2, 300, "", NameEntered, GUI.INDENT, 0, 0)

var doneButton := GUI.CreateButton (maxx div 2 - 30, maxy div 2 - 50, 100, "Done", GUI.Quit)

loop
    exit when GUI.ProcessEvent
end loop

%%%%%%%%RESET GUI%%%%%%%%%%%%%%%%
GUI.Dispose (doneButton)
GUI.Dispose (nameLabel)
GUI.Dispose (name)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%PICK CHARACTER SCREEN%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%VARIABLES%%%%%%%%%%

%%%%%%%PROCEDURES%%%%%%%%%

%%%%%%%CREATE GUI%%%%%%%%%

var charButton := GUI.CreateButton (maxx div 2 - 30, maxy div 2 - 50, 100, "Rate", GUI.Quit)

%%%%%%%OUTPUT%%%%%%%%%%%%%

%%%%%%%RESET GUI%%%%%%%%%%


%put "Name = ", GUI.GetText (name)




Ok so I have two problems. One, for the textfield GUi...what variable does that name actually get stored in? So If I want to use the name that they entered at any time or place do I need to do that GUI.GetText (name)? Also if I get rid of that "Name =" why does it stop working? How do I put JUST that name?

Questiong two. That second button that says Rate on it...It's driving me nuts. What I want to happen is when you click one of those buttons (there will be 4) it will be linked with a number that is linked with a class (this is part of a group assignment to make an rpg...working on the character selection/creation atm). For example, if you click the button that says Rate your class will become Rate (rate is the archer class for example) and the number for that class is 1, so then I can make a variable that says class = 1 so in the future when I need to refer to my class it knows which one it is. The main problem with this is, the only way it is letting me make a button is if I use that GUI.Quit command thing. If I try to link it with a procedure like the examples do or even my first button, I get an error says "Argument is the wrong type". Anyways I'm not sure how much sense question 2 makes but sorry if it is confusing.

Thanks in advance for the help.

Author:  TheGuardian001 [ Wed Dec 03, 2008 5:50 pm ]
Post subject:  Re: GUI's making my head hurt

well, for your first question:
see those lines of code where you said

GUI.Dispose(widget)

That got rid of them. permanently. so there is no text to get from the widget, you just destroyed it.
if you want to hide something without getting rid of it, use

GUI.Hide

hope that helped.

Author:  rcbhs [ Wed Dec 03, 2008 6:37 pm ]
Post subject:  Re: GUI's making my head hurt

Ok So hide the name instead? Thanks...anybody got anything to help with my second one? It is still saying when I put in a procedure in a create button that the argument is the wrong type. Even if I copy and paste chinks of working code from examples and try to put them into my program they don't work. Randomly it gives me Argument is the wrong type.

Author:  SNIPERDUDE [ Wed Dec 03, 2008 7:16 pm ]
Post subject:  RE:GUI\'s making my head hurt

For less of a headache you could try testing my Custom GUI...

Author:  corriep [ Wed Dec 03, 2008 7:18 pm ]
Post subject:  RE:GUI\'s making my head hurt

Sniperdude, how many times have you pluged your LGUI? Razz

Author:  SNIPERDUDE [ Wed Dec 03, 2008 9:35 pm ]
Post subject:  RE:GUI\'s making my head hurt

Umm, maybe about three times. Only on GUI threads. Hey, I'm helping them.
Shush you.

Razz

Author:  rcbhs [ Wed Dec 03, 2008 11:29 pm ]
Post subject:  Re: GUI's making my head hurt

Ok, while that is all fine and dandy, it really doesn't do anything to help solve my problem, like anything at all...

My goal here is to understand how GUI's work so I can use them in the dozen other spots they will be in my game. Being able to rip a GUI off of somebody else program doesn't help whatsoever. Also, like I said earlier, I can't even use GUI's that work in other code in my code which is like 70% of my problem.

Author:  SNIPERDUDE [ Thu Dec 04, 2008 8:02 am ]
Post subject:  RE:GUI\'s making my head hurt

It's not a GUI rip off another programme, it is an alternate GUI library.

Have you tried the GUI tutorial in the Turing Walkthrough?

Author:  rcbhs [ Thu Dec 04, 2008 12:44 pm ]
Post subject:  Re: RE:GUI\'s making my head hurt

SNIPERDUDE @ Thu Dec 04, 2008 8:02 am wrote:
It's not a GUI rip off another programme, it is an alternate GUI library.

Have you tried the GUI tutorial in the Turing Walkthrough?



Well being able to use a different GUI library also doesn't help...anyways I've fixed one of my problems. My problem now is that I don't know where to put the GUI.Hide so it hides them only when I press the button.

code:
import GUI

View.Set ("graphics:800;600")

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%NAME CHARACTER SCREEN%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%VARIABLES%%%%%%%%

var name : int
var username : string

%%%%%%%%%%PROCEDURES%%%%%%%%%%%

GUI.SetBackgroundColour (grey)

procedure NameEntered (text : string)
    GUI.SetSelection (name, 0, 0)
    GUI.SetActive (name)
end NameEntered

procedure assignCharClass
    put "Hello User, your class is fighter."
end assignCharClass

procedure assignUserName
    username := GUI.GetText (name)
    put username
end assignUserName


%%%%%%%%%CREATE GUI%%%%%%%%%%%%%

procedure nameType

    var nameLabel := GUI.CreateLabelFull (maxx div 3, maxy div 2 + 40, "Enter Your Name", 300, 0,
        GUI.CENTER, 0)

    name := GUI.CreateTextFieldFull (maxx div 3, maxy div 2, 300, "", NameEntered, GUI.INDENT, 0, 0)

    var doneButton := GUI.CreateButton (maxx div 2 - 30, maxy div 2 - 50, 100, "Done", assignUserName)

end nameType

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%PICK CHARACTER SCREEN%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

nameType


var fighter : int := GUI.CreateButton (maxx div 4, maxx div 2, 0, "Fighter", assignCharClass)

loop
    exit when GUI.ProcessEvent
end loop

Author:  copthesaint [ Fri Dec 05, 2008 12:31 pm ]
Post subject:  RE:GUI\'s making my head hurt

Umm Above you used GUI.Quit
After the disposal you have to use
GUI.ResetQuit or even use this instead of using

Turing:
var doneButton := GUI.CreateButton (maxx div 2 - 30, maxy div 2 - 50, 100, "Done", GUI.Quit)


USE

Turing:
var doneButton : int := GUI.CreateButtonFull (maxx div 2 - 30maxy div 2 -50, 100, "Done", (Procedure name), 0, '(Hotkey)', true)


Ahead of this make a procedure for what the button will do.

Author:  rcbhs [ Fri Dec 05, 2008 4:16 pm ]
Post subject:  Re: GUI's making my head hurt

Thanks m8, found out that prob slightly after I posted it actually lols...well slightly after my most recent one. My problem now is button size. I want to make my buttons bigger and have no clue how. Atm this is my button draw proc.

code:
procedure classSel
    var fighter : int := GUI.CreateButton (200, 350, 0, "Fighter", classFighter)
    var archer : int := GUI.CreateButton (650, 350, 0, "Archer", classArcher)
    var mage : int := GUI.CreateButton (200, 100, 0, "Mage", classMage)
    var cleric : int := GUI.CreateButton (650, 100, 0, "Cleric", classCleric)
end classSel


They are all the same size and it is bothering me lol.

Author:  copthesaint [ Fri Dec 05, 2008 5:32 pm ]
Post subject:  RE:GUI\'s making my head hurt

Well this doesn't solve that problem but why not just show the 4 pictures of each charater beside each other and a button uderneth each picture.

Author:  rcbhs [ Fri Dec 05, 2008 8:25 pm ]
Post subject:  Re: RE:GUI\'s making my head hurt

copthesaint @ Fri Dec 05, 2008 5:32 pm wrote:
Well this doesn't solve that problem but why not just show the 4 pictures of each charater beside each other and a button uderneth each picture.


Yes I already do that with the character select screen, howver with my actal playscreen GUI I need it to fill a certain space properly and well without increasing button size, I can't do that.

Author:  copthesaint [ Sat Dec 06, 2008 9:10 am ]
Post subject:  Re: GUI's making my head hurt

ok then do you want the button longer or wider?
longer= <-->
^
wider= | (sorry bad arrows ;pWink
V

I Know Longer that is simply changeing the 3rd value of gui creat box
ex
code:

var fighter : int := GUI.CreateButton (200, 350, 200(this is now longer and at 200), "Fighter", classFighter)
    var archer : int := GUI.CreateButton (650, 350, 200(this is now longer and at 200) , "Archer", classArcher)
    var mage : int := GUI.CreateButton (200, 100, 200(this is now longer and at 200) , "Mage", classMage)
    var cleric : int := GUI.CreateButton (650, 100,200(this is now longer and at 200), "Cleric", classCleric)


Wider I will Try and look that up gimme a little and I will see what It is/ how to do it

edit:

ok I didn't find how to make the button wider but I also found something that may be of interest of you

code:
import GUI
        View.Set ("graphics:200;140")
       
        const size : int := 25   % The buttons size.
        const border : int := 3
       
        var starButton, mapleButton, starPic, mapleLeafPic : int
       
        procedure StarPressed
            Text.Locate (1, 1)
            put "Star Pressed    "
        end StarPressed
       
        procedure MaplePressed
            Text.Locate (1, 1)
            put "Maple Pressed "
        end MaplePressed
       
        % Create the pictures.
        % The star.
        Draw.Star (border, border, border + size, border + size, black)
        Draw.Star (border + 1, border + 1, border + size - 1,
            border + size - 1, black)
        Draw.FillStar (border + 2, border + 2, border + size - 2,
            border + size - 2, brightred)
        starPic := Pic.New (0, 0, 2 * border + size, 2 * border + size)
       
        % The mapleleaf.
        Draw.FillBox (border, border, border + size, border + size, white)
        Draw.MapleLeaf (border, border, border + size, border + size, black)
        Draw.MapleLeaf (border + 1, border + 1, border + size - 1,
            border + size - 1, black)
        Draw.FillMapleLeaf (border + 2, border + 2, border + size - 2,
            border + size - 2, brightred)
        mapleLeafPic := Pic.New (0, 0, 2 * border + size, 2 * border + size)
       
        % Create the picture buttons.
        Draw.Cls
        starButton := GUI.CreatePictureButton (10, 10, starPic, StarPressed)
        mapleButton := GUI.CreatePictureButton (55, 10, mapleLeafPic,
            MaplePressed)
       
        loop
            exit when GUI.ProcessEvent
        end loop


With this you could potentionally use your pictures as buttons. Then just lable each of them.

Author:  rcbhs [ Sat Dec 06, 2008 2:21 pm ]
Post subject:  Re: GUI's making my head hurt

Ty for the help with the picture buttons! Makes what I wanted to do alot easier.

However, it still doesn't entirely fix my problem with button size. The reason I need button size increased is because I need to make a battleGUI. In this battleGUI I need to have 4 buttons (Attack, items, abilities, run) take up a very specific amount of space so they do not cover the actual battle screen and they do not leave ugly white spaces in between buttons because the buttons are too small to touch.

Author:  copthesaint [ Mon Dec 08, 2008 7:53 am ]
Post subject:  RE:GUI\'s making my head hurt

ok question is this like a Final Fantasy Type Battle? Or like Collision battle Where if 2 obbjects collide something happens

Author:  rcbhs [ Mon Dec 08, 2008 12:26 pm ]
Post subject:  Re: GUI's making my head hurt

Final Fantasy style...still need me bigger buttons...it has to be possible...doesn't it?

Author:  copthesaint [ Mon Dec 08, 2008 4:39 pm ]
Post subject:  RE:GUI\'s making my head hurt

why not then just draw your buttons?
like first using turing (Draw.Box) (Draw.Line) Design a box then make a mouse collision and so on and so forth?

FYI: I asked that because if you are moving while battleing you make just want a key such as 'A' to be your attack and 'D' to be defend
If it's like the Final Fantasy Battles then no movemnt is required and you then should use buttons.

Author:  rcbhs [ Tue Dec 09, 2008 10:44 am ]
Post subject:  Re: GUI's making my head hurt

Well, I am trying to keep a general look for the whole game, as it is in every game. Your GUI in a real final fantasy game usually looks the same everywhere you see a GUI. I'm going to make a topic "Increasing buttton sizes in GUI's" to see if anybody can help. Thanks for all of your help though.


: