Ejemplo n.º 1
0
        private void UpdateModel()
        {
            WDOMNode cur_object = this;

            while (cur_object.Parent != null)
            {
                cur_object = cur_object.Parent;
            }
            WRoom  currRoom      = cur_object as WRoom;
            string currStageName = World.Map.MapName;

            string model_path;

            switch (Type)
            {
            case TypeEnum.Grass:
                if (currStageName.StartsWith("kin") || currStageName == "Xboss1")
                {
                    // Forbidden Woods grass
                    model_path = "resources/models/foliage/grass_Vmori.obj";
                }
                else
                {
                    model_path = "resources/models/foliage/grass.obj";
                }
                break;

            case TypeEnum.Tree:
                model_path = "resources/models/foliage/tree.obj";
                break;

            case TypeEnum.White_Flower:
                model_path = "resources/models/foliage/flower.obj";
                break;

            case TypeEnum.Pink_Flower:
                if (currStageName == "sea" && currRoom.RoomIndex == 33)
                {
                    // Private Oasis flowers
                    model_path = "resources/models/foliage/pflower_oasis.obj";
                }
                else
                {
                    model_path = "resources/models/foliage/pflower_pink.obj";
                }
                break;

            default:
                model_path = "resources/editor/EditorCube.obj";
                break;
            }

            m_objRender = WResourceManager.LoadObjResource(model_path, new OpenTK.Vector4(1, 1, 1, 1), true, false, TextureWrapMode.MirroredRepeat);
        }
Ejemplo n.º 2
0
        public override void SetParent(WDOMNode newParent)
        {
            base.SetParent(newParent);

            if (IsRendered == true)
            {
                WDOMNode parent = Parent;

                while (parent != null)
                {
                    parent.IsRendered = true;
                    parent            = parent.Parent;
                }
            }
        }
Ejemplo n.º 3
0
        public override void PopulateDefaultProperties()
        {
            Name        = "Link";
            EnemyNumber = -1;
            Event       = null;
            Unknown4    = -1;
            Unknown6    = -1;

            // Try to assign the room index automatically if this is a room spawn.
            WDOMNode cur_object = this;

            while (cur_object.Parent != null)
            {
                cur_object = cur_object.Parent;
            }
            WScene scene = cur_object as WScene;

            if (scene is WRoom)
            {
                WRoom room = scene as WRoom;
                Room = room.RoomIndex;
            }

            // Automatically assign it the first unused spawn ID in this scene.
            List <int>        possibleSpawnIDs = Enumerable.Range(0, 256).ToList();
            List <SpawnPoint> otherSpawns      = scene.GetChildrenOfType <SpawnPoint>();

            foreach (var spawn in otherSpawns)
            {
                if (spawn == this)
                {
                    continue;
                }
                possibleSpawnIDs.Remove(spawn.SpawnID);
            }

            if (possibleSpawnIDs.Count == 0)
            {
                SpawnID = 255;
            }
            else
            {
                SpawnID = possibleSpawnIDs.First();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// We can't use PropertyBinding on the PropertyDefinitions, but we can get a callback when the object changes
        /// and then get the properties off of them manually, insert them, and then forcibly update it again... :D
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PropertyGrid_SelectedObjectChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            PropertyGrid grid = sender as PropertyGrid;

            if (grid != null)
            {
                grid.PropertyDefinitions.Clear();
                WDOMNode node = grid.SelectedObject as WDOMNode;
                if (node != null)
                {
                    foreach (var property in node.VisibleProperties)
                    {
                        grid.PropertyDefinitions.Add(property);
                    }

                    grid.Update();
                }
            }
        }
Ejemplo n.º 5
0
        private WDOMNode Raycast(FRay ray)
        {
            if (m_world.Map == null)
            {
                return(null);
            }

            WDOMNode closestResult   = null;
            float    closestDistance = float.MaxValue;

            foreach (var scene in m_world.Map.SceneList)
            {
                var allActors = scene.GetChildrenOfType <VisibleDOMNode>();

                foreach (VisibleDOMNode actorNode in allActors)
                {
                    float intersectDistance;
                    bool  hitActor = actorNode.Raycast(ray, out intersectDistance);
                    if (hitActor)
                    {
                        if (intersectDistance >= 0 && intersectDistance < closestDistance)
                        {
                            closestDistance = intersectDistance;
                            closestResult   = actorNode;
                        }
                    }
                }
            }

            if (closestResult != null)
            {
                if (!closestResult.IsRendered)
                {
                    closestResult = null;
                }
            }

            return(closestResult);
        }
Ejemplo n.º 6
0
        private List <J3D> GetModelFromStageDir()
        {
            List <J3D> model_list = new List <J3D>();

            VirtualFilesystemDirectory stage_dir = null;
            WDOMNode node = Parent;

            while (!(node is WStage))
            {
                node = node.Parent;
            }

            WStage stage_node = node as WStage;

            stage_dir = stage_node.SourceDirectory;

            if (DoorType == DoorType.Boss)
            {
                model_list.Add(WResourceManager.LoadModelFromVFS(stage_dir, "bdl/door20.bdl"));
                model_list.AddRange(WResourceManager.LoadActorResource("Boss Key Lock"));

                return(model_list);
            }

            model_list.Add(WResourceManager.LoadModelFromVFS(stage_dir, "bdl/door10.bdl"));

            if (DoorType == DoorType.Locked)
            {
                model_list.AddRange(WResourceManager.LoadActorResource("Small Key Lock"));
            }
            else if (DoorType == DoorType.Barred || SwitchBit < 255)
            {
                model_list.Add(WResourceManager.LoadModelFromVFS(stage_dir, "bdl/stop10.bdl"));
            }

            return(model_list);
        }
Ejemplo n.º 7
0
        public void DrawFrame()
        {
            ResetGraphicsState();

            int x      = (int)(m_viewportRect.X * m_viewWidth);
            int y      = (int)(m_viewportRect.Y * m_viewHeight);
            int width  = (int)(m_viewportRect.Width * m_viewWidth);
            int height = (int)(m_viewportRect.Height * m_viewHeight);

            GL.Viewport(x, y, width, height);
            GL.Scissor(x, y, width, height);

            GL.ClearColor(m_viewportRect.X, m_viewportRect.Y, m_viewportRect.Width, 1f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit | ClearBufferMask.DepthBufferBit);

            Matrix4 viewMatrix, projMatrix;

            GetViewAndProjMatrixForView(out viewMatrix, out projMatrix);
            FFrustum frustum = new FFrustum(ref viewMatrix, ref projMatrix);

            // Resize our list if needed.
            m_renderablesInFrustum.Clear();
            m_renderablesInFrustum.Capacity = Math.Max(m_opaqueRenderList.Count, m_transparentRenderList.Count);

            FrustumCullList(frustum, m_opaqueRenderList, m_renderablesInFrustum);
            //m_renderablesInFrustum = new List<IRenderable>(m_opaqueRenderList);

            foreach (var mesh in m_renderablesInFrustum)
            {
                if (mesh.GetType() == typeof(WSkyboxNode))
                {
                    mesh.Draw(this);
                    break;
                }
            }

            // Render all Opaque Geometry first.
            foreach (var mesh in m_renderablesInFrustum)
            {
                if (mesh is WDOMNode)
                {
                    WDOMNode node = (WDOMNode)mesh;
                    if (mesh.GetType() != typeof(WSkyboxNode) && node.IsRendered)
                    {
                        float dist = (mesh.GetPosition() - GetCameraPos()).Length;

                        if (dist < MaxDist || mesh.GetType() == typeof(J3DNode))
                        {
                            mesh.Draw(this);
                        }
                    }
                }
                else
                {
                    mesh.Draw(this);
                }
            }

            // Now cull us against translucent geometry.
            m_renderablesInFrustum.Clear();
            FrustumCullList(frustum, m_transparentRenderList, m_renderablesInFrustum);

            // Render all Transparent Geometry afterwards. ToDo: depth-sort this first.
            foreach (var mesh in m_renderablesInFrustum)
            {
                if (mesh is WDOMNode)
                {
                    WDOMNode node = (WDOMNode)mesh;
                    if (node.IsRendered)
                    {
                        mesh.Draw(this);
                    }
                }
                else
                {
                    mesh.Draw(this);
                }
            }

            DrawOrientationWidget(x, y, viewMatrix, projMatrix);
            ResetGraphicsState();
        }
Ejemplo n.º 8
0
 public SelectEventArgs(WDOMNode selected, bool wasSelected)
 {
     Selection   = selected;
     WasSelected = wasSelected;
 }
Ejemplo n.º 9
0
        public void CreateEntity()
        {
            if (!EditorSelection.SingleObjectSelected)
            {
                return;
            }

            WDOMNode            selected = EditorSelection.PrimarySelectedObject;
            SerializableDOMNode newNode  = null;

            if (selected is SerializableDOMNode)
            {
                SerializableDOMNode origNode = selected as SerializableDOMNode;
                Type selType = selected.GetType();
                newNode = (SerializableDOMNode)Activator.CreateInstance(selType, origNode.FourCC, m_world);
                newNode.PostLoad();
                newNode.SetParent(selected.Parent);

                if (origNode.Parent is WDOMLayeredGroupNode)
                {
                    newNode.Layer = origNode.Layer;
                }
            }
            else if (selected is WDOMLayeredGroupNode)
            {
                WDOMLayeredGroupNode lyrNode = selected as WDOMLayeredGroupNode;
                Type newObjType = null;

                if (lyrNode.FourCC >= FourCC.ACTR && lyrNode.FourCC <= FourCC.ACTb)
                {
                    newObjType = typeof(Actor);
                }
                else if (lyrNode.FourCC >= FourCC.SCOB && lyrNode.FourCC <= FourCC.SCOb)
                {
                    newObjType = typeof(ScaleableObject);
                }
                else if (lyrNode.FourCC >= FourCC.TRES && lyrNode.FourCC <= FourCC.TREb)
                {
                    newObjType = typeof(TreasureChest);
                }

                string   unlayedFourCC = lyrNode.FourCC.ToString();
                MapLayer layer         = ChunkHeader.FourCCToLayer(ref unlayedFourCC);
                FourCC   enumVal       = FourCCConversion.GetEnumFromString(unlayedFourCC);

                newNode       = (SerializableDOMNode)Activator.CreateInstance(newObjType, enumVal, m_world);
                newNode.Layer = layer;
                newNode.PostLoad();
                newNode.SetParent(lyrNode);
            }
            else if (selected is WDOMGroupNode)
            {
                WDOMGroupNode grpNode = selected as WDOMGroupNode;

                if (grpNode.FourCC == FourCC.ACTR || grpNode.FourCC == FourCC.SCOB || grpNode.FourCC == FourCC.TRES)
                {
                    return;
                }

                Type newObjType = FourCCConversion.GetTypeFromEnum(grpNode.FourCC);
                newNode = (SerializableDOMNode)Activator.CreateInstance(newObjType, grpNode.FourCC, m_world);
                newNode.PostLoad();
                newNode.SetParent(grpNode);
            }
            else
            {
                return;
            }

            if (newNode != null)
            {
                EditorSelection.ClearSelection();
                EditorSelection.AddToSelection(newNode);
            }

            // ToDo: This can spawn specific classes the same way that the actor loader does.
        }
Ejemplo n.º 10
0
        private void GetRoomAndSpawnID(WScene scene, out int room, out int spawn)
        {
            room  = 0;
            spawn = 0;

            Selection <WDOMNode> selected = null;

            if (scene.World.CurrentMode is ActorMode)
            {
                ActorMode mode = scene.World.CurrentMode as ActorMode;
                selected = mode.EditorSelection;
            }

            room = GetRoomNumberFromSceneName(scene.Name);
            if (selected != null && selected.PrimarySelectedObject is SpawnPoint)
            {
                // If the user has a spawn point selected, spawn the player at that spawn point.
                SpawnPoint spawn_pt = (SpawnPoint)selected.PrimarySelectedObject;

                room  = spawn_pt.Room;
                spawn = spawn_pt.SpawnID;
            }
            else if (selected != null && selected.PrimarySelectedObject != null)
            {
                // If the user has something besides a spawn point selected, spawn the player at the first spawn point in the room that the selected object is in.
                WDOMNode cur_object = selected.PrimarySelectedObject;
                while (cur_object.Parent != null)
                {
                    cur_object = cur_object.Parent;
                }
                WRoom room_node;
                if (cur_object is WRoom)
                {
                    room_node = cur_object as WRoom;
                }
                else
                {
                    // A stage entity is selected. Use whatever spawn point is physically closest to the selected entity, regardless of what scene that spawn is in.
                    List <SpawnPoint> allSpawnPts = new List <SpawnPoint>();
                    foreach (WScene scn in scene.World.Map.SceneList)
                    {
                        allSpawnPts.AddRange(scn.GetChildrenOfType <SpawnPoint>());
                    }

                    SpawnPoint closestSpawnPt = allSpawnPts.OrderBy(spawnPt => (spawnPt.Transform.Position - selected.PrimarySelectedObject.Transform.Position).Length).First();
                    room  = closestSpawnPt.Room;
                    spawn = closestSpawnPt.SpawnID;
                    return;
                }

                SpawnPoint spawn_pt = room_node.GetChildrenOfType <SpawnPoint>().FirstOrDefault();
                if (spawn_pt != null)
                {
                    room  = spawn_pt.Room;
                    spawn = spawn_pt.SpawnID;
                }
                else
                {
                    WStage stage = room_node.World.Map.SceneList.First(x => x.GetType() == typeof(WStage)) as WStage;
                    spawn_pt = stage.GetChildrenOfType <SpawnPoint>().FirstOrDefault(x => x.Room == room_node.RoomIndex);
                    if (spawn_pt != null)
                    {
                        room  = spawn_pt.Room;
                        spawn = spawn_pt.SpawnID;
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public void RemoveFromSelection(WDOMNode Node)
 {
     RemoveFromSelection(new[] { Node });
 }
Ejemplo n.º 12
0
 public void AddToSelection(WDOMNode Node)
 {
     AddToSelection(new[] { Node });
 }