Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic.PowerPacks
Friend Class ItemTypeEditor
	Inherits System.Windows.Forms.Form
	Public selecteditem As Short
	Private objstrings(200) As String
	
	'UPGRADE_NOTE: graphics was upgraded to graphics_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Public Sub init()
        Dim i As Short
        For i = 1 To 200
            objstrings(i) = App.graphics.f556.objstring(i)
        Next

        selectitem(0)
        'graphics.resetmodifiedcolorarray
        'ItemGraphics(0).Picture = graphics.loadgraphic(43, 0)
        'ItemGraphics(1).Picture = graphics.loadgraphic(44, 0)
        'ItemGraphics(2).Picture = graphics.loadgraphic(45, 0)
        'ItemGraphics(3).Picture = graphics.loadgraphic(46, 0)
        'ItemGraphics(4).Picture = graphics.loadgraphic(47, 0)
        'ItemGraphics(5).Picture = graphics.loadgraphic(48, 0)
        'ItemGraphics(6).Picture = graphics.loadgraphic(49, 0)
        'UPGRADE_WARNING: Couldn't resolve default property of object graphics.curPalette. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        'UPGRADE_WARNING: Couldn't resolve default property of object graphics.gPALETTE_MAIN. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        graphics.curPalette = (graphics.gPALETTE_MAIN)
        Dim offscreen As Bitmap = New Bitmap(Graphic.ClientSize.Width, Graphic.ClientSize.Height)
        Using cv As Drawing.Graphics = Drawing.Graphics.FromImage(offscreen)
            graphics.stretchbmpby(cv, 42, 0, 0, 0, 0, 200, 200)
            graphics.stretchbmpby(cv, 43, 0, 64, 0, 0, 200, 200)
            graphics.stretchbmpby(cv, 44, 0, 128, 0, 0, 200, 200)
            graphics.stretchbmpby(cv, 45, 0, 192, 0, 0, 200, 200)
            graphics.stretchbmpby(cv, 46, 0, 256, 0, 0, 200, 200)
            graphics.stretchbmpby(cv, 47, 0, 320, 0, 0, 200, 200)
            graphics.stretchbmpby(cv, 48, 0, 384, 0, 0, 200, 200)
        End Using
        Graphic.BackgroundImage = offscreen
        Graphic.BackgroundImageLayout = ImageLayout.None
    End Sub
	
    Private Sub Cancel_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cancel.Click
        Hide()

    End Sub
	
	Private Sub Graphic_MouseDown(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles Graphic.MouseDown
		Dim button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = eventArgs.X
		Dim Y As Single = eventArgs.Y
		Dim itemnum As Short
		Dim cx As Short
		Dim cy As Short
		'x = x * 4 / 3
		'y = y * 4 / 3
		'y = y + (Index * 64)
		'MsgBox "Mousedown coords: (" + Str(X) + "," + Str(Y) + ")"
		
		cx = X
		cy = Y
		cx = cx - CShort(cx And &H1F)
		cy = cy - CShort(cy And &H1F)
		cx = cx / 32
		cy = cy / 32
		itemnum = cx + (cy * 16)
		If itemnum < 200 Then
			selectitem(itemnum)
		End If
		'MsgBox "Mousedown on itemnum: " + Str(itemnum)
	End Sub
	
    Sub selectitem(ByVal num As Short)
        Dim X As Short
        Dim Y As Short

        selecteditem = num + 1

        X = num And &HF
        Y = (num - X) / 16
        SelectBox.Left = X * 32
        SelectBox.Top = Y * 32

        ItemName.Text = objstrings(num + 1)
        ItemName.SelectionStart = 0
        ItemName.SelectionLength = Len(ItemName.Text)
        'ItemName.SetFocus
        Dim i As Short
        Dim j As Short
        j = 0
        ItemList.Items.Clear()
        For i = 1 To 180
            If App.graphics.f559.obj(i).ItemType = num Then
                ItemList.Items.Add(zerostr(i, 2)).SubItems.Add(objstrings(num + 1))
                j = j + 1
            End If
        Next
        'ItemName.SetFocus

    End Sub
	
	
	
	'UPGRADE_WARNING: Event ItemName.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub ItemName_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ItemName.TextChanged
		objstrings(selecteditem) = ItemName.Text
	End Sub
	
    Private Sub Ok_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Ok.Click
        Dim i As Integer

        For i = 1 To 200
            App.graphics.f556.setobjstring(i, objstrings(i))
        Next
        App.graphics.f556.update()
        Hide()
    End Sub
End Class