VERSION 5.00
Begin VB.Form frm_main 
   Caption         =   "CrystalEd"
   ClientHeight    =   6360
   ClientLeft      =   60
   ClientTop       =   390
   ClientWidth     =   12240
   LinkTopic       =   "Form1"
   ScaleHeight     =   424
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   816
   StartUpPosition =   2  'CenterScreen
   Begin VB.PictureBox pic_maps 
      BorderStyle     =   0  'None
      Height          =   4695
      Left            =   0
      ScaleHeight     =   4695
      ScaleWidth      =   2520
      TabIndex        =   42
      Top             =   1080
      Width           =   2520
      Begin VB.CommandButton cmd_openmap 
         Caption         =   "open"
         Height          =   375
         Left            =   1320
         TabIndex        =   48
         Top             =   4200
         Width           =   1095
      End
      Begin VB.CommandButton cmd_newmap 
         Caption         =   "create"
         Height          =   375
         Left            =   120
         TabIndex        =   47
         Top             =   4200
         Width           =   1095
      End
      Begin VB.TextBox txt_newmap 
         Appearance      =   0  'Flat
         Height          =   285
         Left            =   120
         MaxLength       =   16
         TabIndex        =   46
         Text            =   "newmap"
         ToolTipText     =   "newmap"
         Top             =   3720
         Width           =   2295
      End
      Begin VB.FileListBox flb_maps 
         Appearance      =   0  'Flat
         Height          =   2955
         Left            =   120
         TabIndex        =   43
         Top             =   360
         Width           =   2295
      End
      Begin VB.Label lab_newmap 
         Caption         =   "Create new map:"
         Height          =   255
         Left            =   120
         TabIndex        =   45
         Top             =   3480
         Width           =   2295
      End
      Begin VB.Label lab_maps 
         Caption         =   "Select map to open:"
         Height          =   255
         Left            =   120
         TabIndex        =   44
         Top             =   120
         Width           =   2295
      End
   End
   Begin VB.PictureBox pic_commands 
      BorderStyle     =   0  'None
      Height          =   4695
      Left            =   0
      ScaleHeight     =   313
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   168
      TabIndex        =   58
      Top             =   1080
      Visible         =   0   'False
      Width           =   2520
      Begin VB.ListBox commands 
         Appearance      =   0  'Flat
         Height          =   2955
         ItemData        =   "frm_main.frx":0000
         Left            =   120
         List            =   "frm_main.frx":0002
         TabIndex        =   64
         Top             =   360
         Width           =   2295
      End
      Begin VB.TextBox txt_command 
         Appearance      =   0  'Flat
         Height          =   285
         Left            =   120
         TabIndex        =   63
         Top             =   3720
         Width           =   2295
      End
      Begin VB.CommandButton cmd_add 
         Caption         =   "add"
         Height          =   375
         Left            =   120
         TabIndex        =   62
         Top             =   4200
         Width           =   495
      End
      Begin VB.CommandButton cmd_cmdok 
         Caption         =   "ok"
         Height          =   375
         Left            =   1920
         TabIndex        =   61
         Top             =   4200
         Width           =   495
      End
      Begin VB.CommandButton Command1 
         Caption         =   "edit"
         Height          =   375
         Left            =   720
         TabIndex        =   60
         Top             =   4200
         Width           =   495
      End
      Begin VB.CommandButton cmd_cmddel 
         Caption         =   "del"
         Height          =   375
         Left            =   1320
         TabIndex        =   59
         Top             =   4200
         Width           =   495
      End
      Begin VB.Label lab_commands 
         Caption         =   "Select command:"
         Height          =   255
         Left            =   120
         TabIndex        =   66
         Top             =   120
         Width           =   2295
      End
      Begin VB.Label lab_editcommand 
         Caption         =   "Command:"
         Height          =   255
         Left            =   120
         TabIndex        =   65
         Top             =   3480
         Width           =   2295
      End
   End
   Begin VB.CommandButton cmd_run 
      Caption         =   "in game"
      Height          =   375
      Left            =   1260
      TabIndex        =   6
      Top             =   720
      Width           =   1260
   End
   Begin VB.CommandButton cmd_mapsave 
      Caption         =   "save"
      Height          =   375
      Left            =   1260
      TabIndex        =   5
      Top             =   360
      Width           =   1260
   End
   Begin VB.PictureBox pic_tiles 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      ForeColor       =   &H80000008&
      Height          =   480
      Left            =   1920
      ScaleHeight     =   30
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   30
      TabIndex        =   67
      Top             =   5760
      Visible         =   0   'False
      Width           =   480
   End
   Begin VB.CommandButton Command2 
      Caption         =   "commands"
      Height          =   375
      Left            =   0
      TabIndex        =   3
      Top             =   720
      Width           =   1260
   End
   Begin VB.CommandButton cmd_mapopen 
      Caption         =   "open"
      Height          =   375
      Left            =   1260
      TabIndex        =   4
      Top             =   0
      Width           =   1260
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   19
      Left            =   1920
      MaxLength       =   2
      TabIndex        =   56
      Text            =   "FB"
      ToolTipText     =   "Fire Ball"
      Top             =   5160
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   19
      Left            =   1920
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   55
      Top             =   4680
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   18
      Left            =   1320
      MaxLength       =   2
      TabIndex        =   54
      Text            =   "NL"
      ToolTipText     =   "Next Level"
      Top             =   5160
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   18
      Left            =   1320
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   53
      Top             =   4680
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   17
      Left            =   720
      MaxLength       =   2
      TabIndex        =   52
      Text            =   "TG"
      Top             =   5160
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   17
      Left            =   720
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   51
      ToolTipText     =   "Trigger"
      Top             =   4680
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   16
      Left            =   120
      MaxLength       =   2
      TabIndex        =   50
      Text            =   "PS"
      Top             =   5160
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   16
      Left            =   120
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   49
      ToolTipText     =   "Player Spawn"
      Top             =   4680
      Width           =   480
   End
   Begin VB.CommandButton cmd_mapclear 
      Caption         =   "clear"
      Height          =   375
      Left            =   0
      TabIndex        =   2
      Top             =   360
      Width           =   1260
   End
   Begin VB.CheckBox chk_names 
      Caption         =   "Edit blocks names"
      Height          =   255
      Left            =   120
      TabIndex        =   41
      Top             =   5520
      Width           =   1815
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   15
      Left            =   1920
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   40
      ToolTipText     =   "Moveble Stone"
      Top             =   3840
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   15
      Left            =   1920
      MaxLength       =   2
      TabIndex        =   39
      Text            =   "MS"
      Top             =   4320
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   14
      Left            =   1320
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   38
      ToolTipText     =   "Alive Crystal"
      Top             =   3840
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   14
      Left            =   1320
      MaxLength       =   2
      TabIndex        =   37
      Text            =   "AC"
      Top             =   4320
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   13
      Left            =   720
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   36
      ToolTipText     =   "Super Crystal"
      Top             =   3840
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   13
      Left            =   720
      MaxLength       =   2
      TabIndex        =   35
      Text            =   "SC"
      Top             =   4320
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   12
      Left            =   120
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   34
      ToolTipText     =   "Normal Crystal"
      Top             =   3840
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   12
      Left            =   120
      MaxLength       =   2
      TabIndex        =   33
      Text            =   "NC"
      Top             =   4320
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   11
      Left            =   1920
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   32
      ToolTipText     =   "Block 12"
      Top             =   3000
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   11
      Left            =   1920
      MaxLength       =   2
      TabIndex        =   31
      Text            =   "12"
      Top             =   3480
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   10
      Left            =   1320
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   30
      ToolTipText     =   "Block 11"
      Top             =   3000
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   10
      Left            =   1320
      MaxLength       =   2
      TabIndex        =   29
      Text            =   "11"
      Top             =   3480
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   9
      Left            =   720
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   28
      ToolTipText     =   "Block 10"
      Top             =   3000
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   9
      Left            =   720
      MaxLength       =   2
      TabIndex        =   27
      Text            =   "10"
      Top             =   3480
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   8
      Left            =   120
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   26
      ToolTipText     =   "Dynamite"
      Top             =   3000
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   8
      Left            =   120
      MaxLength       =   2
      TabIndex        =   25
      Text            =   "DN"
      Top             =   3480
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   7
      Left            =   1920
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   24
      ToolTipText     =   "Wooden Crate"
      Top             =   2160
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   7
      Left            =   1920
      MaxLength       =   2
      TabIndex        =   23
      Text            =   "WC"
      Top             =   2640
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   6
      Left            =   1320
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   22
      ToolTipText     =   "Block 07"
      Top             =   2160
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   6
      Left            =   1320
      MaxLength       =   2
      TabIndex        =   21
      Text            =   "07"
      Top             =   2640
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   5
      Left            =   720
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   20
      ToolTipText     =   "Block 06"
      Top             =   2160
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   5
      Left            =   720
      MaxLength       =   2
      TabIndex        =   19
      Text            =   "06"
      Top             =   2640
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   4
      Left            =   120
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   18
      ToolTipText     =   "Block 05"
      Top             =   2160
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   4
      Left            =   120
      MaxLength       =   2
      TabIndex        =   17
      Text            =   "05"
      Top             =   2640
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   3
      Left            =   1920
      MaxLength       =   2
      TabIndex        =   16
      Text            =   "04"
      Top             =   1800
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   3
      Left            =   1920
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   15
      ToolTipText     =   "Block 04"
      Top             =   1320
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   2
      Left            =   1320
      MaxLength       =   2
      TabIndex        =   14
      Text            =   "03"
      Top             =   1800
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   2
      Left            =   1320
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   13
      ToolTipText     =   "Block 03"
      Top             =   1320
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   1
      Left            =   720
      MaxLength       =   2
      TabIndex        =   12
      Text            =   "02"
      Top             =   1800
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   1
      Left            =   720
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   11
      ToolTipText     =   "Block 02"
      Top             =   1320
      Width           =   480
   End
   Begin VB.TextBox txt_block 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Index           =   0
      Left            =   120
      MaxLength       =   2
      TabIndex        =   10
      Text            =   "01"
      Top             =   1800
      Width           =   480
   End
   Begin VB.PictureBox pic_block 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      Height          =   480
      Index           =   0
      Left            =   120
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   9
      ToolTipText     =   "Block 01"
      Top             =   1320
      Width           =   480
   End
   Begin VB.VScrollBar scrl_height 
      Height          =   6135
      Left            =   12000
      Max             =   512
      SmallChange     =   16
      TabIndex        =   8
      Top             =   0
      Width           =   255
   End
   Begin VB.HScrollBar scrl_width 
      Height          =   255
      Left            =   2520
      Max             =   1024
      SmallChange     =   16
      TabIndex        =   7
      Top             =   6120
      Width           =   9495
   End
   Begin VB.PictureBox pic_view 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      FillColor       =   &H00FFFFFF&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   204
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FF00&
      Height          =   6135
      Left            =   2520
      ScaleHeight     =   409
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   633
      TabIndex        =   0
      Top             =   0
      Width           =   9495
      Begin VB.Label lab_block 
         Alignment       =   2  'Center
         BackStyle       =   0  'Transparent
         ForeColor       =   &H00FFFFFF&
         Height          =   255
         Index           =   0
         Left            =   0
         TabIndex        =   68
         Top             =   600
         Width           =   960
      End
      Begin VB.Label lab_block 
         Alignment       =   2  'Center
         BackStyle       =   0  'Transparent
         ForeColor       =   &H00000000&
         Height          =   255
         Index           =   1
         Left            =   0
         TabIndex        =   69
         Top             =   480
         Width           =   960
      End
      Begin VB.Shape shp_block 
         BorderColor     =   &H00FFFFFF&
         BorderStyle     =   3  'Dot
         Height          =   480
         Left            =   0
         Top             =   0
         Width           =   480
      End
   End
   Begin VB.CommandButton cmd_exit 
      Caption         =   "exit"
      Height          =   375
      Left            =   0
      TabIndex        =   1
      Top             =   0
      Width           =   1260
   End
   Begin VB.Label lab_autor 
      Caption         =   "By ObelardO obelardos@gmail.com"
      ForeColor       =   &H00808080&
      Height          =   495
      Left            =   120
      TabIndex        =   57
      Top             =   5880
      Width           =   1695
   End
   Begin VB.Shape shp_select 
      BorderColor     =   &H000000FF&
      FillColor       =   &H000000FF&
      FillStyle       =   0  'Solid
      Height          =   825
      Left            =   90
      Top             =   1290
      Width           =   540
   End
End
Attribute VB_Name = "frm_main"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'==================================================================
'Project Title: CrystalEd
'Author:        Vladislav Borzunov aka ObelardO
'Email:         Obelardos@gmail.com
'Version:       1.0
'Date:          27.02.13
'Notes:         simple map editor for Crystalium
'==================================================================

'Map
Dim MAP_MATRIX(1024, 512) As Integer

'for painting
Public SELECTEDID As Integer
Public KEYPRESSED As Integer

'for save and load maps
Public MAPNAME As String

'lock / unlock bock's names edit
Private Sub chk_names_Click()
    For i = 0 To txt_block.Count - 1
        txt_block(i).Enabled = chk_names.Value
    Next
End Sub

'add new command to commands list
Private Sub cmd_add_Click()
    If txt_command.Text <> "" Then commands.AddItem txt_command.Text
    txt_command.Text = ""
End Sub

'remove command in commands list
Private Sub cmd_cmddel_Click()
    For i = 0 To commands.ListCount - 1
        If commands.Selected(i) = True Then
            Detected = True
            Index = i
        End If
    Next
    
    If Detected = True Then
        commands.RemoveItem (Index)
    End If
End Sub

'hide commands panel
Private Sub cmd_cmdok_Click()
    pic_commands.Visible = False
End Sub

'exit editor ?
Private Sub cmd_exit_Click()
    decision = MsgBox("Do you really want to exit? Unsaved data will be lost!", vbYesNo, "CrystalEd: exit")
    If decision = vbYes Then End
End Sub

'clear map ?
Private Sub cmd_mapclear_Click()
    decision = MsgBox("Do you really want to clear the map? Unsaved data will be lost!", vbYesNo, "CrystalEd: clear map")
    If decision = vbYes Then Call ClearMap
End Sub

'open new map
Private Sub cmd_mapopen_Click()
    If pic_maps.Visible = False Then
        decision = MsgBox("Do you really want to open another map? Unsaved data will be lost!", vbYesNo, "CrystalEd: open map")
        If decision = vbYes Then
            SELECTEDID = -1
            Call ClearMap
            MAPNAME = ""
            frm_main.Caption = "CrystalEd"
            pic_maps.Visible = True
            commands.Clear
        End If
    End If
End Sub

'save map ?
Private Sub cmd_mapsave_Click()
    decision = MsgBox("Do you really want to save map?", vbYesNo, "CrystalEd: save map")
    If decision = vbYes Then Call SaveMap
End Sub

'create new map
Private Sub cmd_newmap_Click()
    Open App.Path & "\data\maps\" & txt_newmap.Text & ".cmp" For Output As #2
    Close #2
    flb_maps.Refresh
End Sub

'open new map
Private Sub cmd_openmap_Click()
    For i = 0 To flb_maps.ListCount - 1
        If flb_maps.Selected(i) = True Then
            Detected = True
            MAPNAME = flb_maps.List(i)
        End If
    Next
    
    If Detected = True Then
        txt_newmap.Text = txt_newmap.ToolTipText
        pic_maps.Visible = False
        frm_main.Caption = "CrystalEd: " & MAPNAME & " - " & App.Path & "\data\maps\" & MAPNAME
        Call OpenMap
    Else
        decision = MsgBox("Select a map from the list!", 0, "CrystalEd: select map")
    End If
End Sub

Private Sub cmd_run_Click()
    On Error Resume Next
    If MAPNAME <> "" Then
        decision = MsgBox("Run this map in game? Map will be saved!", vbYesNo, "CrystalEd: run map")
        If decision = vbYes Then
            Call SaveMap
            Shell (App.Path & "\Game.exe")  ' /level " & Left(MAPNAME, Len(MAPNAME) - 4))
        End If
    End If
End Sub

'Edit command
Private Sub Command1_Click()
    For i = 0 To commands.ListCount - 1
        If commands.Selected(i) = True Then
            Detected = True
            Index = i
        End If
    Next
    
    If Detected = True And txt_command.Text <> "" Then
        commands.List(Index) = txt_command.Text
        txt_command.Text = ""
    End If
End Sub

'hide or show commands panel
Private Sub Command2_Click()
    pic_commands.Visible = Not pic_commands.Visible
End Sub

'for usefull :P
Private Sub commands_Click()
    For i = 0 To commands.ListCount - 1
        If commands.Selected(i) = True Then txt_command.Text = commands.List(i)
    Next
End Sub

'unselect command
Private Sub commands_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then
        For i = 0 To commands.ListCount - 1
            If commands.Selected(i) = True And commands.List(i) = txt_command.Text Then txt_command.Text = ""
            commands.Selected(i) = False
        Next
    Else
        For i = 0 To commands.ListCount - 1
            If commands.Selected(i) = True Then
                commands.ToolTipText = commands.List(i)
            End If
        Next
    End If
End Sub



'load program
Private Sub Form_Load()
    pic_tiles.Picture = LoadPicture(App.Path & "\data\images\general.bmp")
    flb_maps.Path = App.Path & "\data\maps"
    SELECTEDID = -1
    For i = 0 To pic_block.Count - 1
        pic_block(i).PaintPicture pic_tiles.Picture, 0, 0, 32, 32, i * 32, 0, 32, 32
    Next
End Sub

'move and resize objects
Private Sub Form_Resize()
    Dim width As Integer: width = frm_main.width / 15
    Dim height As Integer: height = frm_main.height / 15

    scrl_width.Move 168, Abs(height - 43), Abs(width - 190), 17
    scrl_height.Move Abs(width - 22), 0, 17, Abs(height - 43)
    pic_view.Move 168, 0, Abs(width - 190), Abs(height - 43)
    lab_autor.Move 8, Abs(height - 63)
End Sub

'Select pointer
Private Sub pic_block_Click(Index As Integer)
    shp_select.Move pic_block(Index).Left - 2, pic_block(Index).Top - 2
    SELECTEDID = Index
End Sub

'add new block to map
Private Sub pic_view_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    blockX = (X - (X Mod 32)) / 32 + scrl_width.Value
    blockY = (Y - (Y Mod 32)) / 32 + scrl_height.Value
    KEYPRESSED = Button
    Select Case KEYPRESSED
        Case 1
            If SELECTEDID = 17 Then
                KEYPRESSED = 0
                pic_commands.Visible = True
                txt_command.Text = "trig(" & blockX & "," & blockY & ",)"
                txt_command.SetFocus
                txt_command.SelStart = Len(txt_command.Text) - 1
            End If
            MAP_MATRIX(blockX, blockY) = SELECTEDID + 1
        Case 2
            MAP_MATRIX(blockX, blockY) = 0
        Case 4
            If MAP_MATRIX(blockX, blockY) > 0 Then
                Call pic_block_Click(MAP_MATRIX(blockX, blockY) - 1)
            End If
    End Select
    Call DrawNap
End Sub

'add new blocks to map
Private Sub pic_view_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    blockX = (X - (X Mod 32))
    blockY = (Y - (Y Mod 32))
    lab_block(0).Move blockX - (lab_block(0).width / 2) + 16, blockY + 34
    lab_block(1).Move blockX - (lab_block(0).width / 2) + 17, blockY + 35
    shp_block.Move blockX, blockY
    blockX = blockX / 32 + scrl_width.Value
    blockY = blockY / 32 + scrl_height.Value
    lab_block(0).Caption = blockX & ", " & blockY
    lab_block(1).Caption = blockX & ", " & blockY
    If Not blockX < 0 And Not blockY < 0 Then
        Select Case KEYPRESSED
            Case 1
                MAP_MATRIX(blockX, blockY) = SELECTEDID + 1
                Call DrawNap
            Case 2
                MAP_MATRIX(blockX, blockY) = 0
                Call DrawNap
        End Select
    End If
End Sub

'Render map
Function DrawNap()
    pic_view.Cls
    For ix = 0 To 1024
        For iy = 0 To 512
            If MAP_MATRIX(ix, iy) > 0 Then
                pic_view.PaintPicture pic_tiles.Picture, ix * 32 - scrl_width.Value * 32, iy * 32 - scrl_height.Value * 32, 32, 32, MAP_MATRIX(ix, iy) * 32 - 32, 0, 32, 32
            End If
        Next
    Next
End Function

'Clear map
Function ClearMap()
    pic_view.Cls
    For ix = 0 To 1024
        For iy = 0 To 512
            MAP_MATRIX(ix, iy) = 0
        Next
    Next
    For i = 0 To commands.ListCount - 1
        commands.List(i) = ""
    Next
End Function

'Load map and commands from file
Function OpenMap()
    Dim width As Integer
    Dim height As Integer
    Dim block As String
    Dim id As Integer
    Dim MapLine As String
    Open App.Path & "\data\maps\" & MAPNAME For Input As #1
    While Not EOF(1)
    Line Input #1, MapLine
        If Left(MapLine, 1) = "{" Then
            commands.AddItem Mid(MapLine, 2, Len(MapLine) - 2)
        Else
        mapwidth = Len(MapLine) / 2 - 1
            For width = 0 To mapwidth
                block = Mid(MapLine, width * 2 + 1, 2)
                If block = "  " Then id = 0
                For i = 0 To txt_block.Count - 1
                    If txt_block(i).Text = block Then id = i + 1
                Next
                MAP_MATRIX(width, height) = id
            Next
            height = height + 1
        End If
    Wend
    Call DrawNap
Close #1
End Function

'Save map and commands to file
Function SaveMap()
    Dim width As Integer
    Dim height As Integer
    Dim block As String
    Dim MapLine As String
    Open App.Path & "\data\maps\" & MAPNAME For Output As #2
    
    For i = 0 To commands.ListCount - 1
        Print #2, "{" & commands.List(i) & "}"
    Next
    
    For height = 0 To GetMapHeight() - 1
        MapLine = ""
        For width = 0 To GetMapWidth() - 1
            If MAP_MATRIX(width, height) = 0 Then block = "  " Else block = txt_block(MAP_MATRIX(width, height) - 1).Text
            MapLine = MapLine + block
        Next
        Print #2, MapLine
    Next
Close #2
End Function

'for save map without spaces
Function GetMapWidth() As Integer
    For ix = 0 To 1024
    For iy = 0 To 512
        If MAP_MATRIX(ix, iy) > 0 Then
            mapwidth = ix
        End If
    Next
    Next
    GetMapWidth = mapwidth + 1
End Function

'for save map without spaces
Function GetMapHeight() As Integer
    For iy = 0 To 512
    For ix = 0 To 1024
        If MAP_MATRIX(ix, iy) > 0 Then
            mapheight = iy
        End If
    Next
    Next
    GetMapHeight = mapheight + 1
End Function

'for "not one click" painting
Private Sub pic_view_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    KEYPRESSED = 0
End Sub

'for usafull :P
Private Sub txt_newmap_GotFocus()
    If txt_newmap.Text = txt_newmap.ToolTipText Then txt_newmap.Text = ""
End Sub

'for usafull :P
Private Sub txt_newmap_LostFocus()
    If txt_newmap.Text = "" Then txt_newmap.Text = txt_newmap.ToolTipText
End Sub

'Update
Private Sub Timer1_Timer()
    Call DrawNap
End Sub

'Update
Private Sub scrl_height_Change()
    Call DrawNap
End Sub

'Update
Private Sub scrl_height_Scroll()
    Call DrawNap
End Sub

'Update
Private Sub scrl_width_Change()
    Call DrawNap
End Sub

'Update
Private Sub scrl_width_Scroll()
    Call DrawNap
End Sub

