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
Beispiel #2
0
    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
Beispiel #3
0
    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 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 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