#include <libraries/mui.h>
#include <proto/muimaster.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <exec/memory.h>
#include <stdlib.h>
#include <stdio.h>

#ifndef MAKE_ID
#define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
#endif

#ifdef _DCC
#define __inline
#endif

struct Library *MUIMasterBase, *LocaleBase;

/*************************/
/*    Fail Function      */
/*************************/

static VOID fail(APTR app,char *str)
{
        if (app)
                MUI_DisposeObject(app);

#ifndef _DCC
        if (MUIMasterBase)
                CloseLibrary(MUIMasterBase);
#endif
	if (str)
        {
                puts(str);
                exit(20);
        }
        exit(0);
}

/*************************/
/*    Init Function      */
/*************************/

static VOID init(VOID)
{
#ifdef _DCC
        onbreak(brkfunc);
#endif

#ifndef _DCC
        if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
                fail(NULL,"Failed to open "MUIMASTER_NAME".");
#endif
}

/*************************/
/* InitLocale Function   */
/*************************/

static VOID initlocale(VOID)
{
#ifndef _DCC
        LocaleBase = OpenLibrary("Locale.library",38L);
#endif
	/* YOU MUST write this function !!! */
        /* OpenCatalog(NULL,NULL); */
}

/****************************************************************/
/*      ExTended KeyButton ( or Eric Totel KeyButton :-) )      */
/*      to use with localization features                       */
/****************************************************************/

static APTR __inline ETKeyButton(char *text)
{
        return (KeyButton(&text[3], text[1]));
}



int main( int argc, char *argv[] )
{
	ULONG	signal;
	BOOL	running = TRUE;
	APTR	App, WI_Characters, STR_name, CY_sex, RA_Race, RA_Class, CH_cloak, CH_shield;
	APTR	CH_gloves, CH_helmet, SL_experience, SL_strength, SL_dexterity, SL_condition;
	APTR	SL_intelligence;
	char	*STR_CY_sex[3], *STR_GR_Register[5], *STR_RA_Race[6], *STR_RA_Class[7];

	STR_CY_sex [0] = "female";
	STR_CY_sex [1] = "male";
	STR_CY_sex [2] = NULL;
	STR_GR_Register [0] = "Race";
	STR_GR_Register [1] = "Class";
	STR_GR_Register [2] = "Armor";
	STR_GR_Register [3] = "Level";
	STR_GR_Register [4] = NULL;
	STR_RA_Race [0] = "Human";
	STR_RA_Race [1] = "Elf";
	STR_RA_Race [2] = "Dwarf";
	STR_RA_Race [3] = "Hobbit";
	STR_RA_Race [4] = "Gnome";
	STR_RA_Race [5] = NULL;
	STR_RA_Class [0] = "Warrior";
	STR_RA_Class [1] = "Rogue";
	STR_RA_Class [2] = "Bard";
	STR_RA_Class [3] = "Monk";
	STR_RA_Class [4] = "Magician";
	STR_RA_Class [5] = "Archmage";
	STR_RA_Class [6] = NULL;

	init();


	App = ApplicationObject,
		MUIA_Application_Author, "Stefan Stuntz",
		MUIA_Application_Base, "CHARACTER",
		MUIA_Application_Title, "Characters",
		MUIA_Application_Version, "$VER: Characters 1.1 (xx.xx.xx)",
		MUIA_Application_Copyright, "Stefan Stuntz",
		MUIA_Application_Description, "Just an example !!",
		MUIA_HelpFile, "character.guide",
		SubWindow, WI_Characters = WindowObject,
			MUIA_Window_Title, "Characters",
			MUIA_HelpNode, "WI_Characters",
			MUIA_Window_ID, MAKE_ID( '0','W','I','N' ),
			WindowContents, GroupObject,
				Child, GroupObject,
					MUIA_HelpNode, "GR_Global",
					MUIA_Group_Columns, 2,
					Child, Label( "Name" ),
					Child, STR_name = StringObject,
						StringFrame,
						MUIA_HelpNode, "STR_name",
						MUIA_String_MaxLen, 80,
						MUIA_String_Format, 0,
					End,
					Child, Label( "Sex" ),
					Child, CY_sex = CycleObject,
						MUIA_HelpNode, "CY_sex",
						MUIA_Cycle_Entries, STR_CY_sex,
					End,
				End,
				Child, RegisterGroup( STR_GR_Register ),
					Child, RA_Race = RadioObject,
						GroupFrameT( "Race" ),
						MUIA_Radio_Entries, STR_RA_Race,
					End,
					Child, RA_Class = RadioObject,
						GroupFrameT( "Class" ),
						MUIA_Radio_Entries, STR_RA_Class,
					End,
					Child, GroupObject,
						GroupFrameT( "Armor" ),
						MUIA_Group_Columns, 2,
						Child, Label( "Cloak" ),
						Child, CH_cloak = CheckMark( 0 ),
						Child, Label( "Shield" ),
						Child, CH_shield = CheckMark( 0 ),
						Child, Label( "Gloves" ),
						Child, CH_gloves = CheckMark( 0 ),
						Child, Label( "Helmet" ),
						Child, CH_helmet = CheckMark( 0 ),
					End,
					Child, GroupObject,
						GroupFrameT( "Level" ),
						MUIA_Group_Columns, 2,
						Child, Label( "Experience" ),
						Child, SL_experience = SliderObject,
							MUIA_Slider_Min, 0,
							MUIA_Slider_Max, 100,
							MUIA_Slider_Quiet, 0,
							MUIA_Slider_Level, 3,
							MUIA_Slider_Reverse, 0,
						End,
						Child, Label( "Strength" ),
						Child, SL_strength = SliderObject,
							MUIA_Slider_Min, 0,
							MUIA_Slider_Max, 100,
							MUIA_Slider_Quiet, 0,
							MUIA_Slider_Level, 10,
							MUIA_Slider_Reverse, 0,
						End,
						Child, Label( "Dexterity" ),
						Child, SL_dexterity = SliderObject,
							MUIA_Slider_Min, 0,
							MUIA_Slider_Max, 100,
							MUIA_Slider_Quiet, 0,
							MUIA_Slider_Level, 24,
							MUIA_Slider_Reverse, 0,
						End,
						Child, Label( "Condition" ),
						Child, SL_condition = SliderObject,
							MUIA_Slider_Min, 0,
							MUIA_Slider_Max, 100,
							MUIA_Slider_Quiet, 0,
							MUIA_Slider_Level, 39,
							MUIA_Slider_Reverse, 0,
						End,
						Child, Label( "Intelligence" ),
						Child, SL_intelligence = SliderObject,
							MUIA_Slider_Min, 0,
							MUIA_Slider_Max, 100,
							MUIA_Slider_Quiet, 0,
							MUIA_Slider_Level, 74,
							MUIA_Slider_Reverse, 0,
						End,
					End,
				End,
			End,
		End,
	End;

	/*  Notification */
	DoMethod(WI_Characters, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);

	set( WI_Characters, MUIA_Window_Open, TRUE );

	while (running)
	{
		switch (DoMethod(App,MUIM_Application_Input,&signal))
		{
		case MUIV_Application_ReturnID_Quit:
		running = FALSE;
		break;
		}
	if (signal) Wait(signal);
	}
	fail(App, NULL);
}
