Files
multi-user/net_ui.py

175 lines
6.0 KiB
Python
Raw Normal View History

import bpy
2019-03-25 15:30:05 +01:00
from . import net_components, net_operators
2019-03-07 13:45:44 +01:00
2019-03-13 17:02:53 +01:00
class SessionSettingsPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
2019-03-13 17:02:53 +01:00
bl_label = "NET settings"
bl_idname = "SCENE_PT_SessionSettings"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
2019-03-14 12:09:33 +01:00
net_settings = context.scene.session_settings
scene = context.scene
2019-03-25 15:30:05 +01:00
row = layout.row()
2019-03-15 17:37:02 +01:00
if net_operators.client is None:
2019-03-13 17:02:53 +01:00
row = layout.row()
box = row.box()
row = box.row()
row.label(text="User infos")
row = box.row()
row.prop(scene.session_settings, "username", text="id")
row = box.row()
row.prop(scene.session_settings, "client_color", text="color")
2019-03-15 16:50:59 +01:00
2019-03-13 17:02:53 +01:00
row = layout.row()
2019-03-15 16:50:59 +01:00
row.prop(scene.session_settings, "session_mode", expand=True)
2019-03-13 17:02:53 +01:00
row = layout.row()
2019-03-25 15:30:05 +01:00
2019-03-15 16:50:59 +01:00
if scene.session_settings.session_mode == 'HOST':
box = row.box()
row = box.row()
row.label(text="init scene:")
row.prop(net_settings, "init_scene", text="")
row = layout.row()
2019-03-25 15:30:05 +01:00
row.operator("session.create", text="HOST")
2019-03-15 16:50:59 +01:00
else:
2019-03-25 14:56:09 +01:00
box = row.box()
row = box.row()
row.prop(net_settings, "ip", text="server ip")
row = box.row()
row.label(text="load data:")
row.prop(net_settings, "load_data", text="")
row = box.row()
row.label(text="clear scene:")
row.prop(net_settings, "clear_scene", text="")
2019-03-25 15:30:05 +01:00
2019-03-15 16:50:59 +01:00
row = layout.row()
2019-03-25 15:30:05 +01:00
row.operator("session.join", text="CONNECT")
2019-03-15 17:37:02 +01:00
else:
2019-03-25 15:30:05 +01:00
if net_operators.client.status is net_components.RCFStatus.CONNECTED:
2019-03-15 17:37:02 +01:00
row.label(text="Net frequency:")
row.prop(net_settings, "update_frequency", text="")
row = layout.row()
row.operator("session.stop", icon='QUIT', text="Exit")
elif net_operators.client.status is net_components.RCFStatus.CONNECTING:
row.label(text="connecting...")
row = layout.row()
row.operator("session.stop", icon='QUIT', text="CANCEL")
2019-03-25 15:30:05 +01:00
2019-03-13 17:02:53 +01:00
row = layout.row()
2019-03-14 12:09:33 +01:00
2019-03-13 17:02:53 +01:00
class SessionUsersPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "NET users"
bl_idname = "SCENE_PT_SessionUsers"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
@classmethod
def poll(cls, context):
2019-03-15 17:37:02 +01:00
if net_operators.client:
2019-03-25 15:30:05 +01:00
return net_operators.client.status == net_components.RCFStatus.CONNECTED
2019-03-15 17:37:02 +01:00
return False
2019-03-13 17:02:53 +01:00
def draw(self, context):
layout = self.layout
2019-03-14 12:09:33 +01:00
2019-03-13 17:02:53 +01:00
net_settings = context.scene.session_settings
scene = context.scene
# Create a simple row.
row = layout.row()
if net_operators.client:
2019-03-14 12:09:33 +01:00
if len(net_operators.client.property_map) > 0:
for key, values in net_operators.client.property_map.items():
2019-03-13 17:02:53 +01:00
if 'client' in key:
info = ""
item_box = row.box()
detail_item_box = item_box.row()
if values.id == net_operators.client.id:
info = "(self)"
# detail_item_box = item_box.row()
2019-03-14 12:09:33 +01:00
detail_item_box.label(
2019-03-28 15:02:21 +01:00
text="{} - {} -{}".format(values.id.decode(),values.body, info))
2019-03-14 11:04:41 +01:00
if net_operators.client.id.decode() not in key:
2019-03-14 12:09:33 +01:00
detail_item_box.operator(
"session.snapview", text="", icon='VIEW_CAMERA').target_client = values.id.decode()
2019-03-13 17:02:53 +01:00
row = layout.row()
else:
row.label(text="Empty")
2019-03-14 12:09:33 +01:00
2019-03-13 17:02:53 +01:00
row = layout.row()
class SessionPropertiesPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "NET properties"
bl_idname = "SCENE_PT_layout"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
@classmethod
def poll(cls, context):
2019-03-15 17:37:02 +01:00
if net_operators.client:
2019-03-25 15:30:05 +01:00
return net_operators.client.status == net_components.RCFStatus.CONNECTED
2019-03-15 17:37:02 +01:00
return False
2019-03-13 17:02:53 +01:00
def draw(self, context):
layout = self.layout
2019-03-14 12:09:33 +01:00
2019-03-13 17:02:53 +01:00
net_settings = context.scene.session_settings
scene = context.scene
# Create a simple row.
row = layout.row()
if net_operators.client:
2019-02-08 18:34:10 +01:00
row = layout.row(align=True)
2019-03-14 12:09:33 +01:00
row.prop(net_settings, "buffer", text="")
2019-03-25 15:30:05 +01:00
row.prop(net_settings, "add_property_depth", text="")
add = row.operator("session.add_prop", text="",
icon="ADD")
add.property_path = net_settings.buffer
add.depth = net_settings.add_property_depth
2019-02-08 18:34:10 +01:00
row = layout.row()
2019-03-14 12:09:33 +01:00
# Property area
2019-02-08 18:34:10 +01:00
area_msg = row.box()
2019-03-14 12:09:33 +01:00
if len(net_operators.client.property_map) > 0:
for key, values in net_operators.client.property_map.items():
item_box = area_msg.box()
detail_item_box = item_box.row()
# detail_item_box = item_box.row()
2019-03-28 18:13:46 +01:00
2019-03-14 12:09:33 +01:00
detail_item_box.label(text="{} ({}) {} ".format(
key, values.mtype, values.id.decode()))
detail_item_box.operator(
"session.remove_prop", text="", icon="X").property_path = key
2019-02-08 18:34:10 +01:00
else:
area_msg.label(text="Empty")
2019-03-14 12:09:33 +01:00
classes = (
2019-03-13 17:02:53 +01:00
SessionSettingsPanel,
SessionUsersPanel,
SessionPropertiesPanel,
)
register, unregister = bpy.utils.register_classes_factory(classes)
if __name__ == "__main__":
2019-03-14 12:09:33 +01:00
register()