Esempio n. 1
0
        public void AddAsset()
        {
            var dict =
                Asset.GatherAssetTypes()
                .Select(type =>
                        new KeyValuePair <string, Type>(type.GetCustomAttribute <AssetAttribute>().Category + ": " + type.GetCustomAttribute <AssetAttribute>().NiceName, type));

            if (!dict.Any())
            {
                MessageBox.Show("There are not asset classes. Make sure that your classes are inherited from Asset class and has attribute AssetAttribute",
                                "Add Asset", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Type result;

            if (ObjectSelector.Show(developerConsole, "Select asset type", "Add Asset", dict, out result))
            {
                string suggestion = result.GetCustomAttribute <AssetAttribute>().Category + @"\";

                var path = NameDialog.Show(developerConsole, "Enter asset name", "Add Asset", suggestion);

                if (path == null)
                {
                    return;
                }

                var desc = (Asset)Activator.CreateInstance(result);
                desc.AssetPath = path;

                try {
                    contentBuilder.AddAsset(desc);
                } catch (ContentException e) {
                    MessageBox.Show(e.Message, "Add Asset", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Modified = true;
                developerConsole.RefreshConsole(false);
                //game.Reload();
            }
        }
Esempio n. 2
0
        public static bool Show <T> (IWin32Window owner, string text, string caption, IEnumerable <KeyValuePair <string, T> > list, out T result)
        {
            var objSel = new ObjectSelector();

            objSel.textLabel.Text = text;
            objSel.Text           = caption;

            objSel.listBox.Items.AddRange(list.Select(a => a.Key).ToArray());
            objSel.listBox.SelectedIndex = 0;

            var r = objSel.ShowDialog(owner);

            if (r == DialogResult.OK)
            {
                result = list.ElementAt(objSel.listBox.SelectedIndex).Value;
                return(true);
            }


            result = default(T);
            return(false);
        }
Esempio n. 3
0
        public void CreateAssetFromAsset()
        {
            var dict =
                Asset.GatherAssetTypes()
                .Select(type =>
                        new KeyValuePair <string, Type>(type.GetCustomAttribute <AssetAttribute>().Category + ": " + type.GetCustomAttribute <AssetAttribute>().NiceName, type));

            if (!dict.Any())
            {
                MessageBox.Show("There are not asset classes. Make sure that your classes are inherited from Asset class and has attribute AssetAttribute",
                                "Add Asset", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Type result;

            if (ObjectSelector.Show(developerConsole, "Select asset type", "Add Asset", dict, out result))
            {
                try {
                    var objs = developerConsole.GetSelectedObjects().Where(o => o is Asset);

                    foreach (var obj in objs)
                    {
                        var asset = Activator.CreateInstance(result);

                        if (asset is IAssetDerivable)
                        {
                            ((IAssetDerivable)asset).InitFromAsset((Asset)obj);
                        }
                    }
                } catch (Exception e) {
                    MessageBox.Show(e.Message, "Create Asset From Asset", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }


                Modified = true;
            }
        }