require "scripts/dialog_common.lua"

play_from_database( "requester_open", false, 1.0, 0, 0 )

EditTextFont = {
    "fonts/arial.mvec",
    25,
    Color(255,255,255,255)
} ;

MakeDialog
{
    name = "new_profile_dialog",

    Bitmap {
        image = "images/background.png",
        x = 0,
        y = 0,
        w = 800,
        h = 600,
        alpha = true,

    Window {
        fit = true,
        x = kCenter,
        y = kCenter,
        w = 497,
        h = dialog_height( 100 ),

        requester_background( 100, "blue", "" ),

		--[[
        Text
        {
            font = RequesterTitleFont,
            name = "window_title",
            x = kCenter, y = 59 + 0, w = 160, h = 34,
            flags = kHAlignCenter + kVAlignCenter,
            label = "profile_new_title"
        },
		--]]
		
		Text {
			    label = "profile_dialog_new_label",
                x = 60, y = 59 + 50, w = 350, h = 27,
                flags = kHAlignLeft + kVAlignCenter,
                font = RequesterButtonFont,
            },
		
		Bitmap
		{
			image = "edit/textfield.png",
			x = kCenter, y = 59 + 80,

			TextEdit
			{
				font = EditTextFont,
				name = "edit",
				label = "",
				enablewindow = "button_ok",
				clearinitial = deleteselected,
				x = 3, y = 5, w = kMax - 3, h = kMax,
				length = 40,
				ignore = kIllegalNameChars
			},
		},

		Button
		{
			x = 50 - 15 , y = 59 + 100 + 70,
			font = RequesterButtonFont,
			graphics = NewButtonGraphics,
			name = "button_ok",
			type = kPush,
			default = true,
			command = function()
                play_from_database( "button_click_alt", false, 1.0, 0, 0 )
				local result = NewProfileDialogOK( GetLabel( "edit" ) )
				if ( result == 0 ) then
                    PopModal( "new_profile_dialog" )
                    NewProfileDialogOKStartGame()
                end
                if ( result == 1 ) then
                    DisplayDialog { "scripts/profile_ok.lua", body = "profile_error_empty" };
                    SetFocus( "edit" )
                end
                if ( result == 2 ) then
                    DisplayDialog { "scripts/profile_ok.lua", body = "profile_error_duplicate" };
                    SetFocus( "edit" )
                end
			end,
			Text {
			    label = "profile_new_ok",
                x = 0, y = 2, w = kMax, h = 27,
                flags = kHAlignRight + kVAlignCenter,
                font = RequesterButtonFont,
            },
		},

		Button
		{
			x = 50 + 250 - 65, y = 59 + 100 + 70,
			font = RequesterButtonFont,
			graphics = NewButtonGraphics,
			name = "button_cancel",
			type = kPush,
			command = function()
                play_from_database( "button_click_alt", false, 1.0, 0, 0 )
                NewProfileDialogCancel()
                PopModal( "new_profile_dialog" )
			end,
            Text {
			    label = "profile_new_cancel",
                x = 0, y = 2, w = kMax, h = 27,
                flags = kHAlignRight + kVAlignCenter,
                font = RequesterButtonFont,
            },
		},
    },
    },
    FitToChildren(),
}

move_to_front( "edit" )
SetFocus( "edit" ) ;
