require( "scripts/style.lua" );

local MIN = 5 + (5 * (curProd / 5));
--local MAX = 35;
local curAmount;
local curValue;
local previewAmount;
local previewValue;
local nInc;

function canAfford (value)
	return availableMoney >= value
end;

function AddToAmount(inc)
	previewAmount = curAmount + inc;
	previewValue = CalcValue(previewAmount);
	
	if previewAmount >= MIN and previewAmount <= COMBINING_MAX_HIRE and canAfford(previewValue) then
		curAmount = previewAmount;
		curValue = previewValue;
	end;	
end;

function UpdateLabels()
	SetLabel("price",GetString("price").." $"..tostring(math.floor(curValue)));
	SetLabel("cases",GetString("production")..(":  ")..tostring(curAmount));
end

function CalcValue(amount)
	return combiningAvPrice * math.pow(combiningMult,(amount / combiningNInc)) * amount;
end;

function setFontSize(size)
	local temp = {
		standardFont,
		size,
		BlackColor
	}	
	return temp;	
end


curAmount = MIN;
curValue = CalcValue(curAmount);
	
MakeDialog
{
	name="hirecombining",
	
	FaderWindow
	{
		wait=0,
		duration=100,
		fit = true,
		startalpha = 0,
		finalalpha = 1,
		skip = false,
	
		--Bitmap
		--{
		--	image="backgrounds/shade",
		--	alpha = 0.99,
		--},
		
		Bitmap
		{
			image="backgrounds/dialog",
			x=306,
			y=226,

			Text
			{
				font = setFontSize(20),
				name = "hiretitle",
				label= "hireprofessional_title",
			},
			
			Text
			{
				font = setFontSize(20),
				name = "hirebody",
				label= "hireprofessional",
				w = kMax - 60,
				h = kMax - 50,
				flags = kHAlignCenter + kVAlignTop,
				x = 50,
				y = 65,
			},
			
			Text
			{
				w = 180,
				h = 30,
				font = setFontSize(25),
				name = "cases",
				x = 100,
				y = 140,
			},
			
			Text
			{
				w = 180,
				h = 30,
				font = setFontSize(20),
				name = "price",
				x = 100,
				y=170,
			},
			
			SetStyle(ButtonStdOkStyle),
			--ShadowedButton
			Button
			{
				command = function()
							--PopModal("hireWindow");
							HireCombining(math.floor(curValue), curAmount);
							showHireTutorial = false;
							ModalReturn(1);
						end;
				clickSound = "audio/sfx/buttons/default_click.ogg",
				close = true,
				flags = 5,
				size = 10,
				--mylabel = "hire",
				label = "hire",
				x = 200,
				y = 200,
			},
			--ShadowedButton
			Button
			{
				--command=cancelfunction;
				command = function ()
						--showHireTutorial = false;
						ModalReturn(0);
					end,
				clickSound = "audio/sfx/buttons/default_click.ogg",
				close = true,
				flags = 5,
				--mylabel = "cancel",
				label = "cancel",
				name = cancelname,
				x = 288,
				y = 200,
			},
	        
			SetStyle(AddButtonStyle),
			Button
			{
				command=function()
							AddToAmount(combiningNInc);
							UpdateLabels();
							end,
				close = false,
				flags = 5,
				--label = "#+"..combiningNInc,
				name = cancelname,
				x = kCenter + 80,
				y = 130,
				graphics = {"buttons/add1up"},
			},
	        
			Button
			{
				command=function()
							AddToAmount(-combiningNInc);
							UpdateLabels();
						end,
				close = false,
				flags = 5,
			--	label = "#-"..combiningNInc,
				name = cancelname,
				x = kCenter + 80,
				y = 160,
				graphics = {"buttons/add1down"},
			},		
		},
		Window
		{
			name = "hiretutorialwindow",
			fit = true,
			Bitmap
			{
				image="gui/tutorial/bg_h",
				x = 130, y = 490,
				SetStyle(DialogBodyText),
				Text
				{
					h = kMax-60,
					flags = kVAlignCenter + kHAlignCenter,
					y = 40,
					name = "okbody",
					--label= "tutorial_quest2_produce",
					label="tutorial_hire_txt4",
				};
			},
			Bitmap
			{
				name="giuseppe",
				image="gui/tutorial/giuseppe",
				x=130-110,
				y=490+40,
			},
			Animation
			{
				w=116,h=54,
				anim_file = "anim/click_arrow_up",
				x=550,
				y=490,
			},
			Blocker
			{
				w = 110, h = 90,
				x = 590, y = 420,
				fake = true,
			},
		}
	},
}
if(showHireTutorial)then
	-- don't do EnableWindow("hiretutorialwindow", showHireTutorial);
	-- because showHireTutorial might be undefined ("bad argument")
    EnableWindow("hiretutorialwindow", true);
else
	EnableWindow("hiretutorialwindow", false);
end
PlayPopupSound();
UpdateLabels();
