From cb0962b4844aa9a3b74f2f3cafa3b291e3789d89 Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 10 Jun 2021 15:39:12 +0200 Subject: [PATCH] feat: server preset working with bad ui/ux --- multi_user/operators.py | 75 +++++++++++++++++++++++++++++++++++++-- multi_user/preferences.py | 49 +++++++++++++++++++++++-- multi_user/ui.py | 29 ++++++++++++--- 3 files changed, 144 insertions(+), 9 deletions(-) diff --git a/multi_user/operators.py b/multi_user/operators.py index 56ad3ec..4603943 100644 --- a/multi_user/operators.py +++ b/multi_user/operators.py @@ -908,11 +908,77 @@ class SessionPresetServerAdd(bpy.types.Operator): """Add a server to the server list preset""" bl_idname = "session.preset_server_add" bl_label = "add server preset" - bl_description = "add the current server preset to the server preset list" + bl_description = "add the current server to the server preset list" bl_options = {"REGISTER"} - # name : + name : bpy.props.StringProperty(default="server_preset") # TODO: add name iteration + @classmethod + def poll(cls, context): + return True + + def execute(self, context): + assert(context) + + if True : # TODO : add condition if name already in list + True # TODO : add window pop to ask confirmation + + + settings = utils.get_preferences() + + new_server = settings.server_preset.add() + + new_server.name = settings.server_name + new_server.server_ip = settings.ip + new_server.server_port = settings.port + new_server.server_password = "admin" # TODO: add password + + return {'FINISHED'} + +class SessionPresetServerRemove(bpy.types.Operator): + """Remove a server to the server list preset""" + bl_idname = "session.preset_server_remove" + bl_label = "remove server preset" + bl_description = "remove the current server from the server preset list" + bl_options = {"REGISTER"} + + @classmethod + def poll(cls, context): + return True + + def execute(self, context): + assert(context) + + settings = utils.get_preferences() + + settings.server_preset.remove(settings.server_preset.find(settings.server_preset_interface)) + + return {'FINISHED'} + +class SessionPresetServerOverwrite(bpy.types.Operator): + bl_idname = "session.preset_server_overwrite" + bl_description = "Overwrite the server preset that already has this name" # TODO : or increment the name + bl_label = "Overwrite server preset ?" + bl_options = {'REGISTER'} + + prop1: bpy.props.BoolProperty() + prop2: bpy.props.BoolProperty() + + @classmethod + def poll(cls, context): + return True + + def execute(self, context): + self.report({'INFO'}, "Server overwrite") + return {'FINISHED'} + + def invoke(self, context, event): + return context.window_manager.invoke_confirm(self, event) + + # def draw(self, context): + # row = self.layout + # row.prop(self, "prop1", text="Overwrite the server") + # row.prop(self, "prop2", text="Keep the server") def menu_func_import(self, context): @@ -932,11 +998,14 @@ classes = ( SessionKickOperator, SessionInitOperator, SessionClearCache, - SessionNotifyOperator, + SessionNotifyOperator, SessionSaveBackupOperator, SessionLoadSaveOperator, SessionStopAutoSaveOperator, SessionPurgeOperator, + SessionPresetServerAdd, + SessionPresetServerRemove, + SessionPresetServerOverwrite, ) def update_external_dependencies(): diff --git a/multi_user/preferences.py b/multi_user/preferences.py index 7ebc2a8..825d362 100644 --- a/multi_user/preferences.py +++ b/multi_user/preferences.py @@ -65,8 +65,11 @@ def update_ip(self, context): logging.error("Wrong IP format") self['ip'] = "127.0.0.1" - - +def update_server_preset(self, context): + self.server_name = self.server_preset.get(self.server_preset_interface).name + self.ip = self.server_preset.get(self.server_preset_interface).server_ip + self.port = self.server_preset.get(self.server_preset_interface).server_port + # TODO: do password def update_directory(self, context): new_dir = Path(self.cache_directory) @@ -93,6 +96,10 @@ class ReplicatedDatablock(bpy.types.PropertyGroup): auto_push: bpy.props.BoolProperty(default=True) icon: bpy.props.StringProperty() +class ServerPreset(bpy.types.PropertyGroup): + server_ip: bpy.props.StringProperty() + server_port: bpy.props.IntProperty(default=5555) + server_password: bpy.props.StringProperty(default="admin", subtype = "PASSWORD") def set_sync_render_settings(self, value): self['sync_render_settings'] = value @@ -160,6 +167,11 @@ class SessionPrefs(bpy.types.AddonPreferences): description='Distant host port', default=5555 ) + server_name: bpy.props.StringProperty( + name="server_name", + description="Name of the server", + default='server_001', + ) sync_flags: bpy.props.PointerProperty( type=ReplicationFlags ) @@ -321,6 +333,25 @@ class SessionPrefs(bpy.types.AddonPreferences): max=59 ) + # Server preset + def server_list_callback(scene, context): + settings = get_preferences() + enum = [] + for i in settings.server_preset: + enum.append((i.name, i.name, "")) + return enum + + server_preset: bpy.props.CollectionProperty( + name="server preset", + type=ServerPreset, + ) + server_preset_interface: bpy.props.EnumProperty( + name="servers", + description="servers enum", + items=server_list_callback, + update=update_server_preset, + ) + # Custom panel panel_category: bpy.props.StringProperty( description="Choose a name for the category of the panel", @@ -419,6 +450,16 @@ class SessionPrefs(bpy.types.AddonPreferences): new_db.use_as_filter = True new_db.icon = type_module_class.bl_icon new_db.bl_name = type_module_class.bl_id + + def generate_server_preset_localhost(self): + # self.server_preset.clear() + + new_server = self.server_preset.add() + + new_server.name = "local host" + new_server.server_ip = "127.0.0.1" + new_server.server_port = 5555 + new_server.server_password = "admin" def client_list_callback(scene, context): @@ -523,6 +564,7 @@ classes = ( SessionProps, ReplicationFlags, ReplicatedDatablock, + ServerPreset, SessionPrefs, ) @@ -537,6 +579,9 @@ def register(): if len(prefs.supported_datablocks) == 0: logging.debug('Generating bl_types preferences') prefs.generate_supported_types() + + if 'local host' not in prefs.server_preset: + prefs.generate_server_preset_localhost() def unregister(): diff --git a/multi_user/ui.py b/multi_user/ui.py index 5e1f34a..0d14abe 100644 --- a/multi_user/ui.py +++ b/multi_user/ui.py @@ -172,15 +172,23 @@ class SESSION_PT_settings_network(bpy.types.Panel): row = box.row() row.operator("session.start", text="HOST").host = True else: + row = box.row() - row.prop(settings, "init_method", text="Preset") + row.prop(settings, "server_preset_interface", text="Preset") + col = row.row(align=True) + col.operator("session.preset_server_add", icon='ADD', text="") + col.operator("session.preset_server_remove", icon='REMOVE', text="") + + # for servers in settings.supported_servers: + # row = box.row() + # row.prop(servers, "use_as_filter", text="") # row = box.row() # row.template_list("SERVER_group","server_group",settings,"server_group", settings, "active_server", rows=3) # col = row.column(align=True) - # col.operator("session.preset_server_add", icon='ADD', text="") - # col.operator("session.preset_server_remove", icon='REMOVE', text="") - + + row = box.row() + row.prop(settings, "server_name", text="name") row = box.row() row.prop(settings, "ip", text="IP") row = box.row() @@ -197,6 +205,18 @@ class SESSION_PT_settings_network(bpy.types.Panel): row = box.row() row.operator("session.start", text="CONNECT").host = False +class SESSION_PT_overwrite_server(bpy.types.Panel): + bl_idname = "MULTIUSER_SETTINGS_NETWORK_PT_panel_overwrite_server" + bl_label = "Server overwrite" + bl_space_type = "VIEW_3D" + bl_region_type = "UI" + + def draw(self, context): + layout = self.layout + + settings = get_preferences() + + layout.operator(settings.SessionPresetServerOverwrite.bl_idname) class SESSION_PT_settings_user(bpy.types.Panel): bl_idname = "MULTIUSER_SETTINGS_USER_PT_panel" @@ -626,6 +646,7 @@ classes = ( SESSION_PT_settings, SESSION_PT_settings_user, SESSION_PT_settings_network, + SESSION_PT_overwrite_server, SESSION_PT_presence, SESSION_PT_advanced_settings, SESSION_PT_user,