--__88888__888888__88___88___8888__888___88____888888
--88____8__88______88___88____88___888___88___88____8
--88_______88_____8888888888__88___8888__88__88
--8888_____88______88___88____88___88_8__88__88
--_888888__888888__88___88____88___88__8_88__88
--___8888__88______88___88____88___88__8888__88__8888
--______8__88______88___88____88___88___888__88____88
--8____88__88______88___88____88___88___888___88___88
--888888___888888___888__888_8888__88____88____888888

fonmenu=Image.load("data/img/fonmenu.jpg")
zagol=Image.load("data/img/zagol.png")
kn=Image.load("data/img/kn.png")
kn2=Image.load("data/img/kn2.png")
font = Font.load("data/font/qwe.ttf")--podgruzka chrifta
font:setPixelSizes(20,20)--zadanie razmera chriftu
font10 = Font.load("data/font/qwe.ttf")--podgruzka chrifta
font10:setPixelSizes(20,25)--zadanie razmera chriftu
font11 = Font.load("data/font/qwe.ttf")--podgruzka chrifta
font11:setPixelSizes(20,17)--zadanie razmera chriftu
function sansAccents (texte)
nomaffiche = string.gsub(texte, "e", "e")
nomaffiche = string.gsub(nomaffiche, "e", "e")
nomaffiche = string.gsub(nomaffiche, "a", "a")
nomaffiche = string.gsub(nomaffiche, "c", "c")
nomaffiche = string.gsub(nomaffiche, "e", "e")
nomaffiche = string.gsub(nomaffiche, "î", "i")
nomaffiche = string.gsub(nomaffiche, "€", "E")
nomaffiche = string.gsub(nomaffiche, "ñ", "n")
nomaffiche = string.gsub(nomaffiche, "ù", "u")
return nomaffiche
end
local mk={4}
local ml={4}
local pin={4}
file=io.open("data/makesave/save25.msn","r")--otkritie storonnego faila
mk[1]=tonumber(file:read())--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save26.msn","r")--otkritie storonnego faila
ml[1]=tonumber(file:read())--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save27.msn","r")--otkritie storonnego faila
mk[2]=tonumber(file:read())--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save28.msn","r")--otkritie storonnego faila
ml[2]=tonumber(file:read())--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save29.msn","r")--otkritie storonnego faila
mk[3]=tonumber(file:read())--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save30.msn","r")--otkritie storonnego faila
ml[3]=tonumber(file:read())--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save.msn","r")--otkritie storonnego faila
mk[4]=tonumber(file:read())--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save2.msn","r")--otkritie storonnego faila
ml[4]=tonumber(file:read())--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save31.msn","r")--otkritie storonnego faila
set=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save32.msn","r")--otkritie storonnego faila
con=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save33.msn","r")--otkritie storonnego faila
bac=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save34.msn","r")--otkritie storonnego faila
setcode=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save35.msn","r")--otkritie storonnego faila
concode=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/makesave/save36.msn","r")--otkritie storonnego faila
baccode=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
function save()
file=io.open("data/makesave/save25.msn","w")
file:write(mk[1])
file:close()
file=io.open("data/makesave/save26.msn","w")
file:write(ml[1])
file:close()
file=io.open("data/makesave/save27.msn","w")
file:write(mk[2])
file:close()
file=io.open("data/makesave/save28.msn","w")
file:write(ml[2])
file:close()
file=io.open("data/makesave/save29.msn","w")
file:write(mk[3])
file:close()
file=io.open("data/makesave/save30.msn","w")
file:write(ml[3])
file:close()
file=io.open("data/makesave/save.msn","w")
file:write(mk[4])
file:close()
file=io.open("data/makesave/save2.msn","w")
file:write(ml[4])
file:close()
file=io.open("data/makesave/save31.msn","w")
file:write(set)
file:close()
file=io.open("data/makesave/save32.msn","w")
file:write(con)
file:close()
file=io.open("data/makesave/save33.msn","w")
file:write(bac)
file:close()
file=io.open("data/makesave/save34.msn","w")
file:write(setcode)
file:close()
file=io.open("data/makesave/save35.msn","w")
file:write(concode)
file:close()
file=io.open("data/makesave/save36.msn","w")
file:write(baccode)
file:close()
end
function nill()
font=nil
fon=nil
kn=nil
kn2=nil
zagol=nil
end
red=Color.new(255,0,0)
qr=1
qupe=0
s=272
ss=-61

while true do
screen:clear()--ochistka ekrana
pad = Controls.read()--podgruzka knopok psp
screen:blit(0,0,fonmenu)--raspechatka fona
Image:blit(mk[4],ml[4],zagol)--zagolovok
if qr==1 then
screen:blit(mk[1]-10,ml[1]-10,kn2)
if pad:cross() then
nill()
dofile(setcode)
end
else
screen:blit(mk[1],ml[1],kn)
end
if qr==2 then
screen:blit(mk[2]-10,ml[2]-10,kn2)
if pad:cross() then
nill()
dofile(concode)
end
else
screen:blit(mk[2],ml[2],kn)
end
if qr==3 then
screen:blit(mk[3]-10,ml[3]-10,kn2)
if pad:cross() then
nill()
dofile(baccode)
end
else
screen:blit(mk[3],ml[3],kn)
end
screen:fontPrint(font,mk[1]+53,ml[1]+27,set,red)
screen:fontPrint(font,mk[2]+33,ml[2]+27,con,red)
screen:fontPrint(font,mk[3]+53,ml[3]+27,bac,red)
if pad:down() and oldpad:down()~=pad:down() then
qr=qr+1
end
if pad:up() and oldpad:up()~=pad:up() then
qr=qr-1
end
if qr>3 then
qr=1
end
if qr<1 then
qr=3
end
if pad:select() then
file=io.open("data/makesave/screenshoter.msn","r")
nscreen=tonumber(file:read())
file:close()
screen:save("data/screenshot/SHOT"..nscreen..".png")
nscreen=nscreen+1
file=io.open("data/makesave/screenshoter.msn","w")
file:write(math.ceil(nscreen))
file:close()
end

--menuchka

if pad:start() and oldpad:start()~=pad:start() then--vkluchenie menu
qupe=1
x = 240
y = 136
end
if qupe==1 then
if s>246 then
s=s-2
end
if ss<-1 then
ss=ss+4
end
screen:blit(0,s,menu)


if x>=mk[1] and x<=mk[1]+150 and y>=ml[1] and y<=ml[1]+40 then
if pad:square() then--pereimenovka
set= System.startOSK(set,"Vvedite")
file=io.open("data/makesave/save31.msn","w")
file:write(set)
file:close()
end
if pad:triangle() then--perenaznachenie
setcode= System.startOSK(setcode,"Vvedite")
file=io.open("data/makesave/save34.msn","w")
file:write(setcode)
file:close()
end
if pad:circle() and pin[2]==0 and pin[3]==0 and pin[4]==0 then--udalenie
pin[1]=1
if x>=0 and x<=27 and y>=248 and y<=270 then
mk[1]=500
ml[1]=300
save()
else--inache peremeshenie
mk[1]=math.ceil(x-20)--75
ml[1]=math.ceil(y-20)--20
screen:fontPrint(font11,200,264,"x= " .. mk[1],blue)
screen:fontPrint(font11,280,264,"y= " .. ml[1],blue)
end
end
else
pin[1]=0
end
if x>=mk[2] and x<=mk[2]+150 and y>=ml[2] and y<=ml[2]+40 then
if pad:square() then--pereimenovka
con= System.startOSK(con,"Vvedite")
file=io.open("data/makesave/save32.msn","w")
file:write(con)
file:close()
end
if pad:triangle() then--perenaznachenie
concode= System.startOSK(concode,"Vvedite")
file=io.open("data/makesave/save35.msn","w")
file:write(concode)
file:close()
end
if pad:circle() and pin[3]==0 and pin[1]==0 and pin[4]==0 then--udalenie
pin[2]=1
if x>=0 and x<=27 and y>=248 and y<=270 then
mk[2]=500
ml[2]=300
save()
else--inache peremeshenie
mk[2]=math.ceil(x-20)--75
ml[2]=math.ceil(y-20)--20
screen:fontPrint(font11,200,264,"x= " .. mk[2],blue)
screen:fontPrint(font11,280,264,"y= " .. ml[2],blue)
end
end
else
pin[2]=0
end
if x>=mk[3] and x<=mk[3]+150 and y>=ml[3] and y<=ml[3]+40 then
if pad:square() then--pereimenovka
bac= System.startOSK(bac,"Vvedite")
file=io.open("data/makesave/save33.msn","w")
file:write(bac)
file:close()
end
if pad:triangle() then--perenaznachenie
baccode= System.startOSK(baccode,"Vvedite")
file=io.open("data/makesave/save36.msn","w")
file:write(baccode)
file:close()
end
if pad:circle() and pin[2]==0 and pin[1]==0 and pin[4]==0 then--udalenie
pin[3]=1
if x>=0 and x<=27 and y>=248 and y<=270 then
mk[3]=500
ml[3]=300
save()
else--inache peremeshenie
mk[3]=math.ceil(x-20)--75
ml[3]=math.ceil(y-20)--20
screen:fontPrint(font11,200,264,"x= " .. mk[3],blue)
screen:fontPrint(font11,280,264,"y= " .. ml[3],blue)
end
end
else
pin[3]=0
end
if x>=mk[4] and x<=mk[4]+160 and y>=ml[4] and y<=ml[4]+26 then
if pad:circle() and pin[2]==0 and pin[3]==0 and pin[1]==0 then
pin[4]=1
if x>=0 and x<=27 and y>=248 and y<=270 then--udalenie
mk[4]=500
ml[4]=300
save()
else -- inache peremeshenie
mk[4]=math.ceil(x-20)--80
ml[4]=math.ceil(y-10)--13
screen:fontPrint(font11,200,264,"x= " .. mk[4],blue)
screen:fontPrint(font11,280,264,"y= " .. ml[4],blue)
end
end
else
pin[4]=0
end

if System.powerIsPowerOnline() then 
zaradbat=zaradbat+1
if zaradbat>=1 then screen:blit(430,s+2,bat14) end
if zaradbat>=10 then screen:blit(430,s+2,bat15) end
if zaradbat>=20 then screen:blit(430,s+2,bat16) end
if zaradbat>=30 then screen:blit(430,s+2,bat17) end
if zaradbat>=40 then screen:blit(430,s+2,bat18) end
if zaradbat>=50 then screen:blit(430,s+2,bat19) end
if zaradbat>=60 then screen:blit(430,s+2,bat20) end
if zaradbat>=70 then screen:blit(430,s+2,bat21) end
if zaradbat>=80 then screen:blit(430,s+2,bat22) end
if zaradbat>=90 then screen:blit(430,s+2,bat23) end
if zaradbat>=100 then screen:blit(430,s+2,bat24) end
if zaradbat>=110 then screen:blit(430,s+2,bat25) end
if zaradbat>=120 then screen:blit(430,s+2,bat26) end
if zaradbat>=130 then zaradbat=1 end
else
zaradbat=1
if System.powerGetBatteryLifePercent() >= 0 and System.powerGetBatteryLifePercent() <=4 then screen:blit(430,s+2,bat0) end
if System.powerGetBatteryLifePercent() > 4 then screen:blit(432,s+2,bat1) end
if System.powerGetBatteryLifePercent() > 8 then screen:blit(432,s+2,bat2) end
if System.powerGetBatteryLifePercent() > 16 then screen:blit(432,s+2,bat3) end
if System.powerGetBatteryLifePercent() > 24 then screen:blit(432,s+2,bat4) end
if System.powerGetBatteryLifePercent() > 32 then screen:blit(432,s+2,bat5) end
if System.powerGetBatteryLifePercent() > 40 then screen:blit(432,s+2,bat6) end
if System.powerGetBatteryLifePercent() > 48 then screen:blit(432,s+2,bat7) end
if System.powerGetBatteryLifePercent() > 56 then screen:blit(432,s+2,bat8) end
if System.powerGetBatteryLifePercent() > 64 then screen:blit(432,s+2,bat9) end
if System.powerGetBatteryLifePercent() > 72 then screen:blit(432,s+2,bat10) end
if System.powerGetBatteryLifePercent() > 80 then screen:blit(432,s+2,bat11) end
if System.powerGetBatteryLifePercent() > 88 then screen:blit(432,s+2,bat12) end
if System.powerGetBatteryLifePercent() > 96 then screen:blit(432,s+2,bat13) end
end
screen:fontPrint(font10,365,s+22,System.getTime(1).." : "..System.getTime(2),blue)
screen:blit(x,y,souris)
end
if x>=450 and x<=471 and y>=248 and y<=269 then--vikluchenie menu
screen:blit(x,y,souris2)
if lang==2 then
screen:fontPrint(font11,200,266,"otkluchenie",blue)
else
screen:fontPrint(font11,200,266,"disconnection",blue)
end
if pad:circle() then
s=272
ss=-61
x=0
y=0
qupe=0
end
end
if pad:select() and qupe==1 then
s=272
ss=-61
x=0
y=0
qupe=0
end
if x>=51 and x<=72 and y>=248 and y<=269 then--sohranenie
screen:blit(x,y,souris2)
if lang==2 then
screen:fontPrint(font11,200,266,"sohranenie",blue)
else
screen:fontPrint(font11,200,266,"save",blue)
end
if pad:circle() and qupe==1 then 
save()
end
end
if x>=143 and x<=163 and y>=248 and y<=269 then--otmena
screen:blit(x,y,souris2)
if lang==2 then
screen:fontPrint(font11,200,266,"otmena",blue)
else
screen:fontPrint(font11,200,266,"cancel",blue)
end
if pad:circle() and qupe==1 then
mk[1]=165
ml[1]=90
mk[2]=165
ml[2]=140
mk[3]=165
ml[3]=190
mk[4]=117
ml[4]=15
save()
end
end
if x>=90 and x<=118 and y>=248 and y<=269 then--notepad
screen:blit(x,y,souris2)
screen:fontPrint(font11,200,266,"lua edit",blue)
if pad:circle() and qupe==1 then
font=nil
nill()
dofile("data/Notepad/Notepad.dat")
end
end
if qupe==1 then
screen:blit(0,ss,gm)--raspechatka kruzka GM
if pad:circle() and x>=0 and x<=60 and y>=0 and y<=61 then
font=nil
nill()
dofile("data/scripts/gm.ttf")
end
if x>=0 and x<=60 and y>=0 and y<=61 then
screen:blit(x,y,souris2)
end
end
if math.abs(pad:analogY()) > 32 then
y = y + pad:analogY() / 32;
end
if math.abs(pad:analogX()) > 32 then
x = x + pad:analogX() / 32;
end
if x < 0 then x = 0 elseif x + souris:width() > 480 then x = 480 -  souris:width() end
if y < 0 then y = 0 elseif y + souris:height() > 272 then y = 268 -  souris:width() end
screen:flip()
oldpad=pad
end