Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic.PowerPacks
Friend Class ItemTypeChooser
	Inherits System.Windows.Forms.Form
	Public selecteditem As Short
	'UPGRADE_NOTE: obj was upgraded to obj_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
	Public obj_Renamed As obj
	Public textfield As System.Windows.Forms.TextBox
	
	
	
	'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()
        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
        Me.Close()

    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
	
    Private Sub ItemGraphics_MouseDown(ByRef Index As Short, ByRef button As Short, ByRef Shift As Short, ByRef X As Single, ByRef Y As Single)
        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

        If num < 0 Or num >= 200 Then
            Exit Sub
        End If

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

        selecteditem = num

        ItemName.Text = App.graphics.f556.objstring(num + 1)

    End Sub
	
    Private Sub Ok_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Ok.Click
        obj_Renamed.ItemType = selecteditem
        textfield.Text = Str(obj_Renamed.ItemType)
        Me.Close()
    End Sub

    Private Sub ItemTypeChooser_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If e.CloseReason = CloseReason.UserClosing Then
            e.Cancel = True
            Hide()
        End If
    End Sub
End Class