% first, must create the dialog window by using the dialog editor
% and EXPORTING to the I/E window. From there, copy its contents
% and paste them to this window, as below:
my_gui :-
_S1 = [dlg_ownedbyprolog,ws_sysmenu,ws_maximizebox,ws_minimizebox,ws_thickframe,ws_caption],
_S2 = [ws_child,ws_visible,ws_tabstop,bs_defpushbutton],
_S3 = [ws_child,ws_visible,ws_tabstop,bs_pushbutton],
_S12 = [ws_child,ws_border,ws_visible],
wdcreate( my_gui, `my_gui`, 232, 40, 400, 400, _S1 ),
wccreate( (my_gui,1000), button, `OK`, 10, 10, 60, 30, _S2 ),
wccreate( (my_gui,1001), button, `Close`, 70, 10, 60, 30, _S3 ),
wccreate( (my_gui,1002), button, `North`, 260, 200, 40, 40, _S2 ),
wccreate( (my_gui,1003), button, `South`, 260, 280, 40, 40, _S2 ),
wccreate( (my_gui,1004), button, `West`, 220, 240, 40, 40, _S2 ),
wccreate( (my_gui,1005), button, `East`, 300, 240, 40, 40, _S2 ),
wccreate( (my_gui,1006), button, `Wait`, 260, 240, 40, 40, _S2 ),
wccreate( (my_gui,9020), grafix, `Grafix1`, 0, 80, 40, 40, _S12 ),
wccreate( (my_gui,9021), grafix, `Grafix1`, 40, 80, 40, 40, _S12 ),
wccreate( (my_gui,9022), grafix, `Grafix1`, 80, 80, 40, 40, _S12 ),
wccreate( (my_gui,9023), grafix, `Grafix1`, 120, 80, 40, 40, _S12 ),
wccreate( (my_gui,9024), grafix, `Grafix1`, 160, 80, 40, 40, _S12 ),
wccreate( (my_gui,9015), grafix, `Grafix1`, 0, 120, 40, 40, _S12 ),
wccreate( (my_gui,9016), grafix, `Grafix1`, 40, 120, 40, 40, _S12 ),
wccreate( (my_gui,9017), grafix, `Grafix1`, 80, 120, 40, 40, _S12 ),
wccreate( (my_gui,9018), grafix, `Grafix1`, 120, 120, 40, 40, _S12 ),
wccreate( (my_gui,9019), grafix, `Grafix1`, 160, 120, 40, 40, _S12 ),
wccreate( (my_gui,9010), grafix, `Grafix1`, 0, 160, 40, 40, _S12 ),
wccreate( (my_gui,9011), grafix, `Grafix1`, 40, 160, 40, 40, _S12 ),
wccreate( (my_gui,9012), grafix, `Grafix1`, 80, 160, 40, 40, _S12 ),
wccreate( (my_gui,9013), grafix, `Grafix1`, 120, 160, 40, 40, _S12 ),
wccreate( (my_gui,9014), grafix, `Grafix1`, 160, 160, 40, 40, _S12 ),
wccreate( (my_gui,9005), grafix, `Grafix1`, 0, 200, 40, 40, _S12 ),
wccreate( (my_gui,9006), grafix, `Grafix1`, 40, 200, 40, 40, _S12 ),
wccreate( (my_gui,9007), grafix, `Grafix1`, 80, 200, 40, 40, _S12 ),
wccreate( (my_gui,9008), grafix, `Grafix1`, 120, 200, 40, 40, _S12 ),
wccreate( (my_gui,9009), grafix, `Grafix1`, 160, 200, 40, 40, _S12 ),
wccreate( (my_gui,9000), grafix, `Grafix1`, 0, 240, 40, 40, _S12 ),
wccreate( (my_gui,9001), grafix, `Grafix1`, 40, 240, 40, 40, _S12 ),
wccreate( (my_gui,9002), grafix, `Grafix1`, 80, 240, 40, 40, _S12 ),
wccreate( (my_gui,9003), grafix, `Grafix1`, 120, 240, 40, 40, _S12 ),
wccreate( (my_gui,9004), grafix, `Grafix1`, 160, 240, 40, 40, _S12 ),
wccreate( (my_gui,9099), grafix, `Grafix1`, 220, 80, 130, 120, _S12 ).
% Health display. Start with a big smile at full health
my_gui_handler((my_gui,9099), msg_paint,_,_):-
gfx_begin((my_gui,9099)),
gfx(ellipse(10,10,110,110)),
gfx_begin((my_gui,9099)),
gfx(ellipse(30,40,50,50)),
gfx_begin((my_gui,9099)),
gfx(ellipse(50,50,70,70)),
gfx(ellipse(70,40,90,50)),
gfx(arc(20,30,100,90,15,70,90,70)),
gfx_end((my_gui,9099)).
%Adventurer starts at 0,0
my_gui_handler((my_gui,9000),msg_paint,_,_):-
gfx_begin((my_gui,9000)),
gfx(ellipse(0,0,38,38)),
gfx_begin((my_gui,9000)),
gfx(ellipse(6,12,18,18)),
gfx_begin((my_gui,9000)),
gfx(ellipse(22,12,34,18)),
gfx(ellipse(18,16,22,26)),
gfx(arc(7,11,35,30,5,25,30,25)),
gfx_end((my_gui,9000)),
Adventurer_XPos(0),
Adventurer_YPos(0).
% now must actually create the dialog and then show it.
start:-
create_world, % use this to declare my_gui
my_gui, % my_gui is the dialog window name
wshow(my_gui,1), % show it - make it appear
window_handler(my_gui,my_gui_handler), % window handler for my_gui=my_gui_handler
call_dialog(my_gui,X). % running the dialog
% now must create a handler program to process the messages that the
% controls generate
%
% The first one is a handler that is specific to the msg_button 1000
% ie the Ok button.
% it does a few things, but importantly, it does not instantiate the final (4th)
% argument - if it did, it would terminate the dialog
my_gui_handler((my_gui,1000), msg_button,_,_):- % ID=1000 is the Ok button
writeq(Text), % also write it to the console window
nl, % and a new line
ttyflush, % housekeeping
beep(440,32). % make a beep noise (frequency, duration)
% the next one is (ort of) simple, when the close button is pressed (ID 1001),
% a message box appears that returns a value B that is:
% OK = 1
% Cancel= 2
% The clause check_close is used to determine what to do. If it is OK=1, then
% this will destroy the dialog window, otherwise do nothing - back to before
my_gui_handler((my_gui,1001), msg_button,_,C):- % C is the var
wclose(my_gui). %msgbox('Warning', 'this will close the dialog',49,B),
% get the value
% what to do?
check_close(B,C):- % takes the vars B & C
B=1, C=1. % must satisfy B=1 and C=1
%
% this next one does a simple check after the X button has been clicked on
% it refuses to close the user-dialog, but directs the user to close in
% the 'proper fashion' It is mildly abusive too!
my_gui_handler((my_gui,1002), msg_button,_,_):-
move_north.
my_gui_handler((my_gui,1003), msg_button,_,_):-
move_south.
my_gui_handler((my_gui,1004), msg_button,_,_):-
move_west.
my_gui_handler((my_gui,1005), msg_button,_,_):-
move_east.
my_gui_handler((my_gui,1006), msg_button,_,_):-
Y is int(rand(4)),
wander(Y).