コード例 #1
0
ファイル: BuilderWindow.cs プロジェクト: MarbleGameDev/2DRPG
        static void SetupNewObject(ObjectData.WorldObjects newType)
        {
            switch (newType)
            {
            case ObjectData.WorldObjects.Animated:
                nt = typeof(WorldObjectAnimated);
                break;

            case ObjectData.WorldObjects.Base:
                nt = typeof(WorldObjectBase);
                break;

            case ObjectData.WorldObjects.Collidable:
                nt = typeof(WorldObjectCollidable);
                break;

            case ObjectData.WorldObjects.Controllable:
                nt = typeof(WorldObjectControllable);
                break;

            case ObjectData.WorldObjects.Dialogue:
                nt = typeof(WorldObjectDialogue);
                break;

            case ObjectData.WorldObjects.Inventory:
                nt = typeof(WorldObjectInventory);
                break;

            case ObjectData.WorldObjects.SimpleItem:
                nt = typeof(WorldObjectSimpleItem);
                break;

            case ObjectData.WorldObjects.Movable:
                nt = typeof(WorldObjectMovable);
                break;

            case ObjectData.WorldObjects.MovableAnimated:
                nt = typeof(WorldObjectMovableAnimated);
                break;

            default:
                System.Diagnostics.Debug.WriteLine("No code path found for this new object!");
                return;
            }
            List <UIButton> b = new List <UIButton>();

            ParameterInfo[] parms = nt.GetConstructors()[0].GetParameters();
            ntParams = new object[parms.Length];
            int counter = 0;

            foreach (ParameterInfo p in parms)
            {
                UITypeBox tb = new UITypeBox(0, 0, objectData.width1, objectData.height1, 2, 1, TextureManager.TextureNames.button);
                tb.text.SetText(p.Name + ":");
                int i = counter++;
                tb.valueAction = () => {
                    string val = tb.text.GetText();
                    val = val.Substring(val.IndexOf(':') + 1);
                    try {
                        if (val.Length > 0)
                        {
                            if (p.ParameterType.Equals(typeof(String)))
                            {
                                ntParams[i] = val;
                            }
                            else
                            {
                                ntParams[i] = int.Parse(val);
                            }
                        }
                    } catch (FormatException) {
                        System.Diagnostics.Debug.WriteLine("Invalid Format");
                        ntParams[i] = null;
                    }
                };
                b.Add(tb);
            }
            objectData.displaySize = (b.Count > 5) ? 5 : b.Count;
            objectData.SetDropdowns(b.ToArray());
            objectName.SetText(nt.Name);
            objectData.showDrops = true;
            applyBut.Visible     = true;
        }
コード例 #2
0
ファイル: BuilderWindow.cs プロジェクト: MarbleGameDev/2DRPG
        static void UpdateObjectInfo()
        {
            if (currentObject == null)
            {
                return;
            }

            if (currentObject is StandardMob s)
            {
                //isEntity = true;
                AIType.Visible   = true;
                AIActive.Visible = true;
                currentMob       = s;
                entityName.SetText(currentObject.GetType().Name);
                AIType.displayLabel.SetText(currentMob.mobAI.type.ToString());
                AIActive.displayLabel.SetText(currentMob.mobAI.active.ToString());
            }
            else
            {
                AIType.Visible   = false;
                AIActive.Visible = false;
                entityName.SetText("Selected Object is not Entity");
            }

            if (objectData != null)
            {
                List <UIButton> b     = new List <UIButton>();
                FieldInfo[]     props = currentObject.GetType().GetFields().Where(prop => Attribute.IsDefined(prop, typeof(Editable))).ToArray();
                foreach (FieldInfo f in props)
                {
                    UITypeBox tb = new UITypeBox(0, 0, objectData.width1, objectData.height1, 2, 1, TextureManager.TextureNames.button);
                    tb.text.SetText(f.Name + ":" + f.GetValue(currentObject).ToString());
                    tb.text.SetLayer(1);
                    tb.valueAction = () => {
                        string val = tb.text.GetText();
                        val = val.Substring(val.IndexOf(':') + 1);
                        try {
                            if (val.Length > 0)
                            {
                                if (f.FieldType.Equals(typeof(String)))
                                {
                                    f.SetValue(currentObject, val);
                                }
                                else
                                {
                                    f.SetValue(currentObject, int.Parse(val));
                                }
                                currentObject.ModificationAction();
                            }
                        } catch (FormatException) {
                            System.Diagnostics.Debug.WriteLine("Invalid Format, could not update Value");
                        }
                    };
                    b.Add(tb);
                }
                objectData.displaySize = (b.Count > 5) ? 5.5f : b.Count;
                objectData.SetDropdowns(b.ToArray());
                objectName.SetText(currentObject.GetType().Name);
                objectData.showDrops = true;
                moveBut.Visible      = true;
            }
            else
            {
                objectData.displayLabel.SetText("No Object Selected");
            }
        }