def __init__(self, menu_window): resx, _ = pf.get_resolution() super(MenuButtonWindow, self).__init__( "MenuButton", (resx - TAB_BAR_COL_WIDTH, 0, TAB_BAR_COL_WIDTH, TAB_BAR_HEIGHT), NK_WINDOW_NO_SCROLLBAR) self.menu = menu_window
def on_new(self, event): globals.active_map = map.Map(4, 4) pf.new_game_string(globals.active_map.pfmap_str()) pf.set_minimap_position( ui.LEFT_PANE_WIDTH + MINIMAP_PX_WIDTH / cos(pi / 4) / 2 + 10, pf.get_resolution()[1] - MINIMAP_PX_WIDTH / cos(pi / 4) / 2 - 10) self.view.hide()
def __init__(self): resx, resy = pf.get_resolution() super(Menu, self).__init__( "Menu", (resx / 2 - Menu.WINDOW_WIDTH / 2, resy / 2 - Menu.WINDOW_HEIGHT / 2, Menu.WINDOW_WIDTH, Menu.WINDOW_HEIGHT), pf.NK_WINDOW_BORDER | pf.NK_WINDOW_NO_SCROLLBAR)
def __init__(self): resx, _ = pf.get_resolution() dims = (0, 0, resx - UI_TAB_BAR_COL_WIDTH, UI_TAB_BAR_HEIGHT) super(TabBarWindow, self).__init__("TabBar", dims, pf.NK_WINDOW_NO_SCROLLBAR) self.active_idx = 0 self.labels = [] self.child_windows = []
def __init__(self): _, resy = pf.get_resolution() super(ObjectsTabWindow, self).__init__("ObjectsTab", (0, UI_TAB_BAR_HEIGHT + 1, UI_LEFT_PANE_WIDTH, resy - UI_TAB_BAR_HEIGHT - 1), pf.NK_WINDOW_BORDER) self.mode = self.OBJECTS_MODE_PLACE self.objects_list = [] self.selected_object_idx = 0
def __init__(self): resx, resy = pf.get_resolution() super(FileChooser, self).__init__( "FileChooser", (resx / 2 - FileChooser.WINDOW_WIDTH / 2, resy / 2 - FileChooser.WINDOW_HEIGHT / 2, FileChooser.WINDOW_WIDTH, FileChooser.WINDOW_HEIGHT), NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR) import os self.filestring = os.path.realpath(pf.get_basedir()) + "/assets/maps/"
def __init__(self, title): resx, resy = pf.get_resolution() super(FileChooser, self).__init__( title, (resx / 2 - FileChooser.WINDOW_WIDTH / 2, resy / 2 - FileChooser.WINDOW_HEIGHT / 2, FileChooser.WINDOW_WIDTH, FileChooser.WINDOW_HEIGHT), pf.NK_WINDOW_BORDER | pf.NK_WINDOW_NO_SCROLLBAR | pf.NK_WINDOW_TITLE) import os self.mapstring = os.path.realpath(pf.get_basedir()) + "/assets/maps/" self.scenestring = os.path.realpath(pf.get_basedir()) + "/assets/maps/" self.scene_flag = False self.title = title
def mouse_over_ui(x, y): def in_bounds(x, y, w, h, test_x, test_y): return (test_x >= x and test_x < x + w) \ and (test_y >= y and test_y < y + h) resx, resy = pf.get_resolution() menu_dims = [ resx / 2 - Menu.WINDOW_WIDTH / 2, resy / 2 - Menu.WINDOW_HEIGHT / 2, Menu.WINDOW_WIDTH, Menu.WINDOW_HEIGHT ] return (in_bounds(*[0, TAB_BAR_HEIGHT, LEFT_PANE_WIDTH, resy - TAB_BAR_HEIGHT], test_x=x, test_y=y)) \ or (in_bounds(*[0, 0, resx, TAB_BAR_HEIGHT], test_x=x, test_y=y)) \ or (in_bounds(*menu_dims, test_x=x, test_y=y) if Menu.menu_shown else False)
def __init__(self): _, resy = pf.get_resolution() super(TerrainTabWindow, self).__init__("TerrainTab", (0, TAB_BAR_HEIGHT + 1, LEFT_PANE_WIDTH, resy - TAB_BAR_HEIGHT - 1), NK_WINDOW_BORDER) self.selected_mat_idx = 0 self.brush_size_idx = 0 self.brush_type_idx = 0 self.edges_type_idx = 0 self.selected_tile = None self.materials_list = [] self.heights = [h for h in range(0, 10)] self.selected_height_idx = 0
def __on_old_game_teardown_end(self, event): assert isinstance(event[0], map.Map) del globals.active_objects_list[:] globals.active_map = event[0] pf.new_game_string(globals.active_map.pfmap_str()) pf.set_minimap_position(UI_LEFT_PANE_WIDTH + MINIMAP_PX_WIDTH/cos(pi/4)/2 + 10, pf.get_resolution()[1] - MINIMAP_PX_WIDTH/cos(pi/4)/2 - 10) self.view.hide() import os if event[1] is not None and os.path.isfile(event[1]): assert len(globals.active_objects_list) == 0 try: globals.active_objects_list = pf.load_scene(event[1]) globals.scene_filename = event[1] for obj in globals.active_objects_list: obj.selectable = True except: print("Failed to load scene! [{0}]".format(event[1]))
def on_load_confirm(self, event): pf.unregister_event_handler(EVENT_FILE_CHOOSER_OKAY, MenuVC.on_load_confirm) pf.unregister_event_handler(EVENT_FILE_CHOOSER_CANCEL, MenuVC.on_load_cancel) assert self.fc is not None self.fc.hide() self.fc = None self.activate() import os.path if os.path.isfile(event): new_map = map.Map.from_filepath(event) if new_map is not None: globals.active_map = new_map pf.new_game_string(globals.active_map.pfmap_str()) pf.set_minimap_position( ui.LEFT_PANE_WIDTH + MINIMAP_PX_WIDTH / cos(pi / 4) / 2 + 10, pf.get_resolution()[1] - MINIMAP_PX_WIDTH / cos(pi / 4) / 2 - 10) self.view.hide()
import views.terrain_tab_window as ttw import views.objects_tab_window as otw import views.menu_window as mw ############################################################ # Global settings # ############################################################ pf.set_ambient_light_color([1.0, 1.0, 1.0]) pf.set_emit_light_color([1.0, 1.0, 1.0]) pf.set_emit_light_pos([1024.0, 512.0, 256.0]) pf.new_game_string(globals.active_map.pfmap_str()) pf.set_minimap_position( UI_LEFT_PANE_WIDTH + MINIMAP_PX_WIDTH / cos(pi / 4) / 2 + 10, pf.get_resolution()[1] - MINIMAP_PX_WIDTH / cos(pi / 4) / 2 - 10) pf.disable_unit_selection() mouse_events.install() ############################################################ # Setup UI # ############################################################ terrain_tab_vc = ttvc.TerrainTabVC(ttw.TerrainTabWindow()) objects_tab_vc = otvc.ObjectsVC(otw.ObjectsTabWindow()) tab_bar_vc = tbvc.TabBarVC(tbw.TabBarWindow()) tab_bar_vc.push_child("Terrain", terrain_tab_vc) tab_bar_vc.push_child("Objects", objects_tab_vc) tab_bar_vc.activate()
def __init__(self): _, resy = pf.get_resolution() super(ObjectsTabWindow, self).__init__("ObjectsTab", (0, TAB_BAR_HEIGHT + 1, LEFT_PANE_WIDTH, resy - TAB_BAR_HEIGHT - 1), NK_WINDOW_BORDER)