Example #1
0
 /// <summary>
 /// Loads in the values from a temp file, after the TextEditor has been closed
 /// </summary>
 public void loadInValuesFromTemp()
 {
     smbxNpcFile = new SMBXNpc();
     if (File.Exists(Environment.CurrentDirectory + @"\temp.npctxt"))
     {
         smbxNpcFile.ReadFromTextFile(Environment.CurrentDirectory + @"\temp.npctxt");
         hasChanges = true;
     }
 }
Example #2
0
        private void menuItem4_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();

            of.Filter = "SMBX NPC Text Files (npc-*.txt)|npc-*.txt|Plain Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            of.Title  = "Select an NPC Text File";
            DialogResult dr = of.ShowDialog();

            switch (dr)
            {
            case (DialogResult.OK):
                ResetItems(this.Controls, true);
                curFile     = of.FileName;
                smbxNpcFile = new SMBXNpc();
                try
                {
                    smbxNpcFile.ReadFromTextFile(curFile);
                    loadValuesFromSmbxNpc();
                }
                catch (BadNpcTextFileException ex)
                {
                    MessageBox.Show(String.Format("An error occurred while trying to process the NPC Text File\n{0}", ex.Message),
                                    "Error Processing Text File",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                //
                hasDoneASaveAs = true;
                if (File.Exists(npcAnimator.GetSpritePath(of.FileName)))
                {
                    npcAnimator.setSprite(npcAnimator.GetSpritePath(of.FileName));
                }
                ///TODO: Load the values into the UI
                break;

            case (DialogResult.Cancel):
                break;
            }
        }
        /// <summary>
        /// This function will merge global config with local SMBX NPC.txt config and will return merged config set
        /// </summary>
        /// <param name="global">Global config, read from INI file</param>
        /// <param name="local">SMBX Locak NPC config, read from NPC.txt or edited by UI</param>
        /// <param name="captured">Size of whole image sprite</param>
        /// <returns></returns>
        public obj_npc mergeConfigs(obj_npc global, SMBXNpc local, Size captured )
        {
            obj_npc merged = global;
            merged.name = (local.en_name)?local.name:global.name;

            merged.gfx_offset_x = (local.en_gfxoffsetx)?local.gfxoffsetx:global.gfx_offset_x;
            merged.gfx_offset_y = (local.en_gfxoffsety)?local.gfxoffsety:global.gfx_offset_y;

            merged.width = (local.en_width)?local.width:global.width;
            merged.height = (local.en_height)?local.height:global.height;

            merged.foreground = (local.en_foreground)?local.foreground:global.foreground;

            merged.framespeed = (local.en_framespeed)?
                (int)Math.Round( (double)(global.framespeed) / ((double)8 / (double)(local.framespeed)) )
                                : global.framespeed;
            merged.framestyle = (local.en_framestyle)?local.framestyle:global.framestyle;

            //Copy physical size to GFX size
            if( (local.en_width) && (merged.custom_physics_to_gfx) )
                merged.gfx_w = (int)merged.width;
            else
            {
                if ((!local.en_gfxwidth) && (captured.Width != 0) && (global.gfx_w != captured.Width))
                    merged.width = (uint)captured.Width;

                merged.gfx_w = ((captured.Width != 0) ? captured.Width : global.gfx_w);
            }

            //Copy physical size to GFX size
            if( (local.en_height) && (merged.custom_physics_to_gfx) )
                merged.gfx_h = (int)merged.height;
            else
                merged.gfx_h = global.gfx_h;

            if ((!local.en_gfxwidth) && (captured.Width != 0) && (global.gfx_w != captured.Width))
                merged.gfx_w = captured.Width;
            else
                merged.gfx_w = (local.en_gfxwidth) ? (local.gfxwidth>0 ? local.gfxwidth : 1 ) : merged.gfx_w;

            merged.gfx_h = (local.en_gfxheight) ? (local.gfxheight>0 ? local.gfxheight : 1 ) : merged.gfx_h;

            if(((int)merged.width>=(int)merged.grid))
                merged.grid_offset_x = -1 * (int)Math.Round( (double)((int)merged.width % merged.grid)/2 );
            else
                merged.grid_offset_x = (int)Math.Round((double)(merged.grid - (int)merged.width) / 2);

            if(merged.grid_attach_style==1) merged.grid_offset_x += 16;

            merged.grid_offset_y = (int)(-merged.height % merged.grid);

            if((merged.framestyle==0)&&((local.en_gfxheight)||(local.en_height))&&(!local.en_frames))
            {
                merged.frames = (int)Math.Round((double)(captured.Height) / (double)(merged.gfx_h));
                //merged.custom_animate = false;
            }
            else
                merged.frames = (local.en_frames)?local.frames:global.frames;

            if((local.en_frames)||(local.en_framestyle))
            {
                merged.ani_bidir = false; //Disable bidirectional animation
                if((local.en_frames)) merged.custom_animate = false; //Disable custom animation
            }

            // Convert out of range frames by framestyle into animation with controlable diraction
            if((merged.framestyle>0)&&(merged.gfx_h*merged.frames >= (uint)captured.Height))
            {
                merged.framestyle = 0;
                merged.ani_direct = false;
                merged.ani_directed_direct = true;
            }

            merged.score = (local.en_score)?local.score:global.score;
            merged.block_player = (local.en_playerblock)?local.playerblock:global.block_player;
            merged.block_player_top = (local.en_playerblocktop)?local.playerblocktop:global.block_player_top;
            merged.block_npc = (local.en_npcblock)?local.npcblock:global.block_npc;
            merged.block_npc_top = (local.en_npcblocktop)?local.npcblocktop:global.block_npc_top;
            merged.grab_side = (local.en_grabside)?local.grabside:global.grab_side;
            merged.grab_top = (local.en_grabtop)?local.grabtop:global.grab_top;
            merged.kill_on_jump = (local.en_jumphurt)? (!local.jumphurt) : global.kill_on_jump ;
            merged.hurt_player = (local.en_nohurt)?!local.nohurt:global.hurt_player;
            merged.collision_with_blocks = (local.en_noblockcollision)?(!local.noblockcollision):global.collision_with_blocks;
            merged.turn_on_cliff_detect = (local.en_cliffturn)?local.cliffturn:global.turn_on_cliff_detect;
            merged.can_be_eaten = (local.en_noyoshi)?(!local.noyoshi):global.can_be_eaten;
            merged.speed = (local.en_speed) ? (int)Math.Round(global.speed * local.speed) : global.speed;
            merged.kill_by_fireball = (local.en_nofireball)?(!local.nofireball):global.kill_by_fireball;
            merged.gravity = (local.en_nogravity)?(!local.nogravity):global.gravity;
            merged.freeze_by_iceball = (local.en_noiceball)?(!local.noiceball):global.freeze_by_iceball;
            merged.kill_hammer = (local.en_nohammer)?(!local.nohammer):global.kill_hammer;
            merged.kill_by_npc = (local.en_noshell)?(!local.noshell):global.kill_by_npc;

            return merged;
        }
Example #4
0
        /// <summary>
        /// This function will merge global config with local SMBX NPC.txt config and will return merged config set
        /// </summary>
        /// <param name="global">Global config, read from INI file</param>
        /// <param name="local">SMBX Locak NPC config, read from NPC.txt or edited by UI</param>
        /// <param name="captured">Size of whole image sprite</param>
        /// <returns></returns>
        public obj_npc mergeConfigs(obj_npc global, SMBXNpc local, Size captured)
        {
            obj_npc merged = global;

            merged.name = (local.en_name)?local.name:global.name;

            merged.gfx_offset_x = (local.en_gfxoffsetx)?local.gfxoffsetx:global.gfx_offset_x;
            merged.gfx_offset_y = (local.en_gfxoffsety)?local.gfxoffsety:global.gfx_offset_y;

            merged.width  = (local.en_width)?local.width:global.width;
            merged.height = (local.en_height)?local.height:global.height;

            merged.foreground = (local.en_foreground)?local.foreground:global.foreground;

            merged.framespeed = (local.en_framespeed)?
                                (int)Math.Round((double)(global.framespeed) / ((double)8 / (double)(local.framespeed)))
                                : global.framespeed;
            merged.framestyle = (local.en_framestyle)?local.framestyle:global.framestyle;

            //Copy physical size to GFX size
            if ((local.en_width) && (merged.custom_physics_to_gfx))
            {
                merged.gfx_w = (int)merged.width;
            }
            else
            {
                if ((!local.en_gfxwidth) && (captured.Width != 0) && (global.gfx_w != captured.Width))
                {
                    merged.width = (uint)captured.Width;
                }

                merged.gfx_w = ((captured.Width != 0) ? captured.Width : global.gfx_w);
            }

            //Copy physical size to GFX size
            if ((local.en_height) && (merged.custom_physics_to_gfx))
            {
                merged.gfx_h = (int)merged.height;
            }
            else
            {
                merged.gfx_h = global.gfx_h;
            }


            if ((!local.en_gfxwidth) && (captured.Width != 0) && (global.gfx_w != captured.Width))
            {
                merged.gfx_w = captured.Width;
            }
            else
            {
                merged.gfx_w = (local.en_gfxwidth) ? (local.gfxwidth > 0 ? local.gfxwidth : 1) : merged.gfx_w;
            }

            merged.gfx_h = (local.en_gfxheight) ? (local.gfxheight > 0 ? local.gfxheight : 1) : merged.gfx_h;


            if (((int)merged.width >= (int)merged.grid))
            {
                merged.grid_offset_x = -1 * (int)Math.Round((double)((int)merged.width % merged.grid) / 2);
            }
            else
            {
                merged.grid_offset_x = (int)Math.Round((double)(merged.grid - (int)merged.width) / 2);
            }

            if (merged.grid_attach_style == 1)
            {
                merged.grid_offset_x += 16;
            }

            merged.grid_offset_y = (int)(-merged.height % merged.grid);


            if ((merged.framestyle == 0) && ((local.en_gfxheight) || (local.en_height)) && (!local.en_frames))
            {
                merged.frames = (int)Math.Round((double)(captured.Height) / (double)(merged.gfx_h));
                //merged.custom_animate = false;
            }
            else
            {
                merged.frames = (local.en_frames)?local.frames:global.frames;
            }

            if ((local.en_frames) || (local.en_framestyle))
            {
                merged.ani_bidir = false; //Disable bidirectional animation
                if ((local.en_frames))
                {
                    merged.custom_animate = false;                   //Disable custom animation
                }
            }

            // Convert out of range frames by framestyle into animation with controlable diraction
            if ((merged.framestyle > 0) && (merged.gfx_h * merged.frames >= (uint)captured.Height))
            {
                merged.framestyle          = 0;
                merged.ani_direct          = false;
                merged.ani_directed_direct = true;
            }

            merged.score                 = (local.en_score)?local.score:global.score;
            merged.block_player          = (local.en_playerblock)?local.playerblock:global.block_player;
            merged.block_player_top      = (local.en_playerblocktop)?local.playerblocktop:global.block_player_top;
            merged.block_npc             = (local.en_npcblock)?local.npcblock:global.block_npc;
            merged.block_npc_top         = (local.en_npcblocktop)?local.npcblocktop:global.block_npc_top;
            merged.grab_side             = (local.en_grabside)?local.grabside:global.grab_side;
            merged.grab_top              = (local.en_grabtop)?local.grabtop:global.grab_top;
            merged.kill_on_jump          = (local.en_jumphurt)? (!local.jumphurt) : global.kill_on_jump;
            merged.hurt_player           = (local.en_nohurt)?!local.nohurt:global.hurt_player;
            merged.collision_with_blocks = (local.en_noblockcollision)?(!local.noblockcollision):global.collision_with_blocks;
            merged.turn_on_cliff_detect  = (local.en_cliffturn)?local.cliffturn:global.turn_on_cliff_detect;
            merged.can_be_eaten          = (local.en_noyoshi)?(!local.noyoshi):global.can_be_eaten;
            merged.speed                 = (local.en_speed) ? (int)Math.Round(global.speed * local.speed) : global.speed;
            merged.kill_by_fireball      = (local.en_nofireball)?(!local.nofireball):global.kill_by_fireball;
            merged.gravity               = (local.en_nogravity)?(!local.nogravity):global.gravity;
            merged.freeze_by_iceball     = (local.en_noiceball)?(!local.noiceball):global.freeze_by_iceball;
            merged.kill_hammer           = (local.en_nohammer)?(!local.nohammer):global.kill_hammer;
            merged.kill_by_npc           = (local.en_noshell)?(!local.noshell):global.kill_by_npc;

            return(merged);
        }