コード例 #1
0
ファイル: importtilesdlg.cpp プロジェクト: andyfriesen/ika
void ImportTilesDlg::OnOk(wxCommandEvent& event)
{
    try
    {
        _width = atoi(XRCCTRL(*this, "edit_framewidth", wxTextCtrl)->GetValue());
        _height = atoi(XRCCTRL(*this, "edit_frameheight", wxTextCtrl)->GetValue());
        _numTiles = atoi(XRCCTRL(*this, "edit_numframes", wxTextCtrl)->GetValue());
        _rowSize = atoi(XRCCTRL(*this, "edit_rowsize", wxTextCtrl)->GetValue());
        _fileName = XRCCTRL(*this, "edit_filename", wxTextCtrl)->GetValue().c_str();
        _pad = XRCCTRL(*this, "check_padding", wxCheckBox)->GetValue();
        _autoCount = XRCCTRL(*this, "check_autocount", wxCheckBox)->GetValue();
        _append = XRCCTRL(*this, "check_append", wxCheckBox)->GetValue();

        if (!File::Exists(_fileName))   throw va("%s does not exist", _fileName.c_str());
        if (_width < 0 || _height < 0)  throw "The frame dimensions must be at least one pixel.";
        if (!_autoCount && _numTiles < 1) throw "Importing less than one frame doesn't make much sense.";
        if (_rowSize < 1)               throw "There should be at least one frame per row.";

        try
        {
            ImportTiles(_width, _height, _numTiles, _rowSize, _fileName, _pad, _autoCount);
            wxDialog::OnOK(event);
        }
        catch (std::exception ex)
        {
            throw va("Import error: %s", ex.what());
        }
    }
    catch (const char* msg)
    {
        wxMessageBox(msg, "Error", wxOK | wxCENTER, this);
    }
}
コード例 #2
0
BOOL CTileMapXML::ImportLayer(CMarkupTag* pcTag, CTileMap* pcMap)
{
	CMarkupTag*		pcName;
	CMarkupTag*		pcObjectClass;
	CMarkupTag*		pcTiles;
	CChars			szName;
	CChars			szObjectClass;
	BOOL			bResult;
	CTileType*		pcType;
	CTileLayer*		pcLayer;

	pcName = CMarkupTextParser::GetTag(pcTag, "Name");
	if (!pcName)
	{
		return FALSE;
	}
	pcObjectClass = CMarkupTextParser::GetTag(pcTag, "ObjectClass");
	if (!pcObjectClass)
	{
		return FALSE;
	}
	pcTiles = CMarkupTextParser::GetTag(pcTag, "Tiles");
	if (!pcTiles)
	{
		return FALSE;
	}

	szName.Init();
	pcName->GetText(&szName);
	if (szName.Empty())
	{
		szName.Kill();
		CMarkupTextParser::LogErrorTagWasEmpty(pcName);
		return FALSE;
	}

	szObjectClass.Init();
	pcObjectClass->GetText(&szObjectClass);
	if (szObjectClass.Empty())
	{
		szName.Kill();
		szObjectClass.Kill();
		CMarkupTextParser::LogErrorTagWasEmpty(pcObjectClass);
		return FALSE;
	}

	pcType = mpcWorld->GetType(szObjectClass.Text());
	if (!pcType)
	{
		CMarkupTextParser::LogError(pcObjectClass, "Could not find a TileType for Tag.");
		return FALSE;
	}

	pcLayer = pcMap->AddLayer(szName.Text(), pcType);

	bResult = ImportTiles(pcTiles, pcLayer);

	szObjectClass.Kill();
	szName.Kill();
	return bResult;
}