Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic.PowerPacks
Friend Class ItemGraphicInfoEditor
	Inherits System.Windows.Forms.Form
    Private itemGraphicInfos() As itemgraphicinfo = ADGEDotNetUt.ArrayUt(Of itemgraphicinfo).NewArray1(85)
    Public selecteditemgraphicinfos As Short
	Public subchange As Boolean
	
    Public Sub init()
        Dim i As Short

        ItemGraphicInfoList.Items.Clear()

        Dim c As Integer
        Dim rows As String() = DUt.Read_Dic_MiscItem()
        For c = 0 To 85 - 1
            ItemGraphicInfoList.Items.Add(c.ToString("00")).SubItems.Add(rows(c))
        Next

        For i = 1 To 85
            itemGraphicInfos(i).GraphicNum = graphics.f558.itemgraphicinfo(i).GraphicNum
            itemGraphicInfos(i).GraphicOffset = graphics.f558.itemgraphicinfo(i).GraphicOffset
            itemGraphicInfos(i).Width = graphics.f558.itemgraphicinfo(i).Width
            itemGraphicInfos(i).Height = graphics.f558.itemgraphicinfo(i).Height
            itemGraphicInfos(i).Byte4 = graphics.f558.itemgraphicinfo(i).Byte4
            itemGraphicInfos(i).FloorItemGroup = graphics.f558.itemgraphicinfo(i).FloorItemGroup
        Next
        subchange = True
        selectitemgraphicinfo(1)
        subchange = False
    End Sub

    Public Sub load_graphics()
        Dim i As Integer
        Dim GWidth As Integer
        Dim GHeight As Integer


        graphics.curPalette = graphics.gPALETTE_MAIN
        i = itemGraphicInfos(selecteditemgraphicinfos).GraphicNum + 360
        GWidth = 4 * itemGraphicInfos(selecteditemgraphicinfos).Width
        GHeight = 2 * itemGraphicInfos(selecteditemgraphicinfos).Height
        GraphicA.Width = GWidth + 4
        GraphicA.Height = GHeight + 4
        If True Then
            Dim offscreen As Bitmap = New Bitmap(GraphicA.ClientSize.Width, GraphicB.ClientSize.Height)
            Using cv As Drawing.Graphics = Drawing.Graphics.FromImage(offscreen)
                graphics.stretchbmp(cv, i, 0, 0, GWidth, GHeight, 0, 0)
            End Using
            GraphicA.Image = offscreen
        End If
        GraphicA.Refresh()
        i = i + 1
        GraphicA.Left = ((LineA.X2) - (LineA.X1)) / 2 + (LineA.X1) - GWidth / 2 - 2

        If itemGraphicInfos(selecteditemgraphicinfos).b4_nicheview > 0 Then
            GraphicB.Width = GWidth + 4
            GraphicB.Height = GHeight + 4
            If True Then
                Dim offscreen As Bitmap = New Bitmap(GraphicB.ClientSize.Width, GraphicB.ClientSize.Height)
                Using cv As Drawing.Graphics = Drawing.Graphics.FromImage(offscreen)
                    graphics.stretchbmp(cv, i, 0, 0, GWidth, GHeight, 0, 0)
                End Using
                GraphicB.Image = offscreen
            End If
            GraphicB.Refresh()
            GraphicB.Left = ((LineB.X2) - (LineB.X1)) / 2 + (LineB.X1) - GWidth / 2 - 2
            GraphicB.Visible = True
        Else
            GraphicB.Visible = False
        End If


    End Sub

    Public Sub selectitemgraphicinfo(ByVal num As Short)
        selecteditemgraphicinfos = num

        ItemGraphicInfoList.Items(selecteditemgraphicinfos - 1).Focused = True
        MyUt.CheckSel(ItemGraphicInfoList, selecteditemgraphicinfos - 1, "BlueGem")
        GraphicNum.Text = Str(itemGraphicInfos(num).GraphicNum)
        GraphicOffset.Text = Str(itemGraphicInfos(num).GraphicOffset)
        GHeight.Text = Str(itemGraphicInfos(num).Height)
        GWidth.Text = Str(itemGraphicInfos(num).Width)
        Byte4.Text = Str(itemGraphicInfos(num).Byte4)
        FloorItemGroup.Text = Str(itemGraphicInfos(num).FloorItemGroup)

        CBMirrored.CheckState = itemGraphicInfos(num).b4_mirrored
        CBNicheView.CheckState = itemGraphicInfos(num).b4_nicheview

        load_graphics()
    End Sub


    'UPGRADE_WARNING: Event byte4.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 byte4_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Byte4.TextChanged
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        itemGraphicInfos(selecteditemgraphicinfos).Byte4 = App.EFChange8(Byte4, 0, 255)
        CBMirrored.CheckState = itemGraphicInfos(selecteditemgraphicinfos).b4_mirrored
        CBNicheView.CheckState = itemGraphicInfos(selecteditemgraphicinfos).b4_nicheview
        subchange = False
    End Sub
    'UPGRADE_WARNING: Event FloorItemGroup.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 FloorItemGroup_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles FloorItemGroup.TextChanged
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        itemGraphicInfos(selecteditemgraphicinfos).FloorItemGroup = App.EFChange8(FloorItemGroup, 0, 255)
        subchange = False
    End Sub

    Private Sub Cancel_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cancel.Click
        Hide()

    End Sub


    'UPGRADE_WARNING: Event GraphicNum.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 GraphicNum_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles GraphicNum.TextChanged
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        itemGraphicInfos(selecteditemgraphicinfos).GraphicNum = App.EFChange8(GraphicNum, 0, 255)
        load_graphics()
        subchange = False
    End Sub
    'UPGRADE_WARNING: Event GraphicOffset.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 GraphicOffset_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles GraphicOffset.TextChanged
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        itemGraphicInfos(selecteditemgraphicinfos).GraphicOffset = App.EFChange8(GraphicOffset, 0, 255)
        subchange = False
    End Sub

    Private Sub itemgraphicinfoList_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ItemGraphicInfoList.SelectedIndexChanged
        If ItemGraphicInfoList.FocusedItem Is Nothing Then Exit Sub
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        selectitemgraphicinfo(ItemGraphicInfoList.FocusedItem.Index + 1)
        subchange = False
    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 85

            'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.f558.itemgraphicinfo(i).GraphicNum = itemGraphicInfos(i).GraphicNum
            'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.f558.itemgraphicinfo(i).GraphicOffset = itemGraphicInfos(i).GraphicOffset
            'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.f558.itemgraphicinfo(i).Width = itemGraphicInfos(i).Width
            'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.f558.itemgraphicinfo(i).Height = itemGraphicInfos(i).Height
            'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.f558.itemgraphicinfo(i).Byte4 = itemGraphicInfos(i).Byte4
            'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.f558.itemgraphicinfo(i).FloorItemGroup = itemGraphicInfos(i).FloorItemGroup
        Next
        graphics.f558.update()
        Hide()
    End Sub
	
	'UPGRADE_WARNING: Event Gwidth.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 Gwidth_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gwidth.TextChanged
		
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		itemGraphicInfos(selecteditemgraphicinfos).width = App.EFChange8(GWidth, 0, 255)
		'ImageA.width = 2 * itemGraphicInfos(selecteditemgraphicinfos).width + 4
		'ImageB.width = 2 * itemGraphicInfos(selecteditemgraphicinfos).width + 4
		load_graphics()
		subchange = False
	End Sub
	'UPGRADE_WARNING: Event Gheight.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 Gheight_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gheight.TextChanged
		
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		itemGraphicInfos(selecteditemgraphicinfos).height = App.EFChange8(GHeight, 0, 255)
		
		'ImageA.height = itemGraphicInfos(selecteditemgraphicinfos).height + 4
		'ImageB.height = itemGraphicInfos(selecteditemgraphicinfos).height + 4
		load_graphics()
		subchange = False
	End Sub
	
	'UPGRADE_WARNING: Event CBNicheView.CheckStateChanged 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 CBNicheView_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CBNicheView.CheckStateChanged
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		itemGraphicInfos(selecteditemgraphicinfos).setb4_nicheview((CBNicheView.CheckState))
		Byte4.Text = Str(itemGraphicInfos(selecteditemgraphicinfos).Byte4)
		load_graphics()
		subchange = False
	End Sub
	
	'UPGRADE_WARNING: Event CBMirrored.CheckStateChanged 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 CBMirrored_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CBMirrored.CheckStateChanged
		If subchange = True Then
			Exit Sub
		End If
		subchange = True
		itemGraphicInfos(selecteditemgraphicinfos).setb4_mirrored((CBMirrored.CheckState))
		Byte4.Text = Str(itemGraphicInfos(selecteditemgraphicinfos).Byte4)
		subchange = False
	End Sub

    Private Sub ItemGraphicInfoEditor_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

    Private Sub ItemGraphicInfoEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ItemGraphicInfoList.SmallImageList = App.JewelIL
    End Sub
End Class