Skip to content

Commit

Permalink
Logic node - default type (#4589)
Browse files Browse the repository at this point in the history
* add buttons of default value type for float/int

* add support of marking old nodes during json importing
  • Loading branch information
Durman authored Jul 27, 2022
1 parent 5ec60ad commit e582fab
Show file tree
Hide file tree
Showing 22 changed files with 332 additions and 3,519 deletions.
37 changes: 33 additions & 4 deletions core/sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,16 @@ def get_prop_data(self):

quick_link_to_node: StringProperty() # this can be overridden by socket instances

default_property_type: bpy.props.EnumProperty(items=[(i, i, '') for i in ['float', 'int']])
default_property_type: bpy.props.EnumProperty( # for internal usage
description="Switch between float and int without node updating",
items=[(i, i, '') for i in ['float', 'int']])

default_float_property: bpy.props.FloatProperty(update=process_from_socket)
default_int_property: bpy.props.IntProperty(update=process_from_socket)

show_property_type: BoolProperty(
description="Add icon to switch default type")

def get_link_parameter_node(self):
if self.quick_link_to_node:
return self.quick_link_to_node
Expand Down Expand Up @@ -931,10 +937,14 @@ def draw_property(self, layout, prop_origin=None, prop_name=None):
if prop_origin and prop_name:
layout.prop(prop_origin, prop_name)
elif self.use_prop:
row = layout.row(align=True)
if self.default_property_type == 'float':
layout.prop(self, 'default_float_property', text=self.name)
row.prop(self, 'default_float_property', text=self.name)
elif self.default_property_type == 'int':
layout.prop(self, 'default_int_property', text=self.name)
row.prop(self, 'default_int_property', text=self.name)
if self.show_property_type:
icon = 'IPO_LINEAR' if self.default_property_type == 'float' else 'IPO_CONSTANT'
row.operator(SvSwitchDefaultOp.bl_idname, icon=icon, text='')

def draw_menu_items(self, context, layout):
self.draw_simplify_modes(layout)
Expand Down Expand Up @@ -1433,6 +1443,24 @@ def invoke(self, context, event):
wm.invoke_search_popup(self)
return {'FINISHED'}


class SvSwitchDefaultOp(bpy.types.Operator):
"""Either Float or Integer"""
bl_idname = "node.sv_switch_default"
bl_label = "Switch default value of string socket"
bl_options = {'INTERNAL', 'REGISTER'}

@classmethod
def poll(cls, context):
return hasattr(context, 'socket')

def execute(self, context):
s = context.socket
s.default_property_type = 'float' if s.default_property_type == 'int' else 'int'
process_from_socket(s, context)
return {'FINISHED'}


classes = [
SV_MT_SocketOptionsMenu, SV_MT_AllSocketsOptionsMenu,
SvVerticesSocket, SvMatrixSocket, SvStringsSocket, SvFilePathSocket,
Expand All @@ -1442,7 +1470,8 @@ def invoke(self, context, event):
SvSolidSocket, SvSvgSocket, SvPulgaForceSocket, SvFormulaSocket,
SvLoopControlSocket, SvLinkNewNodeInput,
SvStringsSocketInterface, SvVerticesSocketInterface,
SvSocketHelpOp, SvInputLinkMenuOp
SvSocketHelpOp, SvInputLinkMenuOp,
SvSwitchDefaultOp,
]

def socket_interface_classes():
Expand Down
6 changes: 6 additions & 0 deletions docs/contributing/node_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ label
use_prop
Expects boolean value. If true the socket will display its default property.

.. image:: https://user-images.githubusercontent.com/28003269/180741280-683987fa-e10c-47e1-91e0-807311697fea.png
:align: right

show_property_type (SvStringsSocket)
It adds icon to switch default type of the string socket

custom_draw
Expects name of a method of the node of the socket. If defined the method
will be used draw UI elements for the socket.
Expand Down
4 changes: 0 additions & 4 deletions docs/nodes/logic/logic_node.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ Advanced Parameters

In the N-Panel (and on the right-click menu) you can find:

**Input 1 Type**: offers int / float selection for socket 1. (Just on N-panel)

**Input 2 Type**: offers int / float selection for socket 2. (Just on N-panel)

**Output NumPy**: Get NumPy arrays in stead of regular lists (makes the node faster). [Not available for GCD or Round-N]

**List Match**: Define how list with different lengths should be matched. [Not available for GCD or Round-N]
Expand Down
2 changes: 1 addition & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@
SvTextureEvaluateNodeMk2

## Logic
SvLogicNode
SvLogicNodeMK2
SvSwitchNodeMK2
SvInputSwitchNodeMOD
SvNeuroElman1LNode
Expand Down
Binary file removed json_examples/Advanced/Pineapple.zip
Binary file not shown.
Binary file added json_examples/Advanced/Pineapple.zip.zip
Binary file not shown.
Loading

0 comments on commit e582fab

Please sign in to comment.