forums

TNT Basic Forums > Programming Q&A
How to do dialog boxes?
< Last Thread     Next Thread >
Author
Thread        Post A Reply

12-10-2006 05:45

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

As you can see, I am having trouble writing up GUI elements for my game... The engine itself is relatively easy.
I want to make a dialog box that will have to appear while you are playing and sprites moving around. I just coded the following.. but realised this dialog box will go behind the sprites, not infront. I can't imagine having to piece together my dialog piece by piece using sprites... help?

window mode 640,480
global int NumberOfLines=1
global int NumberOfImages=0
global int NumberOfButtons=1
if NumberOfLines>0
Global String TextLines[NumberOfLines]
end if
if NumberOfImages>0
Global int DialogueImages[NumberOfImages,2]
end if
if NumberOfButtons>0
Global int DialogueButtons[NumberOfButtons]
end if
TextLines[0]="Please select a resolution from the menu"

Global int DialogueSizeAndLocation[2,2]
'size-x,y
'Location-x,y

DialogueSizeAndLocation[0,0]=300
DialogueSizeAndLocation[0,1]=200
DialogueSizeAndLocation[1,0]=50
DialogueSizeAndLocation[1,1]=50
GLobal int dialoguecanvas=11
load images 128
New Button 0,100,100,0,0,0,128

repeat
draw frame
wait button click
if button click=0
DisplayDialogue()

end if

forever

Procedure DisplayDialogue()
open canvas dialoguecanvas,DialogueSizeAndLocation[0,0],DialogueSizeAndLocation[0,1]
canvas dialoguecanvas
set pen colour blue
paint canvas
int i
set pen colour white
for i=0 to NumberOfLines-1
Draw text 10,20*i+20,TextLines
draw frame
next
draw frame
canvas 0
Open Viewport dialoguecanvas,DialogueSizeAndLocation[1,0],DialogueSizeAndLocation[1,1] to DialogueSizeAndLocation[0,0]+DialogueSizeAndLocation[1,0],DialogueSizeAndLocation[0,1]+DialogueSizeAndLocation[1,1]
draw frame
wait mouse up
end proc

12-10-2006 05:47

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Umm, corrected it, because in the last post, [-i-] got translated to italics.
window mode 640,480
global int NumberOfLines=1
global int NumberOfImages=0
global int NumberOfButtons=1
if NumberOfLines>0
Global String TextLines[NumberOfLines]
end if
if NumberOfImages>0
Global int DialogueImages[NumberOfImages,2]
end if
if NumberOfButtons>0
Global int DialogueButtons[NumberOfButtons]
end if
TextLines[0]="Please select a resolution from the menu"

Global int DialogueSizeAndLocation[2,2]
'size-x,y
'Location-x,y

DialogueSizeAndLocation[0,0]=300
DialogueSizeAndLocation[0,1]=200
DialogueSizeAndLocation[1,0]=50
DialogueSizeAndLocation[1,1]=50
GLobal int dialoguecanvas=11
load images 128
New Button 0,100,100,0,0,0,128

repeat
draw frame
wait button click
if button click=0
DisplayDialogue()

end if

forever

Procedure DisplayDialogue()
open canvas dialoguecanvas,DialogueSizeAndLocation[0,0],DialogueSizeAndLocation[0,1]
canvas dialoguecanvas
set pen colour blue
paint canvas
int i
set pen colour white
for i=0 to NumberOfLines-1
Draw text 10,20*i+20,TextLines(i)
draw frame
next
draw frame
canvas 0
Open Viewport dialoguecanvas,DialogueSizeAndLocation[1,0],DialogueSizeAndLocation[1,1] to DialogueSizeAndLocation[0,0]+DialogueSizeAndLocation[1,0],DialogueSizeAndLocation[0,1]+DialogueSizeAndLocation[1,1]
draw frame
wait mouse up
end proc

12-10-2006 05:48

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Also... can you have sprites in... say canvas 16 instead of 0?

12-10-2006 14:47

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

AFAIK there's no way to draw on top of sprites, except with other sprites.

But why do you need the dialog at the same time as sprites?

12-10-2006 20:52

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Nope, sprites it is...

'someone' is right, the only way to display something in front of a sprite is to make that something a sprite as well and give it a higher priority than everything else. It's a pain in certain circumstances but mostly very handy (as you usually want sprites to appear in the foreground), especially if you're using a sprite to represent the mouse cursor!

I don't know exactly what you're trying to achieve here, but a possible solution may be to display the dialogue in another part of the screen, maybe replacing a control panel or other GUI element? This might not be possible in your case, but it is a common 'way out' in other games. May be worth a thought?

If you choose to go down the sprite route you could use separate ones for the window's backdrop and any other UI elements. A sprite col check would find the hit quickly enough and then you just need to check for the mouse down... Only real headache would be the priority, but if you assign GUI elements a higher value than game sprites and the mouse cursor an even higher one you should be OK. You can't use buttons by the way as they have a priority of -1, and would appear behind everything...

Have fun, and I'm looking forward to the time when you implement scroll bars! They're great!! ;)

Danny (nods)

12-13-2006 08:38

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

I have worked out a method of:
Having only one line of text and one position of text.
Having only at most one image, and only one position.
Having only one menu. (which can have unlimited items(buttons)).

It is made of only a single sprite, minus the menu.

And no, I don't think I will tackle scrollbars yet. ;)

12-13-2006 08:39

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Btw... the control panel you speak of IS the dialog.... ha. And I will need more dialogs later on, so I thought I should 'standardise' it. (so when ever I want one, I just call the procedure and plug in my values.)

12-13-2006 11:33

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Free code. Can have as much text/images/popups as you want.

Global int ResolutionHeight=480
GLobal Int Resolutionwidth=640
start: window mode Resolutionwidth,ResolutionHeight


int DialogStillOn=0 'whether dialog is open
int LocX=(Resolutionwidth/2)-100 'location
int LocY=(ResolutionHeight/2)-100
int Width=200
int Height=200
int DialogImageBank=0 'ImageBank for exclusive use of dialog
int DialogCanvas=1'exclusive use for dialog while it is being drawn.
int DialogSpriteID=0 'exclusive for dialog's display.
int DialogPriority=0 'where you want it, in front or in back.
int BorderColour=White
int BackgroundColour=make colour(80,80,80)
int TextColour=White
int NumberOf[2]
NumberOf[0]=2 '0=text 'Number for how many lines there are
NumberOf[1]=1 '1=Images 'number of images
string text[NumberOf[0]]
Text[0]="Good day"
Text[1]="Please Select"
int ImageID[NumberOf[1]]
ImageID[0]=-1 'no images if equal-1, else, enter the resID
Dialog(1)'dialog mode 1, opens.
'If Wanting Popups/Buttons, Set up the sprite-popup version. (unreleased by appleide as of 13/12) here.
DialogStillOn=1 'its now open
GameLoop() 'the programs loop.

Procedure GameLoop()
if mouse button
wait mouse up
shared int dialogstillon
if dialogstillon=1 'if its on and mouse click
Dialog(2)'close
else
Dialog(1)'else open it
end if
end if
GameLoop()'game loop recurse
end proc

Procedure Dialog(int MODE)'Mode 1=Open Mode 2=Close
if Mode=1
Shared int LocX
Shared int LocY
Shared int Width
Shared int Height
Shared int DialogImageBank
Shared int DialogCanvas
Shared int DialogSpriteID
Shared int DialogPriority
Shared int BorderColour
Shared int BackgroundColour
Shared int TextColour
Shared String Text[] 'ADD MORE TEXT LINES IF NECESSARY
Shared int ImageID[]'ADD MORE IMAGES IF NECESSARY
Shared int NumberOf[]
Shared int DialogStillOn
DialogStillOn=1
'Show
open canvas DialogCanvas,Width,Height
canvas DialogCanvas
Set Pen Colour BackgroundColour 'drawing
paint canvas
Set Pen Colour BorderColour
Frame Rect 0,0 to Width,Height
Set Pen Colour TextColour
'Set Text Location Here.
int k
for k=0 to NumberOf[0]-1
Draw text 10,20*k+20,Text[k] 'draw each line
next
for k=0 to NumberOf[1]-1
if ImageID[k]<>-1
Draw Picture ImageID[k], 10,40*k+35 'ASSUMES IMAGES ONLY 40 PIXEL IN HEIGHT~! CHANGE IF NECESSARY
end if
next
Delete Image 0,DialogImageBank 'Cleanup
Copy image 0,0,width,height,false,false to 0,DialogImageBank 'copy
canvas 0
set image bank DialogSpriteID,DialogImageBank
Sprite DialogSpriteID,LocX,LocY,0
Set Sprite Priority DialogSpriteID,DialogPriority
draw frame
end if

if Mode=2 'if mode=2
int i
DialogStillOn=0'turn dialog off
canvas 0
Sprite Off DialogSpriteID
draw frame
end if
end proc

12-13-2006 13:07

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

great...
if someday we actually get to rewrite TNT i think a GUI part should not be overlooked

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.