Add move buttons for game properties #32292

Closed
opened 11 years ago by AngusHollands-4 · 20 comments

%%%This patch modifies "space_logic.py" to enable the end user to re order game properties
It should be noted that it makes no difference to the game engine pipeline if the order of game properties should differ, so this is a more cosmetic expansion.
Because properties are drawn from the prop_collection collection, it is impossible to modify the order of properties once they have been added.

This operator does the following:
Take the index of the calling button. Determine the new index. Reorder property list and recreate properties.
This could become expensive if the user has hundreds of properties, but that is unlikely that any game user would manually create such a volume - at that point the drawing code is the biggest bottleneck.

I was unsure where to add the operator, so I provide the operator and modified properties panel in the same file - space_logic.py (patch)%%%

%%%This patch modifies "space_logic.py" to enable the end user to re order game properties It should be noted that it makes no difference to the game engine pipeline if the order of game properties should differ, so this is a more cosmetic expansion. Because properties are drawn from the prop_collection collection, it is impossible to modify the order of properties once they have been added. This operator does the following: Take the index of the calling button. Determine the new index. Reorder property list and recreate properties. This could become expensive if the user has hundreds of properties, but that is unlikely that any game user would manually create such a volume - at that point the drawing code is the biggest bottleneck. I was unsure where to add the operator, so I provide the operator and modified properties panel in the same file - space_logic.py (patch)%%%
Poster

Changed status to: 'Open'

Changed status to: 'Open'

%%%version 2.66 (sub 6), revision b'56420M'. b'Release'
build date: b'2013-04-30', b'21:31:38'
platform: b'Windows:32bit'

Manual test:
added three properties:
prop, prop0, prop1 - passed

moved prop1 up. The new order is:
prop, prop1, prop2 - passed

moved prop down:
prop1, prop, prop0 - passed

moved prop1 up:
prop1, prop, prop0 -passed

moved prop0 down:
prop1, prop, prop0 - passed

all test passed.
Fine from my site%%%

%%%version 2.66 (sub 6), revision b'56420M'. b'Release' build date: b'2013-04-30', b'21:31:38' platform: b'Windows:32bit' Manual test: added three properties: prop, prop0, prop1 - passed moved prop1 up. The new order is: prop, prop1, prop2 - passed moved prop down: prop1, prop, prop0 - passed moved prop1 up: prop1, prop, prop0 -passed moved prop0 down: prop1, prop, prop0 - passed all test passed. Fine from my site%%%
hg1 commented 10 years ago
Collaborator

%%%"space_logic.py_HG1.patch" is a cleaned up version and works with the actual trunk.%%%

%%%"space_logic.py_HG1.patch" is a cleaned up version and works with the actual trunk.%%%
Collaborator

%%%Operators have a naming convention. I don't remember it off-hand, but I'm pretty sure your two new operators are not following it. Other than that, I'm assigning this to Dalai since this is more his area of expertise.%%%

%%%Operators have a naming convention. I don't remember it off-hand, but I'm pretty sure your two new operators are not following it. Other than that, I'm assigning this to Dalai since this is more his area of expertise.%%%

Added subscriber: @mahalin

Added subscriber: @mahalin

Can this be merged?

Can this be merged?
Sergey commented 8 years ago
Owner
Added subscribers: @JorgeBernalMartinez, @dr.sybren, @brita, @Sergey
Poster

After reviewing my patch, I have made some changes to improve code quality.
namely, simplifying iterators, removing essentially a duplicate operator (single semantic difference) and attempting to use a more conventional operator name. As I am not at home, I am currently unable to produce a patch for this, but I can attach the reviewed file.

space_logic.py

After reviewing my patch, I have made some changes to improve code quality. namely, simplifying iterators, removing essentially a duplicate operator (single semantic difference) and attempting to use a more conventional operator name. As I am not at home, I am currently unable to produce a patch for this, but I can attach the reviewed file. [space_logic.py](https://archive.blender.org/developer/F145967/space_logic.py)
Collaborator

Overall I think this is a very nice addition. It's something I've missed :)

There are no operators defined in the bl_ui package. I think it would be better to keep it that way, and to move your operator to a new module bl_operators.logic

properties.remove(current) requires O(n) operations just to find the element to remove. It's more efficient to use del properties[index], which only uses O(1) to find the element.

PEP 8: remove the whitespace between i : in the line prop_match = {i : (v.name, v.type, v.value, v.show_debug) for i, v in enumerate(properties)}
More PEP 8: use triple-double quotes for docstrings.

Such an invoke() is unnecessary, as by default self.execute() is called anyway:

    def invoke(self, context, event):
        return self.execute(context)

The up-arrow also moves the property down (at least on my Blender), so add move_up.direction = "UP" to the GUI code.
It would be nice if the top up-arrow and bottom down-arrow are disabled.

Overall I think this is a very nice addition. It's something I've missed :) There are no operators defined in the `bl_ui` package. I think it would be better to keep it that way, and to move your operator to a new module `bl_operators.logic` `properties.remove(current)` requires O(n) operations just to find the element to remove. It's more efficient to use `del properties[index]`, which only uses O(1) to find the element. PEP 8: remove the whitespace between `i :` in the line `prop_match = {i : (v.name, v.type, v.value, v.show_debug) for i, v in enumerate(properties)}` More PEP 8: use triple-double quotes for docstrings. Such an `invoke()` is unnecessary, as by default `self.execute()` is called anyway: ``` def invoke(self, context, event): return self.execute(context) ``` The up-arrow also moves the property down (at least on my Blender), so add `move_up.direction = "UP"` to the GUI code. It would be nice if the top up-arrow and bottom down-arrow are disabled.
Poster

This comment was removed by @AngusHollands-4

*This comment was removed by @AngusHollands-4*
Poster

This comment was removed by @AngusHollands-4

*This comment was removed by @AngusHollands-4*
Poster

license.diff

Made requested changes, included license block.

Thanks for catching the remove call, poor consideration there.

[license.diff](https://archive.blender.org/developer/F146356/license.diff) Made requested changes, included license block. Thanks for catching the remove call, poor consideration there.
brita commented 8 years ago
Collaborator

thumbs up for the patch and thumbs up for sybren's review.
best to move that in before getting in fix-only mode tomorrow at the meeting.

Comments:

  • don't forget to add license block to the new file
  • import bpy
  • bl_label = "Move game property up in stack" -> up/down in the list? I think it is a more common wording... totally non important

another tip, for the direction enum, you can attribute a specific value of -1 for down and +1 for up, so that you attribute it to direction and use directly instead of index + 1
See how other moves do (they are typically executed in C, though, because the order matters for functionality there)

thumbs up for the patch and thumbs up for sybren's review. best to move that in before getting in fix-only mode tomorrow at the meeting. Comments: - don't forget to add license block to the new file - # <pep8 compliant> - import bpy - bl_label = "Move game property up in stack" -> up/down in the list? I think it is a more common wording... totally non important another tip, for the direction enum, you can attribute a specific value of -1 for down and +1 for up, so that you attribute it to direction and use directly instead of index + 1 See how other moves do (they are typically executed in C, though, because the order matters for functionality there)
Poster

Thanks Brita - I thought it better practice to separate that behaviour from the implementation, but perhaps it's not an issue.

Thanks Brita - I thought it better practice to separate that behaviour from the implementation, but perhaps it's not an issue.
dfelinto was unassigned by brita 8 years ago
brita self-assigned this 8 years ago
brita commented 8 years ago
Collaborator

I'll get this in when we're back at bcon1 (I was without internet before, sorry about that).

I'll get this in when we're back at bcon1 (I was without internet before, sorry about that).

Removed subscriber: @mahalin

Removed subscriber: @mahalin
Collaborator

Added subscribers: @ideasman42, @JulianEisel

Added subscribers: @ideasman42, @JulianEisel
Collaborator

A diff for the same functionality was submitted recently (D1163), so we have to make the decision which one to use. I personally prefer D1163 since it is written in C (C in general is faster and things like removing and adding properties for reordering aren't needed).

A diff for the same functionality was submitted recently ([D1163](https://archive.blender.org/developer/D1163)), so we have to make the decision which one to use. I personally prefer [D1163](https://archive.blender.org/developer/D1163) since it is written in C (C in general is faster and things like removing and adding properties for reordering aren't needed).
Collaborator

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
JulianEisel closed this issue 8 years ago
Collaborator

Committed the C version of this (a8adeeb6fb) so this can be closed.

@AngusHollands-4, thanks for this nevertheless :)

Committed the C version of this (a8adeeb6fb) so this can be closed. @AngusHollands-4, thanks for this nevertheless :)
Sign in to join this conversation.
No Label
Interest/Alembic
Interest/Animation & Rigging
Interest/Asset Browser
Interest/Asset Browser Project Overview
Interest/Audio
Interest/Automated Testing
Interest/Blender Asset Bundle
Interest/Collada
Interest/Compositing
Interest/Core
Interest/Cycles
Interest/Dependency Graph
Interest/Development Management
Interest/Eevee & Viewport
Interest/Freestyle
Interest/Geometry Nodes
Interest/Grease Pencil
Interest/ID Management
Interest/Images & Movies
Interest/Import/Export
Interest/Line Art
Interest/Masking
Interest/Modeling
Interest/Modifiers
Interest/Motion Tracking
Interest/Nodes & Physics
Interest/Overrides
Interest/Performance
Interest/Pipeline, Assets & I/O
Interest/Translations
Interest/Undo
Interest/USD
Interest/Video Sequencer
legacy module/Animation & Rigging
legacy module/Core
legacy module/Development Management
legacy module/Eevee & Viewport
legacy module/Grease Pencil
legacy module/Modeling
legacy module/Nodes & Physics
legacy module/Pipeline, Assets & IO
legacy module/Platforms, Builds, Tests & Devices
legacy module/Python API
legacy module/Rendering & Cycles
legacy module/Sculpt, Paint & Texture
legacy module/Triaging
legacy module/User Interface
legacy module/VFX & Video
legacy project/1.0.0-beta.2
legacy project/Asset Browser (Archived)
legacy project/BF Blender: 2.8
legacy project/BF Blender: After Release
legacy project/BF Blender: Next
legacy project/BF Blender: Regressions
legacy project/BF Blender: Unconfirmed
legacy project/Blender 2.70
legacy project/Code Quest
legacy project/Datablocks and Libraries
legacy project/Eevee
legacy project/Game Animation
legacy project/Game Audio
legacy project/Game Data Conversion
legacy project/Game Engine
legacy project/Game Logic
legacy project/Game Physics
legacy project/Game Python
legacy project/Game Rendering
legacy project/Game UI
legacy project/GPU / Viewport
legacy project/GSoC
legacy project/Infrastructure: Websites
legacy project/LibOverrides - Usability and UX
legacy project/Milestone 1: Basic, Local Asset Browser
legacy project/Nodes
legacy project/OpenGL Error
legacy project/Papercut
legacy project/Performance
legacy project/Physics
legacy project/Platforms, Builds, Tests & Devices
legacy project/Pose Library Basics
legacy project/Python API
legacy project/Render & Cycles
legacy project/Render Pipeline
legacy project/Retrospective
legacy project/Sculpt, Paint & Texture
legacy project/Text Editor
legacy project/Tracker Curfew
legacy project/Triaging
legacy project/User Interface
legacy project/UV Editing
legacy project/VFX & Video
legacy project/Virtual Reality
legacy project/Wintab High Frequency
Meta/Good First Issue
Meta/Papercut
migration/requires-manual-verification
Module › Animation & Rigging
Module › Core
Module › Development Management
Module › Eevee & Viewport
Module › Grease Pencil
Module › Modeling
Module › Nodes & Physics
Module › Pipeline, Assets & IO
Module › Platforms, Builds, Tests & Devices
Module › Python API
Module › Render & Cycles
Module › Sculpt, Paint & Texture
Module › Triaging
Module › User Interface
Module › VFX & Video
Platform/FreeBSD
Platform/Linux
Platform/macOS
Platform/Windows
Priority › High
Priority › Low
Priority › Normal
Priority › Unbreak Now!
Status › Archived
Status › Confirmed
Status › Duplicate
Status › Needs Information from Developers
Status › Needs Information from User
Status › Needs Triage
Status › Resolved
Type › Bug
Type › Design
Type › Known Issue
Type › Patch
Type › Report
Type › To Do
No Milestone
No project
No Assignees
9 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#32292
Loading…
There is no content yet.