Пример #1
0
 def __init__(self, facility, menu, prompt, selection):
     self.facilityDisplay = FacilityView(facility)
     self.menuDisplay = MenuDisplay(menu)
     self.prompt = prompt
     self.map_area = (20,0,WIDTH-20, HEIGHT-1)
     self.viewport = Viewport(WIDTH-20, HEIGHT, MAP_WIDTH, MAP_HEIGHT)
     self.selection = selection
     self.build_consoles()
Пример #2
0
class Screen(object):
    MAP = 0
    PANE = 1
    PROMPT = 2
    FEEDBACK = 3

    """This class that manages offscreen console and focus."""
    def __init__(self, facility, menu, prompt, selection):
        self.facilityDisplay = FacilityView(facility)
        self.menuDisplay = MenuDisplay(menu)
        self.prompt = prompt
        self.map_area = (20,0,WIDTH-20, HEIGHT-1)
        self.viewport = Viewport(WIDTH-20, HEIGHT, MAP_WIDTH, MAP_HEIGHT)
        self.selection = selection
        self.build_consoles()

    def build_consoles(self):
        self.consoles = []
        self.consoles.append(MapConsole(20,0,WIDTH-20,HEIGHT, True, self.viewport))
        self.consoles.append(Console(0,0,20,HEIGHT))
        self.consoles.append(Console(0,HEIGHT-2,WIDTH, 1))
        self.consoles.append(Console(0,HEIGHT-1,WIDTH, 1))

    def get_real_console(self, console_id):
        return self.consoles[console_id].console

    def globalize_selection(self):
        (x,y) = self.local_to_global(self.selection.x, self.selection.y)
        (x2,y2) = self.local_to_global(self.selection.x2, self.selection.y2)
        return (x,y,x2,y2)

    def display(self, delta):
        map_console = self.consoles[self.MAP]
        self.facilityDisplay.display(map_console.console
                                    ,map_console.viewport.getX()
                                    ,map_console.viewport.getY()
                                    ,map_console.viewport.getX2()
                                    ,map_console.viewport.getY2()
                                    ,delta)
        (x,y,x2,y2) = self.globalize_selection()
        self.facilityDisplay.display_selection(map_console.console,
                                    self.selection.crosshair,x,y,x2,y2)
        if self.consoles[Screen.PANE].visible:
            self.menuDisplay.display(self.get_real_console(Screen.PANE))
        if self.consoles[Screen.PROMPT].visible:
            self.prompt.display(self.get_real_console(Screen.PROMPT))
        # Global call to the display, will need to get this out
        messages.display(self.get_real_console(Screen.FEEDBACK))
        # Display chain is done : let's blit
        self.blit()

    def hide_pane(self):
        self.consoles[Screen.PANE].visible = False
        map_console = self.consoles[Screen.MAP]
        map_console.x = 0
        map_console.redraw(map_console.w + self.consoles[Screen.PANE].w
                        , map_console.h)

    def show_pane(self):
        self.consoles[Screen.PANE].visible = True
        map_console = self.consoles[Screen.MAP]
        map_console.x = self.consoles[Screen.PANE].w
        map_console.redraw(map_console.w + self.consoles[Screen.PANE].w
                        , map_console.h)

    def hide_prompt(self):
        self.consoles[Screen.PROMPT].visible = False
        map_console = self.consoles[Screen.MAP]
        map_console.redraw(map_console.w,
                        map_console.h + self.consoles[Screen.PROMPT].h)

    def show_prompt(self):
        self.consoles[Screen.PROMPT].visible = True
        map_console = self.consoles[Screen.MAP]
        map_console.redraw(map_console.h,
                        map_console.h - self.consoles[PROMPT].h)

    def move_center(self, x, y):
        self.consoles[Screen.MAP].viewport.move(x,y)

    def blit(self):
        for console in self.consoles:
            if console.visible:
                libtcod.console_blit(console.console, 0,0,0,0,0,
                                        console.x, console.y)
        # End of display : flush the console
        libtcod.console_flush()

    def local_to_global(self, x, y):
        return self.consoles[Screen.MAP].local_to_global(x,y)