Permalink
Browse files

added inventory

  • Loading branch information...
1 parent 270a30e commit f8fb21b1dd69ee3e143792cda86543dd0a8588f4 @invi invi committed Feb 13, 2011
Binary file not shown.
@@ -1,10 +1,12 @@
import traceback
import math
+import uuid
from ..siminfo import GridInfo
from ..compatibility import BaseApplication
from ..tools.logger import logger
from .properties import B2RexObjectProps
+from .properties import B2RexProps
from bpy.props import StringProperty, PointerProperty, IntProperty
from bpy.props import BoolProperty, FloatProperty, CollectionProperty
@@ -187,3 +189,42 @@ def queueRedraw(self):
# if not area.type == 'VIEW_3D':
bpy.ops.b2rex.redraw()
+ def update_folders(self, folders):
+ props = bpy.context.scene.b2rex_props
+ cached_folders = getattr(props, 'folders')
+ for folder in folders:
+ expand_prop = "e_" + str(folder['FolderID']).split('-')[0]
+ if not hasattr(B2RexProps, expand_prop):
+ prop = BoolProperty(name="expand", default=False)
+ setattr(B2RexProps, expand_prop, prop)
+ cached_folders[folder['FolderID']] = folder
+
+ def update_items(self, items):
+ props = bpy.context.scene.b2rex_props
+ cached_items = getattr(props, '_items')
+ for item in items:
+ cached_items[item['ItemID']] = item
+
+ def processInventoryDescendents(self, folder_id, folders, items):
+ self.update_folders(folders)
+ self.update_items(items)
+
+ def processInventorySkeleton(self, inventory):
+
+ props = bpy.context.scene.b2rex_props
+ session = bpy.b2rex_session
+ if not hasattr(B2RexProps, 'folders'):
+ setattr(B2RexProps, 'folders', dict())
+ if not hasattr(B2RexProps, '_items'):
+ setattr(B2RexProps, '_items', dict())
+
+ for inv in inventory:
+ if uuid.UUID(inv['parent_id']).int == 0:
+ if not hasattr(B2RexProps, "root_folder"):
+ setattr(B2RexProps, "root_folder", inv['folder_id'])
+ setattr(props, "root_folder", inv['folder_id'])
+ self.update_folders([{'FolderID' : inv['folder_id'], 'ParentID' : inv['parent_id'], 'Name' : inv['name']}])
+ session.simrt.addCmd(['sendFetchInventoryDescendentsRequest', inv['folder_id']])
+
+ session.inventory = inventory
+
@@ -176,3 +176,15 @@ def execute(self, context):
return {'FINISHED'}
+class FolderStatus(bpy.types.Operator):
+ bl_idname = "b2rex.folder"
+ bl_label = "Folder"
+ expand = bpy.props.BoolProperty(name="Expand")
+ folder_id = bpy.props.StringProperty(name="Folder ID")
+
+ def execute(self, context):
+ setattr(context.scene.b2rex_props, "e_" + self.folder_id.split('-')[0], self.expand)
+ if self.expand == True:
+ bpy.b2rex_session.simrt.addCmd(['sendFetchInventoryDescendentsRequest', self.folder_id])
+
+ return {'FINISHED'}
@@ -3,8 +3,10 @@
"""
import bpy
+import uuid
from b2rexpkg.b25.ops import getLogLabel
+from ..properties import B2RexProps
class ConnectionPanel(bpy.types.Panel):
@@ -100,7 +102,71 @@ def draw(self, context):
self.draw_stats(layout, session, props)
self.draw_settings(layout, session, props)
+ self.draw_inventory(layout, session, props)
+ def draw_folder(self, folder_id, indent):
+
+ props = bpy.context.scene.b2rex_props
+
+ folders = dict()
+ items = dict()
+ if hasattr(B2RexProps, 'folders'):
+ folders = getattr(props, 'folders')
+
+ if hasattr(B2RexProps, '_items'):
+ items = getattr(props, '_items')
+
+ folder = folders[folder_id]
+
+ session = bpy.b2rex_session
+ row = self.layout.row()
+
+ for i in range(indent):
+ row.separator()
+
+ folder_expand = "e_" + str(folder_id).split('-')[0]
+ if hasattr(B2RexProps, folder_expand):
+ if not getattr(props, folder_expand):
+ oper = row.operator('b2rex.folder', text=folder['Name'], icon='ZOOMIN', emboss=False)
+ oper.expand = True
+ else:
+ oper = row.operator('b2rex.folder', text=folder['Name'], icon='ZOOMOUT', emboss=False)
+ for f_id,folder in folders.items():
+ if folder['ParentID'] == folder_id:
+ self.draw_folder(f_id, indent + 1)
+ for i_if,item in items.items():
+ if item['FolderID'] == folder_id:
+ row = self.layout.row()
+ for i in range(indent + 1):
+ row.separator()
+
+ row.label(text=item['Name'], icon='OBJECT_DATA')
+ oper.expand = False
+
+ oper.folder_id = folder_id
+ else:
+ row.label(text="Loading...")
+
+ def draw_inventory(self, layout, session, props):
+ row = layout.column()
+ row.alignment = 'CENTER'
+ if props.inventory_expand:
+ row.prop(props, 'inventory_expand', icon="TRIA_DOWN", text="Inventory")
+ else:
+ row.prop(props, 'inventory_expand', icon="TRIA_RIGHT", text="Inventory")
+ return
+
+ try:
+ inventory = session.inventory
+ except:
+ row = layout.column()
+ row.label(text='Inventory not loaded')
+ return
+
+
+ if hasattr(B2RexProps, "root_folder"):
+ root_folder = getattr(props, "root_folder")
+ self.draw_folder(root_folder, 0)
def draw_stats(self, layout, session, props):
row = layout.row()
@@ -87,6 +87,7 @@ class B2RexProps(bpy.types.IDPropertyGroup):
next_chat = StringProperty(name='next_chat',
default='',
description='')
+ inventory_expand = BoolProperty(default=False, description="Expand inventory")
# B2RexProps.regions.name = StringProperty(name='Name', description='Name of the session', maxlen=128, default='[session]')
@@ -136,10 +136,12 @@ def processLayerData(self, layerType, b64data):
for header, layer in terrpackets:
self.terrain.apply_patch(layer, header.x, header.y)
+ def processInventoryDescendents(self, folder_id, folders, items):
+ pass
+
+
def processInventorySkeleton(self, inventory):
- self.inventory = inventory
- #for inv in inventory:
- # print(inv['parent_id'])
+ pass
def processCoarseLocationUpdate(self, agent_id, pos):
#print("COARSE LOCATION UPDATE", agent_id, pos)
View
@@ -36,6 +36,8 @@
from pyogp.lib.client.namevalue import NameValueList
from pyogp.lib.base.message.message import Message, Block
+import pyogp.lib.client.inventory
+from pyogp.lib.client.inventory import UDP_Inventory
# Extra asset and inventory types for rex
import pyogp.lib.client.enums
@@ -73,6 +75,7 @@ class BlenderAgent(object):
do_megahal = False
verbose = False
def __init__(self, in_queue, out_queue):
+ self.inventory = None
self.nlayers = 0
self.creating = False
self._eatupdates = defaultdict(int)
@@ -518,7 +521,7 @@ def login(self, server_url, username, password, regionname, firstline=""):
out_queue = self.out_queue
client = self.initialize_agent()
-
+ self.inventory = UDP_Inventory(client)
# Now let's log it in
region = regionname
firstname, lastname = username.split(" ", 1)
@@ -563,6 +566,8 @@ def login(self, server_url, username, password, regionname, firstline=""):
#res = client.region.message_handler.register("KillObject")
#res.subscribe(self.onKillObject)
+ self.inventory.enable_callbacks()
+
res = client.region.message_handler.register("RegionHandshake")
res.subscribe(self.onRegionHandshake)
res = client.region.message_handler.register("CoarseLocationUpdate")
@@ -597,6 +602,8 @@ def login(self, server_url, username, password, regionname, firstline=""):
res.subscribe(self.onObjectProperties)
res = client.region.objects.message_handler.register("RexPrimData")
res.subscribe(self.onRexPrimData)
+ res = client.region.message_handler.register("InventoryDescendents")
+ res.subscribe(self.onInventoryDescendents)
caps_sent = False
caps = {}
@@ -624,6 +631,9 @@ def login(self, server_url, username, password, regionname, firstline=""):
# send inventory skeleton
if hasattr(self.client, 'login_response') and 'inventory-skeleton' in self.client.login_response:
out_queue.put(["InventorySkeleton", self.client.login_response['inventory-skeleton']])
+
+ self.inventory._parse_folders_from_login_response()
+
# main loop for the agent
selected = set()
while client.running == True:
@@ -686,8 +696,16 @@ def login(self, server_url, username, password, regionname, firstline=""):
self.updatePermissions(obj, mask, val)
elif cmd[0] == "LayerData":
self.sendLayerData(*cmd[1:])
-
-
+ elif cmd[0] == "sendFetchInventoryDescendentsRequest":
+ func = getattr(self.inventory, cmd[0])
+ func(*cmd[1:])
+
+ def onInventoryDescendents(self, packet):
+ folder_id = packet['AgentData'][0]['FolderID']
+ folders = [{'Name' : member.Name, 'ParentID' : str(member.ParentID), 'FolderID' : str(member.FolderID)} for member in self.inventory.folders if str(member.ParentID) == str(folder_id)]
+ items = [{'Name' : member.Name, 'FolderID' : str(member.FolderID), 'ItemID' : str(member.ItemID)} for member in self.inventory.items if str(member.FolderID) == str(folder_id)]
+
+ self.out_queue.put(['InventoryDescendents', str(folder_id), folders, items])
def sendPositionUpdate(self, obj, pos, rot):
cmd_type = 9 # 1-pos, 2-rot, 3-rotpos 4,20-scale, 5-pos,scale,

0 comments on commit f8fb21b

Please sign in to comment.