indexing description: "Top shell widget for the Design subsystem." class V_DESIGN_SHELL inherit V_SHELL rename make as vs_make redefine on_menu_command, room, show, hide, exit, on_key_up, on_key_down end creation make feature{NONE} room : V_DESIGN_ROOM -- The room in which the pieces will be placed. prepend_text : STRING is "Designing " palette : V_PALETTE -- The palette from which design pieces may be selected. make_room is -- Make the design room. do !!room.make( "room", Current ) end make_palette is -- Make the palette of pieces to choose from. do !!palette.make( "Game Pieces", room ) palette.move( x + room.width + configuration.palette_offset, y ) end make( b : BASE ; s : STRING ) is -- Initialize a puzzle shell window do !!asc !!vk vs_make( b, s ) move( configuration.design_x, configuration.design_y ) make_palette room.set_palette( palette ) end puzzle, edit : WEL_MENU -- Menus for the menu bar. make_menu_bar is -- Make my bar and menus. do !!menu_bar.make make_puzzle_menu menu_bar.append_popup( puzzle, "Puzzle" ) make_edit_menu menu_bar.append_popup( edit, "Edit" ) make_help_menu menu_bar.append_popup( help, "Help" ) end make_puzzle_menu is -- Make the do !!puzzle.make puzzle.append_string( "&New%TN" , new_id) puzzle.append_string( "&Open%TO" , open_id) puzzle.append_separator puzzle.append_string( "&Save%TS" , save_id) puzzle.append_string( "Save &As%TA" , save_as_id) puzzle.append_separator puzzle.append_string( "&Test%TT" , test_id) puzzle.append_string( "&Finalize%TF" , finalize_id) puzzle.append_separator puzzle.append_string( "E&xit%TEsc" , exit_id) -- puzzle.append_string( "Test List Box", 100 ) -- Used for -- testing list boxes as an alternative to file dialogs. -- Ignore for now. end make_edit_menu is do !!edit.make edit.append_string( "&Undo%TU" , undo_id) edit.append_string( "&Redo%TR" , redo_id) end make_list_box_dialog is local d : DIRECTORY ; a : ARRAY[ STRING ] ; i : INTEGER do !!d.make_open_read( "..\puzzles" ) !!a.make( 1, d.count ) from d.start ; i := 1 until i > d.count loop d.readentry a.put( clone( d.lastentry ), i ) i := i + 1 end !!list_box_dialog.make( "Puzzle Selection Dialog", a ) end make_help_menu is -- Make the menu with various help commands. do create help.make help.append_string( "Contents" , contents_id ) help.append_string( "About" , about_id ) end exit_id, open_id, save_id, about_id, contents_id, save_as_id, test_id, new_id, finalize_id, undo_id, redo_id : INTEGER is unique game : V_TEST_GAME_SHELL is -- The top shell of the Game subsystem to be brought up when it's -- time to test the design. once !!Result.make( base, "Testing a Puzzle" ) end -- RML HW5 finalize_game : V_FINALIZE_GAME_SHELL is -- The top shell of the Game subsystem to be brought up when it's -- time to finalize the design. once create Result.make_finalized( Current, base, "Finalizing a Puzzle" ) end help_message : SCROLLED_D -- Help message for the Design subsystem. make_help_message is -- Make the help message, getting the text from a file. do create help_message.make( "Designing A Puzzle", configuration.design_help_width, configuration.design_help_height ) help_message.set_message_from_file( configuration.design_help_file ) end list_box_dialog : LIST_BOX_DIALOG dialog : WEL_MODAL_DIALOG ok_to_clear : BOOLEAN -- Is it OK with the user if I clear myself. check_ok_to_clear is -- Have Room check with user if necessary do -- Maybe this check should be in room? ok_to_clear := not room.modified if not ok_to_clear then room.check_with_user ok_to_clear := room.ok_with_user end end vk : WEL_VK_CONSTANTS asc : ASCII -- vk : expanded WEL_VK_CONSTANTS -- asc : expanded ASCII feature -- Finalizing a puzzle RML HW5 no_show : BOOLEAN -- Show explanatory information box? info_box : INFORMATION_BOX -- Information box displayed to user. prep_finalize_game_room is -- Tell the user about what to do when finalizing a puzzle. do if not no_show then create info_box.make( Current, "Finalizing Your Design", "You must solve the puzzle%Nbefore it can be finalized.", True ) info_box.show else start_finalize_game_room end end start_finalize_game_room is -- Start the finalization process do finalize_game.raise finalize_game.set_focus finalize_game.finalize_puzzle( room.puzzle ) end feature{NONE} -- Finalizing a puzzle in progress finalize_user_data : LINKED_LIST[ STRING ] -- User data arriving from FINALIZE_DIALOG_BOX finalize_dialog_box : FINALIZE_DIALOG_BOX -- Used to gather designer data feature{V_FINALIZE_GAME_SHELL} finish_finalizing( time : STRING ) is -- User solved her puzzle do create finalize_dialog_box.make( Current, "Designer Information", "Puzzle may now be finalized%Nwith a time of " + time + ".", time, True ) finalize_dialog_box.show_finalized_dialog_box end feature{INFORMATION_BOX} info_box_notify is -- If we could get the thread to wait we would not need this. do if not no_show then no_show := info_box.show_no_more end start_finalize_game_room end feature{FINALIZE_DIALOG_BOX} finalize_box_notify is do if finalize_dialog_box.response_available then room.finalize( finalize_dialog_box.name_text_input, finalize_dialog_box.title_text_input, finalize_dialog_box.final_time ) end end feature on_key_down( k, key_data: INTEGER) is -- Attempts to move heard here. Allows automatic repetition. do room.move( configuration.direction( k ) ) end on_key_up( k, key_data: INTEGER) is -- All key presses are heard here. do if k = vk.Vk_escape then on_menu_command( exit_id ) elseif k = asc.Upper_u then on_menu_command( undo_id ) elseif k = asc.Upper_r then on_menu_command( redo_id ) elseif k = asc.upper_s then on_menu_command( save_id ) elseif k = asc.upper_a then on_menu_command( save_as_id ) elseif k = asc.upper_f then on_menu_command( finalize_id ) elseif k = asc.upper_t then on_menu_command( test_id ) elseif k = asc.upper_n then on_menu_command( new_id ) elseif k = asc.upper_o then on_menu_command( open_id ) elseif k = 12 then -- 5 on numeric keypad room.deselect else end -- !!str.make( 0 ) -- str.append_integer( virtual_key ) -- information_message_box( str, "Here's your key code" ) -- To see the virtual key code of any key decomment the above line. end on_menu_command( menu_id : INTEGER ) is -- Respond to menu selection. do inspect menu_id when exit_id then exit when save_as_id then room.save_as when finalize_id then prep_finalize_game_room when open_id then retrieve when save_id then room.save when test_id then test when new_id then clear when contents_id then make_help_message help_message.show when about_id then display_about_message when undo_id then room.undo when redo_id then room.redo -- when 100 then -- used only for testing list boxes. -- !!dialog.make_by_name( Current, "Puzzle selection" ) -- dialog.activate -- make_list_box_dialog -- list_box_dialog.show -- if list_box_dialog.selected then -- wmb.information_message_box( Current, list_box_dialog.selection, "Your selection" ) -- end else end end clear is -- Clear room if ok with user. do check_ok_to_clear if ok_to_clear then room.clear end end retrieve is -- Retrieve new puzzle if ok with user. do check_ok_to_clear if ok_to_clear then room.retrieve end end exit is -- Exit to main menu if ok with user. do check_ok_to_clear if ok_to_clear then room.clear hide base.return end end test is -- Test the design in a game room. do game.raise game.set_focus game.test_puzzle( room.puzzle ) end show is -- show myself and my palette do precursor palette.show end hide is -- Hide myself, my palette, and my testing area. do precursor palette.hide game.hide end -- Now using line drawing as part of the drag and drop. Makes it easy -- to see which palette piece is selected. Problem on multiple drops. -- Can't easily erase the end of the line that's on the new design piece. -- Prefer Sun version, just need to be able to generate a cursor from a -- bitmap. end