Просмотр исходного кода

Adding sounds in scene editor, hooked up sound prop sheet

Ivan Safrin 12 лет назад
Родитель
Сommit
fc7d880132

+ 1 - 0
IDE/Contents/Include/EntityEditorPropertyView.h

@@ -56,6 +56,7 @@ class EntityEditorPropertyView : public UIElement {
         ParticleEmitterSheet *particleSheet;
         SceneLabelSheet *labelSheet;
         SceneSpriteSheet *spriteSheet;
+        SoundSheet *soundSheet;
     
         ShaderTexturesSheet *shaderTexturesSheet;
         ShaderOptionsSheet *shaderOptionsSheet;

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

@@ -743,21 +743,15 @@ class SoundSheet : public PropSheet {
 		~SoundSheet();
 		
 		void handleEvent(Event *event);
-		void Update();
+        void setSound(SceneSound *sound);
 				
 		SceneSound *sound;
 
 		SoundProp *soundProp;		
 		NumberProp *referenceDistance;
 		NumberProp *maxDistance;		
-		NumberProp *volume;
-		NumberProp *pitch;
-		
-		String lastSoundPath;
-		Number lastReferenceDistance;
-		Number lastMaxDistance;
-		Number lastVolume;
-		Number lastPitch;
+		SliderProp *volume;
+		SliderProp *pitch;
 };
 
 class PropList : public UIElement {

BIN
IDE/Contents/Resources/Images/entityEditor/sound_icon.png


BIN
IDE/Contents/Resources/ImagesRetina/entityEditor/sound_icon.png


+ 10 - 1
IDE/Contents/Source/EntityEditorPropertyView.cpp

@@ -67,6 +67,11 @@ EntityEditorPropertyView::EntityEditorPropertyView() : UIElement() {
     entityProps->addPropSheet(primitiveSheet);
     primitiveSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
     
+    soundSheet = new SoundSheet();
+    entityProps->addPropSheet(soundSheet);
+    soundSheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
+
+    
     entitySheet = new EntitySheet();
     entityProps->addPropSheet(entitySheet);
     entitySheet->addEventListener(this, PropEvent::EVENT_PROP_CHANGE);
@@ -131,7 +136,11 @@ void EntityEditorPropertyView::setEntity(Entity *entity) {
     } else {
         primitiveSheet->setScenePrimitive(NULL);
     }
-    
+
+    SceneSound *sound = dynamic_cast<SceneSound*>(entity);
+    if(sound) {
+        soundSheet->setSound(sound);
+    }
 
     SceneParticleEmitter *emitter = dynamic_cast<SceneParticleEmitter*>(entity);
     particleSheet->setParticleEmitter(emitter);

+ 17 - 0
IDE/Contents/Source/PolycodeEntityEditor.cpp

@@ -170,6 +170,11 @@ void EntityEditorMainView::setEditorProps(Entity *entity) {
         createIcon(entity, "emitter_icon.png");
     }
 
+    SceneSound *sound = dynamic_cast<SceneSound*>(entity);
+    if(sound) {
+        createIcon(entity, "sound_icon.png");
+    }
+
     
 }
 
@@ -195,6 +200,18 @@ void EntityEditorMainView::addEntityFromMenu(String command) {
         return;
     }
 
+    if(command == "add_sound") {
+        SceneSound *newSound = new SceneSound("default.wav", 1.0, 2.0);
+        sceneObjectRoot->addChild(newSound);
+        setEditorProps(newSound);
+        newSound->bBox = Vector3(0.5, 0.5, 0.5);
+        newSound->setPosition(cursorPosition);
+        selectEntity(newSound);
+        return;
+    }
+
+    
+
     if(command == "add_primitive") {
         ScenePrimitive  *newPrimitive = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 1.0, 1.0, 1.0);
         sceneObjectRoot->addChild(newPrimitive);

+ 21 - 47
IDE/Contents/Source/PolycodeProps.cpp

@@ -3089,8 +3089,9 @@ void SceneLabelSheet::handleEvent(Event *event) {
 	PropSheet::handleEvent(event);
 }
 
-SoundSheet::SoundSheet() : PropSheet("SCREEN SOUND", "Sound") {
+SoundSheet::SoundSheet() : PropSheet("SOUND", "sound") {
 	sound = NULL;
+    enabled = false;
 	
 	soundProp = new SoundProp("Sound file");
 	soundProp->addEventListener(this, Event::CHANGE_EVENT);
@@ -3104,21 +3105,15 @@ SoundSheet::SoundSheet() : PropSheet("SCREEN SOUND", "Sound") {
 	maxDistance->addEventListener(this, Event::CHANGE_EVENT);
 	addProp(maxDistance);
 
-	volume = new NumberProp("Volume");
+	volume = new SliderProp("Volume", 0.0, 1.0);
 	volume->addEventListener(this, Event::CHANGE_EVENT);
 	addProp(volume);
 	
-	pitch = new NumberProp("Pitch");
+	pitch = new SliderProp("Pitch", 0.0, 2.0);
 	pitch->addEventListener(this, Event::CHANGE_EVENT);
 	addProp(pitch);
-	
-	lastReferenceDistance = 0.0;
-	lastMaxDistance = 0.0;
-	lastVolume = 0.0;
-	lastPitch = 0.0;
-	lastSoundPath = "";
-	
-	propHeight = 230;
+		
+	propHeight = 210;
 }
 
 SoundSheet::~SoundSheet() {
@@ -3130,65 +3125,44 @@ void SoundSheet::handleEvent(Event *event) {
 		return;
 
 	if(event->getDispatcher() == referenceDistance  && event->getEventCode() == Event::CHANGE_EVENT) {
-		lastReferenceDistance = referenceDistance->get();
-		sound->getSound()->setReferenceDistance(lastReferenceDistance);
+		sound->getSound()->setReferenceDistance(referenceDistance->get());
 		dispatchEvent(new Event(), Event::CHANGE_EVENT);
 	}
 
 	if(event->getDispatcher() == maxDistance  && event->getEventCode() == Event::CHANGE_EVENT) {
-		lastMaxDistance = maxDistance->get();
-		sound->getSound()->setMaxDistance(lastMaxDistance);
+		sound->getSound()->setMaxDistance(maxDistance->get());
 		dispatchEvent(new Event(), Event::CHANGE_EVENT);
 	}
 
 	if(event->getDispatcher() == volume  && event->getEventCode() == Event::CHANGE_EVENT) {
-		lastVolume = volume->get();
-		sound->getSound()->setVolume(lastVolume);
+		sound->getSound()->setVolume(volume->get());
 	}
 
 	if(event->getDispatcher() == pitch  && event->getEventCode() == Event::CHANGE_EVENT) {
-		lastPitch = pitch->get();
-		sound->getSound()->setPitch(lastPitch);
+		sound->getSound()->setPitch(pitch->get());
+        soundProp->previewSound->setPitch(pitch->get());
 	}
 
 	if(event->getDispatcher() == soundProp  && event->getEventCode() == Event::CHANGE_EVENT) {
-		lastSoundPath = soundProp->get();
-		sound->getSound()->loadFile(lastSoundPath, false);
+		sound->getSound()->loadFile(soundProp->get(), false);
 	}
 
 
 	PropSheet::handleEvent(event);
 }
 
-void SoundSheet::Update() {
+void SoundSheet::setSound(SceneSound *sound) {
+    this->sound = sound;
+
 	if(sound) {
 		enabled = true;	
-		
-		if(sound->getSound()->getFileName() != lastSoundPath) {
-			lastSoundPath = sound->getSound()->getFileName();
-			soundProp->set(sound->getSound()->getFileName());
-		}
-		
-		if(sound->getSound()->getReferenceDistance() != lastReferenceDistance) {
-			lastReferenceDistance = sound->getSound()->getReferenceDistance();
-			referenceDistance->set(sound->getSound()->getReferenceDistance());
-		}
-
-		if(sound->getSound()->getMaxDistance() != lastMaxDistance) {
-			lastMaxDistance = sound->getSound()->getMaxDistance();
-			maxDistance->set(sound->getSound()->getMaxDistance());
-		}
 
-		if(sound->getSound()->getVolume() != lastVolume) {
-			lastVolume = sound->getSound()->getVolume();
-			volume->set(sound->getSound()->getVolume());
-		}
-
-		if(sound->getSound()->getPitch() != lastPitch) {
-			lastPitch = sound->getSound()->getPitch();
-			pitch->set(sound->getSound()->getPitch());
-		}
-		
+        soundProp->set(sound->getSound()->getFileName());
+        referenceDistance->set(sound->getSound()->getReferenceDistance());
+        maxDistance->set(sound->getSound()->getMaxDistance());
+        volume->set(sound->getSound()->getVolume());
+        pitch->set(sound->getSound()->getPitch());
+        soundProp->previewSound->setPitch(sound->getSound()->getPitch());
 
 	} else {
 		enabled = false;