My game app is progressing well, but I've hit a snag when opening a sub-menu (a child window) for player sign-in. The procedure runs fine, until I have to open a small, windowed screen in the child window to facilitate Keyboard input. For reasons unknown, when this is done and upon opening the 'Sign In' sub-window, the Main Window (parent) is instantly wiped out and left orphaned. I suspect maybe I've left a detail or something undone...? Any ideas?
For clarity I've provided some working code below. ...Just a brief snippet of the process to demonstrate the problem.
Many thanks!
Code: Select all
Enumeration
#Window_Main
#Window_SignIn
#Text_Names
#Text_Pin
#Listview_User
#Listview_Pswd
#Button_Select2
#Button_Done2
#Button_Cancel2
EndEnumeration
#Arial_16 = 16 ;Font for Sign In Name.
Arial_16 = LoadFont(#Arial_16,"Arial",16,#PB_Font_Bold) ;Font for Sign In Name.
#TableGrn = $008000 ;Color for Gaming Table.
#TableYel = $03CFFF ;Color for Table Lettering.
InitSprite() : InitKeyboard() ;Prepare Programming Environment.
Procedure.s GetKeyBoard()
Debug "LINE 197: Start GetKeyBoard()"
Repeat
FlipBuffers()
Debug "LINE 200: GetKeyBoard() - Top of Loop w/ ChrBuffer$ = " + ChrBuffer$
Event = WaitWindowEvent(10) ;Waits until a Click is detected from Windows.
ExamineKeyboard() ;Check Keyboard for Activity.
If KeyboardReleased(#PB_Key_Back) ;Was a Backspace Key Released?
ChrBuffer$ = Left(ChrBuffer$, Len(ChrBuffer$)-1) ;Back up 1 Chr from 'ChrBuffer$' - holds Chrs typed.
Else ;Not BS Key, so...
NewChr$ = KeyboardInkey() ;Store new Chr from Keyboard.
Debug "LINE 207: GetKeyBoard() - Before FindString w/ NewChr$ = " + NewChr$
If FindString("-=+@#$_()|<>?1234567890 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", NewChr$) ; ;Validate the New Character.
ChrBuffer$ + NewChr$ ;Concat the new Char into the current buffer.
Debug "LINE 210: GetKeyBoard() - After KbInKey() w/ ChrBuffer$ = " + ChrBuffer$
EndIf
EndIf
Debug "LINE 212: GetKeyBoard() - Bottom of Loop w/ ChrBuffer$ = " + ChrBuffer$
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Default)
DrawingFont(FontID(#Arial_16)) ;Set Font/Size.
If Right(ChrBuffer$,1) = "_" ;For Blinking Cursor.
RTrim(ChrBuffer$, "_")
DrawText(5, 1, "Name <Enter>: " + ChrBuffer$ + " ", #White, #Blue)
Else
DrawText(5, 1, "Name <Enter>: " + ChrBuffer$ + "_", #White, #Blue)
EndIf
StopDrawing()
Until KeyboardPushed(#PB_Key_Return) Or KeyboardPushed(#PB_Key_PadEnter) ;Event = #PB_Key_Return
Debug "LINE 214: End GetKeyBoard() w/ ChrBuffer$ = " + ChrBuffer$
ProcedureReturn ChrBuffer$
EndProcedure ;GetKeyBoard()
Procedure SignIn(User$,Pswd,Credits,Cost,Player, Date$, Time$)
;*** Set up 'NewLists' for the SignIn Menu ***
;*********************************************
NewList User$() ;Define a New List of Player's Names.
AddElement(User$()) ;Add a name Slot to the List.
User$() = "Add Player" ;Store the "Add Player" choice in Slot 1.
;Read in Player Data File.
;#PLAYER_FILE = 1 ;Provide a "PB" Number for file.
;For Nam = 1 To EOF ;It takes ?? reads to load in the Names.
; PLAYERVAR(0)\USERNAME$ = ReadString(#PLAYER_FILE) ;Get name of a player from Data File.
; AddElement(User$.s()) ;Add a name Slot to the List.
; User() = USERNAME$ ;Store the UserName in Slot.
; Next
;*** Initiate a 'Child' Window for the "Sign In" Menu ***
;********************************************************
OpenWindow(#Window_SignIn, 1050, 400, 320, 280, " SIGN-IN - PLAYER #" + Str(Player+1), #PB_Window_SystemMenu |
#PB_Window_TitleBar, WindowID(#Window_MAIN)) ;This window is defined as child of #Window_Main.
OpenWindowedScreen(WindowID(#Window_SignIn),10,0,300,30)
ClearScreen(#Blue) ;Blue.
;SetGadgetFont(#PB_Default, FontID(#Britannic_16)) ; Set Britannic_16 as new Font.
TextGadget(#Text_Names, 10, 32, 180, 30, "NAMES", #PB_Text_Border | #PB_Text_Center) ;Label for list of Player Names.
TextGadget(#Text_Pin, 200, 32, 110, 30, "PIN", #PB_Text_Border | #PB_Text_Center) ;Label for list of Passwords.
SetGadgetFont(#PB_Default, FontID(#Arial_16)) ; Set Arial 16 as new Font.
ListViewGadget(#Listview_User, 10, 65, 180, 170) ;Declare List Gadget for Player Names.
ListViewGadget(#Listview_Pswd, 200, 65, 110, 170) ;Declare List Gadget for Passwords.
ButtonGadget(#Button_Select2, 10, 240, 90, 30, "Select") ;Declare Button Gadget to Select a Name.
ButtonGadget(#Button_Done2, 110, 240, 80, 30, "Done") ;Declare Button Gadget to be Done.
ButtonGadget(#Button_Cancel2, 210, 240, 100, 30, "Cancel") ;Declare Button Gadget to Cancel Sigb In.
;**** POPULATE "SIGN-IN" LIST ****
;*******************************
FirstElement(User$()) ;Inititialize to 1st slot in User Name List.
For Device = 1 To ListSize(User$())
AddGadgetItem(#Listview_User, -1, User$()) ;Add next User Name to the end of list.
NextElement(User$()) ;Point to next User Name Item in Bet Type List.
Next
;*** Highlight List Item ***
SetGadgetState(#Listview_User,0) ;User may Click on a Listed User.
Repeat
Repeat
Event = WaitWindowEvent() ;Waits until a Click is detected from Windows.
GadgetID = EventGadget() ;IDs which Gadget the User clicked on?
If Event = #PB_Event_Gadget ;If a Gadget Event has Occurred...
If GadgetID = #Button_Cancel2 ;If "Cancel2" Button is clicked ('True'), then.
Event = #Button_Cancel2
CloseWindow(#Window_SignIn) ;Close Sign In Window.
; ProcedureReturn 0
ElseIf GadgetID = #Button_Done2 ;If "Done" Button is clicked ('True'), then...
CloseWindow(#Window_SignIn) ;Close Sign In Window.
; ProcedureReturn 0
ElseIf GadgetID = #Button_Select2 ;If "Select2" Button is clicked ('True'), then...
Event = #Button_Select2 ; preset "Event" to Break out of Loop.
NameSelected = GetGadgetState(#Listview_User) ;Get List Line# of selected UserName.
PswdSelected = GetGadgetState(#Listview_Pswd) ;Get List Line# of selected Password.
EndIf
EndIf
Until Event = #Button_Cancel2 Or Event = #Button_Select2
Debug "LINE 275: After SignIn Selection Loop"
Select NameSelected
Case 0 ;0 = Add Player.
FlipBuffers()
; AddElement(User$()) ;Add a name Slot to the List of User().
; User$() = "Goofy" ;Store a test name in Slot 1.
Debug "LINE 281: Before GetKeyBoard w/ Usr$ = " + Usr$
User$() = GetKeyBoard() ;Get new Name to Store in User List Slot 1.
Debug "LINE 283: After GetKeyBoard w/ Usr$ = " + Usr$
FirstElement(User$()) ;Inititialize to 1st slot in User Name List.
For Device = 1 To ListSize(User$())
AddGadgetItem(#Listview_User, -1, User$()) ;Add next User Name to the end of list.
NextElement(User$()) ;Point to next User Name Item in Bet Type List.
Next
Case 1 ;TBD.
End
EndSelect
Until Event = #PB_Event_CloseWindow ; set "Event" ready to close window & Exit loop.
CloseWindow(#Window_SignIn) ;Close SIGN IN Selection Window.
EndProcedure ;SignIn
;*** Open Main Window of this DEMO. ***
;***********************************
OpenWindow(#Window_MAIN, 800, 100, 400, 400, " DEMO: MAIN WINDOW", #PB_Window_SystemMenu |
#PB_Window_TitleBar)
OpenWindowedScreen(WindowID(#Window_MAIN),0,0,400, 400)
ClearScreen(#TableGrn) ;Green.
StartDrawing(ScreenOutput()) ;Sim Main Window w/ User Prompt.
DrawingMode(#PB_2DDrawing_Default)
DrawingFont(FontID(#Arial_16)) ;Set Font/Size.
DrawText(20, 20, "DEMO --- MAIN SCREEN --- DEMO", #TableYel, #TableGrn)
DrawText(100, 100, "<LEFT-CLICK>", #TableYel, #TableGrn) ;To Prompt User.
StopDrawing()
Repeat
Event = WaitWindowEvent(20) ;Wait for User Action - Mouse Click.
Until Event = #PB_Event_LeftClick Or Event = #PB_Event_CloseWindow
SignIn(User$,Pswd,Credits,Cost,Player, Date$, Time$) ;Call Proc to Open 'Child' of #Window_Main.
Repeat
Event = WaitWindowEvent(20) ;Wait for User Action - Mouse Click.
Until Event = #PB_Event_LeftClick Or Event = #PB_Event_CloseWindow
CloseWindow(#Window_MAIN) ;Close MAIN Window.
End