#include <acknex.h>
#include <default.c>
#include <windows.h>
#include "defines.c"

//#define NONE_PANEL 0
//#define TERRAIN_EDITOR_PANEL 1
#define Terain_Vertices 66049

//------------------------------------------------------------
#define EDITOR_MODE_NONE 0
#define EDITOR_MODE_TERRAIN 1
#define EDITOR_MODE_OBJECTS 2
#define EDITOR_MODE_PED 3
#define EDITOR_MODE_MONSTER 4
#define EDITOR_MODE_TEXTUR 5

#define EDITOR_MODE_TERRAIN_ERODE 6
#define EDITOR_MODE_TERRAIN_SETHIGH 7
#define EDITOR_MODE_TERRAIN_SMOOTH 8

int buttoun_state = 0;
var button_e_over = 0;
var EditorModus = EDITOR_MODE_NONE;
//------------------------------------------------------------


STRING* editor_objects = "";
STRING* aceonlinedir = "";
STRING* ObjectsDir = "";

//---------------------------------------
STRING* str_folder="";
#include "folder_dialog.c"
//---------------------------------------

BMAP* standart_object_textur ="obj_std_textur.tga";


BMAP* NormalS = "N_List_Object.tga";
BMAP* Select = "S_List_Object.tga";




//#include "anet.h"

//#include "updater_scripts.c"
//#include "GSTsqlite.h"
#include <d3d9.h>
#include <strio.c>
_finddata_t finddata;

#include "import_objects.c"
//#include <atypes.h>
#include "dat_structs.h"
//#include "obj_db.c"
#include "variablen.c"

#include "view_script.c"
#include "lbgui.h"
#include "LBGUI_texturs.c"
#include "LBGUI_Def.c"
#include "panel_script.c"
#include "terrain_ed_script.c"
#include "create_ped_map.c"
#include "GUI_Scripte.c"
#include "MainSchleife.c"
//#include "mouse_edit.c"
#include "create_objects.c"
#include "create_terrain.c"

#include "read_map.c"
#include "read_sma.c"
#include "save_dat.c"
#include "save_sma.c"
#include "callback.c"







function on_maximize_event() // adapt the engine resolution to the window size
{
   RECT r;
   GetWindowRect(hWnd,&r); 
}


void main ()
{
	//if(!str_cmp(command_str,"-UptoDate")){exec("Updater.exe","");sys_exit("");}
	wait(1);
	//while(enet_init()!=ANET_SUCCESS)
	 
	 
	fps_max = 60;
	terrain_lod = 0;
	//terrain_chunk = 0;
	 
	 
	 
	//check_tool();
	startLBGUI();	
	var window_dat_editor = 0;
	var window_sma_editor = screen_x - 300;
	max_entities =200000;
	wait(1);
	add_resource("EditorRES.wrs");
	mouse_pointer = 2;
	
	terrain_chunk = 128;
	level_load("");
	vec_set(sky_color,vector(1,1,1));
	newterrain = ent_createterrain(NULL,vector(5120,5120,0),256,256,40);
	set(newterrain,POLYGON);
	c_updatehull(newterrain,0);
	
	camera.clip_far  = 10000000000;
	
	

	video_window(vector(1,1,0),vector(sys_metrics(61),sys_metrics(62),0),1+16+32+64+128,"TheDynamit ACE MapEditor | vALPHA 0.35 | 02.02.2015");
	max_particles = 100000;  	
	OriginalHandler = on_message;
	on_message = WndProc ;//
	menu=CreateMenu();
	hSubMenu=CreateMenu();
	hSubMenu1=CreateMenu();
	hSubMenu2=CreateMenu();
	hSubMenu3=CreateMenu();
	InsertMenu(menu,0,MF_BYPOSITION|MF_STRING|MF_POPUP,hSubMenu,"File");
	InsertMenu(hSubMenu,0,MF_BYPOSITION|MF_STRING,1,"Load Map");
	InsertMenu(hSubMenu,1,MF_BYPOSITION|MF_STRING,2,"Save As *.dat");
	InsertMenu(hSubMenu,2,MF_BYPOSITION|MF_STRING,3,"Save As *.sma");
	InsertMenu(hSubMenu,3,MF_BYPOSITION|MF_STRING,5,"Save All");
	InsertMenu(hSubMenu,5,MF_BYPOSITION|MF_STRING,4,"Exit");
	InsertMenu(hSubMenu,4,MF_BYPOSITION|MF_STRING,8,"Select Res-Obj Folder");
	
	InsertMenu(menu,1,MF_BYPOSITION|MF_STRING|MF_POPUP,hSubMenu1,"Info");	
	InsertMenu(hSubMenu1,0,MF_BYPOSITION|MF_STRING,6,"ChangeLog");
	InsertMenu(hSubMenu1,1,MF_BYPOSITION|MF_STRING,7,"About");
	
	SetMenu(hWnd,menu);
 
	
    video_set(sys_metrics(61),sys_metrics(62)  ,0,2); 
	ShowWindow(hWnd,SW_MAXIMIZE);
	screen_y = sys_metrics(62);
	screen_x = sys_metrics(61);
	titel_leiste.scale_x =1.006;
	//staus_leiste.pos_y = screen_y -115;
	//staus_leiste.scale_x =1.006;
  	object_view.pos_x = screen_x - 230;
  	subwindow.pos_x = screen_x - 232.5;
  	
//  	pannelObjectEditEnde.pos_y = screen_y - 65;
  	
  

  	aceonlinedir = str_create(work_dir);
  	ObjectsDir	 = str_create(work_dir);
	editor_objects = str_create(work_dir);
  	
	str_cat(aceonlinedir,"ACE_OBJECTS\\*.x");
	str_cat(ObjectsDir,"ACE_OBJECTS\\");
	str_cat(editor_objects,"program_obj\\");
	//printf(_chr(ObjectsDir));
	
		
  	main_schleife();
  	
  	
  	
  	LBGUI_open();
	on_exit = LBGUI_close;
	
	wait(-1);
	
	//int done = _findfirst(_chr(aceonlinedir),&fdFile);
	
	HANDLE checkdata = _findfirst(_chr(aceonlinedir),&finddata);
	
//	if(checkdata == -1){error("No Game Objects found! Please Select the Res-Obj folder in the ACE Online game folder and all game Objects importing automatically!");}
//	else
//	{
//		ModifyMenu(hSubMenu,0,MF_BYPOSITION|MF_STRING|MF_ENABLED,1,"Load Map");
//		ModifyMenu(hSubMenu,1,MF_BYPOSITION|MF_STRING|MF_ENABLED,2,"Save As *.dat");
//		ModifyMenu(hSubMenu,2,MF_BYPOSITION|MF_STRING|MF_ENABLED,3,"Save As *.sma");
//		ModifyMenu(hSubMenu,3,MF_BYPOSITION|MF_STRING|MF_ENABLED,5,"Save All");
//	}
	
//	_findclose(checkdata);
	
	
	
}


