#!/bin/bash

# menu.sh
# menu definitions

function menu_main () {
  [ -z "$1" ] && menusys_run menu_main && return
  if [ "$1" == "init" ]; then
    menu_title="Main menu"
    menu_data="
    Download new levelsets ~ menu_download
    Import downloaded levelsets ~ debug_message todo1
    Enable/disable levelsets ~ debug_message todo2
    -
    Manage my levelsets ~ debug_message todo4
    Make new levelset ~ debug_message todo5
    Publish my levels ~ debug_message todo6
    Delete levelsets ~ debug_message todo7
    -
    Preferences ~ debug_message todo9
    Launch Rocks'n'Diamonds ~ launch_rnd
    Quit RLM ~ menusys_stop
    "
    return
  fi
}

function menu_download () {
  [ -z "$1" ] && menusys_run menu_download && return
  if [ "$1" == "init" ]; then
    menu_title="Download new levels"
    menu_data="
    -Note: Make sure this program has access to the internet.
    -
    Browse levels archive ~ menu_download_browse
    -Use this if you don't have any particular levelset in mind.
    -
    Search by name ~ debug_message todo_5
    -Use this if you know what's the name of the levelset you want.
    -
    Download by URL ~ debug_message todo_8
    -Use this if you know the levelset's URL.
    -
    Download by RnD Files Archive by ID ~ debug_message todo_11
    -Use this if you know levelset's ID on RnD Files Archive.
    -
    Back to main menu ~ menusys_back
    "
    return
  fi
}

function menu_download_browse () {
  # get level category
  browse_category=
  menusys_run menu_download_browse_category
  [ -z "$browse_category" ] && return
  
  echo "downloading ($browse_category)"
  sleep 1
  
  # download level list
  header
  echo " Please wait, downloading levelsets list..."
  
  case $browse_category in
    0|2|5|6) # Additional Classic Levels, Multiplayer Levels, Tutorials
      # www.bd-fans.com
      # @todo
      ;;
    1) # Additional Player Levels; www.elemu-project.de and www.bd-fans.com
      ;;
    3) # Contributions; www.artsoft.org and www.bd-fans.com
      ;;
    4) # Examples; www.zomis.net and www.bd-fans.com
      ;;
  esac
    
  # @todo
  
  menu_back
}

function menu_download_browse_category () {
  [ -z "$1" ] && menusys_run menu_download && return
  if [ "$1" == "init" ]; then
    menu_title="Download new levels"
    menu_data="
    Additional Classic Levels
    Additional Player Levels
    Classic Games
    Contributions
    Examples
    Multiplayer Levels
    Tutorials
    -
    Cancel ~ menusys_stop
    "
    return
  fi
  browse_category="${menu_items[$1]}"
  menusys_stop
}



