Sfoglia il codice sorgente

Code format, deleted commented code, tabs to spaces

szamq 11 anni fa
parent
commit
0d21c51c4f

+ 130 - 148
Bin/Data/Scripts/Editor/EditorSpawn.as

@@ -34,43 +34,40 @@ void CreateSpawnEditor()
     CenterDialog(spawnWindow);
     CenterDialog(spawnWindow);
 
 
     HideSpawnEditor();
     HideSpawnEditor();
-	SubscribeToEvent(spawnWindow.GetChild("CloseButton", true), "Released", "HideSpawnEditor");
-	randomRotationX=spawnWindow.GetChild("RandomRotation.x", true);
-	randomRotationY=spawnWindow.GetChild("RandomRotation.y", true);
-	randomRotationZ=spawnWindow.GetChild("RandomRotation.z", true);
-	randomRotationX.text=String(randomRotation.x);
-	randomRotationY.text=String(randomRotation.y);
-	randomRotationZ.text=String(randomRotation.z);
-	
-	randomScaleMinEdit=spawnWindow.GetChild("RandomScaleMin", true);
-	randomScaleMaxEdit=spawnWindow.GetChild("RandomScaleMax", true);
-	randomScaleMinEdit.text=String(randomScaleMin);
-	randomScaleMaxEdit.text=String(randomScaleMax);
-	CheckBox@ useNormalToggle = spawnWindow.GetChild("UseNormal", true);
+    SubscribeToEvent(spawnWindow.GetChild("CloseButton", true), "Released", "HideSpawnEditor");
+    randomRotationX=spawnWindow.GetChild("RandomRotation.x", true);
+    randomRotationY=spawnWindow.GetChild("RandomRotation.y", true);
+    randomRotationZ=spawnWindow.GetChild("RandomRotation.z", true);
+    randomRotationX.text=String(randomRotation.x);
+    randomRotationY.text=String(randomRotation.y);
+    randomRotationZ.text=String(randomRotation.z);
+    
+    randomScaleMinEdit=spawnWindow.GetChild("RandomScaleMin", true);
+    randomScaleMaxEdit=spawnWindow.GetChild("RandomScaleMax", true);
+    randomScaleMinEdit.text=String(randomScaleMin);
+    randomScaleMaxEdit.text=String(randomScaleMax);
+    CheckBox@ useNormalToggle = spawnWindow.GetChild("UseNormal", true);
     useNormalToggle.checked = useNormal;
     useNormalToggle.checked = useNormal;
 
 
-	
-	NumberSpawnedObjectsEdit=spawnWindow.GetChild("NumberSpawnedObjects", true);
-	NumberSpawnedObjectsEdit.text=String(numberSpawnedObjects);
-	
-		
-	spawnRadiusEdit=spawnWindow.GetChild("SpawnRadius", true);
-	spawnCountEdit=spawnWindow.GetChild("SpawnCount", true);
-	spawnRadiusEdit.text=String(spawnRadius);
-	spawnCountEdit.text=String(spawnCount);
-	
-	
-	SubscribeToEvent(randomRotationX, "TextChanged", "EditRandomRotation");
+    NumberSpawnedObjectsEdit=spawnWindow.GetChild("NumberSpawnedObjects", true);
+    NumberSpawnedObjectsEdit.text=String(numberSpawnedObjects);
+    
+    spawnRadiusEdit=spawnWindow.GetChild("SpawnRadius", true);
+    spawnCountEdit=spawnWindow.GetChild("SpawnCount", true);
+    spawnRadiusEdit.text=String(spawnRadius);
+    spawnCountEdit.text=String(spawnCount);
+    
+    SubscribeToEvent(randomRotationX, "TextChanged", "EditRandomRotation");
     SubscribeToEvent(randomRotationY, "TextChanged", "EditRandomRotation");
     SubscribeToEvent(randomRotationY, "TextChanged", "EditRandomRotation");
     SubscribeToEvent(randomRotationZ, "TextChanged", "EditRandomRotation");
     SubscribeToEvent(randomRotationZ, "TextChanged", "EditRandomRotation");
-	SubscribeToEvent(randomScaleMinEdit, "TextChanged", "EditRandomScale");
-	SubscribeToEvent(randomScaleMaxEdit, "TextChanged", "EditRandomScale");
-	SubscribeToEvent(spawnRadiusEdit, "TextChanged", "EditSpawnRadius");
-	SubscribeToEvent(spawnCountEdit, "TextChanged", "EditSpawnCount");
-	SubscribeToEvent(useNormalToggle, "Toggled", "ToggleUseNormal");
-	SubscribeToEvent(NumberSpawnedObjectsEdit, "TextFinished", "UpdateNumberSpawnedObjects");
-	SubscribeToEvent(spawnWindow.GetChild("SetSpawnMode", true), "Released", "SetSpawnMode");
-	RefreshPickedObjects();
+    SubscribeToEvent(randomScaleMinEdit, "TextChanged", "EditRandomScale");
+    SubscribeToEvent(randomScaleMaxEdit, "TextChanged", "EditRandomScale");
+    SubscribeToEvent(spawnRadiusEdit, "TextChanged", "EditSpawnRadius");
+    SubscribeToEvent(spawnCountEdit, "TextChanged", "EditSpawnCount");
+    SubscribeToEvent(useNormalToggle, "Toggled", "ToggleUseNormal");
+    SubscribeToEvent(NumberSpawnedObjectsEdit, "TextFinished", "UpdateNumberSpawnedObjects");
+    SubscribeToEvent(spawnWindow.GetChild("SetSpawnMode", true), "Released", "SetSpawnMode");
+    RefreshPickedObjects();
 }
 }
 
 
 bool ShowSpawnEditor()
 bool ShowSpawnEditor()
@@ -104,12 +101,6 @@ void EditRandomRotation(StringHash eventType, VariantMap& eventData)
 {
 {
     LineEdit@ edit = eventData["Element"].GetPtr();
     LineEdit@ edit = eventData["Element"].GetPtr();
     randomRotation = Vector3(randomRotationX.text.ToFloat(), randomRotationY.text.ToFloat(), randomRotationZ.text.ToFloat());
     randomRotation = Vector3(randomRotationX.text.ToFloat(), randomRotationY.text.ToFloat(), randomRotationZ.text.ToFloat());
-    //if (edit.name == "RandomRotation.x")
-    //    edit.text = String(randomRotation.x);
-    //else if (edit.name == "RandomRotation.y")
-    //    edit.text = String(randomRotation.y);
-    //else if (edit.name == "RandomRotation.z")
-    //    edit.text = String(randomRotation.z);
     UpdateHierarchyItem(editorScene);
     UpdateHierarchyItem(editorScene);
 }
 }
 
 
@@ -117,11 +108,7 @@ void EditRandomScale(StringHash eventType, VariantMap& eventData)
 {
 {
     LineEdit@ edit = eventData["Element"].GetPtr();
     LineEdit@ edit = eventData["Element"].GetPtr();
     randomScaleMin = randomScaleMinEdit.text.ToFloat();
     randomScaleMin = randomScaleMinEdit.text.ToFloat();
-	randomScaleMax = randomScaleMaxEdit.text.ToFloat();
-	//if (edit.name == "RandomScaleMin")
-    //    edit.text = String(randomScaleMin);
-    //else if (edit.name == "RandomScaleMax")
-    //    edit.text = String(randomScaleMax);
+    randomScaleMax = randomScaleMaxEdit.text.ToFloat();
     UpdateHierarchyItem(editorScene);
     UpdateHierarchyItem(editorScene);
 }
 }
 
 
@@ -137,71 +124,66 @@ void ToggleUseNormal(StringHash eventType, VariantMap& eventData)
 void UpdateNumberSpawnedObjects(StringHash eventType, VariantMap& eventData)
 void UpdateNumberSpawnedObjects(StringHash eventType, VariantMap& eventData)
 {
 {
     LineEdit@ edit = eventData["Element"].GetPtr();
     LineEdit@ edit = eventData["Element"].GetPtr();
-	numberSpawnedObjects=edit.text.ToFloat();
-	edit.text=String(numberSpawnedObjects);
-	
-	RefreshPickedObjects();
+    numberSpawnedObjects=edit.text.ToFloat();
+    edit.text=String(numberSpawnedObjects); 
+    RefreshPickedObjects();
 }
 }
 
 
 void EditSpawnRadius(StringHash eventType, VariantMap& eventData)
 void EditSpawnRadius(StringHash eventType, VariantMap& eventData)
 {
 {
     LineEdit@ edit = eventData["Element"].GetPtr();
     LineEdit@ edit = eventData["Element"].GetPtr();
-	spawnRadius=edit.text.ToFloat();
-	//edit.text=String(spawnRadius);
+    spawnRadius=edit.text.ToFloat();
 }
 }
 void EditSpawnCount(StringHash eventType, VariantMap& eventData)
 void EditSpawnCount(StringHash eventType, VariantMap& eventData)
 {
 {
     LineEdit@ edit = eventData["Element"].GetPtr();
     LineEdit@ edit = eventData["Element"].GetPtr();
-	spawnCount=edit.text.ToFloat();
-	//edit.text=String(spawnCount);
+    spawnCount=edit.text.ToFloat();
 }
 }
 
 
 void RefreshPickedObjects()
 void RefreshPickedObjects()
 {
 {
-	spawnedObjectsNames.Resize(numberSpawnedObjects);
-	ListView@ list = spawnWindow.GetChild("SpawnedObjects", true);
-	list.RemoveAllItems();
-
-	for (uint i = 0; i < numberSpawnedObjects; ++i)
-	{
-		UIElement@ parent = CreateAttributeEditorParentWithSeparatedLabel(list, "Object " +(i+1), i, 0, false);
-		
-		UIElement@ container = UIElement();
-		container.SetLayout(LM_HORIZONTAL, 4, IntRect(10, 0, 4, 0));
-		container.SetFixedHeight(ATTR_HEIGHT);
-		parent.AddChild(container);
-
-		LineEdit@ nameEdit = CreateAttributeLineEdit(container, null, i, 0);
-		nameEdit.name = "TextureNameEdit" + String(i);
-
-		Button@ pickButton = CreateResourcePickerButton(container, null, i, 0, "Pick");
-		SubscribeToEvent(pickButton, "Released", "PickSpawnedObject");
-		nameEdit.text = spawnedObjectsNames[i];
-
-		SubscribeToEvent(nameEdit, "TextFinished", "EditSpawnedObjectName");
-	}
-//UpdateHierarchyItem(editorScene);
+    spawnedObjectsNames.Resize(numberSpawnedObjects);
+    ListView@ list = spawnWindow.GetChild("SpawnedObjects", true);
+    list.RemoveAllItems();
+
+    for (uint i = 0; i < numberSpawnedObjects; ++i)
+    {
+        UIElement@ parent = CreateAttributeEditorParentWithSeparatedLabel(list, "Object " +(i+1), i, 0, false);
+        
+        UIElement@ container = UIElement();
+        container.SetLayout(LM_HORIZONTAL, 4, IntRect(10, 0, 4, 0));
+        container.SetFixedHeight(ATTR_HEIGHT);
+        parent.AddChild(container);
+
+        LineEdit@ nameEdit = CreateAttributeLineEdit(container, null, i, 0);
+        nameEdit.name = "TextureNameEdit" + String(i);
+
+        Button@ pickButton = CreateResourcePickerButton(container, null, i, 0, "Pick");
+        SubscribeToEvent(pickButton, "Released", "PickSpawnedObject");
+        nameEdit.text = spawnedObjectsNames[i];
+
+        SubscribeToEvent(nameEdit, "TextFinished", "EditSpawnedObjectName");
+    }
 }
 }
 
 
 void EditSpawnedObjectName(StringHash eventType, VariantMap& eventData)
 void EditSpawnedObjectName(StringHash eventType, VariantMap& eventData)
 {
 {
     LineEdit@ nameEdit = eventData["Element"].GetPtr();
     LineEdit@ nameEdit = eventData["Element"].GetPtr();
-	int index = nameEdit.vars["Index"].GetUInt();
-	String resourceName = nameEdit.text;
-	XMLFile@ xml = cache.GetResource("XMLFile", resourceName);
-	if(xml !is null)
-		spawnedObjectsNames[index]=resourceName;
-	else
-		spawnedObjectsNames[index]=String("");
-		
-	RefreshPickedObjects();
+    int index = nameEdit.vars["Index"].GetUInt();
+    String resourceName = nameEdit.text;
+    XMLFile@ xml = cache.GetResource("XMLFile", resourceName);
+    if(xml !is null)
+        spawnedObjectsNames[index]=resourceName;
+    else
+        spawnedObjectsNames[index]=String("");    
+    RefreshPickedObjects();
 }
 }
 
 
 void PickSpawnedObject(StringHash eventType, VariantMap& eventData)
 void PickSpawnedObject(StringHash eventType, VariantMap& eventData)
 {
 {
     UIElement@ button = eventData["Element"].GetPtr();
     UIElement@ button = eventData["Element"].GetPtr();
     resourcePickIndex = button.vars["Index"].GetUInt();
     resourcePickIndex = button.vars["Index"].GetUInt();
-	CreateFileSelector("Pick spawned object", "Pick", "Cancel", uiNodePath, uiSceneFilters, uiNodeFilter);
+    CreateFileSelector("Pick spawned object", "Pick", "Cancel", uiNodePath, uiSceneFilters, uiNodeFilter);
     
     
     SubscribeToEvent(uiFileSelector, "FileSelected", "PickSpawnedObjectNameDone");
     SubscribeToEvent(uiFileSelector, "FileSelected", "PickSpawnedObjectNameDone");
 }
 }
@@ -218,81 +200,81 @@ void PickSpawnedObjectNameDone(StringHash eventType, VariantMap& eventData)
     }
     }
 
 
     String resourceName = GetResourceNameFromFullName(eventData["FileName"].GetString());
     String resourceName = GetResourceNameFromFullName(eventData["FileName"].GetString());
-	XMLFile@ xml = cache.GetResource("XMLFile", resourceName);
-	if(xml !is null)
-		spawnedObjectsNames[resourcePickIndex]=resourceName;
-	else
-		spawnedObjectsNames[resourcePickIndex]=String("");
+    XMLFile@ xml = cache.GetResource("XMLFile", resourceName);
+    if(xml !is null)
+        spawnedObjectsNames[resourcePickIndex]=resourceName;
+    else
+        spawnedObjectsNames[resourcePickIndex]=String("");
     @resourcePicker = null;
     @resourcePicker = null;
-	RefreshPickedObjects();
+    RefreshPickedObjects();
 }
 }
 
 
 void SetSpawnMode(StringHash eventType, VariantMap& eventData)
 void SetSpawnMode(StringHash eventType, VariantMap& eventData)
 {
 {
-	editMode=EDIT_SPAWN;
+    editMode=EDIT_SPAWN;
 }
 }
 
 
 void PlaceObject(Vector3 spawnPosition, Vector3 normal)
 void PlaceObject(Vector3 spawnPosition, Vector3 normal)
 {
 {
-	Quaternion spawnRotation;
-	if(useNormal)spawnRotation=Quaternion(Vector3(0.f,1.f,0.f),normal);
-	int number=RandomInt(0,spawnedObjectsNames.length);
-	XMLFile@ xml = cache.GetResource("XMLFile", spawnedObjectsNames[number]);
-	Node@ spawnedObject =editorScene.InstantiateXML(xml, spawnPosition, spawnRotation);
-	if(spawnedObject is null)
-	{
-		spawnedObjectsNames[number]=spawnedObjectsNames[spawnedObjectsNames.length-1];
-		--numberSpawnedObjects;
-		RefreshPickedObjects();
-		return;
-	}
-	
-	spawnedObject.scale=spawnedObject.scale*Random(randomScaleMin, randomScaleMax);
-	spawnedObject.Rotate(Quaternion(Random(-randomRotation.x,randomRotation.x),
-	Random(-randomRotation.y,randomRotation.y),Random(-randomRotation.z,randomRotation.z)),false);
-	CreateNodeAction action;
-	action.Define(spawnedObject);
-	SaveEditAction(action);
-	SetSceneModified();
+    Quaternion spawnRotation;
+    if(useNormal)spawnRotation=Quaternion(Vector3(0.f,1.f,0.f),normal);
+    int number=RandomInt(0,spawnedObjectsNames.length);
+    XMLFile@ xml = cache.GetResource("XMLFile", spawnedObjectsNames[number]);
+    Node@ spawnedObject =editorScene.InstantiateXML(xml, spawnPosition, spawnRotation);
+    if(spawnedObject is null)
+    {
+        spawnedObjectsNames[number]=spawnedObjectsNames[spawnedObjectsNames.length-1];
+        --numberSpawnedObjects;
+        RefreshPickedObjects();
+        return;
+    }
+    
+    spawnedObject.scale=spawnedObject.scale*Random(randomScaleMin, randomScaleMax);
+    spawnedObject.Rotate(Quaternion(Random(-randomRotation.x,randomRotation.x),
+    Random(-randomRotation.y,randomRotation.y),Random(-randomRotation.z,randomRotation.z)),false);
+    CreateNodeAction action;
+    action.Define(spawnedObject);
+    SaveEditAction(action);
+    SetSceneModified();
 }
 }
 
 
 void SpawnObject()
 void SpawnObject()
 {
 {
-	if(spawnedObjectsNames.length==0) return;
-	IntRect view = activeViewport.viewport.rect;
-	
-	for(int i=0;i<spawnCount;i++)
-	{	
-		Vector2 norm=Vector2(Random(-1,1),Random(-1,1));
-		norm.Normalize();
-		norm=norm*(spawnRadius*Random(0,1));
-		IntVector2 pos = IntVector2(ui.cursorPosition.x+norm.x,ui.cursorPosition.y+norm.y);
-		Ray cameraRay = camera.GetScreenRay(
-			float(pos.x - view.left) / view.width,
-			float(pos.y - view.top) / view.height);
-
-		if (pickMode < PICK_RIGIDBODIES)
-		{
-			if (editorScene.octree is null)
-				return;
-			RayQueryResult result = editorScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, camera.farClip,
-				pickModeDrawableFlags[pickMode], 0x7fffffff);
-			if (result.drawable !is null)
-				PlaceObject(result.position, result.normal);
-		}
-		else
-		{
-			if (editorScene.physicsWorld is null)
-				return;
-
-			// If we are not running the actual physics update, refresh collisions before raycasting
-			if (!runUpdate)
-				editorScene.physicsWorld.UpdateCollisions();
-
-			PhysicsRaycastResult result = editorScene.physicsWorld.RaycastSingle(cameraRay, camera.farClip);
-			if (result.body !is null)
-				PlaceObject(result.position, result.normal);
-		}
-	}
+    if(spawnedObjectsNames.length==0) return;
+    IntRect view = activeViewport.viewport.rect;
+    
+    for(int i=0;i<spawnCount;i++)
+    {	
+        Vector2 norm=Vector2(Random(-1,1),Random(-1,1));
+        norm.Normalize();
+        norm=norm*(spawnRadius*Random(0,1));
+        IntVector2 pos = IntVector2(ui.cursorPosition.x+norm.x,ui.cursorPosition.y+norm.y);
+        Ray cameraRay = camera.GetScreenRay(
+            float(pos.x - view.left) / view.width,
+            float(pos.y - view.top) / view.height);
+
+        if (pickMode < PICK_RIGIDBODIES)
+        {
+            if (editorScene.octree is null)
+                return;
+            RayQueryResult result = editorScene.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, camera.farClip,
+                pickModeDrawableFlags[pickMode], 0x7fffffff);
+            if (result.drawable !is null)
+                PlaceObject(result.position, result.normal);
+        }
+        else
+        {
+            if (editorScene.physicsWorld is null)
+                return;
+
+            // If we are not running the actual physics update, refresh collisions before raycasting
+            if (!runUpdate)
+                editorScene.physicsWorld.UpdateCollisions();
+
+            PhysicsRaycastResult result = editorScene.physicsWorld.RaycastSingle(cameraRay, camera.farClip);
+            if (result.body !is null)
+                PlaceObject(result.position, result.normal);
+        }
+    }
 }
 }
 
 

+ 2 - 2
Bin/Data/Scripts/Editor/EditorUI.as

@@ -69,7 +69,7 @@ void CreateUI()
     CreateEditorSettingsDialog();
     CreateEditorSettingsDialog();
     CreateEditorPreferencesDialog();
     CreateEditorPreferencesDialog();
     CreateMaterialEditor();
     CreateMaterialEditor();
-	CreateSpawnEditor();
+    CreateSpawnEditor();
     CreateStatsBar();
     CreateStatsBar();
     CreateConsole();
     CreateConsole();
     CreateDebugHud();
     CreateDebugHud();
@@ -406,7 +406,7 @@ void CreateMenuBar()
         popup.AddChild(CreateMenuItem("Hierarchy", @ShowHierarchyWindow, 'H', QUAL_CTRL));
         popup.AddChild(CreateMenuItem("Hierarchy", @ShowHierarchyWindow, 'H', QUAL_CTRL));
         popup.AddChild(CreateMenuItem("Attribute inspector", @ShowAttributeInspectorWindow, 'I', QUAL_CTRL));
         popup.AddChild(CreateMenuItem("Attribute inspector", @ShowAttributeInspectorWindow, 'I', QUAL_CTRL));
         popup.AddChild(CreateMenuItem("Material editor", @ShowMaterialEditor));
         popup.AddChild(CreateMenuItem("Material editor", @ShowMaterialEditor));
-		popup.AddChild(CreateMenuItem("Spawn editor", @ShowSpawnEditor));
+        popup.AddChild(CreateMenuItem("Spawn editor", @ShowSpawnEditor));
         popup.AddChild(CreateMenuItem("Editor settings", @ShowEditorSettingsDialog));
         popup.AddChild(CreateMenuItem("Editor settings", @ShowEditorSettingsDialog));
         popup.AddChild(CreateMenuItem("Editor preferences", @ShowEditorPreferencesDialog));
         popup.AddChild(CreateMenuItem("Editor preferences", @ShowEditorPreferencesDialog));
         CreateChildDivider(popup);
         CreateChildDivider(popup);

+ 8 - 10
Bin/Data/Scripts/Editor/EditorView.as

@@ -1386,17 +1386,15 @@ void ViewRaycast(bool mouseClick)
     if (ui.HasModalElement())
     if (ui.HasModalElement())
         return;
         return;
 
 
-	IntVector2 pos = ui.cursorPosition;
+    IntVector2 pos = ui.cursorPosition;
     UIElement@ elementAtPos = ui.GetElementAt(pos, pickMode != PICK_UI_ELEMENTS);
     UIElement@ elementAtPos = ui.GetElementAt(pos, pickMode != PICK_UI_ELEMENTS);
-	if(editMode==EDIT_SPAWN)
-	{
-		if(mouseClick && input.mouseButtonPress[MOUSEB_LEFT] && elementAtPos is null)
-			SpawnObject();
-		return;
-	}
-	
-	
-	
+    if(editMode==EDIT_SPAWN)
+    {
+        if(mouseClick && input.mouseButtonPress[MOUSEB_LEFT] && elementAtPos is null)
+            SpawnObject();
+        return;
+    }
+
     // Do not raycast / change selection if hovering over the gizmo
     // Do not raycast / change selection if hovering over the gizmo
     if (IsGizmoSelected())
     if (IsGizmoSelected())
         return;
         return;