Пример #1
0
 public static void start()
 {
     int intCursorStartPos = Constants.DEFAULT_CURSOR_START_Y_POS;
     int intCursorCurrentPos = intCursorStartPos;
     int intMaxNumberOfItems = Console.WindowHeight - Constants.NUM_OF_ITEMS_OFFSET; // 3 for top, 3 for bottom
     int playlistStateCounter = 0;
     Playlist objPlaylist = new Playlist ();
     Filelist objFilelist = new Filelist ();
     // Get Files
     objFilelist = getFiles ();
     // Build Screen
     buildScreen();
     objFilelist.showFilelist (((Console.WindowWidth - 1) / 2) + Constants.FILELIST_X_OFFSET , Constants.FILELIST_Y_OFFSET);
     Util.WritePos (((Console.WindowWidth - 1) / 2) + Constants.FILELIST_PAGE_OFFSET, Console.WindowHeight - 1, " 1/" + objFilelist.getPages().ToString(), ConsoleColor.DarkRed, Util.BACKGROUND);
     Util.WritePos(((Console.WindowWidth - 1) / 2) + Constants.DEFAULT_CURSOR_START_X_POS , intCursorStartPos, "-->", ConsoleColor.Blue, Util.BACKGROUND);
     do {
         while(! Console.KeyAvailable) {
             switch(Console.ReadKey(true).Key) {
                 case ConsoleKey.DownArrow:
                         intCursorCurrentPos++;
                         if(intCursorCurrentPos > (intMaxNumberOfItems + intCursorStartPos - 1)) { intCursorCurrentPos = (intMaxNumberOfItems + intCursorStartPos - 1); }
                         if(objFilelist.getFilelist().Count <= (intCursorCurrentPos - intCursorStartPos) + (intMaxNumberOfItems * objFilelist.getPageOffset())) {
                             intCursorCurrentPos--;
                         }
                         Util.WritePos(((Console.WindowWidth - 1) / 2) + Constants.DEFAULT_CURSOR_START_X_POS, intCursorCurrentPos - 1, "   ", ConsoleColor.Blue, Util.BACKGROUND);
                         Util.WritePos(((Console.WindowWidth - 1) / 2) + Constants.DEFAULT_CURSOR_START_X_POS , intCursorCurrentPos, "-->", ConsoleColor.Blue, Util.BACKGROUND);
                 break;
                 case ConsoleKey.UpArrow:
                         intCursorCurrentPos--;
                         if(intCursorCurrentPos < intCursorStartPos) { intCursorCurrentPos = intCursorStartPos; }
                         Util.WritePos(((Console.WindowWidth - 1) / 2) + Constants.DEFAULT_CURSOR_START_X_POS, intCursorCurrentPos + 1, "   ", ConsoleColor.Blue, Util.BACKGROUND);
                         Util.WritePos(((Console.WindowWidth - 1) / 2) + Constants.DEFAULT_CURSOR_START_X_POS , intCursorCurrentPos, "-->", ConsoleColor.Blue, Util.BACKGROUND);
                     break;
                 case ConsoleKey.LeftArrow:
                     break;
                 case ConsoleKey.RightArrow:
                     break;
                 case ConsoleKey.Delete:
                     break;
                 case ConsoleKey.W:
                         // TODO: Switch windows: File list to play list and vice versa
                     break;
                 case ConsoleKey.F1:
                         objPlaylist.pageOffsetInc();
                         if(objPlaylist.getPageOffset() > (objPlaylist.getPages() - 1)) { objPlaylist.setPageOffset(objPlaylist.getPages() - 1); }
                         objPlaylist.showPlaylist (Constants.PLAYLIST_X_OFFSET, Constants.PLAYLIST_Y_OFFSET);
                         Util.WritePos (Constants.FILELIST_PAGE_OFFSET, Console.WindowHeight - 1, " " + (objPlaylist.getPageOffset() + 1).ToString() + "/" + objPlaylist.getPages().ToString() + " ", ConsoleColor.DarkRed, Util.BACKGROUND);
                     break;
                 case ConsoleKey.F2:
                         objPlaylist.pageOffsetDec();
                         if(objPlaylist.getPageOffset() < 0) { objPlaylist.setPageOffset(0); }
                         objPlaylist.showPlaylist (Constants.PLAYLIST_X_OFFSET, Constants.PLAYLIST_Y_OFFSET);
                         Util.WritePos (Constants.FILELIST_PAGE_OFFSET, Console.WindowHeight - 1, " " + (objPlaylist.getPageOffset() + 1).ToString() + "/" + objPlaylist.getPages().ToString() + " ", ConsoleColor.DarkRed, Util.BACKGROUND);
                     break;
                 case ConsoleKey.F6:
                         objFilelist.pageOffsetInc();
                         intCursorCurrentPos = intCursorStartPos;
                         if(objFilelist.getPageOffset() > (objFilelist.getPages() - 1)) { objFilelist.setPageOffset(objFilelist.getPages() - 1); }
                         objFilelist.showFilelist (((Console.WindowWidth - 1) / 2) + Constants.FILELIST_X_OFFSET , Constants.FILELIST_Y_OFFSET);
                         Util.WritePos (((Console.WindowWidth - 1) / 2) + Constants.FILELIST_PAGE_OFFSET, Console.WindowHeight - 1, " " + (objFilelist.getPageOffset() + 1).ToString() + "/" + objFilelist.getPages().ToString() + " ", ConsoleColor.DarkRed, Util.BACKGROUND);
                         Util.WritePos(((Console.WindowWidth - 1) / 2) + Constants.DEFAULT_CURSOR_START_X_POS , intCursorCurrentPos, "-->", ConsoleColor.Blue, Util.BACKGROUND);
                     break;
                 case ConsoleKey.F7:
                         objFilelist.pageOffsetDec();
                         intCursorCurrentPos = intCursorStartPos;
                         if(objFilelist.getPageOffset() < 0) { objFilelist.setPageOffset(0); }
                         objFilelist.showFilelist (((Console.WindowWidth - 1) / 2) + Constants.FILELIST_X_OFFSET , Constants.FILELIST_Y_OFFSET);
                         Util.WritePos (((Console.WindowWidth - 1) / 2) + Constants.FILELIST_PAGE_OFFSET, Console.WindowHeight - 1, " " + (objFilelist.getPageOffset() + 1).ToString() + "/" + objFilelist.getPages().ToString() + " ", ConsoleColor.DarkRed, Util.BACKGROUND);
                         Util.WritePos(((Console.WindowWidth - 1) / 2) + Constants.DEFAULT_CURSOR_START_X_POS , intCursorCurrentPos, "-->", ConsoleColor.Blue, Util.BACKGROUND);
                     break;
                 case ConsoleKey.S:
                         if(objPlaylist.getName() == "") {
                             Util.WritePos(Constants.PLAYLIST_NAME_X_OFFSET, Constants.PLAYLIST_NAME_Y_OFFSET, "Enter playlist name: ");
                             objPlaylist.setName(Console.ReadLine());
                         }
                         if(objPlaylist.getName().Substring(objPlaylist.getName().LastIndexOf(".") + 1) == objPlaylist.getName()) {
                             objPlaylist.setName(objPlaylist.getName() + "." + objPlaylist.getFileFormat());
                         } else {
                             objPlaylist.setFileFormat(objPlaylist.getName().Substring(objPlaylist.getName().LastIndexOf(".") + 1));
                         }
                         Writer objWriter = new Writer(objPlaylist);
                         objWriter.writeFile();
                     break;
                 case ConsoleKey.Enter:
                         playlistStateCounter++;
                         if(playlistStateCounter > intMaxNumberOfItems) {
                             playlistStateCounter = 1; objPlaylist.pageOffsetInc();
                             Util.WritePos (Constants.FILELIST_PAGE_OFFSET, Console.WindowHeight - 1, " " + (objPlaylist.getPageOffset() + 1).ToString() + "/" + objPlaylist.getPages().ToString() + " ", ConsoleColor.DarkRed, Util.BACKGROUND);
                         }
                         PlaylistItem objPlaylistItem = new PlaylistItem();
                         objPlaylistItem.setFilename(objFilelist.getFilelist()[(intCursorCurrentPos - intCursorStartPos) + (intMaxNumberOfItems * objFilelist.getPageOffset())].getFilename());
                         objPlaylistItem.setFullPath(objFilelist.getFilelist()[(intCursorCurrentPos - intCursorStartPos) + (intMaxNumberOfItems * objFilelist.getPageOffset())].getFullPath());
                         objPlaylist.addItem(objPlaylistItem);
                         objPlaylist.showPlaylist (Constants.PLAYLIST_X_OFFSET, Constants.PLAYLIST_Y_OFFSET);
                     break;
                 case ConsoleKey.Escape:
                         Console.BackgroundColor = ConsoleColor.Black;
                         Console.Clear();
                         Environment.Exit(-1);
                     break;
             }
         }
     } while(Console.ReadKey(true).Key != ConsoleKey.Escape);
 }