Esempio n. 1
0
        public new void Load(Project project)
        {
            currentProject = project;
            sheet = project.sheets["tiles"];

            hScrollBar.Enabled = true;
            hScrollBar.Minimum = 0;
            hScrollBar.Maximum = sheet.Cols * sheet.spriteWidth;
            hScrollBar.LargeChange = tilesPanel.Width;
            hScrollBar.SmallChange = sheet.spriteWidth;
            hScrollBar.ValueChanged += (sender, args) => {
                this.offsetX = hScrollBar.Value;
                tilesPanel.Invalidate();
            };
            vScrollBar.Enabled = true;
            vScrollBar.Minimum = 0;
            vScrollBar.Maximum = sheet.sheet.Height + sheet.spriteHeight;
            vScrollBar.LargeChange = tilesPanel.Height;
            vScrollBar.SmallChange = sheet.spriteHeight;
            vScrollBar.ValueChanged += (sender, args) => {
                this.offsetY = vScrollBar.Value;
                tilesPanel.Invalidate();
            };
            tilesPanel.Resize += (sender, args) => {
                hScrollBar.LargeChange = tilesPanel.Width;
                vScrollBar.LargeChange = tilesPanel.Height;
                hScrollBar.Enabled = hScrollBar.LargeChange <= hScrollBar.Maximum;
                vScrollBar.Enabled = vScrollBar.LargeChange <= vScrollBar.Maximum;
            };

            LoadObjects();

            tilePage.Invalidate();
        }
Esempio n. 2
0
 public SpriteDialog(Project project, Sprite sprite)
 {
     InitializeComponent();
     this.project = project;
     foreach (var anim in project.animations.Values) {
         animationComboBox.Items.Add(anim);
     }
     animationComboBox.DisplayMember = "Name";
     if (sprite == null) {
         this.sprite = new Sprite(project);
         this.newSprite = true;
         animationComboBox.SelectedIndex = 0;
     }
     else {
         this.sprite = sprite;
         this.newSprite = false;
         nameTextBox.Text = sprite.Name;
         animationComboBox.SelectedItem = sprite.animation;
         speedNumericUpDown.Value = sprite.speed;
         noclipCheckBox.Checked = sprite.noclip;
         foreach (KeyValuePair<string, string> kvp in sprite.ext) {
             listBox.Items.Add(kvp);
         }
     }
 }
Esempio n. 3
0
 public ScriptSelector(string current, Project project)
 {
     InitializeComponent();
     this.project = project;
     scripts = project.scripts;
     Populate();
     comboBox.SelectedItem = current;
 }
Esempio n. 4
0
 public AnimationSelector(SpriteSheet sheet, Project project)
 {
     InitializeComponent();
     spriteSelector.Image = sheet.sheet;
     spriteSelector.SpriteWidth = sheet.spriteWidth;
     spriteSelector.SpriteHeight = sheet.spriteHeight;
     selectedFrames = new Animation.Frame[1];
     selectedFrames[0] = new Animation.Frame(0, 1);
 }
Esempio n. 5
0
 public Sprite(string spriteName, Project project)
 {
     this.project = project;
     PropertyReader props = project.loader.GetPropertyReader().Select("sprites/" + spriteName + ".xml");
     animation = project.animations[props.GetString("animation")];
     speed = props.GetInt("speed");
     noclip = props.GetBool("noclip");
     foreach (PropertyReader extNode in props.SelectAll("exts/ext")) {
         ext.Add(extNode.GetString("key"), extNode.GetString("value"));
     }
 }
Esempio n. 6
0
        public AnimationDialog(Animation baseAnimation, Project project)
            : this(project)
        {
            this.baseAnimation = baseAnimation;
            nameTextBox.Text = baseAnimation.Name;

            sheetComboBox.SelectedItem = new KeyValuePair<string, SpriteSheet>(baseAnimation.sheet.Name, baseAnimation.sheet);

            foreach (var kvp in baseAnimation.groups) {
                groups.Add(kvp);
            }
        }
Esempio n. 7
0
 public new void Load(Project project)
 {
     this.project = project;
     LoadItems();
     listbox.SelectedIndexChanged += (sender, args) => {
         if (!string.IsNullOrEmpty((string)listbox.SelectedItem)) {
             pictureBox.Image = project.sheets[(string)listbox.SelectedItem].sheet;
         }
     };
     listbox.DoubleClick += (sender, args) => {
         SpriteSheet sheet = project.sheets[(string)listbox.SelectedItem];
         using (SpriteSheetDialog dialog = new SpriteSheetDialog()) {
             string oldName = (string)listbox.SelectedItem;
             dialog.nameTextBox.Text = oldName;
             dialog.okButton.Click += (in_sender, in_args) => {
                 if (dialog.nameTextBox.Text.Trim() == "") {
                     MessageBox.Show("Name cannot be empty");
                 }
                 else if (dialog.pictureBox.Image == null) {
                     MessageBox.Show("Image cannot be empty");
                 }
                 else if (dialog.nameTextBox.Text.ToLower() == oldName) dialog.DialogResult = DialogResult.OK;
                 else {
                     if (!project.sheets.ContainsKey(dialog.nameTextBox.Text.ToLower())) {
                         dialog.DialogResult = DialogResult.OK;
                     }
                     else {
                         MessageBox.Show(this, string.Format("A sprite named \"{0}\" already exists!", dialog.nameTextBox.Text));
                     }
                 }
             };
             dialog.pictureBox.Image = sheet.sheet;
             dialog.widthNumericUpDown.Value = sheet.spriteWidth;
             dialog.HeightNumericUpDown.Value = sheet.spriteHeight;
             dialog.xNumericUpDown.Value = sheet.x;
             dialog.yNumericUpDown.Value = sheet.y;
             if (dialog.ShowDialog(this) == DialogResult.OK) {
                 if (dialog.nameTextBox.Text != oldName) {
                     project.sheets.Remove(oldName);
                     project.sheets.Add(dialog.nameTextBox.Text.Trim().ToLower(), sheet);
                 }
                 sheet.sheet = (Bitmap)dialog.pictureBox.Image;
                 sheet.spriteWidth = (int)dialog.widthNumericUpDown.Value;
                 sheet.spriteHeight = (int)dialog.HeightNumericUpDown.Value;
                 sheet.x = (int)dialog.xNumericUpDown.Value;
                 sheet.y = (int)dialog.yNumericUpDown.Value;
                 int index = listbox.SelectedIndex;
                 LoadItems();
                 listbox.SelectedIndex = index;
             }
         }
     };
 }
Esempio n. 8
0
 public SpriteSheet(string name, Project project)
 {
     this.project = project;
     Loader loader = project.loader;
     using (Bitmap bm = loader.LoadBitmap("img/" + name + ".png")) {
         sheet = new Bitmap(bm);
     }
     PropertyReader props = loader.GetPropertyReader().Select("img/" + name + ".xml");
     spriteWidth = props.GetInt("width");
     spriteHeight = props.GetInt("height");
     x = props.GetInt("x");
     y = props.GetInt("y");
 }
Esempio n. 9
0
        public AnimationSelector(Animation.Group group, SpriteSheet sheet, Project project)
        {
            InitializeComponent();
            spriteSelector.Image = sheet.sheet;
            spriteSelector.SpriteWidth = sheet.spriteWidth;
            spriteSelector.SpriteHeight = sheet.spriteHeight;
            selectedFrames = group.frames.ToArray();

            //Must be set last because their events are already hooked up
            maxFramesNumUpDown.Value = group.frames.Count;
            spriteSelector.SelectedIndex = selectedFrames[0].sheetId;
            timeoutNumericUpDown.Value = selectedFrames[0].time;
        }
Esempio n. 10
0
        public Map(string name, Project project)
        {
            this.name = name;
            Loader loader = project.loader;
            PropertyReader info = loader.GetPropertyReader().Select("maps/" + name + "/info.xml");
            var groups = info.SelectAll("layers/group");
            int numLayers = groups.Count;
            width = info.GetInt("width");
            height = info.GetInt("height");
            for (int i = 0; i < numLayers;) {
                var layerType = groups[i].GetString("type");
                var layerName = groups[i].GetString("name");
                var layerGroup = LayerGroup.Create(layerName, layerType, width, height, "maps/" + name + "/layers/{0}." + i.ToString(), this, project);
                layerGroups.Add(layerGroup);
                i += layerGroup.LayerCount;
            }
            this.ladders = new Ladder[width, height];

            PropertyReader objects = loader.GetPropertyReader().Select("maps/" + name + "/objects.xml");
            foreach (PropertyReader obj in objects.SelectAll("object")) {
                string spriteName = obj.GetString("sprite");
                int x = obj.GetInt("x");
                int y = obj.GetInt("y");
                int layer = obj.GetInt("layer");
                Obj o = new Obj();
                o.Sprite = project.sprites[spriteName];
                o.movementAIScript = obj.GetString("movement");
                o.actionScript = obj.GetString("action");
                o.collideScript = obj.GetString("collide");
                Layers(layer).objects[x, y] = o;
            }

            PropertyReader events = loader.GetPropertyReader().Select("maps/" + name + "/onstep.xml");
            foreach (PropertyReader e in events.SelectAll("event")) {
                int x = e.GetInt("x");
                int y = e.GetInt("y");
                int layer = e.GetInt("layer");
                string script = e.GetString("script");
                Layers(layer).tiles[x, y].onStep = script;
            }

            PropertyReader ladders = loader.GetPropertyReader().Select("maps/" + name + "/ladders.xml");
            foreach (PropertyReader ladder in ladders.SelectAll("ladder")) {
                int x = ladder.GetInt("x");
                int y = ladder.GetInt("y");
                int baseLayer = ladder.GetInt("base");
                int topLayer = ladder.GetInt("top");
                this.ladders[x, y] = new Ladder(Layers(baseLayer), Layers(topLayer));
            }
        }
Esempio n. 11
0
 public Animation(string animationName, Project project)
 {
     this.project = project;
     Loader loader = project.loader;
     PropertyReader props = loader.GetPropertyReader().Select("animations/" + animationName + ".xml");
     foreach (PropertyReader animation in props.SelectAll("group")) {
         string groupName = animation.GetString("name");
         Group group = new Group();
         foreach (PropertyReader frame in animation.SelectAll("frame")) {
             int id = frame.GetInt("sheetid");
             int time = frame.GetInt("time");
             group.frames.Add(new Frame(id, time));
         }
         groups.Add(groupName, group);
     }
     this.sheet = project.sheets[props.GetString("sheet")];
 }
Esempio n. 12
0
 public Layer(int width, int height, string pathBase, Map map, Project project)
 {
     this.Map = map;
     Loader loader = project.loader;
     SpriteSheet sheet = project.sheets["tiles"];
     tiles = new Map.Tile[width, height];
     objects = new Map.Obj[width, height];
     string[] passLines = loader.LoadText(string.Format(pathBase, "passability")).Split('\n');
     string[] gfxLines = loader.LoadText(string.Format(pathBase, "tiles")).Split('\n');
     for (int j = 0; j < height; ++j)
     {
         string[] passLine = passLines[j].Split(' ');
         string[] gfxLine = gfxLines[j].Split(' ');
         for (int i = 0; i < width; ++i)
         {
             tiles[i, j] = new Map.Tile(sheet.GetGfxById(int.Parse(gfxLine[i])), int.Parse(passLine[i]) == 1);
         }
     }
 }
Esempio n. 13
0
        public AnimationDialog(Project project)
        {
            InitializeComponent();
            this.project = project;

            groupsListBox.DisplayMember = "Key";
            groupsListBox.DataSource = groups;

            sheetComboBox.SelectedIndexChanged += (sender, args) => {
                pictureBox.Image = CurrentSheet.sheet;
            };
            sheetComboBox.DisplayMember = "Key";
            sheetComboBox.ValueMember = "Value";
            sheetComboBox.DataSource = project.sheets;

            if (sheetComboBox.Items.Count != 0) {
                sheetComboBox.SelectedIndex = 0;
                pictureBox.Image = CurrentSheet.sheet;
            }
        }
Esempio n. 14
0
 public SpriteSheet(Project project)
 {
     this.project = project;
 }
Esempio n. 15
0
        private new bool Load()
        {
            if (locker.IsLocked(savePath)) {
                if (MessageBox.Show("The project is already open in another application, or the application closed " +
                                    "without properly closing the project. Do you really want to open it?",
                                    "Project is locked",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) {
                    locker.Unlock();
                    locker.Lock(savePath, true);
                }
                else {
                    return true;
                }
            }
            else {
                locker.Lock(savePath);
            }

            try {
                currentProject = Project.FromFiles(savePath);
            }
            catch (Project.LoadException) {
                MessageBox.Show(this, "The selected folder is not a project, or it is corrupted.", "Invalid folder");
                savePath = null;
                return false;
            }

            currentMap = currentProject.maps[currentProject.startupMapName];

            projectLoadables.ForEach(l => l.Load(currentProject));
            layers.Load(currentMap);

            foreach (string mapName in currentProject.maps.Keys) {
                mapComboBox.Items.Add(mapName);
            }
            mapComboBox.SelectedIndex = mapComboBox.Items.IndexOf(currentMap.name);
            mapComboBox.SelectedIndexChanged += (sender, args) => {
                ChangeCurrentMap((string)mapComboBox.SelectedItem);
            };

            OnProjectLoaded(EventArgs.Empty);
            return true;
        }
Esempio n. 16
0
 public Animation(SpriteSheet sheet, Project project)
 {
     this.project = project;
     this.sheet = sheet;
 }
Esempio n. 17
0
 public Sprite(Project project)
 {
     this.project = project;
 }
Esempio n. 18
0
 public new void Load(Project project)
 {
     this.project = project;
     listBox.DisplayMember = "Key";
     listBox.DataSource = project.animations;
 }
Esempio n. 19
0
 public new void Load(Project project)
 {
     this.project = project;
     this.list.DisplayMember = "Key";
     this.list.DataSource = project.musics;
 }