def __init__(self, x, y, w, h, switch=False, allow_offset=False, group=groups.buttons): self.x = x self.y = y self.w = w self.h = h self.color = (0, 0, 0, 100) self.switch = switch #clicked switch shadowbuttons won't highlight global button_status self.status = button_status.NORMAL self.bg = None self.switch_status = False self.visible = True self.allow_offset = allow_offset self.rect = draw.create_rect(x=x, y=y, w=w, h=h, color=self.color, group=group) draw.hide_rect(self.rect)
def init_graphics(self): self.title = draw.create_text(x=self.gw.screen_width - 80, y=376, align='left', t='map editor', c=(255, 255, 255), s=10, group=groups.menu_text) self.add_obj(self.title, draw.go.TEXT) self.text_load = draw.create_text(x=20, y=340, align='left', t='load map', c=(255, 255, 255), s=10, group=groups.menu_text) self.add_obj(self.text_load, draw.go.TEXT) self.topbar = draw.create_rect(x=0, y=self.gw.screen_width - 30, w=self.gw.screen_width, h=30, color=(50, 50, 50, 255), group=groups.menu_rect_back) self.add_obj(self.topbar, draw.go.RECT) self.button_new = button.Button(0, 370, 80, 30, text="new map") self.add_obj(self.button_new, draw.go.BUTTON) utils.mkdir2("maps") #create buttons for every map map_names = utils.list_dirs("./maps") if len(map_names) == 0: draw.change_text(self.text_load, "no maps found") map_names = sorted(map_names) print(map_names) offset = 0 grid = 4 offx = 20 offy = 300 # TODO use utils.grid_coords() method! for mn in map_names: x = int(math.fmod(offset, grid)) y = math.floor(offset / grid) mb = button.Button(offx + (x * 90), offy - (y * 40), 80, 30, text=mn) self.add_obj(mb, draw.go.BUTTON) self.buttons_maps.append(mb) offset += 1
def init_graphics(self): self.title = draw.create_text(x=10, y=self.gw.screen_height - 15, xc='left', yc='bottom', t='map editor settings', c=(200, 200, 200), s=10) self.add_obj(self.title, draw.go.TEXT) self.topbar = draw.create_rect(x=0, y=self.gw.screen_height - 30, w=self.gw.screen_width, h=30, color=(50, 50, 50, 255), group=groups.RECT) self.add_obj(self.topbar, draw.go.RECT) self.button_back = button.Button(10, 10, 100, 30, text='back') self.add_obj(self.button_back, draw.go.BUTTON)
def add_objects( list_found): global list_object global list_types global list_str global index global hl_rect for no in list_found: # only add if allow_offset is True if not draw.allow_offset(no[0],no[1]): continue lin = 0 already = False for lo in list_object: if lo == no[0] and list_types[lin] == no[1]: # already being tracked already = True break lin+=1 if not already: list_object.append( no[0] ) list_types.append( no[1] ) list_str.append( draw.name( no[0], no[1])) index = len(list_object) - 1 pos = draw.get_pos(no[0], no[1]) size = draw.size(no[0], no[1]) if no[1] == draw.go.TEXT: if draw.text_center( no[0] ): pos = (pos[0] - (size[0] / 2), pos[1]) if hl_rect == None: # create new highlight rect hl_rect = draw.create_rect(pos[0], pos[1],size[0], size[1],color=(255,255,0,150 ), group=groups.offsetter) else: # replace old highlight rect draw.set_pos(hl_rect, draw.go.RECT, pos[0], pos[1]) draw.rect_resize(hl_rect, size[0],size[1])
def add_object(obj, obj_type, name=""): # check if that object is already tracked global list_object global list_types global index global hl_rect lin = 0 for lo in list_object: if lo == obj and list_types[lin] == obj_type: print("this object is already being tracked") # highlight it though index = lin pos = draw.get_pos(obj, obj_type) size = draw.size(obj, obj_type) draw.set_pos(hl_rect, draw.go.RECT, pos[0], pos[1]) size = draw.size(obj, obj_type) draw.rect_resize(hl_rect, size[0],size[1]) return lin+=1 list_object.append(obj) list_types.append(obj_type) global list_str index = len(list_object) - 1 if name == "": list_str.append(draw.name(obj, obj_type)) print("added ["+ draw.go.name(obj_type) +"] object "+ list_str[index] + " to offsetter") pos = draw.get_pos(obj, obj_type) size = draw.size(obj, obj_type) if hl_rect == None: # create new highlight rect hl_rect = draw.create_rect(pos[0], pos[1],size[0], size[1],color=(255,255,0,150 )) else: # replace old highlight rect draw.set_pos(hl_rect, draw.go.RECT, pos[0], pos[1]) draw.rect_resize(hl_rect, size[0],size[1])
def __init__(self, x, y, w, h, text="none", color=(100, 100, 100, 255), switch=False, allow_offset=True): self.x = x self.y = y self.w = w self.h = h self.text = text self.c = color self.ch = utils.brighten_color(color) self.co = (150, 150, 100, 255) global button_status self.status = button_status.NORMAL self.switch = switch self.bg = None self.allow_offset = allow_offset self.switch_status = False # false - off, true - on # a menu will add an unique id to each button added for identification self.tid = draw.create_text(x=x + w / 2, y=y + h / 2 - 5, align='center', t=text, c=(255, 255, 255), s=12, group=groups.button_text) self.visible = True self.rect = draw.create_rect(x=x, y=y, w=w, h=h, color=color, group=groups.buttons)
def init_graphics(self): self.title = draw.create_text(x=self.gw.screen_width - 80, y=376, align='left', t='map editor', c=(255, 255, 255), s=10, group=groups.menu_text) self.add_obj(self.title, draw.go.TEXT) self.text_move = draw.create_text(x=self.gw.screen_width - 50, y=340, align='center', t='move map', c=(255, 255, 255), s=10, group=groups.menu_text) self.add_obj(self.text_move, draw.go.TEXT) self.text_move2 = draw.create_text(x=self.gw.screen_width - 50, y=325, align='center', t='with arrows', c=(255, 255, 255), s=10, group=groups.menu_text) self.add_obj(self.text_move2, draw.go.TEXT) self.text_editing = draw.create_text(x=self.gw.screen_width - 50, y=290, align='center', t='editing', c=(255, 255, 255), s=10, group=groups.menu_text) self.add_obj(self.text_editing, draw.go.TEXT) self.text_mapname = draw.create_text(x=self.gw.screen_width - 50, y=275, align='center', t=self.map.name, c=(255, 255, 255), s=10, group=groups.menu_text) self.add_obj(self.text_mapname, draw.go.TEXT) self.text_changes = draw.create_text(x=self.gw.screen_width - 50, y=100, align='center', t="_", c=(200, 20, 20), s=10, group=groups.menu_text) self.add_obj(self.text_changes, draw.go.TEXT) self.topbar = draw.create_rect(x=0, y=self.gw.screen_height - 30, w=self.gw.screen_width, h=30, color=(50, 50, 50, 255), group=groups.menu_rect_back) self.add_obj(self.topbar, draw.go.RECT) self.left_sidebar = draw.create_rect(x=0, y=0, w=100, h=self.gw.screen_height, color=(50, 50, 50, 255), group=groups.menu_rect_back) self.add_obj(self.left_sidebar, draw.go.RECT) self.right_sidebar = draw.create_rect(x=self.gw.screen_width - 100, y=0, w=100, h=self.gw.screen_height, color=(50, 50, 50, 255), group=groups.menu_rect_back) self.add_obj(self.right_sidebar, draw.go.RECT) if not self.map.isinit: self.map.init_graphics() self.map.update_graphics() self.button_save = button.Button(self.gw.screen_width - 90, 50, 80, 30, text="save map") self.add_obj(self.button_save, draw.go.BUTTON) self.button_exit = button.Button(self.gw.screen_width - 90, 10, 80, 30, text="exit map") self.add_obj(self.button_exit, draw.go.BUTTON) self.subinit() self.timer_changes = utils.Timer(interval=2.0)