-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move collection stuff to its own file
- Loading branch information
Showing
8 changed files
with
190 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import bpy | ||
|
||
from bpy.types import Operator | ||
from bpy.utils import register_class, unregister_class | ||
from bpy.props import IntProperty, StringProperty | ||
from ..utility import PluginError, ootGetSceneOrRoomHeader | ||
|
||
|
||
class OOTCollectionAdd(Operator): | ||
bl_idname = "object.oot_collection_add" | ||
bl_label = "Add Item" | ||
bl_options = {"REGISTER", "UNDO"} | ||
|
||
option: IntProperty() | ||
collectionType: StringProperty(default="Actor") | ||
subIndex: IntProperty(default=0) | ||
objName: StringProperty() | ||
|
||
def execute(self, context): | ||
collection = getCollection(self.objName, self.collectionType, self.subIndex) | ||
|
||
collection.add() | ||
collection.move(len(collection) - 1, self.option) | ||
return {"FINISHED"} | ||
|
||
|
||
class OOTCollectionRemove(Operator): | ||
bl_idname = "object.oot_collection_remove" | ||
bl_label = "Remove Item" | ||
bl_options = {"REGISTER", "UNDO"} | ||
|
||
option: IntProperty() | ||
collectionType: StringProperty(default="Actor") | ||
subIndex: IntProperty(default=0) | ||
objName: StringProperty() | ||
|
||
def execute(self, context): | ||
collection = getCollection(self.objName, self.collectionType, self.subIndex) | ||
collection.remove(self.option) | ||
return {"FINISHED"} | ||
|
||
|
||
class OOTCollectionMove(Operator): | ||
bl_idname = "object.oot_collection_move" | ||
bl_label = "Move Item" | ||
bl_options = {"REGISTER", "UNDO"} | ||
|
||
option: IntProperty() | ||
offset: IntProperty() | ||
subIndex: IntProperty(default=0) | ||
objName: StringProperty() | ||
|
||
collectionType: StringProperty(default="Actor") | ||
|
||
def execute(self, context): | ||
collection = getCollection(self.objName, self.collectionType, self.subIndex) | ||
collection.move(self.option, self.option + self.offset) | ||
return {"FINISHED"} | ||
|
||
|
||
def getCollectionFromIndex(obj, prop, subIndex, isRoom): | ||
header = ootGetSceneOrRoomHeader(obj, subIndex, isRoom) | ||
return getattr(header, prop) | ||
|
||
|
||
# Operators cannot store mutable references (?), so to reuse PropertyCollection modification code we do this. | ||
# Save a string identifier in the operator, then choose the member variable based on that. | ||
# subIndex is for a collection within a collection element | ||
def getCollection(objName, collectionType, subIndex): | ||
obj = bpy.data.objects[objName] | ||
if collectionType == "Actor": | ||
collection = obj.ootActorProperty.headerSettings.cutsceneHeaders | ||
elif collectionType == "Transition Actor": | ||
collection = obj.ootTransitionActorProperty.actor.headerSettings.cutsceneHeaders | ||
elif collectionType == "Entrance": | ||
collection = obj.ootEntranceProperty.actor.headerSettings.cutsceneHeaders | ||
elif collectionType == "Room": | ||
collection = obj.ootAlternateRoomHeaders.cutsceneHeaders | ||
elif collectionType == "Scene": | ||
collection = obj.ootAlternateSceneHeaders.cutsceneHeaders | ||
elif collectionType == "Light": | ||
collection = getCollectionFromIndex(obj, "lightList", subIndex, False) | ||
elif collectionType == "Exit": | ||
collection = getCollectionFromIndex(obj, "exitList", subIndex, False) | ||
elif collectionType == "Object": | ||
collection = getCollectionFromIndex(obj, "objectList", subIndex, True) | ||
elif collectionType == "Curve": | ||
collection = obj.ootSplineProperty.headerSettings.cutsceneHeaders | ||
elif collectionType.startswith("CSHdr."): | ||
# CSHdr.HeaderNumber[.ListType] | ||
# Specifying ListType means uses subIndex | ||
toks = collectionType.split(".") | ||
assert len(toks) in [2, 3] | ||
hdrnum = int(toks[1]) | ||
collection = getCollectionFromIndex(obj, "csLists", hdrnum, False) | ||
if len(toks) == 3: | ||
collection = getattr(collection[subIndex], toks[2]) | ||
elif collectionType.startswith("Cutscene."): | ||
# Cutscene.ListType | ||
toks = collectionType.split(".") | ||
assert len(toks) == 2 | ||
collection = obj.ootCutsceneProperty.csLists | ||
collection = getattr(collection[subIndex], toks[1]) | ||
elif collectionType == "Cutscene": | ||
collection = obj.ootCutsceneProperty.csLists | ||
elif collectionType == "extraCutscenes": | ||
collection = obj.ootSceneHeader.extraCutscenes | ||
elif collectionType == "BgImage": | ||
collection = obj.ootRoomHeader.bgImageList | ||
else: | ||
raise PluginError("Invalid collection type: " + collectionType) | ||
|
||
return collection | ||
|
||
|
||
def drawAddButton(layout, index, collectionType, subIndex, objName): | ||
if subIndex is None: | ||
subIndex = 0 | ||
addOp = layout.operator(OOTCollectionAdd.bl_idname) | ||
addOp.option = index | ||
addOp.collectionType = collectionType | ||
addOp.subIndex = subIndex | ||
addOp.objName = objName | ||
|
||
|
||
def drawCollectionOps(layout, index, collectionType, subIndex, objName, allowAdd=True, compact=False): | ||
if subIndex is None: | ||
subIndex = 0 | ||
|
||
if not compact: | ||
buttons = layout.row(align=True) | ||
else: | ||
buttons = layout | ||
|
||
if allowAdd: | ||
addOp = buttons.operator(OOTCollectionAdd.bl_idname, text="Add" if not compact else "", icon="ADD") | ||
addOp.option = index + 1 | ||
addOp.collectionType = collectionType | ||
addOp.subIndex = subIndex | ||
addOp.objName = objName | ||
|
||
removeOp = buttons.operator(OOTCollectionRemove.bl_idname, text="Delete" if not compact else "", icon="REMOVE") | ||
removeOp.option = index | ||
removeOp.collectionType = collectionType | ||
removeOp.subIndex = subIndex | ||
removeOp.objName = objName | ||
|
||
moveUp = buttons.operator(OOTCollectionMove.bl_idname, text="Up" if not compact else "", icon="TRIA_UP") | ||
moveUp.option = index | ||
moveUp.offset = -1 | ||
moveUp.collectionType = collectionType | ||
moveUp.subIndex = subIndex | ||
moveUp.objName = objName | ||
|
||
moveDown = buttons.operator(OOTCollectionMove.bl_idname, text="Down" if not compact else "", icon="TRIA_DOWN") | ||
moveDown.option = index | ||
moveDown.offset = 1 | ||
moveDown.collectionType = collectionType | ||
moveDown.subIndex = subIndex | ||
moveDown.objName = objName | ||
|
||
|
||
collections_classes = ( | ||
OOTCollectionAdd, | ||
OOTCollectionRemove, | ||
OOTCollectionMove, | ||
) | ||
|
||
|
||
def collections_register(): | ||
for cls in collections_classes: | ||
register_class(cls) | ||
|
||
|
||
def collections_unregister(): | ||
for cls in reversed(collections_classes): | ||
unregister_class(cls) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.