Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic.PowerPacks
Friend Class FoodEditor
	Inherits System.Windows.Forms.Form
	Public itemnum As Short
	Public obj As New obj
	Public foodval As Short
	Public dlg_itemtypechooser As ItemTypeChooser
	Public dlg_comboeditor As ComboEditor
	Public dlg_attackeditor As AttackEditor
    Public dlg_objectlist As ObjectListForm
	Public parenttype As Short
	
	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()
        subchange = True

        'graphics.resetmodifiedcolorarray
        'ImageInventory.Picture = graphics.loadgraphic(18, 0)
        'ImageChest.Picture = graphics.loadgraphic(26, 0)

        Dim i As Short

        parenttype = 0
        For i = 1 To 44
            CBCombo.Items.Add(Str(i - 1) & " " & graphics.f560.Combo(i).tostring_Renamed())
        Next

        foodval = graphics.f559.FoodValue(itemnum - 156)
        obj.Combos = graphics.f559.obj(itemnum).Combos
        obj.FloorGraphic = graphics.f559.obj(itemnum).FloorGraphic
        obj.ItemType = graphics.f559.obj(itemnum).ItemType
        obj.WearLocs = graphics.f559.obj(itemnum).WearLocs

        ItemName.Text = graphics.f556.objstring(obj.ItemType + 1)
        ItemType.Text = Str(obj.ItemType)
        Combo.Text = Str(obj.Combos)
        CBCombo.SelectedIndex = obj.Combos
        FoodValue.Text = Str(foodval)

        Dim offscreen As Bitmap = New Bitmap(GraphicInventory.ClientSize.Width, GraphicInventory.ClientSize.Height)
        Using cv As Drawing.Graphics = Drawing.Graphics.FromImage(offscreen)
            graphics.drawbmp(cv, 17)
            graphics.drawtransparentbmpat(cv, 25, 80, 52, 8)
        End Using
        GraphicInventory.BackgroundImage = offscreen
        GraphicInventory.BackgroundImageLayout = ImageLayout.None
        GraphicInventory.Refresh()

        Me.IWearRect1.Left = graphics.f561.csbbutton(91).x1
        Me.IWearRect1.Top = graphics.f561.csbbutton(91).y1 - 33
        Me.IWearRect2.Left = graphics.f561.csbbutton(86).x1
        Me.IWearRect2.Top = graphics.f561.csbbutton(86).y1 - 33
        Me.IWearRect3.Left = graphics.f561.csbbutton(96).x1
        Me.IWearRect3.Top = graphics.f561.csbbutton(96).y1 - 33
        Me.IWearRect4.Left = graphics.f561.csbbutton(87).x1
        Me.IWearRect4.Top = graphics.f561.csbbutton(87).y1 - 33
        Me.IWearRect5.Left = graphics.f561.csbbutton(88).x1
        Me.IWearRect5.Top = graphics.f561.csbbutton(88).y1 - 33
        Me.IWearRect6.Left = graphics.f561.csbbutton(89).x1
        Me.IWearRect6.Top = graphics.f561.csbbutton(89).y1 - 33
        Me.IWearRect7.Left = graphics.f561.csbbutton(98).x1
        Me.IWearRect7.Top = graphics.f561.csbbutton(98).y1 - 33
        Me.IWearRect8.Left = graphics.f561.csbbutton(94).x1
        Me.IWearRect8.Top = graphics.f561.csbbutton(94).y1 - 33
        Me.IWearRect9.Left = graphics.f561.csbbutton(97).x1
        Me.IWearRect9.Top = graphics.f561.csbbutton(97).y1 - 33
        Me._IWearRect10_0.Left = graphics.f561.csbbutton(84).x1
        Me._IWearRect10_0.Top = graphics.f561.csbbutton(84).y1 - 33
        Me._IWearRect10_1.Left = graphics.f561.csbbutton(85).x1
        Me._IWearRect10_1.Top = graphics.f561.csbbutton(85).y1 - 33
        Me._IWearRect11_0.Left = graphics.f561.csbbutton(33).x1
        Me._IWearRect11_0.Top = graphics.f561.csbbutton(33).y1 - 33
        Me._IWearRect11_1.Left = graphics.f561.csbbutton(34).x1
        Me._IWearRect11_1.Top = graphics.f561.csbbutton(34).y1 - 33
        Me._IWearRect11_2.Left = graphics.f561.csbbutton(35).x1
        Me._IWearRect11_2.Top = graphics.f561.csbbutton(35).y1 - 33
        Me._IWearRect11_3.Left = graphics.f561.csbbutton(36).x1
        Me._IWearRect11_3.Top = graphics.f561.csbbutton(36).y1 - 33
        Me._IWearRect11_4.Left = graphics.f561.csbbutton(37).x1
        Me._IWearRect11_4.Top = graphics.f561.csbbutton(37).y1 - 33
        Me._IWearRect11_5.Left = graphics.f561.csbbutton(38).x1
        Me._IWearRect11_5.Top = graphics.f561.csbbutton(38).y1 - 33
        Me._IWearRect11_6.Left = graphics.f561.csbbutton(39).x1
        Me._IWearRect11_6.Top = graphics.f561.csbbutton(39).y1 - 33
        Me._IWearRect11_7.Left = graphics.f561.csbbutton(40).x1
        Me._IWearRect11_7.Top = graphics.f561.csbbutton(40).y1 - 33


        init_floorgraphics()
        init_wearlocs()

        subchange = False
    End Sub

    '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_floorgraphics()
        Dim num As Short


        FloorGraphic.Text = Str(obj.FloorGraphic)

        If obj.FloorGraphic > 84 Then
            num = 84
        Else
            num = obj.FloorGraphic
        End If

        'graphics.resetmodifiedcolorarray
        'ImageFloorGraphic.Picture = graphics.loadgraphic(362 + num, 0)
        Dim inum As Integer
        'UPGRADE_WARNING: Couldn't resolve default property of object graphics.f558. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        inum = graphics.f558.itemgraphicinfo(num + 1).GraphicNum + 360

        'UPGRADE_WARNING: Couldn't resolve default property of object graphics.getgbitmapwidth. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        GraphicFloorItem.Width = 2 * graphics.getgbitmapwidth(inum) + 4
        'UPGRADE_WARNING: Couldn't resolve default property of object graphics.getgbitmapheight. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        GraphicFloorItem.Height = 2 * graphics.getgbitmapheight(inum) + 4
        Dim offscreen As Bitmap = New Bitmap(GraphicFloorItem.ClientSize.Width, GraphicFloorItem.ClientSize.Height)
        Using cv As Drawing.Graphics = Drawing.Graphics.FromImage(offscreen)
            graphics.stretchbmpby(cv, inum, 0, 0, 0, 0, 200, 200)
        End Using
        GraphicFloorItem.Image = offscreen
        GraphicFloorItem.Refresh()
    End Sub
    Public Sub init_wearlocs()
        WearLocs.Text = Str(obj.WearLocs)

        If obj.wearlocnum(0) = 1 Then
            IWearRect1.Visible = True
        Else
            IWearRect1.Visible = False
        End If
        If obj.wearlocnum(1) = 1 Then
            IWearRect2.Visible = True
        Else
            IWearRect2.Visible = False
        End If
        If obj.wearlocnum(2) = 1 Then
            IWearRect3.Visible = True
        Else
            IWearRect3.Visible = False
        End If
        If obj.wearlocnum(3) = 1 Then
            IWearRect4.Visible = True
        Else
            IWearRect4.Visible = False
        End If
        If obj.wearlocnum(4) = 1 Then
            IWearRect5.Visible = True
        Else
            IWearRect5.Visible = False
        End If
        If obj.wearlocnum(5) = 1 Then
            IWearRect6.Visible = True
        Else
            IWearRect6.Visible = False
        End If
        If obj.wearlocnum(6) = 1 Then
            IWearRect7.Visible = True
        Else
            IWearRect7.Visible = False
        End If
        If obj.wearlocnum(7) = 1 Then
            IWearRect8.Visible = True
        Else
            IWearRect8.Visible = False
        End If
        If obj.wearlocnum(8) = 1 Then
            IWearRect9.Visible = True
        Else
            IWearRect9.Visible = False
        End If
        If obj.wearlocnum(9) = 1 Then
            _IWearRect10_0.Visible = True
            _IWearRect10_1.Visible = True
        Else
            _IWearRect10_0.Visible = False
            _IWearRect10_1.Visible = False
        End If
        If obj.wearlocnum(10) = 1 Then
            _IWearRect11_0.Visible = True
            _IWearRect11_1.Visible = True
            _IWearRect11_2.Visible = True
            _IWearRect11_3.Visible = True
            _IWearRect11_4.Visible = True
            _IWearRect11_5.Visible = True
            _IWearRect11_6.Visible = True
            _IWearRect11_7.Visible = True
        Else
            _IWearRect11_0.Visible = False
            _IWearRect11_1.Visible = False
            _IWearRect11_2.Visible = False
            _IWearRect11_3.Visible = False
            _IWearRect11_4.Visible = False
            _IWearRect11_5.Visible = False
            _IWearRect11_6.Visible = False
            _IWearRect11_7.Visible = False
        End If

    End Sub
    Public Function point_isin(ByVal X As Short, ByVal Y As Short, ByVal x1 As Short, ByVal y1 As Short, ByVal x2 As Short, ByVal y2 As Short) As Boolean
        point_isin = False

        If X >= x1 And X <= x2 Then
            If Y >= y1 And Y <= y2 Then
                point_isin = True
            End If
        End If
    End Function


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

        Me.Close()
    End Sub

    'UPGRADE_WARNING: Event CBCombo.SelectedIndexChanged 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 CBCombo_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CBCombo.SelectedIndexChanged
        If subchange = True Then
            Exit Sub
        End If

        subchange = True
        obj.Combos = CBCombo.SelectedIndex

        Combo.Text = Str(obj.Combos)

        subchange = False
    End Sub

    'UPGRADE_WARNING: Event Combo.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 Combo_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Combo.TextChanged
        If subchange = True Then
            Exit Sub
        End If

        subchange = True
        obj.Combos = App.EFChange8(Combo, 0, 43)
        CBCombo.SelectedIndex = obj.Combos
        subchange = False
    End Sub

    Private Sub ComboEdit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ComboEdit.Click
        App.dlg_comboeditor.init()
        App.dlg_comboeditor.selectcombo(obj.Combos + 1)
        App.dlg_comboeditor.Show()
    End Sub

    'UPGRADE_WARNING: Event FloorGraphic.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 FloorGraphic_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles FloorGraphic.TextChanged
        If subchange = True Then
            Exit Sub
        End If

        subchange = True
        obj.FloorGraphic = App.EFChange8(FloorGraphic, 0, 255)
        init_floorgraphics()
        subchange = False
    End Sub


    'UPGRADE_WARNING: Event FoodValue.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 FoodValue_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles FoodValue.TextChanged
        If subchange = True Then
            Exit Sub
        End If

        subchange = True
        foodval = App.EFChange16(FoodValue, 0, 65535)
        subchange = False
    End Sub

    Private Sub GraphicInventory_MouseDown(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles GraphicInventory.MouseDown, IWearRect9.MouseDown, IWearRect8.MouseDown, IWearRect7.MouseDown, IWearRect6.MouseDown, IWearRect5.MouseDown, IWearRect4.MouseDown, IWearRect3.MouseDown, IWearRect2.MouseDown, IWearRect1.MouseDown, _IWearRect11_7.MouseDown, _IWearRect11_6.MouseDown, _IWearRect11_5.MouseDown, _IWearRect11_4.MouseDown, _IWearRect11_3.MouseDown, _IWearRect11_2.MouseDown, _IWearRect11_1.MouseDown, _IWearRect11_0.MouseDown, _IWearRect10_1.MouseDown, _IWearRect10_0.MouseDown
        Dim button As Short = eventArgs.Button \ &H100000
        Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
        Dim pt As Point = If(TypeOf eventSender Is System.Windows.Forms.Control, CType(eventSender, Control).PointToScreen(eventArgs.Location), CType(eventSender, Shape).PointToScreen(eventArgs.Location))
        Dim X As Single = pt.X
        Dim Y As Single = pt.Y
        'X = X * 4 / 3
        'Y = Y * 4 / 3

        'X = X + ImageInventory.Left
        'Y = Y + ImageInventory.Top

        'MsgBox "mousedown at (" + Str(x) + "," + Str(y) + ")"

        obj.wearlocation = 0
        wearloc_f(X, Y, IWearRect1)
        obj.wearlocation = 1
        wearloc_f(X, Y, IWearRect2)
        obj.wearlocation = 2
        wearloc_f(X, Y, IWearRect3)
        obj.wearlocation = 3
        wearloc_f(X, Y, IWearRect4)
        obj.wearlocation = 4
        wearloc_f(X, Y, IWearRect5)
        obj.wearlocation = 5
        wearloc_f(X, Y, IWearRect6)
        obj.wearlocation = 6
        wearloc_f(X, Y, IWearRect7)
        obj.wearlocation = 7
        wearloc_f(X, Y, IWearRect8)
        obj.wearlocation = 8
        wearloc_f(X, Y, IWearRect9)
        obj.wearlocation = 9
        wearloc_f(X, Y, _IWearRect10_0)
        wearloc_f(X, Y, _IWearRect10_1)


        obj.wearlocation = 10
        wearloc_f(X, Y, _IWearRect11_0)
        wearloc_f(X, Y, _IWearRect11_1)
        wearloc_f(X, Y, _IWearRect11_2)
        wearloc_f(X, Y, _IWearRect11_3)
        wearloc_f(X, Y, _IWearRect11_4)
        wearloc_f(X, Y, _IWearRect11_5)
        wearloc_f(X, Y, _IWearRect11_6)
        wearloc_f(X, Y, _IWearRect11_7)

        subchange = True
        init_wearlocs()
        subchange = False
    End Sub
    Public Sub wearloc_f(ByVal X As Short, ByVal Y As Short, ByRef s As Microsoft.VisualBasic.PowerPacks.RectangleShape)
        Dim isin As Boolean

        isin = MyUt.CheckHit(s, X, Y)

        'MsgBox "p(" + Str(X) + "," + Str(Y) + ") ?in ((" + Str(s.Left) + "," + Str(s.Top) + "),(" + Str(s.Left + s.Width) + "," + Str(s.Top + s.Height) + "))"

        If isin = True Then
            'msgBox "button press in shape: " + s.Name
            If s.Visible = True Then
                obj.setwearlocnum(0)
            Else
                obj.setwearlocnum(1)
            End If
        End If
    End Sub
	
	'UPGRADE_WARNING: Event ItemType.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 ItemType_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ItemType.TextChanged
		If subchange = True Then
			Exit Sub
		End If
		
		subchange = True
		obj.ItemType = App.EFChange16(ItemType, 0, 199) 'fixme
        ItemName.Text = graphics.f556.objstring(obj.ItemType + 1)
		subchange = False
	End Sub
	
	Private Sub ItemTypeEdit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ItemTypeEdit.Click
		dlg_itemtypechooser = New ItemTypeChooser
		dlg_itemtypechooser.obj_Renamed = obj
		dlg_itemtypechooser.textfield = ItemType
		dlg_itemtypechooser.init()
		dlg_itemtypechooser.selectitem(obj.ItemType)
		dlg_itemtypechooser.Show()
	End Sub
	
    Private Sub Ok_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Ok.Click
        graphics.f559.obj(itemnum).Combos = obj.Combos
        graphics.f559.obj(itemnum).FloorGraphic = obj.FloorGraphic
        graphics.f559.obj(itemnum).ItemType = obj.ItemType
        graphics.f559.obj(itemnum).WearLocs = obj.WearLocs
        graphics.f559.setfoodvalue(itemnum - 156, foodval)
        If parenttype = 1 Then
            dlg_comboeditor.init_itemlist()
        ElseIf parenttype = 2 Then
            dlg_attackeditor.init_itemlist()
        ElseIf parenttype = 3 Then
            dlg_objectlist.modifieditem(itemnum)
        End If

        graphics.f559.update()
        Me.Close()
    End Sub
	
	'UPGRADE_WARNING: Event WearLocs.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 WearLocs_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles WearLocs.TextChanged
		If subchange = True Then
			Exit Sub
		End If
		
		subchange = True
		obj.WearLocs = App.EFChange16(WearLocs, 0, 65535)
		init_wearlocs()
		subchange = False
	End Sub
End Class