Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic.PowerPacks
Imports System.Xml

Friend Class ButtonEditor
    Inherits System.Windows.Forms.Form

    Private csbbuttons() As csbButton = ADGEDotNetUt.ArrayUt(Of csbButton).NewArray1(152)
    Public selectedcsbbutton As Short
    'Public selectedsublocation As Integer
    Public subchange As Boolean


    '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 152
            csbbuttons(i).word0 = graphics.f561.csbbutton(i).word0
            csbbuttons(i).x1 = graphics.f561.csbbutton(i).x1
            csbbuttons(i).x2 = graphics.f561.csbbutton(i).x2
            csbbuttons(i).y1 = graphics.f561.csbbutton(i).y1
            csbbuttons(i).y2 = graphics.f561.csbbutton(i).y2
            csbbuttons(i).button = graphics.f561.csbbutton(i).button
            csbbuttons(i).name = graphics.f561.csbbutton(i).name
            csbbuttons(i).description = graphics.f561.csbbutton(i).description
            csbbuttons(i).samplepic = graphics.f561.csbbutton(i).samplepic
        Next

        CGCSBButtonList.Items.Clear()
        For i = 1 To 152
            CGCSBButtonList.Items.Add(zerostr(i, 3)).SubItems.Add(csbbuttons(i).name)
        Next

        subchange = True
        selectcsbbutton((1))
        subchange = False

        update_Renamed()
    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 GX1_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles GX1.TextChanged
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        csbbuttons(selectedcsbbutton).x1 = App.EFChange16(GX1, 0, 65535)
        subchange = False
        update_Renamed()
    End Sub
    'UPGRADE_WARNING: Event Gx2.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 Gx2_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gx2.TextChanged
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        csbbuttons(selectedcsbbutton).x2 = App.EFChange16(GX2, 0, 65535)
        subchange = False
        update_Renamed()
    End Sub
    'UPGRADE_WARNING: Event Gy1.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 Gy1_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gy1.TextChanged
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        csbbuttons(selectedcsbbutton).y1 = App.EFChange16(GY1, 0, 65535)
        subchange = False
        update_Renamed()
    End Sub
    'UPGRADE_WARNING: Event Gy2.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 Gy2_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gy2.TextChanged
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        csbbuttons(selectedcsbbutton).y2 = App.EFChange16(GY2, 0, 65535)
        subchange = False
        update_Renamed()
    End Sub
    'UPGRADE_WARNING: Event Gword0.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 Gword0_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gword0.TextChanged
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        csbbuttons(selectedcsbbutton).word0 = App.EFChange16(GWord0, 0, 65535)
        subchange = False
        update_Renamed()
    End Sub
    'UPGRADE_WARNING: Event Gbutton.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 Gbutton_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Gbutton.TextChanged
        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        csbbuttons(selectedcsbbutton).button = App.EFChange16(GButton, 0, 65535)
        subchange = False
        update_Renamed()
    End Sub

    Private Sub Ok_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Ok.Click
        Dim i As Short
        For i = 1 To 152
            graphics.f561.csbbutton(i).word0 = csbbuttons(i).word0
            graphics.f561.csbbutton(i).x1 = csbbuttons(i).x1
            graphics.f561.csbbutton(i).x2 = csbbuttons(i).x2
            graphics.f561.csbbutton(i).y1 = csbbuttons(i).y1
            graphics.f561.csbbutton(i).y2 = csbbuttons(i).y2
            graphics.f561.csbbutton(i).button = csbbuttons(i).button
        Next
        App.graphics.f561.update()
        Me.Close()

    End Sub
    Public Sub selectcsbbutton(ByVal num As Short)
        selectedcsbbutton = num
        CGCSBButtonList.Items(num - 1).Focused = True
        MyUt.CheckSel(CGCSBButtonList, num - 1, "BlueGem")

        GX1.Text = Str(csbbuttons(num).x1)
        GX2.Text = Str(csbbuttons(num).x2)
        GY1.Text = Str(csbbuttons(num).y1)
        GY2.Text = Str(csbbuttons(num).y2)
        GWord0.Text = Str(csbbuttons(num).word0)
        GButton.Text = Str(csbbuttons(num).button)

        GName.Text = csbbuttons(num).name
        GDescription.Text = csbbuttons(num).description

        Dim samplepic As String = csbbuttons(num).samplepic
        If samplepic <> "" Then
            ImageA.BackgroundImage = MyPicUt.LoadPicFromFile(IO.Path.Combine(Application.StartupPath, samplepic))
        Else
            ImageA.BackgroundImage = My.Resources.buttonEditorPic
        End If

        update_Renamed()
    End Sub


    'Public Sub selectsublocation(ByVal num As Integer)
    '    selectedsublocation = num
    '    CGSubLocationList.ListIndex = num - 1
    '    update
    'End Sub

    'UPGRADE_NOTE: update was upgraded to update_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Public Sub update_Renamed()

        Dim x2, x1, y2, y1 As Integer
        'UPGRADE_NOTE: height was upgraded to height_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
        'UPGRADE_NOTE: width was upgraded to width_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
        Dim width_Renamed As Integer
        Dim height_Renamed As Integer


        'UPGRADE_WARNING: Couldn't resolve default property of object x1. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        x1 = csbbuttons(selectedcsbbutton).x1
        'UPGRADE_WARNING: Couldn't resolve default property of object x2. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        x2 = csbbuttons(selectedcsbbutton).x2
        'UPGRADE_WARNING: Couldn't resolve default property of object y1. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        y1 = csbbuttons(selectedcsbbutton).y1
        y2 = csbbuttons(selectedcsbbutton).y2

        'UPGRADE_WARNING: Couldn't resolve default property of object x1. 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 x2. 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 width_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        width_Renamed = (x2 - x1)
        'UPGRADE_WARNING: Couldn't resolve default property of object y1. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        height_Renamed = (y2 - y1)
        'UPGRADE_WARNING: Couldn't resolve default property of object width_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        If width_Renamed < 0 Then
            'UPGRADE_WARNING: Couldn't resolve default property of object width_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            width_Renamed = 0
        End If
        If height_Renamed < 0 Then
            height_Renamed = 0
        End If

        'UPGRADE_WARNING: Couldn't resolve default property of object x1. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        RectShape.Left = +2 * x1 + 1
        'UPGRADE_WARNING: Couldn't resolve default property of object y1. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        RectShape.Top = +2 * y1 + 1
        'UPGRADE_WARNING: Couldn't resolve default property of object width_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        RectShape.Width = 2 * width_Renamed
        RectShape.Height = 2 * height_Renamed


    End Sub

    Private Sub ButtonEditor_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 CGCSBButtonList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CGCSBButtonList.SelectedIndexChanged
        If CGCSBButtonList.FocusedItem Is Nothing Then Exit Sub

        If subchange = True Then
            Exit Sub
        End If
        subchange = True
        selectcsbbutton((CGCSBButtonList.FocusedItem.Index + 1))
        subchange = False
    End Sub

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

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Process.Start("explorer.exe", " /select,""" & IO.Path.Combine(Application.StartupPath, "_csbbuttons.xml") & """")
    End Sub
End Class