def __init__(self, tool): Panel.__init__(self) self.tool = tool level = tool.editor.level if hasattr(level, 'players'): players = level.players or ["[No players]"] else: players = ["Player"] self.players = players tableview = TableView(columns=[ TableColumn("Player Name", 200), ]) tableview.index = 0 tableview.num_rows = lambda: len(players) tableview.row_data = lambda i: (players[i],) tableview.row_is_selected = lambda x: x == tableview.index tableview.zebra_color = (0, 0, 0, 48) def selectTableRow(i, evt): tableview.index = i tableview.click_row = selectTableRow self.table = tableview l = Label("Player: ") col = [l, tableview] gotoButton = Button("Goto Player", action=self.tool.gotoPlayer) gotoCameraButton = Button("Goto Player's View", action=self.tool.gotoPlayerCamera) moveButton = Button("Move Player", action=self.tool.movePlayer) moveToCameraButton = Button("Align Player to Camera", action=self.tool.movePlayerToCamera) col.extend([gotoButton, gotoCameraButton, moveButton, moveToCameraButton]) col = Column(col) self.add(col) self.shrink_wrap()
def removePreset(self): """ Brings up a panel to remove presets. """ panel = Dialog() p = self.getBrushFileList() if not p: alert('No presets saved') return def okPressed(): panel.dismiss() name = p[presetTable.selectedIndex] + ".preset" os.remove(os.path.join(directories.brushesDir, name)) self.tool.showPanel() def selectTableRow(i, evt): presetTable.selectedIndex = i if evt.num_clicks == 2: okPressed() presetTable = TableView(columns=(TableColumn("", 200),)) presetTable.num_rows = lambda: len(p) presetTable.row_data = lambda i: (p[i],) presetTable.row_is_selected = lambda x: x == presetTable.selectedIndex presetTable.click_row = selectTableRow presetTable.selectedIndex = 0 choiceCol = Column((ValueDisplay(width=200, get_value=lambda: "Select preset to delete"), presetTable)) okButton = Button("OK", action=okPressed) cancelButton = Button("Cancel", action=panel.dismiss) row = Row([okButton, cancelButton]) panel.add(Column((choiceCol, row))) panel.shrink_wrap() panel.present()
def __init__(self, tool): Panel.__init__(self) self.tool = tool self.player_UUID = {} self.level = tool.editor.level if hasattr(self.level, 'players'): players = self.level.players or ["[No players]"] if not self.level.oldPlayerFolderFormat: for player in players: if player != "Player" and player != "[No players]": self.player_UUID[version_utils.getPlayerNameFromUUID(player)] = player if "Player" in players: self.player_UUID["Player"] = "Player" if "[No players]" not in players: players = sorted(self.player_UUID.keys(), key=lambda x: False if x == "Player" else x.lower()) else: players = ["Player"] self.players = players max_height = self.tool.editor.mainViewport.height - self.tool.editor.netherPanel.height - self.tool.editor.subwidgets[0].height - self.margin - 2 addButton = Button("Add Player", action=self.tool.addPlayer) removeButton = Button("Remove Player", action=self.tool.removePlayer) gotoButton = Button("Goto Player", action=self.tool.gotoPlayer) gotoCameraButton = Button("Goto Player's View", action=self.tool.gotoPlayerCamera) moveButton = Button("Move Player", action=self.tool.movePlayer) moveToCameraButton = Button("Align Player to Camera", action=self.tool.movePlayerToCamera) reloadSkin = Button("Reload Skins", action=self.tool.reloadSkins, tooltipText="This pulls skins from the online server, so this may take a while") print max_height max_height -= sum((a.height for a in (addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin))) print max_height tableview = TableView(columns=[ TableColumn("Player Name(s):", 200), ], height=max_height) tableview.index = 0 tableview.num_rows = lambda: len(players) tableview.row_data = lambda i: (players[i],) tableview.row_is_selected = lambda x: x == tableview.index tableview.zebra_color = (0, 0, 0, 48) def selectTableRow(i, evt): tableview.index = i tableview.click_row = selectTableRow self.table = tableview col = [self.table] col.extend([addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin]) col = Column(col, margin=0, spacing=2) col.shrink_wrap() self.add(col) self.shrink_wrap()
def __init__(self, inventory, data, *args, **kwargs): Dialog.__init__(self, *args, **kwargs) self.inventory = inventory slot, id, count, damage = data self.former_id_text = id self.slot = slot self.id = TextFieldWrapped(text=str(id), doNotTranslate=True, width=300) self.id.change_action = self.text_entered self.id.escape_action = self.cancel self.id.enter_action = self.ok self.count = IntField(text="%s" % count, min=0, max=64) self.damage = IntField(text="%s" % damage, min=0, max=os.sys.maxint) header = Label(_("Inventory Slot #%s") % slot, doNotTranslate=True) row = Row([ Label("id"), self.id, Label("Count"), self.count, Label("Damage"), self.damage, ]) self.matching_items = [ mclangres.translate(k) for k in map_items.keys() ] self.matching_items.sort() self.selected_item_index = None if id in self.matching_items: self.selected_item_index = self.matching_items.index(id) self.tableview = tableview = TableView( columns=[TableColumn("", 415, 'l')]) tableview.num_rows = lambda: len(self.matching_items) tableview.row_data = lambda x: (self.matching_items[x], ) tableview.row_is_selected = lambda x: x == self.selected_item_index tableview.click_row = self.select_tablerow buttons = Row([ Button("Save", action=self.dismiss), Button("Cancel", action=self.cancel) ]) col = Column([header, row, tableview, buttons], spacing=2) self.add(col) self.shrink_wrap() try: self.tableview.rows.scroll_to_item(self.selected_item_index) except Exception, e: print e pass
def __init__(self, tool): Panel.__init__(self) self.tool = tool self.player_UUID = {} self.level = tool.editor.level if hasattr(self.level, 'players'): players = self.level.players or ["[No players]"] if not self.level.oldPlayerFolderFormat: for player in players: if player != "Player": self.player_UUID[ version_compatability_utils.getPlayerNameFromUUID( player)] = player self.player_UUID["Player"] = "Player" players = self.player_UUID.keys() else: players = ["Player"] self.players = players tableview = TableView(columns=[ TableColumn("Player Name", 200), ]) tableview.index = 0 tableview.num_rows = lambda: len(players) tableview.row_data = lambda i: (players[i], ) tableview.row_is_selected = lambda x: x == tableview.index tableview.zebra_color = (0, 0, 0, 48) def selectTableRow(i, evt): tableview.index = i tableview.click_row = selectTableRow self.table = tableview l = Label("Player: ") col = [l, tableview] gotoButton = Button("Goto Player", action=self.tool.gotoPlayer) gotoCameraButton = Button("Goto Player's View", action=self.tool.gotoPlayerCamera) moveButton = Button("Move Player", action=self.tool.movePlayer) moveToCameraButton = Button("Align Player to Camera", action=self.tool.movePlayerToCamera) col.extend( [gotoButton, gotoCameraButton, moveButton, moveToCameraButton]) col = Column(col) self.add(col) self.shrink_wrap()
def __init__(self, tool): Panel.__init__(self) self.tool = tool self.player_UUID = {} self.level = tool.editor.level if hasattr(self.level, 'players'): players = self.level.players or ["[No players]"] if not self.level.oldPlayerFolderFormat: for player in players: if player != "Player": self.player_UUID[version_utils.getPlayerNameFromUUID(player)] = player self.player_UUID["Player"] = "Player" players = self.player_UUID.keys() else: players = ["Player"] self.players = players tableview = TableView(columns=[ TableColumn("Player Name", 200), ]) tableview.index = 0 tableview.num_rows = lambda: len(players) tableview.row_data = lambda i: (players[i],) tableview.row_is_selected = lambda x: x == tableview.index tableview.zebra_color = (0, 0, 0, 48) def selectTableRow(i, evt): tableview.index = i tableview.click_row = selectTableRow self.table = tableview l = Label("Player: ") col = [l, self.table] addButton = Button("Add Player", action=self.tool.addPlayer) removeButton = Button("Remove Player", action=self.tool.removePlayer) gotoButton = Button("Goto Player", action=self.tool.gotoPlayer) gotoCameraButton = Button("Goto Player's View", action=self.tool.gotoPlayerCamera) moveButton = Button("Move Player", action=self.tool.movePlayer) moveToCameraButton = Button("Align Player to Camera", action=self.tool.movePlayerToCamera) col.extend([addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton]) col = Column(col) self.add(col) self.shrink_wrap()
def __init__(self, tool): Panel.__init__(self) self.tool = tool level = tool.editor.level if hasattr(level, 'players'): players = level.players or ["[No players]"] else: players = ["Player"] self.players = players tableview = TableView(columns=[ TableColumn("Player Name", 200), ]) tableview.index = 0 tableview.num_rows = lambda: len(players) tableview.row_data = lambda i: (players[i], ) tableview.row_is_selected = lambda x: x == tableview.index tableview.zebra_color = (0, 0, 0, 48) def selectTableRow(i, evt): tableview.index = i tableview.click_row = selectTableRow self.table = tableview l = Label("Player: ") col = [l, tableview] gotoButton = Button("Goto Player", action=self.tool.gotoPlayer) gotoCameraButton = Button("Goto Player's View", action=self.tool.gotoPlayerCamera) moveButton = Button("Move Player", action=self.tool.movePlayer) moveToCameraButton = Button("Align Player to Camera", action=self.tool.movePlayerToCamera) col.extend( [gotoButton, gotoCameraButton, moveButton, moveToCameraButton]) col = Column(col) self.add(col) self.shrink_wrap()
def build_inventory(self, items): inventory = self.data.get('Player', {}).get('Inventory', TAG_List()) or self.data.get('Inventory', TAG_List()) rows = [] items = items[0] slots = [["%s"%i,"","0","0"] for i in range(36)] slots += [["%s"%i,"","0","0"] for i in range(100, 104)] slots_set = [] for item in items: #&# Prototype for blocks/items names item_dict = mcitems.items.get(item['id'].value, None) if item_dict == None: name = item['id'].value else: if type(item_dict['name']) == list: if int(item['Damage'].value) >= len(item_dict['name']): block_id = map_block.get(item['id'].value, None) name = alphaMaterials.get((int(block_id), int(item['Damage'].value))).name.rsplit('(', 1)[0].strip() else: name = item_dict['name'][int(item['Damage'].value)] else: name = item_dict['name'] s = int(item['Slot'].value) slots_set.append(s) if s >= 100: s = s - 100 + 36 slots[s] = item['Slot'].value, mclangres.translate(name), item['Count'].value, item['Damage'].value #slots[s] = item['Slot'].value, item['id'].value.split(':')[-1], item['Count'].value, item['Damage'].value #&# width = self.side_panel_width - self.margin * 5 c0w = max(15, self.font.size("000")[0]) + 4 c2w = max(15, self.font.size("00")[0]) + 4 c3w = max(15, self.font.size("000")[0]) + 4 c1w = width - c0w - c2w - c3w font_height = self.font.size("qd")[1] tableCols = [TableColumn("#", c0w), TableColumn("ID", c1w), TableColumn("C", c2w), TableColumn("D", c3w), ] height = self.displayRow.subwidgets[0].height table = TableView(height=height - (self.margin * 2), width=width, nrows=((height - (self.margin * 2) - font_height / 2) / font_height), columns=tableCols, row_height=font_height, header_height=font_height / 2) table.rows.tooltipText = "Double-click to edit" table.selected_row = None table.slots = slots def num_rows(): return len(slots) table.num_rows = num_rows def row_data(n): return slots[n] table.row_data = row_data def click_row(n, e): table.selected_row = n if e.num_clicks > 1: SlotEditor(table, row_data(n)).present() table.click_row = click_row def row_is_selected(n): return n == table.selected_row table.row_is_selected = row_is_selected def change_value(data): s, i, c, d = data s = int(s) s_idx = 0 #&# Prototype for blocks/items names name, state = map_items.get(mclangres.untranslate(i), (i, '0')) if ':' not in name: name = 'minecraft:%s'%name #&# if s in slots_set: for slot in inventory: if slot['Slot'].value == s: if not i or int(c) < 1: del inventory[s_idx] i = "" c = u'0' d = u'0' else: #&# Prototype for blocks/items names #slot['id'].value = 'minecraft:%s'%i slot['id'].value = name #&# slot['Count'].value = int(c) slot['Damage'].value = int(state) break s_idx += 1 else: new_slot = TAG_Compound() new_slot['Slot'] = TAG_Byte(s) #&# Prototype for blocka/items names #new_slot['id'] = TAG_String('minecraft:%s'%i) new_slot['id'] = TAG_String(name) #&# new_slot['Count'] = TAG_Byte(int(c)) new_slot['Damage'] = TAG_Short(int(state)) idx = s for slot in inventory: if slot['Slot'].value >= s: idx = slot['Slot'].value break inventory.insert(s, new_slot) slots_set.append(s) #&# Prototype for blocks/items names # if i == name: # i = name #&# if s >= 100: n = s - 100 + 36 else: n = s table.slots[n] = slots[n] = s, i, c, state table.change_value = change_value rows.append(table) return rows
def build_inventory(self, items): print "build_inventory" print "Inventory" in self.data.keys() # print type(self.data['Inventory']) inventory = self.data.get('Player', {}).get('Inventory', TAG_List()) or self.data.get('Inventory', TAG_List()) rows = [] items = items[0] slots = [["%s"%i,"","0","0"] for i in range(36)] slots_set = [] for item in items: s = int(item['Slot'].value) slots_set.append(s) slots[s] = item['Slot'].value, item['id'].value.split(':')[-1], item['Count'].value, item['Damage'].value width = self.width / 2 - self.margin * 4 c0w = max(15, self.font.size("00")[0]) + 4 c2w = max(15, self.font.size("00")[0]) + 4 c3w = max(15, self.font.size("000")[0]) + 4 c1w = width - c0w - c2w - c3w font_height = self.font.size("qd")[1] tableCols = [TableColumn("#", c0w), TableColumn("ID", c1w), TableColumn("C", c2w), TableColumn("D", c3w), ] height = self.displayRow.subwidgets[0].height table = TableView(height=height - (self.margin * 2), width=width, nrows=((height - (self.margin * 2) - font_height / 2) / font_height), columns=tableCols, row_height=font_height, header_height=font_height / 2) table.rows.tooltipText = "Double-click to edit" table.selected_row = None table.slots = slots def num_rows(): return len(slots) table.num_rows = num_rows def row_data(n): return slots[n] table.row_data = row_data def click_row(n, e): table.selected_row = n if e.num_clicks > 1: SlotEditor(table, row_data(n)).present() table.click_row = click_row def row_is_selected(n): return n == table.selected_row table.row_is_selected = row_is_selected def change_value(data): s, i, c, d = data s = int(s) s_idx = 0 if s in slots_set: # for slot in self.data['Player']['Inventory']: for slot in inventory: if slot['Slot'].value == s: if not i or int(c) < 1: del inventory[s_idx] i = "" c = u'0' d = u'0' else: slot['id'].value = 'minecraft:%s'%i slot['Count'].value = int(c) slot['Damage'].value = int(d) break s_idx += 1 else: new_slot = TAG_Compound() new_slot['Slot'] = TAG_Byte(s) new_slot['id'] = TAG_String('minecraft:%s'%i) new_slot['Count'] = TAG_Byte(int(c)) new_slot['Damage'] = TAG_Short(int(d)) idx = s for slot in inventory: if slot['Slot'].value >= s: idx = slot['Slot'].value break inventory.insert(s, new_slot) slots_set.append(s) table.slots[s] = slots[s] = s, i, c, d table.change_value = change_value rows.append(table) return rows
def build_inventory(self, items): inventory = self.data.get('Player', {}).get( 'Inventory', TAG_List()) or self.data.get('Inventory', TAG_List()) rows = [] items = items[0] slots = [["%s" % i, "", "0", "0"] for i in range(36)] slots += [["%s" % i, "", "0", "0"] for i in range(100, 104)] slots_set = [] for item in items: #&# Prototype for blocks/items names item_dict = mcitems.items.get(item['id'].value, None) if item_dict == None: name = item['id'].value else: if type(item_dict['name']) == list: if int(item['Damage'].value) >= len(item_dict['name']): block_id = map_block.get(item['id'].value, None) name = alphaMaterials.get( (int(block_id), int(item['Damage'].value))).name.rsplit( '(', 1)[0].strip() else: name = item_dict['name'][int(item['Damage'].value)] else: name = item_dict['name'] s = int(item['Slot'].value) slots_set.append(s) if s >= 100: s = s - 100 + 36 slots[s] = item['Slot'].value, mclangres.translate( name), item['Count'].value, item['Damage'].value #slots[s] = item['Slot'].value, item['id'].value.split(':')[-1], item['Count'].value, item['Damage'].value #&# width = self.side_panel_width - self.margin * 5 c0w = max(15, self.font.size("000")[0]) + 4 c2w = max(15, self.font.size("00")[0]) + 4 c3w = max(15, self.font.size("000")[0]) + 4 c1w = width - c0w - c2w - c3w font_height = self.font.size("qd")[1] tableCols = [ TableColumn("#", c0w), TableColumn("ID", c1w), TableColumn("C", c2w), TableColumn("D", c3w), ] height = self.displayRow.subwidgets[0].height table = TableView(height=height - (self.margin * 2), width=width, nrows=((height - (self.margin * 2) - font_height / 2) / font_height), columns=tableCols, row_height=font_height, header_height=font_height / 2) table.rows.tooltipText = "Double-click to edit" table.selected_row = None table.slots = slots def num_rows(): return len(slots) table.num_rows = num_rows def row_data(n): return slots[n] table.row_data = row_data def click_row(n, e): table.selected_row = n if e.num_clicks > 1: SlotEditor(table, row_data(n)).present() table.click_row = click_row def row_is_selected(n): return n == table.selected_row table.row_is_selected = row_is_selected def change_value(data): s, i, c, d = data s = int(s) s_idx = 0 #&# Prototype for blocks/items names name, state = map_items.get(mclangres.untranslate(i), (i, '0')) if ':' not in name: name = 'minecraft:%s' % name #&# if s in slots_set: for slot in inventory: if slot['Slot'].value == s: if not i or int(c) < 1: del inventory[s_idx] i = "" c = u'0' d = u'0' else: #&# Prototype for blocks/items names #slot['id'].value = 'minecraft:%s'%i slot['id'].value = name #&# slot['Count'].value = int(c) slot['Damage'].value = int(state) break s_idx += 1 else: new_slot = TAG_Compound() new_slot['Slot'] = TAG_Byte(s) #&# Prototype for blocka/items names #new_slot['id'] = TAG_String('minecraft:%s'%i) new_slot['id'] = TAG_String(name) #&# new_slot['Count'] = TAG_Byte(int(c)) new_slot['Damage'] = TAG_Short(int(state)) idx = s for slot in inventory: if slot['Slot'].value >= s: idx = slot['Slot'].value break inventory.insert(s, new_slot) slots_set.append(s) #&# Prototype for blocks/items names # if i == name: # i = name #&# if s >= 100: n = s - 100 + 36 else: n = s table.slots[n] = slots[n] = s, i, c, state table.change_value = change_value rows.append(table) return rows
def editMonsterSpawner(self, point): mobs = self.mobs tileEntity = self.editor.level.tileEntityAt(*point) undoBackupEntityTag = copy.deepcopy(tileEntity) if not tileEntity: tileEntity = pymclevel.TAG_Compound() tileEntity["id"] = pymclevel.TAG_String("MobSpawner") tileEntity["x"] = pymclevel.TAG_Int(point[0]) tileEntity["y"] = pymclevel.TAG_Int(point[1]) tileEntity["z"] = pymclevel.TAG_Int(point[2]) tileEntity["Delay"] = pymclevel.TAG_Short(120) tileEntity["EntityId"] = pymclevel.TAG_String(mobs[0]) self.editor.level.addTileEntity(tileEntity) panel = Dialog() def addMob(id): if id not in mobs: mobs.insert(0, id) mobTable.selectedIndex = 0 def selectTableRow(i, evt): if mobs[i] == "[Custom]": id = input_text("Type in an EntityID for this spawner. Invalid IDs may crash Minecraft.", 150) if id: addMob(id) else: return mobTable.selectedIndex = mobs.index(id) else: mobTable.selectedIndex = i if evt.num_clicks == 2: panel.dismiss() mobTable = TableView(columns=( TableColumn("", 200), ) ) mobTable.num_rows = lambda: len(mobs) mobTable.row_data = lambda i: (mobs[i],) mobTable.row_is_selected = lambda x: x == mobTable.selectedIndex mobTable.click_row = selectTableRow mobTable.selectedIndex = 0 def selectedMob(): return mobs[mobTable.selectedIndex] id = tileEntity["EntityId"].value addMob(id) mobTable.selectedIndex = mobs.index(id) choiceCol = Column((ValueDisplay(width=200, get_value=lambda: selectedMob() + " spawner"), mobTable)) okButton = Button("OK", action=panel.dismiss) panel.add(Column((choiceCol, okButton))) panel.shrink_wrap() panel.present() class MonsterSpawnerEditOperation(Operation): def __init__(self, tool, level): self.tool = tool self.level = level self.undoBackupEntityTag = undoBackupEntityTag self.canUndo = False def perform(self, recordUndo=True): if self.level.saving: alert("Cannot perform action while saving is taking place") return self.level.addTileEntity(tileEntity) self.canUndo = True def undo(self): self.redoBackupEntityTag = copy.deepcopy(tileEntity) self.level.addTileEntity(self.undoBackupEntityTag) return pymclevel.BoundingBox(pymclevel.TileEntity.pos(tileEntity), (1, 1, 1)) def redo(self): self.level.addTileEntity(self.redoBackupEntityTag) return pymclevel.BoundingBox(pymclevel.TileEntity.pos(tileEntity), (1, 1, 1)) if id != selectedMob(): tileEntity["EntityId"] = pymclevel.TAG_String(selectedMob()) op = MonsterSpawnerEditOperation(self.editor, self.editor.level) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit()
def __init__old(self, blockInfo, materials, *a, **kw): self.root = get_root() self.allowWildcards = False Dialog.__init__(self, *a, **kw) panelWidth = 518 self.click_outside_response = 0 self.materials = materials self.anySubtype = blockInfo.wildcard self.matchingBlocks = materials.allBlocks try: self.selectedBlockIndex = self.matchingBlocks.index(blockInfo) except ValueError: self.selectedBlockIndex = 0 for i, b in enumerate(self.matchingBlocks): if blockInfo.ID == b.ID and blockInfo.blockData == b.blockData: self.selectedBlockIndex = i break lbl = Label("Search") # lbl.rect.topleft = (0,0) fld = TextFieldWrapped(300) # fld.rect.topleft = (100, 10) # fld.centery = lbl.centery # fld.left = lbl.right fld.change_action = self.textEntered fld.enter_action = self.ok fld.escape_action = self.cancel self.awesomeField = fld searchRow = Row((lbl, fld)) def formatBlockName(x): block = self.matchingBlocks[x] r = "{name}".format(name=block.name) if block.aka: r += " [{0}]".format(block.aka) return r def formatBlockID(x): block = self.matchingBlocks[x] ident = "({id}:{data})".format(id=block.ID, data=block.blockData) return ident tableview = TableView(columns=[ TableColumn(" ", 24, "l", lambda x: ""), TableColumn("Name", 415, "l", formatBlockName), TableColumn("ID", 45, "l", formatBlockID) ]) tableicons = [ blockview.BlockView(materials) for i in xrange(tableview.rows.num_rows()) ] for t in tableicons: t.size = (16, 16) t.margin = 0 icons = Column(tableicons, spacing=2) # tableview.margin = 5 tableview.num_rows = lambda: len(self.matchingBlocks) tableview.row_data = lambda x: (self.matchingBlocks[x], x, x) tableview.row_is_selected = lambda x: x == self.selectedBlockIndex tableview.click_row = self.selectTableRow draw_table_cell = tableview.draw_table_cell def draw_block_table_cell(surf, i, data, cell_rect, column): if isinstance(data, Block): tableicons[i - tableview.rows.scroll].blockInfo = data else: draw_table_cell(surf, i, data, cell_rect, column) tableview.draw_table_cell = draw_block_table_cell tableview.width = panelWidth tableview.anchor = "lrbt" # self.add(tableview) self.tableview = tableview tableWidget = Widget() tableWidget.add(tableview) tableWidget.shrink_wrap() def wdraw(*args): for t in tableicons: t.blockInfo = materials.Air tableWidget.draw = wdraw self.blockButton = blockView = thumbview.BlockThumbView( materials, self.blockInfo) blockView.centerx = self.centerx blockView.top = tableview.bottom # self.add(blockview) but = Button("OK") but.action = self.ok but.top = blockView.bottom but.centerx = self.centerx but.align = "c" but.height = 30 if self.allowWildcards: # self.add(but) anyRow = CheckBoxLabel( "Any Subtype", ref=AttrRef(self, 'anySubtype'), tooltipText= "Replace blocks with any data value. Only useful for Replace operations." ) col = Column((searchRow, tableWidget, anyRow, blockView, but)) else: col = Column((searchRow, tableWidget, blockView, but)) col.anchor = "wh" self.anchor = "wh" panel = GLBackground() panel.bg_color = [i / 255. for i in self.bg_color] panel.anchor = "tlbr" self.add(panel) self.add(col) self.add(icons) icons.topleft = tableWidget.topleft icons.top += tableWidget.margin + 30 icons.left += tableWidget.margin + 4 self.shrink_wrap() panel.size = self.size try: self.tableview.rows.scroll_to_item(self.selectedBlockIndex) except: pass
def build_inventory(self, items): if 'playerGameType' in self.tree.get_item_parent(self.displayed_item)[9].keys(): player = True else: player = False inventory = self.tree.get_item_parent(self.displayed_item)[9].get('Inventory', TAG_List()) rows = [] items = items[0] slots = [["%s"%i,"","0","0"] for i in range(36)] slots += [["%s"%i,"","0","0"] for i in range(100, 104)] slots_set = [] for item, i in zip(items, range(len(items))): #&# Prototype for blocks/items names item_dict = mcitems.items.get(item['id'].value, None) if item_dict == None: name = item['id'].value else: if type(item_dict['name']) == list: if int(item['Damage'].value) >= len(item_dict['name']): block_id = map_block.get(item['id'].value, None) name = alphaMaterials.get((int(block_id), int(item['Damage'].value))).name.rsplit('(', 1)[0].strip() else: name = item_dict['name'][int(item['Damage'].value)] else: name = item_dict['name'] s = i _s = 0 + i if player: s = int(item['Slot'].value) _s = 0 + s slots_set.append(s) if s >= 100: s = s - 100 + 36 slots[s] = _s, mclangres.translate(name), item['Count'].value, item['Damage'].value #slots[s] = item['Slot'].value, item['id'].value.split(':')[-1], item['Count'].value, item['Damage'].value #&# width = self.side_panel_width - self.margin * 5 c0w = max(15, self.font.size("000")[0]) + 4 c2w = max(15, self.font.size("00")[0]) + 4 c3w = max(15, self.font.size("000")[0]) + 4 c1w = width - c0w - c2w - c3w font_height = self.font.size("qd")[1] tableCols = [TableColumn("#", c0w), TableColumn("ID", c1w), TableColumn("C", c2w), TableColumn("D", c3w), ] height = self.displayRow.subwidgets[0].height table = TableView(height=height - (self.margin * 2), width=width, nrows=((height - (self.margin * 2) - font_height / 2) / font_height), columns=tableCols, row_height=font_height, header_height=font_height / 2) table.rows.tooltipText = "Double-click to edit" table.selected_row = None table.slots = slots def num_rows(): return len(slots) table.num_rows = num_rows def row_data(n): return slots[n] table.row_data = row_data def click_row(n, e): table.focus() table.selected_row = n if e.num_clicks > 1: SlotEditor(table, row_data(n)).present() table.click_row = click_row def row_is_selected(n): return n == table.selected_row table.row_is_selected = row_is_selected def change_value(data): s, i, c, d = data s = int(s) s_idx = 0 #&# Prototype for blocks/items names name, state = map_items.get(mclangres.untranslate(i), (i, '0')) if ':' not in name: name = 'minecraft:%s'%name #&# if s in slots_set: for slot in inventory: ok1 = False if player: ok1 = slot['Slot'].value == s else: ok1 = inventory.index(slot) == s if ok1: if not i or int(c) < 1: del inventory[s_idx] i = "" c = u'0' d = u'0' else: #&# Prototype for blocks/items names #slot['id'].value = 'minecraft:%s'%i slot['id'].value = name #&# slot['Count'].value = int(c) slot['Damage'].value = int(state) break s_idx += 1 else: new_slot = TAG_Compound() if player: new_slot['Slot'] = TAG_Byte(s) #&# Prototype for blocka/items names #new_slot['id'] = TAG_String('minecraft:%s'%i) new_slot['id'] = TAG_String(name) #&# new_slot['Count'] = TAG_Byte(int(c)) new_slot['Damage'] = TAG_Short(int(state)) idx = s for slot in inventory: ok2 = False if player: ok2 = slot['Slot'].value >= s else: ok2 = inventory.index(slot) >= s if ok2: idx = slot['Slot'].value break inventory.insert(s, new_slot) slots_set.append(s) #&# Prototype for blocks/items names # if i == name: # i = name #&# if s >= 100: n = s - 100 + 36 else: n = s table.slots[n] = slots[n] = s, i, c, state table.change_value = change_value def dispatch_key(name, evt): keyname = self.root.getKey(evt) if keyname == 'Return': SlotEditor(table, row_data(table.selected_row)).present() elif keyname == "Up" and table.selected_row > 0: table.selected_row -= 1 table.rows.scroll_to_item(table.selected_row) elif keyname == "Down" and table.selected_row < len(slots) - 1: table.selected_row += 1 table.rows.scroll_to_item(table.selected_row) elif keyname == 'Page down': table.selected_row = min(len(slots) - 1, table.selected_row + table.rows.num_rows()) elif keyname == 'Page up': table.selected_row = max(0, table.selected_row - table.rows.num_rows()) if table.rows.cell_to_item_no(0, 0) != None and (table.rows.cell_to_item_no(0, 0) + table.rows.num_rows() -1 > table.selected_row or table.rows.cell_to_item_no(0, 0) + table.rows.num_rows() -1 < table.selected_row): table.rows.scroll_to_item(table.selected_row) table.dispatch_key = dispatch_key rows.append(table) return rows
def __init__old(self, blockInfo, materials, *a, **kw): self.root = get_root() self.allowWildcards = False Dialog.__init__(self, *a, **kw) panelWidth = 518 self.click_outside_response = 0 self.materials = materials self.anySubtype = blockInfo.wildcard self.matchingBlocks = materials.allBlocks try: self.selectedBlockIndex = self.matchingBlocks.index(blockInfo) except ValueError: self.selectedBlockIndex = 0 for i, b in enumerate(self.matchingBlocks): if blockInfo.ID == b.ID and blockInfo.blockData == b.blockData: self.selectedBlockIndex = i break lbl = Label("Search") # lbl.rect.topleft = (0,0) fld = TextFieldWrapped(300) # fld.rect.topleft = (100, 10) # fld.centery = lbl.centery # fld.left = lbl.right fld.change_action = self.textEntered fld.enter_action = self.ok fld.escape_action = self.cancel self.awesomeField = fld searchRow = Row((lbl, fld)) def formatBlockName(x): block = self.matchingBlocks[x] r = "{name}".format(name=block.name) if block.aka: r += " [{0}]".format(block.aka) return r def formatBlockID(x): block = self.matchingBlocks[x] ident = "({id}:{data})".format(id=block.ID, data=block.blockData) return ident tableview = TableView(columns=[TableColumn(" ", 24, "l", lambda x: ""), TableColumn("Name", 415, "l", formatBlockName), TableColumn("ID", 45, "l", formatBlockID) ]) tableicons = [blockview.BlockView(materials) for i in range(tableview.rows.num_rows())] for t in tableicons: t.size = (16, 16) t.margin = 0 icons = Column(tableicons, spacing=2) # tableview.margin = 5 tableview.num_rows = lambda: len(self.matchingBlocks) tableview.row_data = lambda x: (self.matchingBlocks[x], x, x) tableview.row_is_selected = lambda x: x == self.selectedBlockIndex tableview.click_row = self.selectTableRow draw_table_cell = tableview.draw_table_cell def draw_block_table_cell(surf, i, data, cell_rect, column): if isinstance(data, Block): tableicons[i - tableview.rows.scroll].blockInfo = data else: draw_table_cell(surf, i, data, cell_rect, column) tableview.draw_table_cell = draw_block_table_cell tableview.width = panelWidth tableview.anchor = "lrbt" # self.add(tableview) self.tableview = tableview tableWidget = Widget() tableWidget.add(tableview) tableWidget.shrink_wrap() def wdraw(*args): for t in tableicons: t.blockInfo = materials.Air tableWidget.draw = wdraw self.blockButton = blockView = thumbview.BlockThumbView(materials, self.blockInfo) blockView.centerx = self.centerx blockView.top = tableview.bottom # self.add(blockview) but = Button("OK") but.action = self.ok but.top = blockView.bottom but.centerx = self.centerx but.align = "c" but.height = 30 if self.allowWildcards: # self.add(but) anyRow = CheckBoxLabel("Any Subtype", ref=AttrRef(self, 'anySubtype'), tooltipText="Replace blocks with any data value. Only useful for Replace operations.") col = Column((searchRow, tableWidget, anyRow, blockView, but)) else: col = Column((searchRow, tableWidget, blockView, but)) col.anchor = "wh" self.anchor = "wh" panel = GLBackground() panel.bg_color = [i / 255. for i in self.bg_color] panel.anchor = "tlbr" self.add(panel) self.add(col) self.add(icons) icons.topleft = tableWidget.topleft icons.top += tableWidget.margin + 30 icons.left += tableWidget.margin + 4 self.shrink_wrap() panel.size = self.size try: self.tableview.rows.scroll_to_item(self.selectedBlockIndex) except: pass
def __init__(self, tool): Panel.__init__(self) self.tool = tool self.player_UUID = {} self.level = tool.editor.level if hasattr(self.level, 'players'): players = self.level.players or ["[No players]"] if not self.level.oldPlayerFolderFormat: for player in players: if player != "Player" and player != "[No players]": if len(player) > 4 and player[4] == "-": os.rename(os.path.join(self.level.worldFolder.getFolderPath("playerdata"), player+".dat"), os.path.join(self.level.worldFolder.getFolderPath("playerdata"), player.replace("-", "", 1)+".dat")) player = player.replace("-", "", 1) data = version_utils.playercache.getPlayerInfo(player) if isinstance(data, tuple): self.player_UUID[data[1]] = data[0] else: self.player_UUID[player] = data if "Player" in players: self.player_UUID["Player (Single Player)"] = "Player" if "[No players]" not in players: players = sorted(self.player_UUID.keys(), key=lambda x: False if x == "Player (Single Player)" else x) else: players = ["Player (Single Player)"] self.players = players self.pages = TabPanel() tab_height = self.pages.tab_height max_height = tab_height + self.tool.editor.mainViewport.height - self.tool.editor.toolbar.height - self.tool.editor.subwidgets[0].height - self.pages.margin * 2 #-# Uncomment the following line to have a maximum height for this panel. # max_height = min(max_height, 500) self.editNBTDataButton = Button("Edit NBT", action=self.editNBTData, tooltipText="Open the NBT Explorer to edit player's attributes and inventory") addButton = Button("Add", action=self.tool.addPlayer) removeButton = Button("Remove", action=self.tool.removePlayer) gotoButton = Button("Goto", action=self.tool.gotoPlayer) gotoCameraButton = Button("Goto View", action=self.tool.gotoPlayerCamera) moveButton = Button("Move", action=self.tool.movePlayer) moveToCameraButton = Button("Align to Camera", action=self.tool.movePlayerToCamera) reloadSkin = Button("Reload Skins", action=self.tool.reloadSkins, tooltipText="This pulls skins from the online server, so this may take a while") btns = Column([self.editNBTDataButton, addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin], margin=0, spacing=2) h = max_height - btns.height - self.pages.margin * 2 - 2 - self.font.get_linesize() * 2 col = Label('') def close(): self.pages.show_page(col) self.nbttree = NBTExplorerToolPanel(self.tool.editor, nbtObject={}, height=max_height, \ close_text="Go Back", no_header=True, close_action=close, load_text=None) self.nbttree.shrink_wrap() self.nbtpage = Column([self.nbttree,]) self.nbtpage.shrink_wrap() self.pages.add_page("NBT Data", self.nbtpage) self.pages.set_rect(map(lambda x:x+self.margin, self.nbttree._rect)) tableview = TableView(nrows=(h - (self.font.get_linesize() * 2.5)) / self.font.get_linesize(), header_height=self.font.get_linesize(), columns=[TableColumn("Player Name(s):", self.nbttree.width - (self.margin * 3)),], ) tableview.index = 0 tableview.num_rows = lambda: len(players) tableview.row_data = lambda i: (players[i],) tableview.row_is_selected = lambda x: x == tableview.index tableview.zebra_color = (0, 0, 0, 48) def selectTableRow(i, evt): tableview.index = i tableview.click_row = selectTableRow def mouse_down(e): if e.button == 1 and e.num_clicks > 1: self.editNBTData() TableRowView.mouse_down(tableview.rows, e) tableview.rows.mouse_down = mouse_down tableview.rows.tooltipText = "Double-click or use the button below to edit the NBT Data." self.table = tableview col.set_parent(None) self.col = col = Column([tableview, btns], spacing=2) self.pages.add_page("Players", col, 0) self.pages.shrink_wrap() self.pages.show_page(col) self.add(self.pages) self.shrink_wrap() self.max_height = max_height
def __init__(self, tool): Panel.__init__(self) self.tool = tool self.player_UUID = {} self.level = tool.editor.level if hasattr(self.level, 'players'): players = self.level.players or ["[No players]"] if not self.level.oldPlayerFolderFormat: for player in players: if player != "Player" and player != "[No players]": self.player_UUID[version_utils.playercache. getPlayerFromUUID(player)] = player if "Player" in players: self.player_UUID["Player"] = "Player" if "[No players]" not in players: players = sorted(self.player_UUID.keys(), key=lambda x: False if x == "Player" else x) else: players = ["Player"] self.players = players max_height = self.tool.editor.mainViewport.height - self.tool.editor.toolbar.height - self.tool.editor.subwidgets[ 0].height - self.margin - 2 max_height = min(max_height, 500) addButton = Button("Add Player", action=self.tool.addPlayer) removeButton = Button("Remove Player", action=self.tool.removePlayer) gotoButton = Button("Goto Player", action=self.tool.gotoPlayer) gotoCameraButton = Button("Goto Player's View", action=self.tool.gotoPlayerCamera) moveButton = Button("Move Player", action=self.tool.movePlayer) moveToCameraButton = Button("Align Player to Camera", action=self.tool.movePlayerToCamera) reloadSkin = Button( "Reload Skins", action=self.tool.reloadSkins, tooltipText= "This pulls skins from the online server, so this may take a while" ) # The Label("qb", doNotTranslate=True) is not nice, but is used to have a correct layout for the table. btns = (Label("qb", doNotTranslate=True), addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin) max_height -= sum((a.height for a in btns)) - len(btns) * 2 tableview = TableView(nrows=0, row_height=self.font.size(" ")[1], columns=[ TableColumn("Player Name(s):", 200), ], height=max_height) tableview.index = 0 tableview.num_rows = lambda: len(players) tableview.row_data = lambda i: (players[i], ) tableview.row_is_selected = lambda x: x == tableview.index tableview.zebra_color = (0, 0, 0, 48) def selectTableRow(i, evt): tableview.index = i tableview.click_row = selectTableRow self.table = tableview col = [self.table] col.extend([ addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin ]) col = Column(col, spacing=2) col.shrink_wrap() self.add(col) self.shrink_wrap()
def __init__(self, tool): Panel.__init__(self, name='Panel.PlayerPositionPanel') self.tool = tool self.player_UUID = {"UUID": [], "Name": []} self.level = tool.editor.level self.playercache = PlayerCache() # Add this instance to PlayerCache 'targets'. PlayerCache generated processes will call # this instance 'update_player' method when they have finished their execution. self.playercache.add_target(self.update_player) if hasattr(self.level, 'players'): players = self.level.players or ["[No players]"] if not self.level.oldPlayerFolderFormat: for player in players: if player != "Player" and player != "[No players]": if len(player) > 4 and player[4] == "-": os.rename(os.path.join(self.level.worldFolder.getFolderPath("playerdata"), player+".dat"), os.path.join(self.level.worldFolder.getFolderPath("playerdata"), player.replace("-", "", 1)+".dat")) player = player.replace("-", "", 1) # print 5 data = self.playercache.getPlayerInfo(player, use_old_data=True) #self.player_UUID[data[0]] = data[1] self.player_UUID["UUID"].append(data[0]) self.player_UUID["Name"].append(data[1]) #self.player_UUID[player] = data if "Player" in players: #self.player_UUID["Player (Single Player)"] = "Player" self.player_UUID["UUID"].append("Player") self.player_UUID["Name"].append("Player (Single Player)") if "[No players]" not in players: self.player_names = sorted(self.player_UUID.values(), key=lambda x: False if x == "Player (Single Player)" else x) else: self.player_UUID["UUID"].append("[No players]") self.player_UUID["Name"].append("[No players]") else: players = ["Player (Single Player)"] self.players = players if 'Player' in self.player_UUID['UUID'] and 'Player (Single Player)' in self.player_UUID['Name']: self.player_UUID['UUID'].insert(0, self.player_UUID['UUID'].pop(self.player_UUID['UUID'].index('Player'))) self.player_UUID['Name'].insert(0, self.player_UUID['Name'].pop(self.player_UUID['Name'].index('Player (Single Player)'))) self.pages = TabPanel() tab_height = self.pages.tab_height max_height = tab_height + self.tool.editor.mainViewport.height - self.tool.editor.toolbar.height - self.tool.editor.subwidgets[0].height - self.pages.margin * 2 #-# Uncomment the following line to have a maximum height for this panel. # max_height = min(max_height, 500) self.editNBTDataButton = Button("Edit NBT", action=self.editNBTData, tooltipText="Open the NBT Explorer to edit player's attributes and inventory") addButton = Button("Add", action=self.tool.addPlayer) removeButton = Button("Remove", action=self.tool.removePlayer) gotoButton = Button("Goto", action=self.tool.gotoPlayer) gotoCameraButton = Button("Goto View", action=self.tool.gotoPlayerCamera) moveButton = Button("Move", action=self.tool.movePlayer) moveToCameraButton = Button("Align to Camera", action=self.tool.movePlayerToCamera) reloadSkin = Button("Reload Skins", action=self.tool.reloadSkins, tooltipText="This pulls skins from the online server, so this may take a while") btns = [self.editNBTDataButton] if not isinstance(self.level, pymclevel.leveldbpocket.PocketLeveldbWorld): btns.extend([addButton, removeButton]) btns.extend([gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin]) btns = Column(btns, margin=0, spacing=2) h = max_height - btns.height - self.pages.margin * 2 - 2 - self.font.get_linesize() * 2 col = Label('') def close(): self.pages.show_page(col) self.nbttree = NBTExplorerToolPanel(self.tool.editor, nbtObject={}, height=max_height, \ close_text="Go Back", no_header=True, close_action=close, load_text=None) self.nbttree.shrink_wrap() self.nbtpage = Column([self.nbttree]) self.nbtpage.shrink_wrap() self.pages.add_page("NBT Data", self.nbtpage) self.pages.set_rect(map(lambda x:x+self.margin, self.nbttree._rect)) tableview = TableView(nrows=(h - (self.font.get_linesize() * 2.5)) / self.font.get_linesize(), header_height=self.font.get_linesize(), columns=[TableColumn("Player Name(s):", (self.nbttree.width - (self.margin * 3)) / 3), TableColumn("Player UUID(s):", (self.nbttree.width - (self.margin * 3)))], ) tableview.index = 0 tableview.num_rows = lambda: len(self.player_UUID["UUID"]) tableview.row_data = lambda i: (self.player_UUID["Name"][i],self.player_UUID["UUID"][i]) tableview.row_is_selected = lambda x: x == tableview.index tableview.zebra_color = (0, 0, 0, 48) def selectTableRow(i, evt): tableview.index = i tableview.click_row = selectTableRow def mouse_down(e): if e.button == 1 and e.num_clicks > 1: self.editNBTData() TableRowView.mouse_down(tableview.rows, e) tableview.rows.mouse_down = mouse_down tableview.rows.tooltipText = "Double-click or use the button below to edit the NBT Data." self.table = tableview col.set_parent(None) self.col = col = Column([tableview, btns], spacing=2) self.pages.add_page("Players", col, 0) self.pages.shrink_wrap() self.pages.show_page(col) self.add(self.pages) self.shrink_wrap() self.max_height = max_height
def __init__(self, tool): Panel.__init__(self, name='Panel.PlayerPositionPanel') self.tool = tool self.player_UUID = {"UUID": [], "Name": []} self.level = tool.editor.level self.playercache = PlayerCache() # Add this instance to PlayerCache 'targets'. PlayerCache generated processes will call # this instance 'update_player' method when they have finished their execution. self.playercache.add_target(self.update_player) if hasattr(self.level, 'players'): players = self.level.players or ["[No players]"] if not self.level.oldPlayerFolderFormat: for player in players: if player != "Player" and player != "[No players]": if len(player) > 4 and player[4] == "-": os.rename( os.path.join( self.level.worldFolder.getFolderPath( "playerdata"), player + ".dat"), os.path.join( self.level.worldFolder.getFolderPath( "playerdata"), player.replace("-", "", 1) + ".dat")) player = player.replace("-", "", 1) # print 5 data = self.playercache.getPlayerInfo( player, use_old_data=True) #self.player_UUID[data[0]] = data[1] self.player_UUID["UUID"].append(data[0]) self.player_UUID["Name"].append(data[1]) #self.player_UUID[player] = data if "Player" in players: #self.player_UUID["Player (Single Player)"] = "Player" self.player_UUID["UUID"].append("Player") self.player_UUID["Name"].append("Player (Single Player)") if "[No players]" not in players: self.player_names = sorted( self.player_UUID.values(), key=lambda x: False if x == "Player (Single Player)" else x) else: self.player_UUID["UUID"].append("[No players]") self.player_UUID["Name"].append("[No players]") else: players = ["Player (Single Player)"] self.players = players if 'Player' in self.player_UUID[ 'UUID'] and 'Player (Single Player)' in self.player_UUID[ 'Name']: self.player_UUID['UUID'].insert( 0, self.player_UUID['UUID'].pop( self.player_UUID['UUID'].index('Player'))) self.player_UUID['Name'].insert( 0, self.player_UUID['Name'].pop( self.player_UUID['Name'].index('Player (Single Player)'))) self.pages = TabPanel() tab_height = self.pages.tab_height max_height = tab_height + self.tool.editor.mainViewport.height - self.tool.editor.toolbar.height - self.tool.editor.subwidgets[ 0].height - self.pages.margin * 2 #-# Uncomment the following line to have a maximum height for this panel. # max_height = min(max_height, 500) self.editNBTDataButton = Button( "Edit NBT", action=self.editNBTData, tooltipText= "Open the NBT Explorer to edit player's attributes and inventory") addButton = Button("Add", action=self.tool.addPlayer) removeButton = Button("Remove", action=self.tool.removePlayer) gotoButton = Button("Goto", action=self.tool.gotoPlayer) gotoCameraButton = Button("Goto View", action=self.tool.gotoPlayerCamera) moveButton = Button("Move", action=self.tool.movePlayer) moveToCameraButton = Button("Align to Camera", action=self.tool.movePlayerToCamera) reloadSkin = Button( "Reload Skins", action=self.tool.reloadSkins, tooltipText= "This pulls skins from the online server, so this may take a while" ) btns = [self.editNBTDataButton] if not isinstance(self.level, pymclevel.leveldbpocket.PocketLeveldbWorld): btns.extend([addButton, removeButton]) btns.extend([ gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin ]) btns = Column(btns, margin=0, spacing=2) h = max_height - btns.height - self.pages.margin * 2 - 2 - self.font.get_linesize( ) * 2 col = Label('') def close(): self.pages.show_page(col) self.nbttree = NBTExplorerToolPanel(self.tool.editor, nbtObject={}, height=max_height, \ close_text="Go Back", no_header=True, close_action=close, load_text=None) self.nbttree.shrink_wrap() self.nbtpage = Column([self.nbttree]) self.nbtpage.shrink_wrap() self.pages.add_page("NBT Data", self.nbtpage) self.pages.set_rect(map(lambda x: x + self.margin, self.nbttree._rect)) tableview = TableView( nrows=(h - (self.font.get_linesize() * 2.5)) / self.font.get_linesize(), header_height=self.font.get_linesize(), columns=[ TableColumn("Player Name(s):", (self.nbttree.width - (self.margin * 3)) / 3), TableColumn("Player UUID(s):", (self.nbttree.width - (self.margin * 3))) ], ) tableview.index = 0 tableview.num_rows = lambda: len(self.player_UUID["UUID"]) tableview.row_data = lambda i: (self.player_UUID["Name"][i], self. player_UUID["UUID"][i]) tableview.row_is_selected = lambda x: x == tableview.index tableview.zebra_color = (0, 0, 0, 48) def selectTableRow(i, evt): tableview.index = i tableview.click_row = selectTableRow def mouse_down(e): if e.button == 1 and e.num_clicks > 1: self.editNBTData() TableRowView.mouse_down(tableview.rows, e) tableview.rows.mouse_down = mouse_down tableview.rows.tooltipText = "Double-click or use the button below to edit the NBT Data." self.table = tableview col.set_parent(None) self.col = col = Column([tableview, btns], spacing=2) self.pages.add_page("Players", col, 0) self.pages.shrink_wrap() self.pages.show_page(col) self.add(self.pages) self.shrink_wrap() self.max_height = max_height
def editContainer(self, point, containerID): tileEntityTag = self.editor.level.tileEntityAt(*point) if tileEntityTag is None: tileEntityTag = pymclevel.TileEntity.Create(containerID) pymclevel.TileEntity.setpos(tileEntityTag, point) self.editor.level.addTileEntity(tileEntityTag) if tileEntityTag["id"].value != containerID: return undoBackupEntityTag = copy.deepcopy(tileEntityTag) def itemProp(key): # xxx do validation here def getter(self): if 0 == len(tileEntityTag["Items"]): return 0 return tileEntityTag["Items"][self.selectedItemIndex][key].value def setter(self, val): if 0 == len(tileEntityTag["Items"]): return self.dirty = True tileEntityTag["Items"][self.selectedItemIndex][key].value = val return property(getter, setter) class ChestWidget(Widget): dirty = False Slot = itemProp("Slot") id = itemProp("id") Damage = itemProp("Damage") Count = itemProp("Count") itemLimit = pymclevel.TileEntity.maxItems.get(containerID, 26) def slotFormat(slot): slotNames = pymclevel.TileEntity.slotNames.get(containerID) if slotNames: return slotNames.get(slot, slot) return slot chestWidget = ChestWidget() chestItemTable = TableView(columns=[ TableColumn("Slot", 60, "l", fmt=slotFormat), TableColumn("ID / ID Name", 345, "l"), TableColumn("DMG", 50, "l"), TableColumn("Count", 65, "l"), TableColumn("Name", 260, "l"), ]) def itemName(id, damage): try: return pymclevel.items.items.findItem(id, damage).name except pymclevel.items.ItemNotFound: return "Unknown Item" def getRowData(i): item = tileEntityTag["Items"][i] slot, id, damage, count = item["Slot"].value, item["id"].value, item["Damage"].value, item["Count"].value return slot, id, damage, count, itemName(id, damage) chestWidget.selectedItemIndex = 0 def selectTableRow(i, evt): chestWidget.selectedItemIndex = i chestItemTable.num_rows = lambda: len(tileEntityTag["Items"]) chestItemTable.row_data = getRowData chestItemTable.row_is_selected = lambda x: x == chestWidget.selectedItemIndex chestItemTable.click_row = selectTableRow fieldRow = ( mceutils.IntInputRow("Slot: ", ref=AttrRef(chestWidget, 'Slot'), min=0, max=26), mceutils.TextInputRow("ID / ID Name: ", ref=AttrRef(chestWidget, 'id'), width=300), # Text to allow the input of internal item names mceutils.IntInputRow("DMG: ", ref=AttrRef(chestWidget, 'Damage'), min=-32768, max=32767), mceutils.IntInputRow("Count: ", ref=AttrRef(chestWidget, 'Count'), min=-64, max=64), ) def deleteFromWorld(): i = chestWidget.selectedItemIndex item = tileEntityTag["Items"][i] id = item["id"].value Damage = item["Damage"].value deleteSameDamage = mceutils.CheckBoxLabel("Only delete items with the same damage value") deleteBlocksToo = mceutils.CheckBoxLabel("Also delete blocks placed in the world") if id not in (8, 9, 10, 11): # fluid blocks deleteBlocksToo.value = True w = wrapped_label( "WARNING: You are about to modify the entire world. This cannot be undone. Really delete all copies of this item from all land, chests, furnaces, dispensers, dropped items, item-containing tiles, and player inventories in this world?", 60) col = (w, deleteSameDamage) if id < 256: col += (deleteBlocksToo,) d = Dialog(Column(col), ["OK", "Cancel"]) if d.present() == "OK": def deleteItemsIter(): i = 0 if deleteSameDamage.value: def matches(t): return t["id"].value == id and t["Damage"].value == Damage else: def matches(t): return t["id"].value == id def matches_itementity(e): if e["id"].value != "Item": return False if "Item" not in e: return False t = e["Item"] return matches(t) for player in self.editor.level.players: tag = self.editor.level.getPlayerTag(player) l = len(tag["Inventory"]) tag["Inventory"].value = [t for t in tag["Inventory"].value if not matches(t)] for chunk in self.editor.level.getChunks(): if id < 256 and deleteBlocksToo.value: matchingBlocks = chunk.Blocks == id if deleteSameDamage.value: matchingBlocks &= chunk.Data == Damage if any(matchingBlocks): chunk.Blocks[matchingBlocks] = 0 chunk.Data[matchingBlocks] = 0 chunk.chunkChanged() self.editor.invalidateChunks([chunk.chunkPosition]) for te in chunk.TileEntities: if "Items" in te: l = len(te["Items"]) te["Items"].value = [t for t in te["Items"].value if not matches(t)] if l != len(te["Items"]): chunk.dirty = True entities = [e for e in chunk.Entities if matches_itementity(e)] if len(entities) != len(chunk.Entities): chunk.Entities.value = entities chunk.dirty = True yield (i, self.editor.level.chunkCount) i += 1 progressInfo = _("Deleting the item {0} from the entire world ({1} chunks)").format( itemName(chestWidget.id, 0), self.editor.level.chunkCount) mceutils.showProgress(progressInfo, deleteItemsIter(), cancel=True) self.editor.addUnsavedEdit() chestWidget.selectedItemIndex = min(chestWidget.selectedItemIndex, len(tileEntityTag["Items"]) - 1) def deleteItem(): i = chestWidget.selectedItemIndex item = tileEntityTag["Items"][i] tileEntityTag["Items"].value = [t for t in tileEntityTag["Items"].value if t is not item] chestWidget.selectedItemIndex = min(chestWidget.selectedItemIndex, len(tileEntityTag["Items"]) - 1) def deleteEnable(): return len(tileEntityTag["Items"]) and chestWidget.selectedItemIndex != -1 def addEnable(): return len(tileEntityTag["Items"]) < chestWidget.itemLimit def addItem(): slot = 0 for item in tileEntityTag["Items"]: if slot == item["Slot"].value: slot += 1 if slot >= chestWidget.itemLimit: return item = pymclevel.TAG_Compound() item["id"] = pymclevel.TAG_String("minecraft:") item["Damage"] = pymclevel.TAG_Short(0) item["Slot"] = pymclevel.TAG_Byte(slot) item["Count"] = pymclevel.TAG_Byte(1) tileEntityTag["Items"].append(item) addItemButton = Button("New Item (1.7+)", action=addItem, enable=addEnable) deleteItemButton = Button("Delete This Item", action=deleteItem, enable=deleteEnable) deleteFromWorldButton = Button("Delete All Instances Of This Item From World", action=deleteFromWorld, enable=deleteEnable) deleteCol = Column((addItemButton, deleteItemButton, deleteFromWorldButton)) fieldRow = Row(fieldRow) col = Column((chestItemTable, fieldRow, deleteCol)) chestWidget.add(col) chestWidget.shrink_wrap() Dialog(client=chestWidget, responses=["Done"]).present() level = self.editor.level class ChestEditOperation(Operation): def __init__(self, tool, level): self.tool = tool self.level = level self.undoBackupEntityTag = undoBackupEntityTag self.canUndo = False def perform(self, recordUndo=True): if self.level.saving: alert("Cannot perform action while saving is taking place") return level.addTileEntity(tileEntityTag) self.canUndo = True def undo(self): self.redoBackupEntityTag = copy.deepcopy(tileEntityTag) level.addTileEntity(self.undoBackupEntityTag) return pymclevel.BoundingBox(pymclevel.TileEntity.pos(tileEntityTag), (1, 1, 1)) def redo(self): level.addTileEntity(self.redoBackupEntityTag) return pymclevel.BoundingBox(pymclevel.TileEntity.pos(tileEntityTag), (1, 1, 1)) if chestWidget.dirty: op = ChestEditOperation(self.editor, self.editor.level) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit()
def build_inventory(self, items): parent = self.tree.get_item_parent(self.displayed_item) if parent: parent = parent[9] else: parent = self.data if 'playerGameType' in parent.keys(): player = True else: player = False inventory = parent.get('Inventory', TAG_List()) rows = [] items = items[0] slots = [["%s" % i, "", "0", "0"] for i in range(36)] slots += [["%s" % i, "", "0", "0"] for i in range(100, 104)] slots_set = [] for item, i in zip(items, range(len(items))): # &# Prototype for blocks/items names item_dict = mcitems.items.get(item['id'].value, None) if item_dict is None: item_name = item['id'].value else: if type(item_dict['name']) == list: if int(item['Damage'].value) >= len(item_dict['name']): block_id = map_block.get(item['id'].value, None) item_name = alphaMaterials.get( (int(block_id), int(item['Damage'].value))).name.rsplit( '(', 1)[0].strip() else: item_name = item_dict['name'][int( item['Damage'].value)] else: item_name = item_dict['name'] s = i _s = 0 + i if player: s = int(item['Slot'].value) _s = 0 + s slots_set.append(s) if s >= 100: s = s - 100 + 36 if type(item_name) in (unicode, str): translated_item_name = mclangres.translate(item_name) else: translated_item_name = item_name slots[s] = _s, translated_item_name, item['Count'].value, item[ 'Damage'].value # slots[s] = item['Slot'].value, item['id'].value.split(':')[-1], item['Count'].value, item['Damage'].value # &# width = self.side_panel_width - self.margin * 5 c0w = max(15, self.font.size("000")[0]) + 4 c2w = max(15, self.font.size("00")[0]) + 4 c3w = max(15, self.font.size("000")[0]) + 4 c1w = width - c0w - c2w - c3w font_height = self.font.size("qd")[1] tableCols = [ TableColumn("#", c0w), TableColumn("ID", c1w), TableColumn("C", c2w), TableColumn("D", c3w), ] height = self.displayRow.subwidgets[0].height table = TableView(height=height - (self.margin * 2), width=width, nrows=((height - (self.margin * 2) - font_height / 2) / font_height), columns=tableCols, row_height=font_height, header_height=font_height / 2) table.rows.tooltipText = "Double-click to edit" table.selected_row = None table.slots = slots def num_rows(): return len(slots) table.num_rows = num_rows def row_data(n): return slots[n] table.row_data = row_data def click_row(n, e): table.focus() table.selected_row = n if e.num_clicks > 1: SlotEditor(table, row_data(n)).present() table.click_row = click_row def row_is_selected(n): return n == table.selected_row table.row_is_selected = row_is_selected def change_value(data): s, i, c, d = data s = int(s) s_idx = 0 # &# Prototype for blocks/items names name, state = map_items.get(mclangres.untranslate(i), (i, '0')) if ':' not in name: name = 'minecraft:%s' % name # &# if s in slots_set: for slot in inventory: ok1 = False if player: ok1 = slot['Slot'].value == s else: ok1 = inventory.index(slot) == s if ok1: if not i or int(c) < 1: del inventory[s_idx] i = "" c = u'0' d = u'0' else: # &# Prototype for blocks/items names # slot['id'].value = 'minecraft:%s'%i slot['id'].value = name # &# slot['Count'].value = int(c) slot['Damage'].value = int(state) break s_idx += 1 else: new_slot = TAG_Compound() if player: new_slot['Slot'] = TAG_Byte(s) # &# Prototype for blocka/items names # new_slot['id'] = TAG_String('minecraft:%s'%i) new_slot['id'] = TAG_String(name) # &# new_slot['Count'] = TAG_Byte(int(c)) new_slot['Damage'] = TAG_Short(int(state)) idx = s for slot in inventory: ok2 = False if player: ok2 = slot['Slot'].value >= s else: ok2 = inventory.index(slot) >= s if ok2: idx = slot['Slot'].value break inventory.insert(s, new_slot) slots_set.append(s) # &# Prototype for blocks/items names # if i == name: # i = name # &# if s >= 100: n = s - 100 + 36 else: n = s table.slots[n] = slots[n] = s, i, c, state table.change_value = change_value def dispatch_key(name, evt): keyname = self.root.getKey(evt) if keyname == 'Return': SlotEditor(table, row_data(table.selected_row)).present() elif keyname == "Up" and table.selected_row > 0: table.selected_row -= 1 table.rows.scroll_to_item(table.selected_row) elif keyname == "Down" and table.selected_row < len(slots) - 1: table.selected_row += 1 table.rows.scroll_to_item(table.selected_row) elif keyname == 'Page down': table.selected_row = min( len(slots) - 1, table.selected_row + table.rows.num_rows()) elif keyname == 'Page up': table.selected_row = max( 0, table.selected_row - table.rows.num_rows()) someRowBool = table.rows.cell_to_item_no( 0, 0) + table.rows.num_rows() - 1 != table.selected_row if table.rows.cell_to_item_no(0, 0) is not None and someRowBool: table.rows.scroll_to_item(table.selected_row) table.dispatch_key = dispatch_key rows.append(table) return rows
def __init__(self, tool): Panel.__init__(self) self.tool = tool self.player_UUID = {} self.level = tool.editor.level if hasattr(self.level, 'players'): players = self.level.players or ["[No players]"] if not self.level.oldPlayerFolderFormat: for player in players: if player != "Player" and player != "[No players]": if player[4] == "-": os.rename(os.path.join(self.level.worldFolder.getFolderPath("playerdata"), player+".dat"), os.path.join(self.level.worldFolder.getFolderPath("playerdata"), player.replace("-", "", 1)+".dat")) player = player.replace("-", "", 1) self.player_UUID[version_utils.playercache.getPlayerFromUUID(player)] = player if "Player" in players: self.player_UUID["Player"] = "Player" if "[No players]" not in players: players = sorted(self.player_UUID.keys(), key=lambda x: False if x == "Player" else x) else: players = ["Player"] self.players = players self.pages = TabPanel() tab_height = self.pages.tab_height max_height = tab_height + self.tool.editor.mainViewport.height - self.tool.editor.toolbar.height - self.tool.editor.subwidgets[0].height - self.pages.margin * 2 #-# Uncomment the following line to have a maximum height for this panel. # max_height = min(max_height, 500) self.editNBTDataButton = Button("Edit NBT Data", action=self.editNBTData, tooltipText="Open the NBT Explorer to edit player's attributes and inventory") addButton = Button("Add Player", action=self.tool.addPlayer) removeButton = Button("Remove Player", action=self.tool.removePlayer) gotoButton = Button("Goto Player", action=self.tool.gotoPlayer) gotoCameraButton = Button("Goto Player's View", action=self.tool.gotoPlayerCamera) moveButton = Button("Move Player", action=self.tool.movePlayer) moveToCameraButton = Button("Align Player to Camera", action=self.tool.movePlayerToCamera) reloadSkin = Button("Reload Skins", action=self.tool.reloadSkins, tooltipText="This pulls skins from the online server, so this may take a while") btns = Column([self.editNBTDataButton, addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin], margin=0, spacing=2) h = max_height - btns.height - self.pages.margin * 2 - 2 - self.font.size(" ")[1] * 2 tableview = TableView(nrows=(h - (self.font.size(" ")[1] * 2.5)) / self.font.size(" ")[1], header_height=self.font.size(" ")[1], columns=[TableColumn("Player Name(s):", 200),], height=h, ) tableview.index = 0 tableview.num_rows = lambda: len(players) tableview.row_data = lambda i: (players[i],) tableview.row_is_selected = lambda x: x == tableview.index tableview.zebra_color = (0, 0, 0, 48) def selectTableRow(i, evt): tableview.index = i tableview.click_row = selectTableRow def mouse_down(e): if e.button == 1 and e.num_clicks > 1: self.editNBTData() TableRowView.mouse_down(tableview.rows, e) tableview.rows.mouse_down = mouse_down tableview.rows.tooltipText = "Double-click or use the button below to edit the NBT Data." self.table = tableview col = Column([tableview, btns], spacing=2) self.col = col def close(): self.pages.show_page(col) self.nbttree = NBTExplorerToolPanel(self.tool.editor, nbtObject={}, height=max_height, \ close_text="Go Back", no_header=True, close_action=close, load_text=None) self.nbttree.shrink_wrap() self.pages.add_page("Players", col) self.nbtpage = Column([self.nbttree,]) self.nbtpage.shrink_wrap() self.pages.add_page("NBT Data", self.nbtpage) self.pages.set_rect(self.nbttree._rect) self.pages.shrink_wrap() self.pages.show_page(col) self.add(self.pages) self.shrink_wrap() self.max_height = max_height
def __init__(self, tool): Panel.__init__(self) self.tool = tool self.player_UUID = {} self.level = tool.editor.level if hasattr(self.level, 'players'): players = self.level.players or ["[No players]"] if not self.level.oldPlayerFolderFormat: for player in players: if player != "Player" and player != "[No players]": self.player_UUID[version_utils.getPlayerNameFromUUID( player)] = player if "Player" in players: self.player_UUID["Player"] = "Player" if "[No players]" not in players: players = sorted(self.player_UUID.keys(), key=lambda x: False if x == "Player" else x.lower()) else: players = ["Player"] self.players = players max_height = self.tool.editor.mainViewport.height - self.tool.editor.netherPanel.height - self.tool.editor.subwidgets[ 0].height - self.margin - 2 addButton = Button("Add Player", action=self.tool.addPlayer) removeButton = Button("Remove Player", action=self.tool.removePlayer) gotoButton = Button("Goto Player", action=self.tool.gotoPlayer) gotoCameraButton = Button("Goto Player's View", action=self.tool.gotoPlayerCamera) moveButton = Button("Move Player", action=self.tool.movePlayer) moveToCameraButton = Button("Align Player to Camera", action=self.tool.movePlayerToCamera) reloadSkin = Button( "Reload Skins", action=self.tool.reloadSkins, tooltipText= "This pulls skins from the online server, so this may take a while" ) max_height -= sum( (a.height for a in (addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin))) tableview = TableView(columns=[ TableColumn("Player Name(s):", 200), ], height=max_height) tableview.index = 0 tableview.num_rows = lambda: len(players) tableview.row_data = lambda i: (players[i], ) tableview.row_is_selected = lambda x: x == tableview.index tableview.zebra_color = (0, 0, 0, 48) def selectTableRow(i, evt): tableview.index = i tableview.click_row = selectTableRow self.table = tableview col = [self.table] col.extend([ addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin ]) col = Column(col, margin=0, spacing=2) col.shrink_wrap() self.add(col) self.shrink_wrap()