Beispiel #1
0
        private EditorEntity GenerateEditorEntity(RSDKv5.SceneEntity sceneEntity)
        {
            try
            {
                // ideally this would be driven by configuration...one day
                // or can we assume anything with a "Go" and "Tag" Attributes is linked to another?
                if (sceneEntity.Object.Name.ToString().Equals("WarpDoor", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(new LinkedEditorEntity(sceneEntity));
                }
            }
            catch
            {
                Debug.WriteLine("Failed to generate a LinkedEditorEntity, will create a basic one instead.");
            }

            EditorEntity entity = new EditorEntity(sceneEntity);

            if (entity.hasFilter && DefaultFilter > -1)
            {
                entity.Entity.GetAttribute("filter").ValueUInt8 = (byte)DefaultFilter;
                DefaultFilter = -1;
            }

            entity.SetFilter();

            return(entity);
        }
Beispiel #2
0
        private void DrawLinkArrow(DevicePanel d, RSDKv5.SceneEntity start, RSDKv5.SceneEntity end)
        {
            int startX = start.Position.X.High;
            int startY = start.Position.Y.High;
            int endX   = end.Position.X.High;
            int endY   = end.Position.Y.High;

            int dx = endX - startX;
            int dy = endY - startY;

            int offsetX            = 0;
            int offsetY            = 0;
            int offsetDestinationX = 0;
            int offsetDestinationY = 0;

            if (Math.Abs(dx) > Math.Abs(dy))
            {
                // horizontal difference greater than vertical difference
                offsetY            = NAME_BOX_HALF_HEIGHT;
                offsetDestinationY = NAME_BOX_HALF_HEIGHT;

                if (dx > 0)
                {
                    offsetX = NAME_BOX_WIDTH;
                }
                else
                {
                    offsetDestinationX = NAME_BOX_WIDTH;
                }
            }
            else
            {
                // vertical difference greater than horizontal difference
                offsetX            = NAME_BOX_HALF_WIDTH;
                offsetDestinationX = NAME_BOX_HALF_WIDTH;

                if (dy > 0)
                {
                    offsetY = NAME_BOX_HEIGHT;
                }
                else
                {
                    offsetDestinationY = NAME_BOX_HEIGHT;
                }
            }

            d.DrawArrow(startX + offsetX,
                        startY + offsetY,
                        end.Position.X.High + offsetDestinationX,
                        end.Position.Y.High + offsetDestinationY,
                        Color.GreenYellow);
        }
        private EditorEntity GenerateEditorEntity(RSDKv5.SceneEntity sceneEntity)
        {
            try
            {
                // ideally this would be driven by configuration...one day
                // or can we assume anything with a "Go" and "Tag" Attributes is linked to another?
                if (sceneEntity.Object.Name.ToString().Equals("WarpDoor", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(new LinkedEditorEntity(sceneEntity));
                }
            }
            catch
            {
                Debug.WriteLine("Failed to generate a LinkedEditorEntity, will create a basic one instead.");
            }

            EditorEntity entity = new EditorEntity(sceneEntity);

            // Check the first entity spawned to see if this Scene uses filters
            if (FirstEntity)
            {
                FirstEntity = false;

                // Try to get "filter"
                try
                {
                    int filter = entity.Entity.GetAttribute("filter").ValueUInt8;
                }

                // If this is an old Scene that doesn't have them, disable future filter checks
                catch (KeyNotFoundException)
                {
                    SceneWithoutFilters = true;
                }
            }

            if (!SceneWithoutFilters && DefaultFilter > -1)
            {
                entity.Entity.GetAttribute("filter").ValueUInt8 = (byte)DefaultFilter;
                DefaultFilter = -1;
            }

            entity.SetFilter();

            return(entity);
        }
Beispiel #4
0
 private ushort getFreeSlot(RSDKv5.SceneEntity preferred)
 {
     if (preferred != null && !entitiesBySlot.ContainsKey(preferred.SlotID))
     {
         return(preferred.SlotID);
     }
     while (entitiesBySlot.ContainsKey(nextFreeSlot))
     {
         ++nextFreeSlot;
     }
     if (nextFreeSlot == 2048)
     {
         if (entitiesBySlot.Count < 2048)
         {
             // Next time search from beggining
             nextFreeSlot = 0;
         }
         throw new TooManyEntitiesException();
     }
     return(nextFreeSlot++);
 }
Beispiel #5
0
 public LinkedEditorEntity(RSDKv5.SceneEntity entity) : base(entity)
 {
     goProperty     = Entity.GetAttribute("go").ValueVar;
     destinationTag = Entity.GetAttribute("destinationTag").ValueVar;
     tag            = Entity.GetAttribute("tag").ValueUInt8;
 }
Beispiel #6
0
 public EditorEntity(RSDKv5.SceneEntity entity)
 {
     this.entity = entity;
 }
Beispiel #7
0
        private void setEntitiyProperty(RSDKv5.SceneEntity entity, string tag, object value, object oldValue)
        {
            string[] parts    = tag.Split('.');
            string   category = parts[0];
            string   name     = parts[1];

            if (category == "position")
            {
                float fvalue = (float)value;
                if (fvalue < Int16.MinValue || fvalue > Int16.MaxValue)
                {
                    // Invalid
                    var obj = (entityProperties.SelectedObject as LocalPropertyGridObject);
                    obj.setValue(tag, oldValue);
                    return;
                }
                var pos = entity.Position;
                if (name == "x")
                {
                    pos.X.High = (short)fvalue;
                    pos.X.Low  = (ushort)(fvalue * 0x10000);
                }
                else if (name == "y")
                {
                    pos.Y.High = (short)fvalue;
                    pos.Y.Low  = (ushort)(fvalue * 0x10000);
                }
                entity.Position = pos;
                if (entity == currentEntity)
                {
                    UpdateCurrentEntityProperites();
                }
            }
            else if (category == "object")
            {
                if (name == "name" && oldValue != value)
                {
                    var info = RSDKv5.Objects.GetObjectInfo(new RSDKv5.NameIdentifier(value as string));
                    if (info == null)
                    {
                        MessageBox.Show("Unknown Object", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    var objects = ((BindingList <RSDKv5.SceneObject>)_bindingSceneObjectsSource.DataSource).ToList();
                    var obj     = objects.FirstOrDefault(t => t.Name.Name == value as string);
                    if (obj != null)
                    {
                        entity.Attributes.Clear();
                        entity.attributesMap.Clear();
                        foreach (var attb in info.Attributes)
                        {
                            var attributeValue = new RSDKv5.AttributeValue(attb.Type);
                            entity.Attributes.Add(attributeValue);
                            entity.attributesMap.Add(attb.Name.Name, attributeValue);
                        }
                        entity.Object.Entities.Remove(entity);
                        entity.Object = obj;
                        obj.Entities.Add(entity);
                    }
                    else
                    {
                        // The new object
                        var sobj = new RSDKv5.SceneObject(info.Name, info.Attributes);

                        entity.Attributes.Clear();
                        entity.attributesMap.Clear();
                        foreach (var attb in info.Attributes)
                        {
                            var attributeValue = new RSDKv5.AttributeValue(attb.Type);
                            entity.Attributes.Add(attributeValue);
                            entity.attributesMap.Add(attb.Name.Name, attributeValue);
                        }
                        entity.Object.Entities.Remove(entity);
                        entity.Object = sobj;
                        sobj.Entities.Add(entity);
                        _bindingSceneObjectsSource.Add(sobj);
                    }
                }
                // Update Properties
                currentEntity = null;
                UpdateEntitiesProperties(new List <RSDKv5.SceneEntity>()
                {
                    entity
                });
            }
            else
            {
                var attribute = entity.GetAttribute(category);
                switch (attribute.Type)
                {
                case RSDKv5.AttributeTypes.UINT8:
                    attribute.ValueUInt8 = (byte)value;
                    break;

                case RSDKv5.AttributeTypes.UINT16:
                    attribute.ValueUInt16 = (ushort)value;
                    break;

                case RSDKv5.AttributeTypes.UINT32:
                    attribute.ValueUInt32 = (uint)value;
                    break;

                case RSDKv5.AttributeTypes.INT8:
                    attribute.ValueInt8 = (sbyte)value;
                    break;

                case RSDKv5.AttributeTypes.INT16:
                    attribute.ValueInt16 = (short)value;
                    break;

                case RSDKv5.AttributeTypes.INT32:
                    attribute.ValueInt32 = (int)value;
                    break;

                case RSDKv5.AttributeTypes.VAR:
                    attribute.ValueVar = (uint)value;
                    break;

                case RSDKv5.AttributeTypes.BOOL:
                    attribute.ValueBool = (bool)value;
                    break;

                case RSDKv5.AttributeTypes.STRING:
                    attribute.ValueString = (string)value;
                    break;

                case RSDKv5.AttributeTypes.POSITION:
                    float fvalue = (float)value;
                    if (fvalue < Int16.MinValue || fvalue > Int16.MaxValue)
                    {
                        // Invalid
                        var obj = (entityProperties.SelectedObject as LocalPropertyGridObject);
                        obj.setValue(tag, oldValue);
                        return;
                    }
                    var pos = attribute.ValuePosition;
                    if (name == "x")
                    {
                        pos.X.High = (short)fvalue;
                        pos.X.Low  = (ushort)(fvalue * 0x10000);
                    }
                    else if (name == "y")
                    {
                        pos.Y.High = (short)fvalue;
                        pos.Y.Low  = (ushort)(fvalue * 0x10000);
                    }
                    attribute.ValuePosition = pos;
                    if (entity == currentEntity)
                    {
                        UpdateCurrentEntityProperites();
                    }
                    break;

                case RSDKv5.AttributeTypes.COLOR:
                    Color c = (Color)value;
                    attribute.ValueColor = new RSDKv5.Color(c.R, c.G, c.B, c.A);
                    break;
                }
            }
        }
Beispiel #8
0
        private void UpdateEntitiesProperties(List <RSDKv5.SceneEntity> selectedEntities)
        {
            // TODO: Allow to change multiple entities

            /*bool first_entity = true;
             * RSDKv5.SceneObject commonObject = null;
             *
             * foreach (var entity in selectedEntities)
             * {
             *  if (first_entity) commonObject = entity.Object;
             *  else if (entity.Object != commonObject) commonObject = null;
             * }
             *
             * if (commonObject != currentObject)
             * {
             *  currentObject = commonObject;*/

            if (selectedEntities.Count != 1)
            {
                entityProperties.SelectedObject = null;
                currentEntity = null;
                entitiesList.ResetText();
                if (selectedEntities.Count > 1)
                {
                    entitiesList.SelectedText = String.Format("{0} entities selected", selectedEntities.Count);
                }
                return;
            }

            RSDKv5.SceneEntity entity = selectedEntities[0];

            if (entity == currentEntity)
            {
                return;
            }
            currentEntity = entity;

            if (entitiesList.SelectedIndex >= 0 && entitiesList.SelectedIndex < _entities.Count && _entities[entitiesList.SelectedIndex] == currentEntity)
            {
                // Than it is called from selected item in the menu, so changeing the text will remove it, we don't want that
            }
            else
            {
                entitiesList.ResetText();
                entitiesList.SelectedText = String.Format("{0} - {1}", currentEntity.SlotID, currentEntity.Object.Name);
                //entitiesList.SelectedIndex = entities.IndexOf(entity);
            }

            LocalProperties objProperties  = new LocalProperties();
            int             category_index = 2 + entity.Attributes.Count;

            addProperty(objProperties, category_index, "object", "name", "string", entity.Object.Name.ToString(), false);
            addProperty(objProperties, category_index, "object", "entitySlot", "ushort", entity.SlotID, true);
            --category_index;
            addProperty(objProperties, category_index, "position", "x", "float", entity.Position.X.High + ((float)entity.Position.X.Low / 0x10000));
            addProperty(objProperties, category_index, "position", "y", "float", entity.Position.Y.High + ((float)entity.Position.Y.Low / 0x10000));
            --category_index;


            foreach (var attribute in entity.Object.Attributes)
            {
                string attribute_name  = attribute.Name.ToString();
                var    attribute_value = currentEntity.GetAttribute(attribute_name);
                switch (attribute.Type)
                {
                case RSDKv5.AttributeTypes.UINT8:
                    addProperty(objProperties, category_index, attribute_name, "uint8", "byte", attribute_value.ValueUInt8);
                    break;

                case RSDKv5.AttributeTypes.UINT16:
                    addProperty(objProperties, category_index, attribute_name, "uint16", "ushort", attribute_value.ValueUInt16);
                    break;

                case RSDKv5.AttributeTypes.UINT32:
                    addProperty(objProperties, category_index, attribute_name, "uint32", "uint", attribute_value.ValueUInt32);
                    break;

                case RSDKv5.AttributeTypes.INT8:
                    addProperty(objProperties, category_index, attribute_name, "int8", "sbyte", attribute_value.ValueInt8);
                    break;

                case RSDKv5.AttributeTypes.INT16:
                    addProperty(objProperties, category_index, attribute_name, "int16", "short", attribute_value.ValueInt16);
                    break;

                case RSDKv5.AttributeTypes.INT32:
                    addProperty(objProperties, category_index, attribute_name, "int32", "int", attribute_value.ValueInt32);
                    break;

                case RSDKv5.AttributeTypes.VAR:
                    addProperty(objProperties, category_index, attribute_name, "var", "uint", attribute_value.ValueVar);
                    break;

                case RSDKv5.AttributeTypes.BOOL:
                    addProperty(objProperties, category_index, attribute_name, "bool", "bool", attribute_value.ValueBool);
                    break;

                case RSDKv5.AttributeTypes.STRING:
                    addProperty(objProperties, category_index, attribute_name, "string", "string", attribute_value.ValueString);
                    break;

                case RSDKv5.AttributeTypes.POSITION:
                    addProperty(objProperties, category_index, attribute_name, "x", "float", attribute_value.ValuePosition.X.High + ((float)attribute_value.ValuePosition.X.Low / 0x10000));
                    addProperty(objProperties, category_index, attribute_name, "y", "float", attribute_value.ValuePosition.Y.High + ((float)attribute_value.ValuePosition.Y.Low / 0x10000));
                    break;

                case RSDKv5.AttributeTypes.COLOR:
                    var color = attribute_value.ValueColor;
                    addProperty(objProperties, category_index, attribute_name, "color", "color", Color.FromArgb(255 /* color.A */, color.R, color.G, color.B));
                    break;
                }
                --category_index;
            }
            entityProperties.SelectedObject
                = new LocalPropertyGridObject(objProperties);
        }
Beispiel #9
0
        private void setEntitiyProperty(RSDKv5.SceneEntity entity, string tag, object value, object oldValue)
        {
            string[] parts    = tag.Split('.');
            string   category = parts[0];
            string   name     = parts[1];

            if (category == "position")
            {
                float fvalue = (float)value;
                if (fvalue < Int16.MinValue || fvalue > Int16.MaxValue)
                {
                    // Invalid
                    var obj = (entityProperties.SelectedObject as LocalPropertyGridObject);
                    obj.setValue(tag, oldValue);
                    return;
                }
                var pos = entity.Position;
                if (name == "x")
                {
                    pos.X.High = (short)fvalue;
                    pos.X.Low  = (ushort)(fvalue * 0x10000);
                }
                else if (name == "y")
                {
                    pos.Y.High = (short)fvalue;
                    pos.Y.Low  = (ushort)(fvalue * 0x10000);
                }
                entity.Position = pos;
                if (entity == currentEntity)
                {
                    UpdateCurrentEntityProperites();
                }
            }
            else
            {
                var attribute = entity.GetAttribute(category);
                switch (attribute.Type)
                {
                case RSDKv5.AttributeTypes.UINT8:
                    attribute.ValueUInt8 = (byte)value;
                    break;

                case RSDKv5.AttributeTypes.UINT16:
                    attribute.ValueUInt16 = (ushort)value;
                    break;

                case RSDKv5.AttributeTypes.UINT32:
                    attribute.ValueUInt32 = (uint)value;
                    break;

                case RSDKv5.AttributeTypes.INT8:
                    attribute.ValueInt8 = (sbyte)value;
                    break;

                case RSDKv5.AttributeTypes.INT16:
                    attribute.ValueInt16 = (short)value;
                    break;

                case RSDKv5.AttributeTypes.INT32:
                    attribute.ValueInt32 = (int)value;
                    break;

                case RSDKv5.AttributeTypes.VAR:
                    attribute.ValueVar = (uint)value;
                    break;

                case RSDKv5.AttributeTypes.BOOL:
                    attribute.ValueBool = (bool)value;
                    break;

                case RSDKv5.AttributeTypes.STRING:
                    attribute.ValueString = (string)value;
                    break;

                case RSDKv5.AttributeTypes.POSITION:
                    float fvalue = (float)value;
                    if (fvalue < Int16.MinValue || fvalue > Int16.MaxValue)
                    {
                        // Invalid
                        var obj = (entityProperties.SelectedObject as LocalPropertyGridObject);
                        obj.setValue(tag, oldValue);
                        return;
                    }
                    var pos = attribute.ValuePosition;
                    if (name == "x")
                    {
                        pos.X.High = (short)fvalue;
                        pos.X.Low  = (ushort)(fvalue * 0x10000);
                    }
                    else if (name == "y")
                    {
                        pos.Y.High = (short)fvalue;
                        pos.Y.Low  = (ushort)(fvalue * 0x10000);
                    }
                    attribute.ValuePosition = pos;
                    if (entity == currentEntity)
                    {
                        UpdateCurrentEntityProperites();
                    }
                    break;

                case RSDKv5.AttributeTypes.COLOR:
                    Color c = (Color)value;
                    attribute.ValueColor = new RSDKv5.Color(c.R, c.G, c.B, c.A);
                    break;
                }
            }
        }