/* /-------------------------------------------/ タイトル マップエディタ  バージョン 5.0 公開日 2004/03/05 制作 HAL Homepage http://www.harukitchen.com/ /-------------------------------------------/ ★バージョンアップ履歴 ver5.0 2004/03/05 リストから選択可能。右クリックでのパーツ表示を全部表示するようにする。 ver4.0 2004/01/29 右クリックでチップ一覧。32×32に対応。 ver3.0 2004/01/25 データファイルがない場合、新規作成するようにした。 画面を広くした。 セーブ時にメッセージが出るようにした。 */ #define SUB_PROGRAM #define DIRECTINPUT #include"harulib.h" #include"el.h" #define FONTSIZE 16 //フォントサイズ #define MAX_LIST 100 //リスト最大数 static char *list_file = "list.txt";//リストファイル static char *map_initdata = "map.ini";//設定ファイル //リスト static struct _list{ char name[128];//名前 int width,height;//横幅、縦幅 char data[128];//データファイル }List[MAX_LIST]; //マウス状態構造体 static struct _mouse{ POINT p;//座標 int Left,Right;//左と右状態 }mouse; //マップ構造体 static struct _map{ POINT p;//座標 DDOBJ Bmp;//ビットマップ画像 int width;//マップ最大長 int height;//マップ最大長 int chipwidth;//チップ画像の横幅[512] int chipheight;//チップ画像の縦幅[512] int chipwnum;//チップの数(横)[512/32 = 16] int chiphnum;//チップの数(縦)[512/32 = 16] char bmpfile[64];//チップ画像ファイル名 char data[64];//マップデータファイル名 int selectchip;//選択チップ unsigned char maps[512][512];//マップデータ }map; //管理構造体 static struct _kanri{ int chipsize; //チップサイズ float save_message;//セーブメッセージウェイト int now_state;//現在の状態(0=リスト選択,1=マップ作成) int now_point;//現在の選択リスト int end_point;//リストの終わり番号 BOOL DragFlag;//ドラッグフラグ BOOL ModeFlag;//モードフラグ(TRUE=番号表示) BOOL ChipFlag;//チップ表示フラグ(TRUE=パーツ選択) DDOBJ MouseBmp;//マウス画像 }kanri; //関数プロトタイプ static void Init();//初期化 static void KeyAction();//キー入力 static void Paint();//描画 static void Save();//セーブ static void DispList();//リスト選択画面 static void LoadData(int no);//データロード static void Action();//処理 static void DispMap();//マップ表示 static void DispFont();//フォント表示 static void DispParts();//パーツ表示 /********************************************************************************/ /* */ /* エディタ画面 */ /* */ /********************************************************************************/ void MapEditScreen(void){ //初期化 if(elChangeScreen()){ Init(); } //クリアー elDraw::Clear(); //描画 Paint(); //キー入力 KeyAction(); //処理 Action(); //リフレッシュ elDraw::Refresh(); } /********************************************************************************/ /* */ /* 初期化 */ /* */ /********************************************************************************/ void Init(){ int i; FILE *fin; char Buffer2[1024]; //リストファイルの読み込み fin = fopen(list_file,"r"); if(fin == NULL)exit(1); i=0; while( fgets(Buffer,1024,fin) != NULL ){ Chomp(Buffer);//改行削除 Replace(","," ",Buffer,Buffer2);//カンマをスペースに変換 sscanf(Buffer2,"%s %d %d %s", List[i].name,&List[i].width,&List[i].height,List[i].data); i++; //限界値 if(i == MAX_LIST-1){ break; } } kanri.end_point = i; fclose(fin); //設定ファイルの読み込み fin = fopen(map_initdata,"r"); if(fin == NULL)exit(1); fgets(Buffer,100,fin); fclose(fin); Chomp(Buffer); Replace(","," ",Buffer,Buffer2);//カンマをスペースに変換 sscanf(Buffer2,"%d %d %d %s", &kanri.chipsize,&map.chipwidth,&map.chipheight,map.bmpfile); //計算 map.chipwnum = map.chipwidth/kanri.chipsize; map.chiphnum = map.chipheight/kanri.chipsize; //画像ロード elDraw::SetSpriteColor(RGB(0,255,0)); kanri.MouseBmp = elDraw::LoadObject("bmp\\hand.bmp"); map.Bmp = elDraw::LoadObject(map.bmpfile); //各初期化 mouse.p.x = VC_INITMX; mouse.p.y = VC_INITMY; map.p.x = map.p.y = 0; mouse.Left = mouse.Right = VC_FREE; map.selectchip = 0; kanri.now_state = 0; kanri.ChipFlag = FALSE; } /********************************************************************************/ /* */ /* 描画 */ /* */ /********************************************************************************/ void Paint(){ //最初にマップセレクト画面 if(kanri.now_state == 0){ DispList(); } //マップスクリーン else{ //マップ表示 if(!kanri.ChipFlag){ DispMap(); } //パーツ表示 else{ DispParts(); } //マウス表示 elDraw::Layer(MousePX,MousePY,kanri.MouseBmp,kanri.chipsize*2,0,kanri.chipsize*2+4,4); //カーソル表示 elDraw::Layer(mouse.p.x,mouse.p.y,kanri.MouseBmp,kanri.chipsize,0,kanri.chipsize*2,kanri.chipsize); //フォント表示 DispFont(); } } /********************************************************************************/ /* */ /* パーツ描画 */ /* */ /********************************************************************************/ void DispParts(){ int i,j,k; k=0;//チップ番号 for(j=0;j=F(0) ){ kanri.save_message-=FrameTime; SHOW(200,400,"セーブしました。"); } } /********************************************************************************/ /* */ /* マップ表示 */ /* */ /********************************************************************************/ void DispMap(){ int i,j,k,l; int mapdata; k=l=0; for(i=map.p.x;i= map.width || j >= map.height){;} else{ mapdata=map.maps[j][i]; elDraw::Layer(k*kanri.chipsize,l*kanri.chipsize,map.Bmp, kanri.chipsize*(mapdata%map.chipwnum),kanri.chipsize*(mapdata/map.chipwnum), kanri.chipsize*(mapdata%map.chipwnum+1),kanri.chipsize*(mapdata/map.chipwnum+1)); } //番号表示 if(kanri.ModeFlag){ SHOW2(k*kanri.chipsize,l*kanri.chipsize,"%d",mapdata); } if(++l >= 480/kanri.chipsize){k++;l=0;} } } } /********************************************************************************/ /* */ /* キー入力 */ /* */ /********************************************************************************/ void KeyAction(){ int data; while(elSystem::InputLoop()){ //状態保存 elSystem::GetInput(VC_LBUTTON,&mouse.Left); elSystem::GetInput(VC_RBUTTON,&mouse.Right); switch(elSystem::Get.Code){ case VC_S: if(elSystem::Get.Status)Save(); break; case VC_TAB: if(elSystem::Get.Status)kanri.ModeFlag = !kanri.ModeFlag; break; case VC_SPACE: if(elSystem::Get.Status)kanri.now_state = 0; break; case VC_RIGHT: if(elSystem::Get.Status){ if(map.p.x0)map.p.x-=160/kanri.chipsize; } break; case VC_UP: if(elSystem::Get.Status){ if(map.p.y>0)map.p.y-=3; } break; case VC_DOWN: if(elSystem::Get.Status){ if(map.p.y= 255){ map.selectchip = 255; } } } } //離された時 else if(mouse.Left == VC_PULL){ kanri.DragFlag = FALSE; } //右クリック if(mouse.Right == VC_PUSH){ //リスト一覧のとき、次のページ。 if(kanri.now_state == 0){ kanri.now_point += 20; if(kanri.now_point >= kanri.end_point){ kanri.now_point = 0; } } //マップページ else{ //マップチップ表示 kanri.ChipFlag = !kanri.ChipFlag; } } //マウスの座標 if(elSystem::Get.Code==VC_MX){mouse.p.x = elSystem::Get.Status;} if(elSystem::Get.Code==VC_MY){mouse.p.y = elSystem::Get.Status;} //チップサイズの倍数に合わせる if(kanri.now_state == 1){ mouse.p.x -= mouse.p.x % kanri.chipsize; mouse.p.y -= mouse.p.y % kanri.chipsize; }else if(kanri.now_state == 0){ mouse.p.x -= mouse.p.x % FONTSIZE; mouse.p.y -= mouse.p.y % FONTSIZE; } } } /********************************************************************************/ /* */ /* セーブ */ /* */ /********************************************************************************/ void Save(){ int i,j; FILE *fout; //マップセーブ fout = fopen(map.data,"wb"); if(fout == NULL)exit(1); for(i=0;i= map.width){++i;j=0;} } fclose(fin); } /********************************************************************************/ /* */ /* リスト選択画面 */ /* */ /********************************************************************************/ void DispList(){ int i,k; int start,end; elFont::Begin(GOTHIC,FONTSIZE); elFont::Color(RGB(200,250,0)); start = kanri.now_point; if(start <= 0){ start = 0; } end = start+480/FONTSIZE; if(end >= kanri.end_point){ end = kanri.end_point; } for(i=start,k=0;i= 0 && mouse.p.y <= kanri.chipsize*map.chiphnum){ map.maps[mouse.p.y/kanri.chipsize+map.p.y][mouse.p.x/kanri.chipsize+map.p.x] = map.selectchip; } } } } }