Преглед изворни кода

Made ScreenSprite force replay on playAnimation if playing once, fixed crash in entity prop undos

Ivan Safrin пре 12 година
родитељ
комит
2e7aadb9a3

+ 1 - 1
Core/Contents/Source/PolyScreenSprite.cpp

@@ -239,7 +239,7 @@ void ScreenSprite::playAnimation(const String& name, int startFrame, bool once)
 	paused = false;
 	for(int i=0; i < animations.size(); i++) {
 		if(animations[i]->name == name) {
-			if(currentAnimation == animations[i] && !playingOnce)
+			if(currentAnimation == animations[i] && !playingOnce && !once)
 				return;
 			currentFrame = 0;			
 			currentAnimation = animations[i];

+ 7 - 3
IDE/Contents/Include/PolycodeProps.h

@@ -326,6 +326,8 @@ class PropSheet : public UIElement {
 		
 		bool collapsed;
 		
+		bool customUndoHandler;
+		
 		std::vector<PropProp*> props;
 };
 
@@ -631,8 +633,10 @@ class PropList : public UIElement {
 
 class PolycodeEditorPropActionData : public PolycodeEditorActionData {
 	public:
-		PolycodeEditorPropActionData(){}
-		virtual ~PolycodeEditorPropActionData(){}
+		PolycodeEditorPropActionData(){ entity = NULL; }
+		virtual ~PolycodeEditorPropActionData(){
+			delete entity;
+		}
 		
 		bool boolVal;
 		String stringVal;
@@ -642,7 +646,7 @@ class PolycodeEditorPropActionData : public PolycodeEditorActionData {
 		Vector3 vector3Val;
 		Vector2 vector2Val;
 		
-		Entity entity;
+		Entity *entity;
 		
 		PropSheet *sheet;
 		PropProp *prop;

+ 13 - 7
IDE/Contents/Source/PolycodeProps.cpp

@@ -71,10 +71,10 @@ PolycodeEditorPropActionData *PropDataVector2(Vector2 val) {
 
 PolycodeEditorPropActionData *PropDataEntity(Entity *entity) {
 	PolycodeEditorPropActionData *data = new PolycodeEditorPropActionData();
-	data->entity = *entity;
-	data->entity.ownsChildren = false;
-	for(int i=0; i < data->entity.getNumChildren(); i++) {
-		data->entity.removeChild(data->entity.getChildAtIndex(i));
+	data->entity = entity->Clone(false, true);
+	data->entity->ownsChildren = false;
+	for(int i=0; i < data->entity->getNumChildren(); i++) {
+		data->entity->removeChild(data->entity->getChildAtIndex(i));
 	}
 	return data;
 }
@@ -208,6 +208,8 @@ PropSheet::PropSheet(String caption, String type) : UIElement() {
 	this->caption = caption;
 	this->type = type;
 	
+	customUndoHandler = false;
+	
 	bg = new ScreenShape(ScreenShape::SHAPE_RECT, 30,30);
 	addChild(bg);
 	bg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiSmallHeaderBgColor"));
@@ -267,11 +269,13 @@ void PropSheet::handleEvent(Event *event) {
 		}
 	}
 	
+	if(!customUndoHandler) {
 	if(event->getEventCode() == PropEvent::EVENT_PROP_CHANGE ) {
 		PropEvent *propEvent = (PropEvent*) event;
 		PropEvent *newEvent = new PropEvent(propEvent->prop, this, propEvent->beforeData, propEvent->afterData);		
 		dispatchEvent(newEvent, PropEvent::EVENT_PROP_CHANGE);
-	}	
+	}
+	}
 }
 
 PropSheet::~PropSheet() {
@@ -1214,6 +1218,8 @@ EntityPropSheet::EntityPropSheet() : PropSheet("CUSTOM PROPERTIES", "entityProps
 	addChild(addButton);
 	addButton->setPosition(15, 35);
 	
+	customUndoHandler = true;
+	
 	entity = NULL;
 	lastEntity = NULL;
 	
@@ -1227,8 +1233,8 @@ void EntityPropSheet::applyPropActionData(PolycodeEditorPropActionData *data) {
 		return;
 		
 	entity->entityProps.clear();
-	for(int i=0; i < data->entity.entityProps.size(); i++) {
-			entity->entityProps.push_back(data->entity.entityProps[i]);
+	for(int i=0; i < data->entity->entityProps.size(); i++) {
+			entity->entityProps.push_back(data->entity->entityProps[i]);
 	}
 	
 	refreshProps();

+ 8 - 1
Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp

@@ -258,8 +258,15 @@ void PhysicsScreenEntity::applyImpulse(Number fx, Number fy) {
 }
 			
 void PhysicsScreenEntity::setTransform(Vector2 pos, Number angle) {
+	if(screenEntity->getParentEntity()) {
+		Matrix4 matrix = screenEntity->getParentEntity()->getConcatenatedMatrix();
+		Vector3 parentPos = matrix.getPosition();		
+		pos.x = parentPos.x + pos.x;
+		pos.y = parentPos.y + pos.y;		
+	}
+
 	body->SetTransform(b2Vec2(pos.x/worldScale, pos.y/worldScale), angle*(PI/180.0f));
-    screenEntity->setPosition(pos);
+	Update();
 }
 
 void PhysicsScreenEntity::Update() {