#include <stdio.h>

#include "concorde.h"
#include "ysmaze2.h"
#include "mzedit.h"
#include "ysgui.h"

#include <stdlib.h>
#include <string.h>
#include <winb.h>
#include <te.h>
#include <fntb.h>
#include <gui.h>

extern int ActiveWin;
extern MAZEWIN mzWin[MAZEWIN_NUM];

extern int	pdWallN[5];


static int SetInputFloorNumber();
static int SetInputWallNumber(int n,int flrnflag);

int InputWallN=0;   /* 入力壁の種類 */
int InputNum=1;     /* フロアへの数字入力用 */


/*	initDataMZEDIT:pdWallAuto:MJ_MITEML40の呼び出し関数	*/
int	CreateMazeAuto()
{
	if(mzWin[ActiveWin].openflag==TRUE)
	{
		MazeCreate(&mzWin[ActiveWin].map);
		YsRepaintWindowUserArea(mzWin[ActiveWin].win);
	}

	return NOERR ;
}



/*	initDataMZEDIT:pdWallN[0]:MJ_MITEML40の呼び出し関数	*/
/*	initDataMZEDIT:pdWallN[1]:MJ_MITEML40の呼び出し関数	*/
/*	initDataMZEDIT:pdWallN[2]:MJ_MITEML40の呼び出し関数	*/
/*	initDataMZEDIT:pdWallN[3]:MJ_MITEML40の呼び出し関数	*/
/*	initDataMZEDIT:pdWallN[4]:MJ_MITEML40の呼び出し関数	*/
/*	initDataMZEDIT:pdWallN[5]:MJ_MITEML40の呼び出し関数	*/
/*	initDataMZEDIT:pdWallN[6]:MJ_MITEML40の呼び出し関数	*/
/*	initDataMZEDIT:pdWallN[7]:MJ_MITEML40の呼び出し関数	*/
int	SetWallNumber(int kobj)
{
	int num;

	for(num=0; num<INPUT_KINDS; num++)
	{
		if(kobj==pdWallN[num])
		{
			SetInputWallNumber(num,1);
		}
	}

	return NOERR ;
}

int	OperationToggle(int kobj)
{
	extern int InpOpeToggle[2],InpOpeDlg;

	int n;

	if(kobj==InpOpeToggle[0])
	{
		n=(InputWallN+(INPUT_KINDS-1))%INPUT_KINDS;
	}
	else
	{
		n=(InputWallN+1)%INPUT_KINDS;
	}

	SetInputWallNumber(n,0);

	return NOERR;
}


static int SetInputWallNumber(int n,int flrnflag)
{
	extern int InpOpeDlg,InpOpeMes;

	static char flrnum[80]={0};

	int num;
	char *obj[]=
	{
		"壁",
		"通過可能壁",
		"扉",
		"見えない壁",
		"壁除去",
		"床マーク",
		"天井マーク",
		"床番号",
		"床マーク除去",
		"天井マーク除去",
		NULL
	};

	InputWallN=n;

	for(num=0; num<INPUT_KINDS; num++)
	{
		if(num==n)
		{
			MTL_setAtrObj(pdWallN[num],MS_CHECKL40);

			if(num!=FLOOR_NUMBER)
			{
				MMI_SendMessage(InpOpeMes,MM_SETMSG,1,obj[num]);
			}
			else
			{
				if(flrnflag!=0)
				{
					InputNum=SetInputFloorNumber();
				}
				if(InputNum==0)
				{
					MMI_SendMessage(InpOpeMes,MM_SETMSG,1,"床番号消去");
				}
				else
				{
					sprintf(flrnum,"床番号(%d)",InputNum);
					MMI_SendMessage(InpOpeMes,MM_SETMSG,1,flrnum);
				}
			}

			MMI_SendMessage(InpOpeDlg,MM_ERASE,0);
			MMI_SendMessage(InpOpeDlg,MM_SHOW,0);
		}
		else
		{
			MTL_resetAtrObj(pdWallN[num],~MS_CHECKL40);
		}
	}
}



static int SetInputFloorNumber()
{
	int num,dmy;
	extern int Ys11Id,InputFloorNumDlg,InputFloorNumBox;

	MMI_SendMessage(InputFloorNumDlg,MM_ATTACH,1,Ys11Id);
	MMI_SendMessage(InputFloorNumDlg,MM_SHOW,0);
	MMI_ExecSystem();
	MMI_SendMessage(InputFloorNumDlg,MM_ERASE,0);
	MMI_SendMessage(InputFloorNumDlg,MM_DETACH,0);

	MMI_SendMessage
	    (InputFloorNumBox, MM_GETNUMBOX, 5,&num, &dmy,&dmy,&dmy,&dmy);

	return num;
}


/*	initDataMZEDIT:InputFloorNumSet:MJ_DBUTTONL40の呼び出し関数	*/
int	InputFloorNumSetFunc()
{
	MMI_SetHaltFlag(TRUE);
	return NOERR ;
}
