Comment 6 for bug 632490

Revision history for this message
Tom Bell (bushbaby2511) wrote :

Thanks for this! much appreciated. As a concept, Is the bar across the top what you're looking for? With the data relating to screen size etc? Prehaps a more formal layout should be drawn up.. as far as my code is going the attachment gives a general idea of how it is to work.

Notes regarding file:

I'm not sure whether a drop-down Options dialog would be more suitable to give more space for Highscores when options are not being accessed.. As far as the rest is shaping up, the General selection mechanism and toggling for Option items in the submenu is working. I'm working on the scrolling currently. The API is easy-to-use with a few functions required for complete control:

The following code is all that's needed for a menu to be setup:

menu = SnakeMenu(screen)
    playgame = menu.new_head("Play Game")
    optionsm = menu.new_head("Options")
    menu.new_sub(optionsm,"ValueA")
    menu.new_sub(optionsm,"ValueB")
    quitgame = menu.new_head("Quit",quit)
    while True:
        c = screen.getch()
        if c == curses.KEY_LEFT: menu.move_left()
        elif c == curses.KEY_RIGHT: menu.move_right()
        elif c == curses.KEY_UP: menu.move_up()
        elif c == curses.KEY_DOWN: menu.move_down()
        else: pass

Each item has option to connect to a function as shown in quitgame and the parenting is shown with the ValueA and ValueB submenu items.

The move_left/right/up/down() functions control all redrawing and internals such that the above code works in an Event-based way.

The API can be initiated with an optional Style parameter which could later be extended to accomodate more styles etc.

Please let me know if this is suitable or i've gone a little overboard, I started coding and it just kept coming and coming! :)

Regards

Tom Bell