예제 #1
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CUIEntity::LoadBuffer(byte  *Buffer, bool Complete) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(ENTITY_CONTAINER)
	TOKEN_TABLE(TEMPLATE)
	TOKEN_TABLE(DISABLED)
	TOKEN_TABLE(VISIBLE)
	TOKEN_TABLE(X)
	TOKEN_TABLE(Y)
	TOKEN_TABLE(NAME)
	TOKEN_TABLE(ENTITY)
	TOKEN_TABLE(SCRIPT)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE_END

	byte *params;
	int cmd = 2;
	CBParser parser(Game);

	if (Complete) {
		if (parser.GetCommand((char **)&Buffer, commands, (char **)&params) != TOKEN_ENTITY_CONTAINER) {
			Game->LOG(0, "'ENTITY_CONTAINER' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while (cmd > 0 && (cmd = parser.GetCommand((char **)&Buffer, commands, (char **)&params)) > 0) {
		switch (cmd) {
		case TOKEN_TEMPLATE:
			if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_NAME:
			SetName((char *)params);
			break;

		case TOKEN_X:
			parser.ScanStr((char *)params, "%d", &m_PosX);
			break;

		case TOKEN_Y:
			parser.ScanStr((char *)params, "%d", &m_PosY);
			break;

		case TOKEN_DISABLED:
			parser.ScanStr((char *)params, "%b", &m_Disable);
			break;

		case TOKEN_VISIBLE:
			parser.ScanStr((char *)params, "%b", &m_Visible);
			break;

		case TOKEN_ENTITY:
			if (FAILED(SetEntity((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_SCRIPT:
			AddScript((char *)params);
			break;

		case TOKEN_EDITOR_PROPERTY:
			ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		Game->LOG(0, "Syntax error in ENTITY_CONTAINER definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC) {
		Game->LOG(0, "Error loading ENTITY_CONTAINER definition");
		return E_FAIL;
	}

	CorrectSize();

	if (Game->m_EditorMode) {
		m_Width = 50;
		m_Height = 50;
	}

	return S_OK;
}
예제 #2
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CUIButton::LoadBuffer(byte  *Buffer, bool Complete) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(BUTTON)
	TOKEN_TABLE(TEMPLATE)
	TOKEN_TABLE(DISABLED)
	TOKEN_TABLE(VISIBLE)
	TOKEN_TABLE(FOCUSABLE)
	TOKEN_TABLE(BACK_HOVER)
	TOKEN_TABLE(BACK_PRESS)
	TOKEN_TABLE(BACK_DISABLE)
	TOKEN_TABLE(BACK_FOCUS)
	TOKEN_TABLE(BACK)
	TOKEN_TABLE(CENTER_IMAGE)
	TOKEN_TABLE(IMAGE_HOVER)
	TOKEN_TABLE(IMAGE_PRESS)
	TOKEN_TABLE(IMAGE_DISABLE)
	TOKEN_TABLE(IMAGE_FOCUS)
	TOKEN_TABLE(IMAGE)
	TOKEN_TABLE(FONT_HOVER)
	TOKEN_TABLE(FONT_PRESS)
	TOKEN_TABLE(FONT_DISABLE)
	TOKEN_TABLE(FONT_FOCUS)
	TOKEN_TABLE(FONT)
	TOKEN_TABLE(TEXT_ALIGN)
	TOKEN_TABLE(TEXT)
	TOKEN_TABLE(X)
	TOKEN_TABLE(Y)
	TOKEN_TABLE(WIDTH)
	TOKEN_TABLE(HEIGHT)
	TOKEN_TABLE(CURSOR)
	TOKEN_TABLE(NAME)
	TOKEN_TABLE(EVENTS)
	TOKEN_TABLE(SCRIPT)
	TOKEN_TABLE(CAPTION)
	TOKEN_TABLE(PARENT_NOTIFY)
	TOKEN_TABLE(PRESSED)
	TOKEN_TABLE(PIXEL_PERFECT)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE_END

	byte *params;
	int cmd = 2;
	CBParser parser(Game);

	if (Complete) {
		if (parser.GetCommand((char **)&Buffer, commands, (char **)&params) != TOKEN_BUTTON) {
			Game->LOG(0, "'BUTTON' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while (cmd > 0 && (cmd = parser.GetCommand((char **)&Buffer, commands, (char **)&params)) > 0) {
		switch (cmd) {
		case TOKEN_TEMPLATE:
			if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_NAME:
			SetName((char *)params);
			break;

		case TOKEN_CAPTION:
			SetCaption((char *)params);
			break;

		case TOKEN_BACK:
			delete m_Back;
			m_Back = new CUITiledImage(Game);
			if (!m_Back || FAILED(m_Back->LoadFile((char *)params))) {
				delete m_Back;
				m_Back = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_BACK_HOVER:
			delete m_BackHover;
			m_BackHover = new CUITiledImage(Game);
			if (!m_BackHover || FAILED(m_BackHover->LoadFile((char *)params))) {
				delete m_BackHover;
				m_BackHover = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_BACK_PRESS:
			delete m_BackPress;
			m_BackPress = new CUITiledImage(Game);
			if (!m_BackPress || FAILED(m_BackPress->LoadFile((char *)params))) {
				delete m_BackPress;
				m_BackPress = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_BACK_DISABLE:
			delete m_BackDisable;
			m_BackDisable = new CUITiledImage(Game);
			if (!m_BackDisable || FAILED(m_BackDisable->LoadFile((char *)params))) {
				delete m_BackDisable;
				m_BackDisable = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_BACK_FOCUS:
			delete m_BackFocus;
			m_BackFocus = new CUITiledImage(Game);
			if (!m_BackFocus || FAILED(m_BackFocus->LoadFile((char *)params))) {
				delete m_BackFocus;
				m_BackFocus = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE:
			delete m_Image;
			m_Image = new CBSprite(Game);
			if (!m_Image || FAILED(m_Image->LoadFile((char *)params))) {
				delete m_Image;
				m_Image = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE_HOVER:
			delete m_ImageHover;
			m_ImageHover = new CBSprite(Game);
			if (!m_ImageHover || FAILED(m_ImageHover->LoadFile((char *)params))) {
				delete m_ImageHover;
				m_ImageHover = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE_PRESS:
			delete m_ImagePress;
			m_ImagePress = new CBSprite(Game);
			if (!m_ImagePress || FAILED(m_ImagePress->LoadFile((char *)params))) {
				delete m_ImagePress;
				m_ImagePress = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE_DISABLE:
			delete m_ImageDisable;
			m_ImageDisable = new CBSprite(Game);
			if (!m_ImageDisable || FAILED(m_ImageDisable->LoadFile((char *)params))) {
				delete m_ImageDisable;
				m_ImageDisable = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE_FOCUS:
			delete m_ImageFocus;
			m_ImageFocus = new CBSprite(Game);
			if (!m_ImageFocus || FAILED(m_ImageFocus->LoadFile((char *)params))) {
				delete m_ImageFocus;
				m_ImageFocus = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_FONT:
			if (m_Font) Game->m_FontStorage->RemoveFont(m_Font);
			m_Font = Game->m_FontStorage->AddFont((char *)params);
			if (!m_Font) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_FONT_HOVER:
			if (m_FontHover) Game->m_FontStorage->RemoveFont(m_FontHover);
			m_FontHover = Game->m_FontStorage->AddFont((char *)params);
			if (!m_FontHover) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_FONT_PRESS:
			if (m_FontPress) Game->m_FontStorage->RemoveFont(m_FontPress);
			m_FontPress = Game->m_FontStorage->AddFont((char *)params);
			if (!m_FontPress) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_FONT_DISABLE:
			if (m_FontDisable) Game->m_FontStorage->RemoveFont(m_FontDisable);
			m_FontDisable = Game->m_FontStorage->AddFont((char *)params);
			if (!m_FontDisable) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_FONT_FOCUS:
			if (m_FontFocus) Game->m_FontStorage->RemoveFont(m_FontFocus);
			m_FontFocus = Game->m_FontStorage->AddFont((char *)params);
			if (!m_FontFocus) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_TEXT:
			SetText((char *)params);
			Game->m_StringTable->Expand(&m_Text);
			break;

		case TOKEN_TEXT_ALIGN:
			if (scumm_stricmp((char *)params, "left") == 0) m_Align = TAL_LEFT;
			else if (scumm_stricmp((char *)params, "right") == 0) m_Align = TAL_RIGHT;
			else m_Align = TAL_CENTER;
			break;

		case TOKEN_X:
			parser.ScanStr((char *)params, "%d", &m_PosX);
			break;

		case TOKEN_Y:
			parser.ScanStr((char *)params, "%d", &m_PosY);
			break;

		case TOKEN_WIDTH:
			parser.ScanStr((char *)params, "%d", &m_Width);
			break;

		case TOKEN_HEIGHT:
			parser.ScanStr((char *)params, "%d", &m_Height);
			break;

		case TOKEN_CURSOR:
			delete m_Cursor;
			m_Cursor = new CBSprite(Game);
			if (!m_Cursor || FAILED(m_Cursor->LoadFile((char *)params))) {
				delete m_Cursor;
				m_Cursor = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_SCRIPT:
			AddScript((char *)params);
			break;

		case TOKEN_PARENT_NOTIFY:
			parser.ScanStr((char *)params, "%b", &m_ParentNotify);
			break;

		case TOKEN_DISABLED:
			parser.ScanStr((char *)params, "%b", &m_Disable);
			break;

		case TOKEN_VISIBLE:
			parser.ScanStr((char *)params, "%b", &m_Visible);
			break;

		case TOKEN_FOCUSABLE:
			parser.ScanStr((char *)params, "%b", &m_CanFocus);
			break;

		case TOKEN_CENTER_IMAGE:
			parser.ScanStr((char *)params, "%b", &m_CenterImage);
			break;

		case TOKEN_PRESSED:
			parser.ScanStr((char *)params, "%b", &m_StayPressed);
			break;

		case TOKEN_PIXEL_PERFECT:
			parser.ScanStr((char *)params, "%b", &m_PixelPerfect);
			break;

		case TOKEN_EDITOR_PROPERTY:
			ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		Game->LOG(0, "Syntax error in BUTTON definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC) {
		Game->LOG(0, "Error loading BUTTON definition");
		return E_FAIL;
	}

	CorrectSize();

	return S_OK;
}
예제 #3
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdTalkDef::LoadBuffer(byte  *Buffer, bool Complete) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(TALK)
	TOKEN_TABLE(TEMPLATE)
	TOKEN_TABLE(ACTION)
	TOKEN_TABLE(DEFAULT_SPRITESET_FILE)
	TOKEN_TABLE(DEFAULT_SPRITESET)
	TOKEN_TABLE(DEFAULT_SPRITE)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE_END

	byte *params;
	int cmd;
	CBParser parser(Game);

	if (Complete) {
		if (parser.GetCommand((char **)&Buffer, commands, (char **)&params) != TOKEN_TALK) {
			Game->LOG(0, "'TALK' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while ((cmd = parser.GetCommand((char **)&Buffer, commands, (char **)&params)) > 0) {
		switch (cmd) {
		case TOKEN_TEMPLATE:
			if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_ACTION: {
			CAdTalkNode *Node = new CAdTalkNode(Game);
			if (Node && SUCCEEDED(Node->LoadBuffer(params, false))) m_Nodes.Add(Node);
			else {
				delete Node;
				Node = NULL;
				cmd = PARSERR_GENERIC;
			}
		}
		break;

		case TOKEN_DEFAULT_SPRITE:
			CBUtils::SetString(&m_DefaultSpriteFilename, (char *)params);
			break;

		case TOKEN_DEFAULT_SPRITESET_FILE:
			CBUtils::SetString(&m_DefaultSpriteSetFilename, (char *)params);
			break;

		case TOKEN_DEFAULT_SPRITESET: {
			delete m_DefaultSpriteSet;
			m_DefaultSpriteSet = new CAdSpriteSet(Game);
			if (!m_DefaultSpriteSet || FAILED(m_DefaultSpriteSet->LoadBuffer(params, false))) {
				delete m_DefaultSpriteSet;
				m_DefaultSpriteSet = NULL;
				cmd = PARSERR_GENERIC;
			}
		}
		break;


		case TOKEN_EDITOR_PROPERTY:
			ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		Game->LOG(0, "Syntax error in TALK definition");
		return E_FAIL;
	}

	if (cmd == PARSERR_GENERIC) {
		Game->LOG(0, "Error loading TALK definition");
		return E_FAIL;
	}

	delete m_DefaultSprite;
	delete m_DefaultSpriteSet;
	m_DefaultSprite = NULL;
	m_DefaultSpriteSet = NULL;

	if (m_DefaultSpriteFilename) {
		m_DefaultSprite = new CBSprite(Game);
		if (!m_DefaultSprite || FAILED(m_DefaultSprite->LoadFile(m_DefaultSpriteFilename))) return E_FAIL;
	}

	if (m_DefaultSpriteSetFilename) {
		m_DefaultSpriteSet = new CAdSpriteSet(Game);
		if (!m_DefaultSpriteSet || FAILED(m_DefaultSpriteSet->LoadFile(m_DefaultSpriteSetFilename))) return E_FAIL;
	}


	return S_OK;
}
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdSpriteSet::LoadBuffer(BYTE * Buffer, bool Complete, int LifeTime, TSpriteCacheType CacheType)
{
    TOKEN_TABLE_START(commands)
    TOKEN_TABLE (SPRITESET)
    TOKEN_TABLE (NAME)
    TOKEN_TABLE (UP_LEFT)
    TOKEN_TABLE (DOWN_LEFT)
    TOKEN_TABLE (LEFT)
    TOKEN_TABLE (UP_RIGHT)
    TOKEN_TABLE (DOWN_RIGHT)
    TOKEN_TABLE (RIGHT)
    TOKEN_TABLE (UP)
    TOKEN_TABLE (DOWN)
    TOKEN_TABLE (TEMPLATE)
    TOKEN_TABLE (EDITOR_PROPERTY)
    TOKEN_TABLE_END

    BYTE* params;
    int cmd;
    CBParser parser(Game);

    if(Complete) {
        if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_SPRITESET) {
            Game->LOG(0, "'SPRITESET' keyword expected.");
            return E_FAIL;
        }
        Buffer = params;
    }

    CBSprite* spr=NULL;
    while ((cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
    {
        switch (cmd)
        {
        case TOKEN_TEMPLATE:
            if(FAILED(LoadFile((char*)params, LifeTime, CacheType))) cmd = PARSERR_GENERIC;
            break;

        case TOKEN_NAME:
            SetName((char*)params);
            break;

        case TOKEN_LEFT:
            SAFE_DELETE(m_Sprites[DI_LEFT]);
            spr = new CBSprite(Game, m_Owner);
            if(!spr || FAILED(spr->LoadFile((char*)params, LifeTime, CacheType))) cmd = PARSERR_GENERIC;
            else m_Sprites[DI_LEFT] = spr;
            break;

        case TOKEN_RIGHT:
            SAFE_DELETE(m_Sprites[DI_RIGHT]);
            spr = new CBSprite(Game, m_Owner);
            if(!spr || FAILED(spr->LoadFile((char*)params, LifeTime, CacheType))) cmd = PARSERR_GENERIC;
            else m_Sprites[DI_RIGHT] = spr;
            break;

        case TOKEN_UP:
            SAFE_DELETE(m_Sprites[DI_UP]);
            spr = new CBSprite(Game, m_Owner);
            if(!spr || FAILED(spr->LoadFile((char*)params, LifeTime, CacheType))) cmd = PARSERR_GENERIC;
            else m_Sprites[DI_UP] = spr;
            break;

        case TOKEN_DOWN:
            SAFE_DELETE(m_Sprites[DI_DOWN]);
            spr = new CBSprite(Game, m_Owner);
            if(!spr || FAILED(spr->LoadFile((char*)params, LifeTime, CacheType))) cmd = PARSERR_GENERIC;
            else m_Sprites[DI_DOWN] = spr;
            break;

        case TOKEN_UP_LEFT:
            SAFE_DELETE(m_Sprites[DI_UPLEFT]);
            spr = new CBSprite(Game, m_Owner);
            if(!spr || FAILED(spr->LoadFile((char*)params, LifeTime, CacheType))) cmd = PARSERR_GENERIC;
            else m_Sprites[DI_UPLEFT] = spr;
            break;

        case TOKEN_UP_RIGHT:
            SAFE_DELETE(m_Sprites[DI_UPRIGHT]);
            spr = new CBSprite(Game, m_Owner);
            if(!spr || FAILED(spr->LoadFile((char*)params, LifeTime, CacheType))) cmd = PARSERR_GENERIC;
            else m_Sprites[DI_UPRIGHT] = spr;
            break;

        case TOKEN_DOWN_LEFT:
            SAFE_DELETE(m_Sprites[DI_DOWNLEFT]);
            spr = new CBSprite(Game, m_Owner);
            if(!spr || FAILED(spr->LoadFile((char*)params, LifeTime, CacheType))) cmd = PARSERR_GENERIC;
            else m_Sprites[DI_DOWNLEFT] = spr;
            break;

        case TOKEN_DOWN_RIGHT:
            SAFE_DELETE(m_Sprites[DI_DOWNRIGHT]);
            spr = new CBSprite(Game, m_Owner);
            if(!spr || FAILED(spr->LoadFile((char*)params, LifeTime, CacheType))) cmd = PARSERR_GENERIC;
            else m_Sprites[DI_DOWNRIGHT] = spr;
            break;

        case TOKEN_EDITOR_PROPERTY:
            ParseEditorProperty(params, false);
            break;
        }
    }
    if (cmd == PARSERR_TOKENNOTFOUND) {
        Game->LOG(0, "Syntax error in SPRITESET definition");
        return E_FAIL;
    }

    if (cmd == PARSERR_GENERIC) {
        Game->LOG(0, "Error loading SPRITESET definition");
        if(spr) delete spr;
        return E_FAIL;
    }

    return S_OK;
}
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdInventoryBox::LoadBuffer(BYTE* Buffer, bool Complete)
{
	TOKEN_TABLE_START(commands)
		TOKEN_TABLE (INVENTORY_BOX)
		TOKEN_TABLE (TEMPLATE)
		TOKEN_TABLE (WINDOW)
		TOKEN_TABLE (EXCLUSIVE)
		TOKEN_TABLE (ALWAYS_VISIBLE)
		TOKEN_TABLE (AREA)
		TOKEN_TABLE (SPACING)
		TOKEN_TABLE (ITEM_WIDTH)
		TOKEN_TABLE (ITEM_HEIGHT)
		TOKEN_TABLE (SCROLL_BY)
		TOKEN_TABLE (NAME)
		TOKEN_TABLE (CAPTION)
		TOKEN_TABLE (HIDE_SELECTED)
		TOKEN_TABLE (EDITOR_PROPERTY)
	TOKEN_TABLE_END
	
	BYTE* params;
	int cmd=2;
	CBParser parser(Game);
	bool always_visible=false;

	m_Exclusive = false;
	if(Complete)
	{
		if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_INVENTORY_BOX)
		{
			Game->LOG(0, "'INVENTORY_BOX' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while (cmd>0 && (cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
	{
		switch (cmd)
		{
			case TOKEN_TEMPLATE:
				if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC;
			break;

			case TOKEN_NAME:
				SetName((char*)params);
			break;

			case TOKEN_CAPTION:
				SetCaption((char*)params);
			break;

			case TOKEN_WINDOW:
				SAFE_DELETE(m_Window);
				m_Window = new CUIWindow(Game);				
				if(!m_Window || FAILED(m_Window->LoadBuffer(params, false)))
				{
					SAFE_DELETE(m_Window);
					cmd = PARSERR_GENERIC;
				}
				else Game->RegisterObject(m_Window);
			break;

			case TOKEN_AREA:
				parser.ScanStr((char*)params, "%d,%d,%d,%d", &m_ItemsArea.left, &m_ItemsArea.top, &m_ItemsArea.right, &m_ItemsArea.bottom);
			break;

			case TOKEN_EXCLUSIVE:
				parser.ScanStr((char*)params, "%b", &m_Exclusive);
			break;

			case TOKEN_HIDE_SELECTED:
				parser.ScanStr((char*)params, "%b", &m_HideSelected);
			break;

			case TOKEN_ALWAYS_VISIBLE:
				parser.ScanStr((char*)params, "%b", &always_visible);
			break;

			case TOKEN_SPACING:
				parser.ScanStr((char*)params, "%d", &m_Spacing);
			break;

			case TOKEN_ITEM_WIDTH:
				parser.ScanStr((char*)params, "%d", &m_ItemWidth);
			break;

			case TOKEN_ITEM_HEIGHT:
				parser.ScanStr((char*)params, "%d", &m_ItemHeight);
			break;

			case TOKEN_SCROLL_BY:
				parser.ScanStr((char*)params, "%d", &m_ScrollBy);
			break;

			case TOKEN_EDITOR_PROPERTY:
				ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND)
	{
		Game->LOG(0, "Syntax error in INVENTORY_BOX definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC)
	{
		Game->LOG(0, "Error loading INVENTORY_BOX definition");
		return E_FAIL;
	}

	if(m_Exclusive)
	{
		SAFE_DELETE(m_CloseButton);
		m_CloseButton = new CUIButton(Game);
		if(m_CloseButton)
		{
			m_CloseButton->SetName("close");
			m_CloseButton->SetListener(this, m_CloseButton, 0);
			m_CloseButton->m_Parent = m_Window;
		}
	}

	m_Visible = always_visible;

	if(m_Window)
	{
		for(int i=0; i<m_Window->m_Widgets.GetSize(); i++)
		{
			if(!m_Window->m_Widgets[i]->m_ListenerObject)
				m_Window->m_Widgets[i]->SetListener(this, m_Window->m_Widgets[i], 0);
		}
	}

	return S_OK;
}
예제 #6
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CUITiledImage::LoadBuffer(byte  *Buffer, bool Complete) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(TILED_IMAGE)
	TOKEN_TABLE(TEMPLATE)
	TOKEN_TABLE(IMAGE)
	TOKEN_TABLE(UP_LEFT)
	TOKEN_TABLE(UP_RIGHT)
	TOKEN_TABLE(UP_MIDDLE)
	TOKEN_TABLE(DOWN_LEFT)
	TOKEN_TABLE(DOWN_RIGHT)
	TOKEN_TABLE(DOWN_MIDDLE)
	TOKEN_TABLE(MIDDLE_LEFT)
	TOKEN_TABLE(MIDDLE_RIGHT)
	TOKEN_TABLE(MIDDLE_MIDDLE)
	TOKEN_TABLE(VERTICAL_TILES)
	TOKEN_TABLE(HORIZONTAL_TILES)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE_END

	byte *params;
	int cmd;
	CBParser parser(Game);
	bool HTiles = false, VTiles = false;
	int H1 = 0, H2 = 0, H3 = 0;
	int V1 = 0, V2 = 0, V3 = 0;

	if (Complete) {
		if (parser.GetCommand((char **)&Buffer, commands, (char **)&params) != TOKEN_TILED_IMAGE) {
			Game->LOG(0, "'TILED_IMAGE' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while ((cmd = parser.GetCommand((char **)&Buffer, commands, (char **)&params)) > 0) {
		switch (cmd) {
		case TOKEN_TEMPLATE:
			if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_IMAGE:
			SAFE_DELETE(m_Image);
			m_Image = new CBSubFrame(Game);
			if (!m_Image || FAILED(m_Image->SetSurface((char *)params))) {
				SAFE_DELETE(m_Image);
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_UP_LEFT:
			parser.ScanStr((char *)params, "%d,%d,%d,%d", &m_UpLeft.left, &m_UpLeft.top, &m_UpLeft.right, &m_UpLeft.bottom);
			break;

		case TOKEN_UP_RIGHT:
			parser.ScanStr((char *)params, "%d,%d,%d,%d", &m_UpRight.left, &m_UpRight.top, &m_UpRight.right, &m_UpRight.bottom);
			break;

		case TOKEN_UP_MIDDLE:
			parser.ScanStr((char *)params, "%d,%d,%d,%d", &m_UpMiddle.left, &m_UpMiddle.top, &m_UpMiddle.right, &m_UpMiddle.bottom);
			break;

		case TOKEN_DOWN_LEFT:
			parser.ScanStr((char *)params, "%d,%d,%d,%d", &m_DownLeft.left, &m_DownLeft.top, &m_DownLeft.right, &m_DownLeft.bottom);
			break;

		case TOKEN_DOWN_RIGHT:
			parser.ScanStr((char *)params, "%d,%d,%d,%d", &m_DownRight.left, &m_DownRight.top, &m_DownRight.right, &m_DownRight.bottom);
			break;

		case TOKEN_DOWN_MIDDLE:
			parser.ScanStr((char *)params, "%d,%d,%d,%d", &m_DownMiddle.left, &m_DownMiddle.top, &m_DownMiddle.right, &m_DownMiddle.bottom);
			break;

		case TOKEN_MIDDLE_LEFT:
			parser.ScanStr((char *)params, "%d,%d,%d,%d", &m_MiddleLeft.left, &m_MiddleLeft.top, &m_MiddleLeft.right, &m_MiddleLeft.bottom);
			break;

		case TOKEN_MIDDLE_RIGHT:
			parser.ScanStr((char *)params, "%d,%d,%d,%d", &m_MiddleRight.left, &m_MiddleRight.top, &m_MiddleRight.right, &m_MiddleRight.bottom);
			break;

		case TOKEN_MIDDLE_MIDDLE:
			parser.ScanStr((char *)params, "%d,%d,%d,%d", &m_MiddleMiddle.left, &m_MiddleMiddle.top, &m_MiddleMiddle.right, &m_MiddleMiddle.bottom);
			break;

		case TOKEN_HORIZONTAL_TILES:
			parser.ScanStr((char *)params, "%d,%d,%d", &H1, &H2, &H3);
			HTiles = true;
			break;

		case TOKEN_VERTICAL_TILES:
			parser.ScanStr((char *)params, "%d,%d,%d", &V1, &V2, &V3);
			VTiles = true;
			break;

		case TOKEN_EDITOR_PROPERTY:
			ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		Game->LOG(0, "Syntax error in TILED_IMAGE definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC) {
		Game->LOG(0, "Error loading TILED_IMAGE definition");
		return E_FAIL;
	}

	if (VTiles && HTiles) {
		// up row
		CBPlatform::SetRect(&m_UpLeft,   0,     0, H1,       V1);
		CBPlatform::SetRect(&m_UpMiddle, H1,    0, H1 + H2,    V1);
		CBPlatform::SetRect(&m_UpRight,  H1 + H2, 0, H1 + H2 + H3, V1);

		// middle row
		CBPlatform::SetRect(&m_MiddleLeft,   0,     V1, H1,       V1 + V2);
		CBPlatform::SetRect(&m_MiddleMiddle, H1,    V1, H1 + H2,    V1 + V2);
		CBPlatform::SetRect(&m_MiddleRight,  H1 + H2, V1, H1 + H2 + H3, V1 + V2);

		// down row
		CBPlatform::SetRect(&m_DownLeft,   0,     V1 + V2, H1,       V1 + V2 + V3);
		CBPlatform::SetRect(&m_DownMiddle, H1,    V1 + V2, H1 + H2,    V1 + V2 + V3);
		CBPlatform::SetRect(&m_DownRight,  H1 + H2, V1 + V2, H1 + H2 + H3, V1 + V2 + V3);
	}

	// default
	if (m_Image && m_Image->m_Surface) {
		int Width = m_Image->m_Surface->GetWidth() / 3;
		int Height = m_Image->m_Surface->GetHeight() / 3;

		if (CBPlatform::IsRectEmpty(&m_UpLeft))   CBPlatform::SetRect(&m_UpLeft,   0,       0, Width,   Height);
		if (CBPlatform::IsRectEmpty(&m_UpMiddle)) CBPlatform::SetRect(&m_UpMiddle, Width,   0, 2 * Width, Height);
		if (CBPlatform::IsRectEmpty(&m_UpRight))  CBPlatform::SetRect(&m_UpRight,  2 * Width, 0, 3 * Width, Height);

		if (CBPlatform::IsRectEmpty(&m_MiddleLeft))   CBPlatform::SetRect(&m_MiddleLeft,   0,       Height, Width,   2 * Height);
		if (CBPlatform::IsRectEmpty(&m_MiddleMiddle)) CBPlatform::SetRect(&m_MiddleMiddle, Width,   Height, 2 * Width, 2 * Height);
		if (CBPlatform::IsRectEmpty(&m_MiddleRight))  CBPlatform::SetRect(&m_MiddleRight,  2 * Width, Height, 3 * Width, 2 * Height);

		if (CBPlatform::IsRectEmpty(&m_DownLeft))   CBPlatform::SetRect(&m_DownLeft,   0,       2 * Height, Width,   3 * Height);
		if (CBPlatform::IsRectEmpty(&m_DownMiddle)) CBPlatform::SetRect(&m_DownMiddle, Width,   2 * Height, 2 * Width, 3 * Height);
		if (CBPlatform::IsRectEmpty(&m_DownRight))  CBPlatform::SetRect(&m_DownRight,  2 * Width, 2 * Height, 3 * Width, 3 * Height);
	}

	return S_OK;
}
예제 #7
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdRegion::LoadBuffer(byte  *Buffer, bool Complete) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(REGION)
	TOKEN_TABLE(TEMPLATE)
	TOKEN_TABLE(NAME)
	TOKEN_TABLE(ACTIVE)
	TOKEN_TABLE(ZOOM)
	TOKEN_TABLE(SCALE)
	TOKEN_TABLE(BLOCKED)
	TOKEN_TABLE(DECORATION)
	TOKEN_TABLE(POINT)
	TOKEN_TABLE(ALPHA_COLOR)
	TOKEN_TABLE(ALPHA)
	TOKEN_TABLE(EDITOR_SELECTED_POINT)
	TOKEN_TABLE(EDITOR_SELECTED)
	TOKEN_TABLE(SCRIPT)
	TOKEN_TABLE(CAPTION)
	TOKEN_TABLE(PROPERTY)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE_END

	byte *params;
	int cmd;
	CBParser parser(Game);

	if (Complete) {
		if (parser.GetCommand((char **)&Buffer, commands, (char **)&params) != TOKEN_REGION) {
			Game->LOG(0, "'REGION' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	int i;

	for (i = 0; i < m_Points.GetSize(); i++) delete m_Points[i];
	m_Points.RemoveAll();

	int ar = 255, ag = 255, ab = 255, alpha = 255;

	while ((cmd = parser.GetCommand((char **)&Buffer, commands, (char **)&params)) > 0) {
		switch (cmd) {
		case TOKEN_TEMPLATE:
			if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_NAME:
			SetName((char *)params);
			break;

		case TOKEN_CAPTION:
			SetCaption((char *)params);
			break;

		case TOKEN_ACTIVE:
			parser.ScanStr((char *)params, "%b", &m_Active);
			break;

		case TOKEN_BLOCKED:
			parser.ScanStr((char *)params, "%b", &m_Blocked);
			break;

		case TOKEN_DECORATION:
			parser.ScanStr((char *)params, "%b", &m_Decoration);
			break;

		case TOKEN_ZOOM:
		case TOKEN_SCALE: {
			int i;
			parser.ScanStr((char *)params, "%d", &i);
			m_Zoom = (float)i;
		}
		break;

		case TOKEN_POINT: {
			int x, y;
			parser.ScanStr((char *)params, "%d,%d", &x, &y);
			m_Points.Add(new CBPoint(x, y));
		}
		break;

		case TOKEN_ALPHA_COLOR:
			parser.ScanStr((char *)params, "%d,%d,%d", &ar, &ag, &ab);
			break;

		case TOKEN_ALPHA:
			parser.ScanStr((char *)params, "%d", &alpha);
			break;

		case TOKEN_EDITOR_SELECTED:
			parser.ScanStr((char *)params, "%b", &m_EditorSelected);
			break;

		case TOKEN_EDITOR_SELECTED_POINT:
			parser.ScanStr((char *)params, "%d", &m_EditorSelectedPoint);
			break;

		case TOKEN_SCRIPT:
			AddScript((char *)params);
			break;

		case TOKEN_PROPERTY:
			ParseProperty(params, false);
			break;

		case TOKEN_EDITOR_PROPERTY:
			ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		Game->LOG(0, "Syntax error in REGION definition");
		return E_FAIL;
	}

	CreateRegion();

	m_Alpha = DRGBA(ar, ag, ab, alpha);

	return S_OK;
}
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdWaypointGroup::LoadBuffer(BYTE * Buffer, bool Complete)
{
	TOKEN_TABLE_START(commands)
		TOKEN_TABLE (WAYPOINTS)
		TOKEN_TABLE (TEMPLATE)
		TOKEN_TABLE (NAME)
		TOKEN_TABLE (POINT)
		TOKEN_TABLE (EDITOR_SELECTED_POINT)
		TOKEN_TABLE (EDITOR_SELECTED)
		TOKEN_TABLE (PROPERTY)
		TOKEN_TABLE (EDITOR_PROPERTY)
	TOKEN_TABLE_END
	
	BYTE* params;
	int cmd;
	CBParser parser(Game);

	if(Complete){
		if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_WAYPOINTS){
			Game->LOG(0, "'WAYPOINTS' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while ((cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
	{
		switch (cmd)
		{
			case TOKEN_TEMPLATE:
				if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC;
			break;

			case TOKEN_NAME:
				SetName((char*)params);
			break;

			case TOKEN_POINT:
			{
				int x,y;
				parser.ScanStr((char*)params, "%d,%d", &x, &y);
				m_Points.Add(new CBPoint(x, y));
			}
			break;

			case TOKEN_EDITOR_SELECTED:
				parser.ScanStr((char*)params, "%b", &m_EditorSelected);
			break;

			case TOKEN_EDITOR_SELECTED_POINT:
				parser.ScanStr((char*)params, "%d", &m_EditorSelectedPoint);
			break;

			case TOKEN_PROPERTY:
				ParseProperty(params, false);
			break;

			case TOKEN_EDITOR_PROPERTY:
				ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND){
		Game->LOG(0, "Syntax error in WAYPOINTS definition");
		return E_FAIL;
	}

	return S_OK;
}
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CUIWindow::LoadBuffer(BYTE* Buffer, bool Complete)
{
    TOKEN_TABLE_START(commands)
    TOKEN_TABLE (WINDOW)
    TOKEN_TABLE (ALPHA_COLOR)
    TOKEN_TABLE (ALPHA)
    TOKEN_TABLE (TEMPLATE)
    TOKEN_TABLE (DISABLED)
    TOKEN_TABLE (VISIBLE)
    TOKEN_TABLE (BACK_INACTIVE)
    TOKEN_TABLE (BACK)
    TOKEN_TABLE (IMAGE_INACTIVE)
    TOKEN_TABLE (IMAGE)
    TOKEN_TABLE (FONT_INACTIVE)
    TOKEN_TABLE (FONT)
    TOKEN_TABLE (TITLE_ALIGN)
    TOKEN_TABLE (TITLE_RECT)
    TOKEN_TABLE (TITLE)
    TOKEN_TABLE (DRAG_RECT)
    TOKEN_TABLE (X)
    TOKEN_TABLE (Y)
    TOKEN_TABLE (WIDTH)
    TOKEN_TABLE (HEIGHT)
    TOKEN_TABLE (FADE_ALPHA)
    TOKEN_TABLE (FADE_COLOR)
    TOKEN_TABLE (CURSOR)
    TOKEN_TABLE (NAME)
    TOKEN_TABLE (BUTTON)
    TOKEN_TABLE (STATIC)
    TOKEN_TABLE (TRANSPARENT)
    TOKEN_TABLE (SCRIPT)
    TOKEN_TABLE (CAPTION)
    TOKEN_TABLE (PARENT_NOTIFY)
    TOKEN_TABLE (MENU)
    TOKEN_TABLE (IN_GAME)
    TOKEN_TABLE (CLIP_CONTENTS)
    TOKEN_TABLE (PAUSE_MUSIC)
    TOKEN_TABLE (EDITOR_PROPERTY)
    TOKEN_TABLE (EDIT)
    TOKEN_TABLE_END

    BYTE* params;
    int cmd=2;
    CBParser parser(Game);

    int FadeR=0, FadeG=0, FadeB=0, FadeA=0;
    int ar=0, ag=0, ab=0, alpha=0;

    if(Complete)
    {
        if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_WINDOW)
        {
            Game->LOG(0, "'WINDOW' keyword expected.");
            return E_FAIL;
        }
        Buffer = params;
    }

    while (cmd >= PARSERR_TOKENNOTFOUND && (cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) >= PARSERR_TOKENNOTFOUND)
    {
        switch (cmd)
        {
        case TOKEN_TEMPLATE:
            if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC;
            break;

        case TOKEN_NAME:
            SetName((char*)params);
            break;

        case TOKEN_CAPTION:
            SetCaption((char*)params);
            break;

        case TOKEN_BACK:
            SAFE_DELETE(m_Back);
            m_Back = new CUITiledImage(Game);
            if(!m_Back || FAILED(m_Back->LoadFile((char*)params)))
            {
                SAFE_DELETE(m_Back);
                cmd = PARSERR_GENERIC;
            }
            break;

        case TOKEN_BACK_INACTIVE:
            SAFE_DELETE(m_BackInactive);
            m_BackInactive = new CUITiledImage(Game);
            if(!m_BackInactive || FAILED(m_BackInactive->LoadFile((char*)params)))
            {
                SAFE_DELETE(m_BackInactive);
                cmd = PARSERR_GENERIC;
            }
            break;

        case TOKEN_IMAGE:
            SAFE_DELETE(m_Image);
            m_Image = new CBSprite(Game);
            if(!m_Image || FAILED(m_Image->LoadFile((char*)params)))
            {
                SAFE_DELETE(m_Image);
                cmd = PARSERR_GENERIC;
            }
            break;

        case TOKEN_IMAGE_INACTIVE:
            SAFE_DELETE(m_ImageInactive);
            m_ImageInactive = new CBSprite(Game);
            if(!m_ImageInactive || FAILED(m_ImageInactive->LoadFile((char*)params)))
            {
                SAFE_DELETE(m_ImageInactive);
                cmd = PARSERR_GENERIC;
            }
            break;

        case TOKEN_FONT:
            if(m_Font) Game->m_FontStorage->RemoveFont(m_Font);
            m_Font = Game->m_FontStorage->AddFont((char*)params);
            if(!m_Font) cmd = PARSERR_GENERIC;
            break;

        case TOKEN_FONT_INACTIVE:
            if(m_FontInactive) Game->m_FontStorage->RemoveFont(m_FontInactive);
            m_FontInactive = Game->m_FontStorage->AddFont((char*)params);
            if(!m_FontInactive) cmd = PARSERR_GENERIC;
            break;

        case TOKEN_TITLE:
            SetText((char*)params);
            Game->m_StringTable->Expand(&m_Text);
            break;

        case TOKEN_TITLE_ALIGN:
            if(CBPlatform::stricmp((char*)params, "left")==0) m_TitleAlign = TAL_LEFT;
            else if(CBPlatform::stricmp((char*)params, "right")==0) m_TitleAlign = TAL_RIGHT;
            else m_TitleAlign = TAL_CENTER;
            break;

        case TOKEN_TITLE_RECT:
            parser.ScanStr((char*)params, "%d,%d,%d,%d", &m_TitleRect.left, &m_TitleRect.top, &m_TitleRect.right, &m_TitleRect.bottom);
            break;

        case TOKEN_DRAG_RECT:
            parser.ScanStr((char*)params, "%d,%d,%d,%d", &m_DragRect.left, &m_DragRect.top, &m_DragRect.right, &m_DragRect.bottom);
            break;

        case TOKEN_X:
            parser.ScanStr((char*)params, "%d", &m_PosX);
            break;

        case TOKEN_Y:
            parser.ScanStr((char*)params, "%d", &m_PosY);
            break;

        case TOKEN_WIDTH:
            parser.ScanStr((char*)params, "%d", &m_Width);
            break;

        case TOKEN_HEIGHT:
            parser.ScanStr((char*)params, "%d", &m_Height);
            break;

        case TOKEN_CURSOR:
            SAFE_DELETE(m_Cursor);
            m_Cursor = new CBSprite(Game);
            if(!m_Cursor || FAILED(m_Cursor->LoadFile((char*)params)))
            {
                SAFE_DELETE(m_Cursor);
                cmd = PARSERR_GENERIC;
            }
            break;

        case TOKEN_BUTTON:
        {
            CUIButton* btn = new CUIButton(Game);
            if(!btn || FAILED(btn->LoadBuffer(params, false)))
            {
                SAFE_DELETE(btn);
                cmd = PARSERR_GENERIC;
            }
            else
            {
                btn->m_Parent = this;
                m_Widgets.Add(btn);
            }
        }
        break;

        case TOKEN_STATIC:
        {
            CUIText* text = new CUIText(Game);
            if(!text || FAILED(text->LoadBuffer(params, false)))
            {
                SAFE_DELETE(text);
                cmd = PARSERR_GENERIC;
            }
            else
            {
                text->m_Parent = this;
                m_Widgets.Add(text);
            }
        }
        break;

        case TOKEN_EDIT:
        {
            CUIEdit* edit = new CUIEdit(Game);
            if(!edit || FAILED(edit->LoadBuffer(params, false)))
            {
                SAFE_DELETE(edit);
                cmd = PARSERR_GENERIC;
            }
            else
            {
                edit->m_Parent = this;
                m_Widgets.Add(edit);
            }
        }
        break;

        case TOKEN_WINDOW:
        {
            CUIWindow* win = new CUIWindow(Game);
            if(!win || FAILED(win->LoadBuffer(params, false)))
            {
                SAFE_DELETE(win);
                cmd = PARSERR_GENERIC;
            }
            else
            {
                win->m_Parent = this;
                m_Widgets.Add(win);
            }
        }
        break;


        case TOKEN_TRANSPARENT:
            parser.ScanStr((char*)params, "%b", &m_Transparent);
            break;

        case TOKEN_SCRIPT:
            AddScript((char*)params);
            break;

        case TOKEN_PARENT_NOTIFY:
            parser.ScanStr((char*)params, "%b", &m_ParentNotify);
            break;

        case TOKEN_PAUSE_MUSIC:
            parser.ScanStr((char*)params, "%b", &m_PauseMusic);
            break;

        case TOKEN_DISABLED:
            parser.ScanStr((char*)params, "%b", &m_Disable);
            break;

        case TOKEN_VISIBLE:
            parser.ScanStr((char*)params, "%b", &m_Visible);
            break;

        case TOKEN_MENU:
            parser.ScanStr((char*)params, "%b", &m_IsMenu);
            break;

        case TOKEN_IN_GAME:
            parser.ScanStr((char*)params, "%b", &m_InGame);
            break;

        case TOKEN_CLIP_CONTENTS:
            parser.ScanStr((char*)params, "%b", &m_ClipContents);
            break;

        case TOKEN_FADE_COLOR:
            parser.ScanStr((char*)params, "%d,%d,%d", &FadeR, &FadeG, &FadeB);
            m_FadeBackground = true;
            break;

        case TOKEN_FADE_ALPHA:
            parser.ScanStr((char*)params, "%d", &FadeA);
            m_FadeBackground = true;
            break;

        case TOKEN_EDITOR_PROPERTY:
            ParseEditorProperty(params, false);
            break;

        case TOKEN_ALPHA_COLOR:
            parser.ScanStr((char*)params, "%d,%d,%d", &ar, &ag, &ab);
            break;

        case TOKEN_ALPHA:
            parser.ScanStr((char*)params, "%d", &alpha);
            break;


        default:
            if(FAILED(Game->WindowLoadHook(this, (char**)&Buffer, (char**)params)))
            {
                cmd = PARSERR_GENERIC;
            }
        }
    }
    if (cmd == PARSERR_TOKENNOTFOUND)
    {
        Game->LOG(0, "Syntax error in WINDOW definition");
        return E_FAIL;
    }
    if (cmd == PARSERR_GENERIC)
    {
        Game->LOG(0, "Error loading WINDOW definition");
        return E_FAIL;
    }

    CorrectSize();

    if(alpha != 0 && ar==0 && ag == 0 && ab == 0)
    {
        ar = ag = ab = 255;
    }
    m_AlphaColor = DRGBA(ar, ag, ab, alpha);

    if(m_FadeBackground) m_FadeColor = DRGBA(FadeR, FadeG, FadeB, FadeA);

    m_FocusedWidget = NULL;

    return S_OK;
}
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////
HRESULT CBSprite::LoadBuffer(BYTE* Buffer, bool Complete, int LifeTime, TSpriteCacheType CacheType)
{
	TOKEN_TABLE_START(commands)
		TOKEN_TABLE (CONTINUOUS)
		TOKEN_TABLE (SPRITE)
		TOKEN_TABLE (LOOPING)
		TOKEN_TABLE (FRAME)
		TOKEN_TABLE (NAME)
		TOKEN_TABLE (PRECISE)
		TOKEN_TABLE (EDITOR_MUTED)
		TOKEN_TABLE (STREAMED_KEEP_LOADED)
		TOKEN_TABLE (STREAMED)
		TOKEN_TABLE (SCRIPT)
		TOKEN_TABLE (EDITOR_BG_FILE)
		TOKEN_TABLE (EDITOR_BG_OFFSET_X)
		TOKEN_TABLE (EDITOR_BG_OFFSET_Y)
		TOKEN_TABLE (EDITOR_BG_ALPHA)
		TOKEN_TABLE (EDITOR_PROPERTY)
	TOKEN_TABLE_END
	
	BYTE* params;
	int cmd;
	CBParser parser(Game);

	Cleanup();


	if(Complete)
	{
		if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_SPRITE)
		{
			Game->LOG(0, "'SPRITE' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	int frame_count = 1;
	CBFrame* frame;
	while ((cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
	{
		switch (cmd)
		{
			case TOKEN_CONTINUOUS:
				parser.ScanStr((char*)params, "%b", &m_Continuous);
			break;

			case TOKEN_EDITOR_MUTED:
				parser.ScanStr((char*)params, "%b", &m_EditorMuted);
			break;

			case TOKEN_SCRIPT:
				AddScript((char*)params);
			break;

			case TOKEN_LOOPING:
				parser.ScanStr((char*)params, "%b", &m_Looping);
			break;

			case TOKEN_PRECISE:
				parser.ScanStr((char*)params, "%b", &m_Precise);
			break;

			case TOKEN_STREAMED:
				parser.ScanStr((char*)params, "%b", &m_Streamed);				
				if(m_Streamed && LifeTime==-1)
				{
					LifeTime = 500;
					CacheType = CACHE_ALL;
				}
			break;

			case TOKEN_STREAMED_KEEP_LOADED:
				parser.ScanStr((char*)params, "%b", &m_StreamedKeepLoaded);
			break;

			case TOKEN_NAME:
				SetName((char*)params);
			break;

			case TOKEN_EDITOR_BG_FILE:
				if(Game->m_EditorMode)
				{
					SAFE_DELETE_ARRAY(m_EditorBgFile);
					m_EditorBgFile = new char[strlen((char*)params)+1];
					if(m_EditorBgFile) strcpy(m_EditorBgFile, (char*)params);
				}
			break;

			case TOKEN_EDITOR_BG_OFFSET_X:
				parser.ScanStr((char*)params, "%d", &m_EditorBgOffsetX);
			break;

			case TOKEN_EDITOR_BG_OFFSET_Y:
				parser.ScanStr((char*)params, "%d", &m_EditorBgOffsetY);
			break;

			case TOKEN_EDITOR_BG_ALPHA:
				parser.ScanStr((char*)params, "%d", &m_EditorBgAlpha);
				m_EditorBgAlpha = min(m_EditorBgAlpha, 255);
				m_EditorBgAlpha = max(m_EditorBgAlpha, 0);
			break;

			case TOKEN_FRAME:
			{
				int FrameLifeTime = LifeTime;
				if(CacheType==CACHE_HALF && frame_count%2!=1) FrameLifeTime = -1;

				frame = new CBFrame(Game);

				if(FAILED(frame->LoadBuffer(params, FrameLifeTime, m_StreamedKeepLoaded)))
				{
					delete frame;
					Game->LOG(0, "Error parsing frame %d", frame_count);
					return E_FAIL;
				}

				m_Frames.Add(frame);
				frame_count++;
				if(m_CurrentFrame==-1) m_CurrentFrame = 0;
			}
			break;

			case TOKEN_EDITOR_PROPERTY:
				ParseEditorProperty(params, false);
			break;
		}
	}

	if (cmd == PARSERR_TOKENNOTFOUND)
	{
		Game->LOG(0, "Syntax error in SPRITE definition");
		return E_FAIL;
	}
	m_CanBreak = !m_Continuous;

	return S_OK;
}
예제 #11
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdLayer::LoadBuffer(BYTE * Buffer, bool Complete)
{
	TOKEN_TABLE_START(commands)
		TOKEN_TABLE (LAYER)
		TOKEN_TABLE (TEMPLATE)
		TOKEN_TABLE (NAME)
		TOKEN_TABLE (WIDTH)
		TOKEN_TABLE (HEIGHT)
		TOKEN_TABLE (MAIN)
		TOKEN_TABLE (ENTITY)
		TOKEN_TABLE (REGION)
		TOKEN_TABLE (ACTIVE)
		TOKEN_TABLE (EDITOR_SELECTED)
		TOKEN_TABLE (SCRIPT)
		TOKEN_TABLE (CAPTION)
		TOKEN_TABLE (PROPERTY)
		TOKEN_TABLE (CLOSE_UP)
		TOKEN_TABLE (EDITOR_PROPERTY)
	TOKEN_TABLE_END
	
	BYTE* params;
	int cmd;
	CBParser parser(Game);

	if(Complete){
		if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_LAYER){
			Game->LOG(0, "'LAYER' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while ((cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
	{
		switch (cmd)
		{
			case TOKEN_TEMPLATE:
				if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC;
			break;

			case TOKEN_NAME:
				SetName((char*)params);
			break;

			case TOKEN_CAPTION:
				SetCaption((char*)params);
			break;

			case TOKEN_MAIN:
				parser.ScanStr((char*)params, "%b", &m_Main);
			break;

			case TOKEN_CLOSE_UP:
				parser.ScanStr((char*)params, "%b", &m_CloseUp);
			break;

			case TOKEN_WIDTH:
				parser.ScanStr((char*)params, "%d", &m_Width);
			break;

			case TOKEN_HEIGHT:
				parser.ScanStr((char*)params, "%d", &m_Height);
			break;

			case TOKEN_ACTIVE:
				parser.ScanStr((char*)params, "%b", &m_Active);
			break;

			case TOKEN_REGION:
			{
				CAdRegion* region = new CAdRegion(Game);
				CAdSceneNode* node = new CAdSceneNode(Game);
				if(!region || !node || FAILED(region->LoadBuffer(params, false))){
					cmd = PARSERR_GENERIC;
					SAFE_DELETE(region);
					SAFE_DELETE(node);
				}
				else{
					node->SetRegion(region);
					m_Nodes.Add(node);
				}
			}
			break;

			case TOKEN_ENTITY:
			{
				CAdEntity* entity = new CAdEntity(Game);
				CAdSceneNode* node = new CAdSceneNode(Game);
				if(entity) entity->m_Zoomable = false; // scene entites default to NOT zoom
				if(!entity || !node || FAILED(entity->LoadBuffer(params, false))){
					cmd = PARSERR_GENERIC;
					SAFE_DELETE(entity);
					SAFE_DELETE(node);
				}
				else{					
					node->SetEntity(entity);
					m_Nodes.Add(node);
				}
			}
			break;

			case TOKEN_EDITOR_SELECTED:
				parser.ScanStr((char*)params, "%b", &m_EditorSelected);
			break;

			case TOKEN_SCRIPT:
				AddScript((char*)params);
			break;

			case TOKEN_PROPERTY:
				ParseProperty(params, false);
			break;

			case TOKEN_EDITOR_PROPERTY:
				ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND){
		Game->LOG(0, "Syntax error in LAYER definition");
		return E_FAIL;
	}

	return S_OK;
}
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdActor::LoadBuffer(BYTE * Buffer, bool Complete)
{
	TOKEN_TABLE_START(commands)
		TOKEN_TABLE (ACTOR)
		TOKEN_TABLE (X)
		TOKEN_TABLE (Y)
		TOKEN_TABLE (TEMPLATE)
		TOKEN_TABLE (NAME)
		TOKEN_TABLE (SCALABLE)
		TOKEN_TABLE (REGISTRABLE)
		TOKEN_TABLE (INTERACTIVE)
		TOKEN_TABLE (SHADOWABLE)
		TOKEN_TABLE (COLORABLE)
		TOKEN_TABLE (ACTIVE)
		TOKEN_TABLE (WALK)
		TOKEN_TABLE (STAND)
		TOKEN_TABLE (TALK_SPECIAL)
		TOKEN_TABLE (TALK)
		TOKEN_TABLE (TURN_LEFT)
		TOKEN_TABLE (TURN_RIGHT)
		TOKEN_TABLE (EVENTS)
		TOKEN_TABLE (FONT)
		TOKEN_TABLE (CURSOR)
		TOKEN_TABLE (SCRIPT)
		TOKEN_TABLE (SOUND_VOLUME)
		TOKEN_TABLE (SOUND_PANNING)
		TOKEN_TABLE (CAPTION)
		TOKEN_TABLE (PROPERTY)
		TOKEN_TABLE (BLOCKED_REGION)
		TOKEN_TABLE (WAYPOINTS)
		TOKEN_TABLE (IGNORE_ITEMS)
		TOKEN_TABLE (ROTABLE)
		TOKEN_TABLE (ROTATABLE)
		TOKEN_TABLE (ALPHA_COLOR)
		TOKEN_TABLE (SCALE)
		TOKEN_TABLE (RELATIVE_SCALE)
		TOKEN_TABLE (ALPHA)
		TOKEN_TABLE (EDITOR_PROPERTY)
		TOKEN_TABLE (ANIMATION)
	TOKEN_TABLE_END
	
	BYTE* params;
	int cmd;
	CBParser parser(Game);

	if(Complete)
	{
		if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_ACTOR)
		{
			Game->LOG(0, "'ACTOR' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	CAdGame* AdGame = (CAdGame*)Game;
	CAdSpriteSet* spr = NULL;
	int ar=0, ag=0, ab=0, alpha=0;
	while ((cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
	{
		switch (cmd)
		{
			case TOKEN_TEMPLATE:
				if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC;
			break;

			case TOKEN_X:
				parser.ScanStr((char*)params, "%d", &m_PosX);
			break;

			case TOKEN_Y:
				parser.ScanStr((char*)params, "%d", &m_PosY);
			break;

			case TOKEN_NAME:
				SetName((char*)params);
			break;

			case TOKEN_CAPTION:
				SetCaption((char*)params);
			break;

			case TOKEN_FONT:
				SetFont((char*)params);
			break;

			case TOKEN_SCALABLE:
				parser.ScanStr((char*)params, "%b", &m_Zoomable);
			break;

			case TOKEN_ROTABLE:
			case TOKEN_ROTATABLE:
				parser.ScanStr((char*)params, "%b", &m_Rotatable);
			break;

			case TOKEN_REGISTRABLE:
			case TOKEN_INTERACTIVE:
				parser.ScanStr((char*)params, "%b", &m_Registrable);
			break;

			case TOKEN_SHADOWABLE:
			case TOKEN_COLORABLE:
				parser.ScanStr((char*)params, "%b", &m_Shadowable);
			break;

			case TOKEN_ACTIVE:
				parser.ScanStr((char*)params, "%b", &m_Active);
			break;

			case TOKEN_WALK:
				SAFE_DELETE(m_WalkSprite);
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexWalkLifeTime, CACHE_HALF))) cmd = PARSERR_GENERIC;
				else m_WalkSprite = spr;
			break;

			case TOKEN_TALK:
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC;
				else m_TalkSprites.Add(spr);
			break;

			case TOKEN_TALK_SPECIAL:
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC;
				else m_TalkSpritesEx.Add(spr);
			break;

			case TOKEN_STAND:
				SAFE_DELETE(m_StandSprite);
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true, AdGame->m_TexStandLifeTime))) cmd = PARSERR_GENERIC;
				else m_StandSprite = spr;
			break;

			case TOKEN_TURN_LEFT:
				SAFE_DELETE(m_TurnLeftSprite);
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true))) cmd = PARSERR_GENERIC;
				else m_TurnLeftSprite = spr;
			break;

			case TOKEN_TURN_RIGHT:
				SAFE_DELETE(m_TurnRightSprite);
				spr = new CAdSpriteSet(Game, this);
				if(!spr || FAILED(spr->LoadBuffer(params, true))) cmd = PARSERR_GENERIC;
				else m_TurnRightSprite = spr;
			break;

			case TOKEN_SCRIPT:
				AddScript((char*)params);
			break;

			case TOKEN_CURSOR:
				SAFE_DELETE(m_Cursor);
				m_Cursor = new CBSprite(Game);
				if(!m_Cursor || FAILED(m_Cursor->LoadFile((char*)params)))
				{
					SAFE_DELETE(m_Cursor);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_SOUND_VOLUME:
				parser.ScanStr((char*)params, "%d", &m_SFXVolume);
			break;

			case TOKEN_SCALE:
			{
				int s;
				parser.ScanStr((char*)params, "%d", &s);
				m_Scale = (float)s;

			}
			break;

			case TOKEN_RELATIVE_SCALE:
			{
				int s;
				parser.ScanStr((char*)params, "%d", &s);
				m_RelativeScale = (float)s;

			}
			break;

			case TOKEN_SOUND_PANNING:
				parser.ScanStr((char*)params, "%b", &m_AutoSoundPanning);
			break;

			case TOKEN_PROPERTY:
				ParseProperty(params, false);
			break;

			case TOKEN_BLOCKED_REGION:
			{
				SAFE_DELETE(m_BlockRegion);
				SAFE_DELETE(m_CurrentBlockRegion);
				CBRegion* rgn = new CBRegion(Game);
				CBRegion* crgn = new CBRegion(Game);
				if(!rgn || !crgn || FAILED(rgn->LoadBuffer(params, false)))
				{
					SAFE_DELETE(m_BlockRegion);
					SAFE_DELETE(m_CurrentBlockRegion);
					cmd = PARSERR_GENERIC;
				}
				else{
					m_BlockRegion = rgn;
					m_CurrentBlockRegion = crgn;
					m_CurrentBlockRegion->Mimic(m_BlockRegion);
				}
			}
			break;

			case TOKEN_WAYPOINTS:
			{
				SAFE_DELETE(m_WptGroup);
				SAFE_DELETE(m_CurrentWptGroup);
				CAdWaypointGroup* wpt = new CAdWaypointGroup(Game);
				CAdWaypointGroup* cwpt = new CAdWaypointGroup(Game);
				if(!wpt || !cwpt || FAILED(wpt->LoadBuffer(params, false)))
				{
					SAFE_DELETE(m_WptGroup);
					SAFE_DELETE(m_CurrentWptGroup);
					cmd = PARSERR_GENERIC;
				}
				else{
					m_WptGroup = wpt;
					m_CurrentWptGroup = cwpt;
					m_CurrentWptGroup->Mimic(m_WptGroup);
				}
			}
			break;

			case TOKEN_IGNORE_ITEMS:
				parser.ScanStr((char*)params, "%b", &m_IgnoreItems);
			break;

			case TOKEN_ALPHA_COLOR:
				parser.ScanStr((char*)params, "%d,%d,%d", &ar, &ag, &ab);
			break;

			case TOKEN_ALPHA:
				parser.ScanStr((char*)params, "%d", &alpha);
			break;

			case TOKEN_EDITOR_PROPERTY:
				ParseEditorProperty(params, false);
			break;

			case TOKEN_ANIMATION:
			{
				CAdSpriteSet* Anim = new CAdSpriteSet(Game, this);
				if(!Anim || FAILED(Anim->LoadBuffer(params, false))) cmd = PARSERR_GENERIC;
				else m_Anims.Add(Anim);
			}
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND)
	{
		Game->LOG(0, "Syntax error in ACTOR definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC)
	{
		if(spr) delete spr;
		Game->LOG(0, "Error loading ACTOR definition");
		return E_FAIL;
	}
	
	if(alpha != 0 && ar==0 && ag == 0 && ab == 0)
	{
		ar = ag = ab = 255;
	}
	m_AlphaColor = DRGBA(ar, ag, ab, alpha);
	m_State = m_NextState = STATE_READY;

	return S_OK;
}
예제 #13
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdTalkNode::LoadBuffer(byte  *Buffer, bool Complete) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(ACTION)
	TOKEN_TABLE(SPRITESET_FILE)
	TOKEN_TABLE(SPRITESET)
	TOKEN_TABLE(SPRITE)
	TOKEN_TABLE(START_TIME)
	TOKEN_TABLE(END_TIME)
	TOKEN_TABLE(COMMENT)
	TOKEN_TABLE(PRECACHE)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE_END

	byte *params;
	int cmd;
	CBParser parser(Game);

	if (Complete) {
		if (parser.GetCommand((char **)&Buffer, commands, (char **)&params) != TOKEN_ACTION) {
			Game->LOG(0, "'ACTION' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	m_EndTime = 0;
	m_PlayToEnd = false;
	m_PreCache = false;

	while ((cmd = parser.GetCommand((char **)&Buffer, commands, (char **)&params)) > 0) {
		switch (cmd) {
		case TOKEN_SPRITE:
			CBUtils::SetString(&m_SpriteFilename, (char *)params);
			break;

		case TOKEN_SPRITESET_FILE:
			CBUtils::SetString(&m_SpriteSetFilename, (char *)params);
			break;

		case TOKEN_SPRITESET: {
			delete m_SpriteSet;
			m_SpriteSet = new CAdSpriteSet(Game);
			if (!m_SpriteSet || FAILED(m_SpriteSet->LoadBuffer(params, false))) {
				delete m_SpriteSet;
				m_SpriteSet = NULL;
				cmd = PARSERR_GENERIC;
			}
		}
		break;

		case TOKEN_START_TIME:
			parser.ScanStr((char *)params, "%d", &m_StartTime);
			break;

		case TOKEN_END_TIME:
			parser.ScanStr((char *)params, "%d", &m_EndTime);
			break;

		case TOKEN_PRECACHE:
			parser.ScanStr((char *)params, "%b", &m_PreCache);
			break;

		case TOKEN_COMMENT:
			if (Game->m_EditorMode) CBUtils::SetString(&m_Comment, (char *)params);
			break;

		case TOKEN_EDITOR_PROPERTY:
			ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		Game->LOG(0, "Syntax error in ACTION definition");
		return E_FAIL;
	}

	if (cmd == PARSERR_GENERIC) {
		Game->LOG(0, "Error loading ACTION definition");
		return E_FAIL;
	}

	if (m_EndTime == 0) m_PlayToEnd = true;
	else m_PlayToEnd = false;

	if (m_PreCache && m_SpriteFilename) {
		delete m_Sprite;
		m_Sprite = new CBSprite(Game);
		if (!m_Sprite || FAILED(m_Sprite->LoadFile(m_SpriteFilename))) return E_FAIL;
	}

	if (m_PreCache && m_SpriteSetFilename) {
		delete m_SpriteSet;
		m_SpriteSet = new CAdSpriteSet(Game);
		if (!m_SpriteSet || FAILED(m_SpriteSet->LoadFile(m_SpriteSetFilename))) return E_FAIL;
	}


	return S_OK;
}
예제 #14
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CUIEdit::LoadBuffer(byte  *Buffer, bool Complete) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(TEMPLATE)
	TOKEN_TABLE(DISABLED)
	TOKEN_TABLE(VISIBLE)
	TOKEN_TABLE(BACK)
	TOKEN_TABLE(IMAGE)
	TOKEN_TABLE(FONT_SELECTED)
	TOKEN_TABLE(FONT)
	TOKEN_TABLE(TEXT)
	TOKEN_TABLE(X)
	TOKEN_TABLE(Y)
	TOKEN_TABLE(WIDTH)
	TOKEN_TABLE(HEIGHT)
	TOKEN_TABLE(CURSOR_BLINK_RATE)
	TOKEN_TABLE(CURSOR)
	TOKEN_TABLE(FRAME_WIDTH)
	TOKEN_TABLE(NAME)
	TOKEN_TABLE(SCRIPT)
	TOKEN_TABLE(PARENT_NOTIFY)
	TOKEN_TABLE(MAX_LENGTH)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE(EDIT)
	TOKEN_TABLE(CAPTION)
	TOKEN_TABLE_END

	byte *params;
	int cmd = 2;
	CBParser parser(Game);

	if (Complete) {
		if (parser.GetCommand((char **)&Buffer, commands, (char **)&params) != TOKEN_EDIT) {
			Game->LOG(0, "'EDIT' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	while (cmd > 0 && (cmd = parser.GetCommand((char **)&Buffer, commands, (char **)&params)) > 0) {
		switch (cmd) {
		case TOKEN_TEMPLATE:
			if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_NAME:
			SetName((char *)params);
			break;

		case TOKEN_BACK:
			delete m_Back;
			m_Back = new CUITiledImage(Game);
			if (!m_Back || FAILED(m_Back->LoadFile((char *)params))) {
				delete m_Back;
				m_Back = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_IMAGE:
			delete m_Image;
			m_Image = new CBSprite(Game);
			if (!m_Image || FAILED(m_Image->LoadFile((char *)params))) {
				delete m_Image;
				m_Image = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_FONT:
			if (m_Font) Game->m_FontStorage->RemoveFont(m_Font);
			m_Font = Game->m_FontStorage->AddFont((char *)params);
			if (!m_Font) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_FONT_SELECTED:
			if (m_FontSelected) Game->m_FontStorage->RemoveFont(m_FontSelected);
			m_FontSelected = Game->m_FontStorage->AddFont((char *)params);
			if (!m_FontSelected) cmd = PARSERR_GENERIC;
			break;

		case TOKEN_TEXT:
			SetText((char *)params);
			Game->m_StringTable->Expand(&m_Text);
			break;

		case TOKEN_X:
			parser.ScanStr((char *)params, "%d", &m_PosX);
			break;

		case TOKEN_Y:
			parser.ScanStr((char *)params, "%d", &m_PosY);
			break;

		case TOKEN_WIDTH:
			parser.ScanStr((char *)params, "%d", &m_Width);
			break;

		case TOKEN_HEIGHT:
			parser.ScanStr((char *)params, "%d", &m_Height);
			break;

		case TOKEN_MAX_LENGTH:
			parser.ScanStr((char *)params, "%d", &m_MaxLength);
			break;

		case TOKEN_CAPTION:
			SetCaption((char *)params);
			break;

		case TOKEN_CURSOR:
			delete m_Cursor;
			m_Cursor = new CBSprite(Game);
			if (!m_Cursor || FAILED(m_Cursor->LoadFile((char *)params))) {
				delete m_Cursor;
				m_Cursor = NULL;
				cmd = PARSERR_GENERIC;
			}
			break;

		case TOKEN_CURSOR_BLINK_RATE:
			parser.ScanStr((char *)params, "%d", &m_CursorBlinkRate);
			break;

		case TOKEN_FRAME_WIDTH:
			parser.ScanStr((char *)params, "%d", &m_FrameWidth);
			break;

		case TOKEN_SCRIPT:
			AddScript((char *)params);
			break;

		case TOKEN_PARENT_NOTIFY:
			parser.ScanStr((char *)params, "%b", &m_ParentNotify);
			break;

		case TOKEN_DISABLED:
			parser.ScanStr((char *)params, "%b", &m_Disable);
			break;

		case TOKEN_VISIBLE:
			parser.ScanStr((char *)params, "%b", &m_Visible);
			break;

		case TOKEN_EDITOR_PROPERTY:
			ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		Game->LOG(0, "Syntax error in EDIT definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC) {
		Game->LOG(0, "Error loading EDIT definition");
		return E_FAIL;
	}

	CorrectSize();

	return S_OK;
}
예제 #15
0
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdItem::LoadBuffer(BYTE* Buffer, bool Complete)
{
	TOKEN_TABLE_START(commands)
		TOKEN_TABLE (ITEM)
		TOKEN_TABLE (TEMPLATE)
		TOKEN_TABLE (CURSOR_HOVER)
		TOKEN_TABLE (CURSOR_COMBINED)
		TOKEN_TABLE (CURSOR)
		TOKEN_TABLE (NAME)
		TOKEN_TABLE (IMAGE_HOVER)
		TOKEN_TABLE (IMAGE)
		TOKEN_TABLE (EVENTS)
		TOKEN_TABLE (SCRIPT)
		TOKEN_TABLE (CAPTION)
		TOKEN_TABLE (PROPERTY)
		TOKEN_TABLE (EDITOR_PROPERTY)
		TOKEN_TABLE (FONT)
		TOKEN_TABLE (ALPHA_COLOR)
		TOKEN_TABLE (ALPHA)
		TOKEN_TABLE (TALK_SPECIAL)
		TOKEN_TABLE (TALK)
		TOKEN_TABLE (SPRITE_HOVER)
		TOKEN_TABLE (SPRITE)
		TOKEN_TABLE (DISPLAY_AMOUNT)
		TOKEN_TABLE (AMOUNT_OFFSET_X)
		TOKEN_TABLE (AMOUNT_OFFSET_Y)
		TOKEN_TABLE (AMOUNT_ALIGN)
		TOKEN_TABLE (AMOUNT_STRING)
		TOKEN_TABLE (AMOUNT)
	TOKEN_TABLE_END
	
	BYTE* params;
	int cmd=2;
	CBParser parser(Game);

	if(Complete){
		if(parser.GetCommand ((char**)&Buffer, commands, (char**)&params)!=TOKEN_ITEM){
			Game->LOG(0, "'ITEM' keyword expected.");
			return E_FAIL;
		}
		Buffer = params;
	}

	int ar=0, ag=0, ab=0, alpha=255;
	while (cmd>0 && (cmd = parser.GetCommand ((char**)&Buffer, commands, (char**)&params)) > 0)
	{
		switch (cmd)
		{
			case TOKEN_TEMPLATE:
				if(FAILED(LoadFile((char*)params))) cmd = PARSERR_GENERIC;
			break;

			case TOKEN_NAME:
				SetName((char*)params);
			break;

			case TOKEN_FONT:
				SetFont((char*)params);
			break;

			case TOKEN_CAPTION:
				SetCaption((char*)params);
			break;

			case TOKEN_IMAGE:
			case TOKEN_SPRITE:
				SAFE_DELETE(m_Sprite);
				m_Sprite = new CBSprite(Game, this);
				if(!m_Sprite || FAILED(m_Sprite->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_Sprite);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_IMAGE_HOVER:
			case TOKEN_SPRITE_HOVER:
				SAFE_DELETE(m_SpriteHover);
				m_SpriteHover = new CBSprite(Game, this);
				if(!m_SpriteHover || FAILED(m_SpriteHover->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_SpriteHover);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_AMOUNT:
				parser.ScanStr((char*)params, "%d", &m_Amount);
			break;

			case TOKEN_DISPLAY_AMOUNT:
				parser.ScanStr((char*)params, "%b", &m_DisplayAmount);
			break;

			case TOKEN_AMOUNT_OFFSET_X:
				parser.ScanStr((char*)params, "%d", &m_AmountOffsetX);
			break;

			case TOKEN_AMOUNT_OFFSET_Y:
				parser.ScanStr((char*)params, "%d", &m_AmountOffsetY);
			break;

			case TOKEN_AMOUNT_ALIGN:
				if(CBPlatform::stricmp((char*)params, "left")==0) m_AmountAlign = TAL_LEFT;
				else if(CBPlatform::stricmp((char*)params, "right")==0) m_AmountAlign = TAL_RIGHT;
				else m_AmountAlign = TAL_CENTER;
			break;

			case TOKEN_AMOUNT_STRING:
				CBUtils::SetString(&m_AmountString, (char*)params);
			break;

			case TOKEN_TALK:
			{
				CBSprite* spr = new CBSprite(Game, this);
				if(!spr || FAILED(spr->LoadFile((char*)params, ((CAdGame*)Game)->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC;
				else m_TalkSprites.Add(spr);
			}
			break;

			case TOKEN_TALK_SPECIAL:
			{
				CBSprite* spr = new CBSprite(Game, this);
				if(!spr || FAILED(spr->LoadFile((char*)params, ((CAdGame*)Game)->m_TexTalkLifeTime))) cmd = PARSERR_GENERIC;
				else m_TalkSpritesEx.Add(spr);
			}
			break;

			case TOKEN_CURSOR:
				SAFE_DELETE(m_CursorNormal);
				m_CursorNormal = new CBSprite(Game);
				if(!m_CursorNormal || FAILED(m_CursorNormal->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_CursorNormal);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_CURSOR_HOVER:
				SAFE_DELETE(m_CursorHover);
				m_CursorHover = new CBSprite(Game);
				if(!m_CursorHover || FAILED(m_CursorHover->LoadFile((char*)params, ((CAdGame*)Game)->m_TexItemLifeTime))){
					SAFE_DELETE(m_CursorHover);
					cmd = PARSERR_GENERIC;
				}
			break;

			case TOKEN_CURSOR_COMBINED:
				parser.ScanStr((char*)params, "%b", &m_CursorCombined);
			break;

			case TOKEN_SCRIPT:
				AddScript((char*)params);
			break;

			case TOKEN_PROPERTY:
				ParseProperty(params, false);
			break;

			case TOKEN_ALPHA_COLOR:
				parser.ScanStr((char*)params, "%d,%d,%d", &ar, &ag, &ab);
				break;

			case TOKEN_ALPHA:
				parser.ScanStr((char*)params, "%d", &alpha);
			break;

			case TOKEN_EDITOR_PROPERTY:
				ParseEditorProperty(params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND){
		Game->LOG(0, "Syntax error in ITEM definition");
		return E_FAIL;
	}
	if (cmd == PARSERR_GENERIC){
		Game->LOG(0, "Error loading ITEM definition");
		return E_FAIL;
	}

	if(alpha != 0 && ar==0 && ag == 0 && ab == 0){
		ar = ag = ab = 255;
	}
	m_AlphaColor = DRGBA(ar, ag, ab, alpha);

	return S_OK;
}