diff --git a/Utils/MapEdit/Core.cpp b/Utils/MapEdit/Core.cpp index 4aa9ff3fb..5d20aba90 100644 --- a/Utils/MapEdit/Core.cpp +++ b/Utils/MapEdit/Core.cpp @@ -33,7 +33,10 @@ CCore::CCore() CurrentMousePos=CPoint(0,0); ActiveLayer=0; MapCam=Vec(0,0,0); + MapCamOfs=Vec(-15,10,0); TileCam=Vec(0,0,0); + TileCamOfs=Vec(-15,10,0); + Is3dFlag=TRUE; } @@ -64,11 +67,11 @@ CMultiBar *ParamBar=Frm->GetParamBar(); void CCore::New() { // Create Gfx Layers -// Name Width Height SizeDiv ViewDiv 3d? Resizable? - Layer.push_back(new CLayerTile( "Back", 32, 32, 1.0f, 4.0f, FALSE, FALSE)); - Layer.push_back(new CLayerTile( "Mid", TileLayerDefaultWidth, TileLayerDefaultHeight, 2.0f, 2.0f, FALSE, TRUE)); - Layer.push_back(new CLayerTile( "Action",TileLayerDefaultWidth, TileLayerDefaultHeight, 1.0f, 1.0f, TRUE, TRUE)); - Layer.push_back(new CLayerTile( "Fore", TileLayerDefaultWidth, TileLayerDefaultHeight, 0.5f, 0.5f, FALSE, TRUE)); +// Name Width Height SizeDiv ViewDiv 3d? Resizable? + Layer.push_back(new CLayerTile( "Back", 32, 32, 4.0f, 4.0f, FALSE, FALSE)); + Layer.push_back(new CLayerTile( "Mid", TileLayerDefaultWidth, TileLayerDefaultHeight, 2.0f, 2.0f, FALSE, TRUE)); + Layer.push_back(new CLayerTile( "Action", TileLayerDefaultWidth, TileLayerDefaultHeight, 1.0f, 1.0f, TRUE, TRUE)); +// Layer.push_back(new CLayerTile( "Fore", TileLayerDefaultWidth, TileLayerDefaultHeight, 0.5f, 0.5f, FALSE, TRUE)); ActiveLayer=LAYER_ACTION; MapCam=Vec(0,0,0); @@ -113,6 +116,7 @@ int LayerCount; } TileBank.Load(File,Version); Init(); + MapCam=Vec(0,0,0); } @@ -171,14 +175,14 @@ void CCore::RenderLayers(CMapEditView *View) { Vec &ThisCam=GetCam(); int ListSize=Layer.size(); - + for (int i=0;iRender(this,ThisCam,Is3dFlag); + if (GridFlag) Layer[i]->RenderGrid(this,ThisCam,i==ActiveLayer); } Layer[ActiveLayer]->RenderCursor(this,ThisCam,Is3dFlag); - if (GridFlag) Layer[ActiveLayer]->RenderGrid(this,ThisCam); // Get Cursor Pos LastCursorPos=CursorPos; @@ -294,8 +298,17 @@ Vec &ThisCam=GetCam(); Ofs.x*=XS; Ofs.y*=YS; - - UpdateView(View,Ofs); +/* if (nFlags & MK_CONTROL) + { // Move Ofs + Vec &CamOfs=GetCamOfs(); + Ofs.y=-Ofs.y; + CamOfs+=Ofs; + UpdateView(View); + } + else +*/ { + UpdateView(View,Ofs); + } } else { // Mouse still moved, so need to redraw windows, to get CursorPos (And pos render) @@ -349,23 +362,21 @@ int ListSize=Layer.size(); for (int i=0; iListBox.AddString(Layer[i]->GetName()); -// List->ListBox.SetCheck(i,Layer[i]->IsVisible()); } // Now sets checks (silly MSoft bug!!) for (i=0; iListBox.SetCheck(i,Layer[i]->IsVisible()); } - + List->ListBox.SetCurSel(ActiveLayer); } /*****************************************************************************/ -/* -void CCore::SetActiveLayer(int i) +void CCore::SetLayer(int Layer) { -// UpdateParamBar(NULL,ParamViewFlag); + ActiveLayer=Layer; } -*/ + /*****************************************************************************/ /*** Grid ********************************************************************/ /*****************************************************************************/ @@ -467,6 +478,16 @@ Vec &CCore::GetCam() } +/*****************************************************************************/ +Vec &CCore::GetCamOfs() +{ + if (TileViewFlag) + return(TileCamOfs); + else + return(MapCamOfs); + +} + /*****************************************************************************/ void CCore::UpdateGUI(CMapEditView *View) { @@ -517,20 +538,40 @@ void CCore::Toggle2d3d(CMapEditView *View) { Is3dFlag=!Is3dFlag; UpdateView(View); - - Export(); } /*****************************************************************************/ -void CCore::Export() + +Vec CCore::OffsetCam(Vec &Cam,float DivVal) +{ +Vec ThisCam; + + ThisCam=Cam/DivVal; + ThisCam.z=Cam.z; + ThisCam+=GetCamOfs(); + + return(ThisCam); +} + +/*****************************************************************************/ +void CCore::ExportAGB(char *Filename) { int LayerCount=Layer.size(); -CExportAGB Exp("c:/temp/test.c"); +char ExportName[256]; + + SetFileExt(Filename,ExportName,"C"); + +CExportAGB Exp(ExportName); for (int i=0;iExport(Exp); } Exp.ExportAll(this); - +} + +/*****************************************************************************/ +void CCore::ExportPSX(char *Filename) +{ + } \ No newline at end of file diff --git a/Utils/MapEdit/Core.h b/Utils/MapEdit/Core.h index bc420bfb8..68ef94263 100644 --- a/Utils/MapEdit/Core.h +++ b/Utils/MapEdit/Core.h @@ -39,7 +39,8 @@ public: void Render(CMapEditView *View,BOOL ForceRender=FALSE); void RenderLayers(CMapEditView *View); void RenderTileView(CMapEditView *View); - void Export(); + void ExportAGB(char *Filename); + void ExportPSX(char *Filename); // Control @@ -66,6 +67,7 @@ public: void UpdateParamBar(); // Layers + void SetLayer(int Layer); void UpdateLayerGUI(CMapEditView *View); // void SetActiveLayer(int Layer); // int GetActiveLayer() {return(ActiveLayer);} @@ -84,6 +86,8 @@ public: void UpdateView(CMapEditView *View,Vec Ofs=Vec(0,0,0)); Vec &GetCam(); + Vec &GetCamOfs(); + Vec OffsetCam(Vec &Cam,float DivVal); void SetCursorPos(CPoint &Pos) {CursorPos=Pos;} CPoint &GetCursorPos() {return(CursorPos);} @@ -98,6 +102,7 @@ private: CPoint CurrentMousePos,LastMousePos; CPoint CursorPos,LastCursorPos; Vec MapCam,TileCam; + Vec MapCamOfs,TileCamOfs; std::vector Layer; int ActiveLayer; @@ -106,6 +111,7 @@ private: CTexCache TexCache; + BOOL TileViewFlag; BOOL GridFlag; BOOL Is3dFlag; diff --git a/Utils/MapEdit/Export.cpp b/Utils/MapEdit/Export.cpp index 943f2fcfa..3b0ace127 100644 --- a/Utils/MapEdit/Export.cpp +++ b/Utils/MapEdit/Export.cpp @@ -17,7 +17,7 @@ /*****************************************************************************/ CExport::CExport(char *Filename) { - _splitpath(Filename,0,0,Name,0); + _splitpath(Filename,Drive,Path,Name,Ext); } /*****************************************************************************/ @@ -30,28 +30,42 @@ CExport::~CExport() void CExport::ExportAll(CCore *Core) { ExportTiles(Core); - } -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ -void CExport::ExportTileMap(char *LayerName,CMap &Map) -{ -int Width=Map.GetWidth(); -int Height=Map.GetHeight(); - ExportTileMapStart(LayerName,Width,Height); - for (int Y=0; Y UsedTileList; diff --git a/Utils/MapEdit/Layer.h b/Utils/MapEdit/Layer.h index f339720fd..169d32d8b 100644 --- a/Utils/MapEdit/Layer.h +++ b/Utils/MapEdit/Layer.h @@ -43,7 +43,7 @@ virtual int GetType()=0; virtual float GetLayerZPosDiv() {return(ZPosDiv);} virtual void Render(CCore *Core,Vec &CamPos,BOOL Is3d)=0; -virtual void RenderGrid(CCore *Core,Vec &CamPos)=0; +virtual void RenderGrid(CCore *Core,Vec &CamPos,BOOL Active)=0; virtual void FindCursorPos(CCore *Core,CMapEditView *View,Vec &CamPos,CPoint &MousePos)=0; virtual void RenderCursor(CCore *Core,Vec &CamPos,BOOL Is3d)=0; diff --git a/Utils/MapEdit/LayerTile.cpp b/Utils/MapEdit/LayerTile.cpp index 9a0169794..12f80c6bb 100644 --- a/Utils/MapEdit/LayerTile.cpp +++ b/Utils/MapEdit/LayerTile.cpp @@ -63,6 +63,13 @@ void CLayerTile::Load(CFile *File,float Version) File->Read(&VisibleFlag,sizeof(BOOL)); File->Read(&Mode,sizeof(MouseMode)); Map.Load(File,Version); + + TRACE1("%s ",Name); + TRACE1("Div:%g ",ZPosDiv); + TRACE1("Size:%g ",MapSizeDiv); + TRACE1("%i\n",VisibleFlag); + + } /*****************************************************************************/ @@ -93,8 +100,7 @@ void CLayerTile::Resize(int Width,int Height) /*****************************************************************************/ void CLayerTile::Render(CCore *Core,Vec &CamPos,BOOL Is3d) { -float XYDiv=GetLayerZPosDiv(); -Vec ThisCam=CamPos/XYDiv; +Vec ThisCam=Core->OffsetCam(CamPos,GetLayerZPosDiv()); if (Is3d && Render3dFlag) { @@ -112,7 +118,8 @@ Vec ThisCam=CamPos/XYDiv; void CLayerTile::RenderCursorPaint(CCore *Core,Vec &CamPos,BOOL Is3d) { CTileBank &TileBank=Core->GetTileBank(); -Vec ThisCam=CamPos; +//Vec ThisCam=CamPos; +Vec ThisCam=Core->OffsetCam(CamPos,GetLayerZPosDiv()); CPoint &CursPos=Core->GetCursorPos(); CMap &Brush=TileBank.GetActiveBrush(); @@ -142,8 +149,6 @@ int Height=ThisMap.GetHeight(); if (Alpha<1) { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Alpha Blend Style glColor4f(0.5,0.5,0.5,Alpha); } else @@ -168,30 +173,30 @@ int Height=ThisMap.GetHeight(); } } } - glDisable(GL_BLEND); } /*****************************************************************************/ -void CLayerTile::RenderGrid(CCore *Core,Vec &CamPos) +void CLayerTile::RenderGrid(CCore *Core,Vec &CamPos,BOOL Active) { -float XYDiv=GetLayerZPosDiv(); int Width=Map.GetWidth(); int Height=Map.GetHeight(); -float StartX=CamPos.x/XYDiv; -float StartY=CamPos.y/XYDiv; +Vec ThisCam=Core->OffsetCam(CamPos,GetLayerZPosDiv()); float OverVal=0.5; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(StartX,StartY,CamPos.z); + glTranslatef(ThisCam.x,ThisCam.y,ThisCam.z); glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); #ifdef UseLighting glNormal3f( 1,1,1); #endif - glColor3ub(255,255,255); + if (Active) + glColor3ub(255,255,255); + else + glColor3ub(127,127,127); for (int YLoop=0; YLoopGetCursorPos(); -float XYDiv=GetLayerZPosDiv(); int Width=Map.GetWidth(); int Height=Map.GetHeight(); -float StartX=CamPos.x/XYDiv; -float StartY=CamPos.y/XYDiv; +Vec ThisCam=Core->OffsetCam(CamPos,GetLayerZPosDiv()); glGetIntegerv(GL_VIEWPORT, Viewport); @@ -240,7 +243,7 @@ float StartY=CamPos.y/XYDiv; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(StartX,StartY,CamPos.z); + glTranslatef(ThisCam.x,ThisCam.y,ThisCam.z); for (int YLoop=0; YLoopSetFocus(); // Put control back to Window :o) } +/*********************************************************************************/ +void CMapEditDoc::SetLayer(int Layer) +{ + Core.SetLayer(Layer); + theApp.GetMainWnd()->SetFocus(); // Put control back to Window :o) +} + +/*********************************************************************************/ +/*********************************************************************************/ +/*********************************************************************************/ +void CMapEditDoc::OnExportAgb() +{ +char BASED_CODE AGBFilter[]= "AGB Data Type (*.c)|*.c|All Files (*.*)|*.*||"; +CFileDialog Dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,AGBFilter); + + if (Dlg.DoModal()!=IDOK) return; + +char Filename[256]; + sprintf(Filename,"%s",Dlg.GetPathName()); + + + Core.ExportAGB(Filename); +} + +/*********************************************************************************/ +void CMapEditDoc::OnExportPsx() +{ + +} + /*********************************************************************************/ /*** Tilebank Functions **********************************************************/ /*********************************************************************************/ diff --git a/Utils/MapEdit/MapEditDoc.h b/Utils/MapEdit/MapEditDoc.h index 1c1b232af..64c7c62f0 100644 --- a/Utils/MapEdit/MapEditDoc.h +++ b/Utils/MapEdit/MapEditDoc.h @@ -43,6 +43,7 @@ public: void TileBankSet(); void SetMode(int NewMode); + void SetLayer(int Layer); // Operations public: @@ -71,6 +72,8 @@ protected: protected: //{{AFX_MSG(CMapEditDoc) afx_msg void OnStatusCursorXY(CCmdUI *pCmdUI); + afx_msg void OnExportAgb(); + afx_msg void OnExportPsx(); //}}AFX_MSG DECLARE_MESSAGE_MAP() diff --git a/Utils/MapEdit/MapEditView.cpp b/Utils/MapEdit/MapEditView.cpp index 16ce7f0dd..7e277d297 100644 --- a/Utils/MapEdit/MapEditView.cpp +++ b/Utils/MapEdit/MapEditView.cpp @@ -82,9 +82,8 @@ void CMapEditView::OnCreateGL() glEnable(GL_COLOR_MATERIAL); // Enable Material Coloring #endif glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations -// glDisable(GL_BLEND); // Enable Alpha Channel -// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Alpha Blend Style - + glEnable(GL_BLEND); // Enable Alpha Channel + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Alpha Blend Style } @@ -99,6 +98,7 @@ void CMapEditView::OnDrawGL() void CMapEditView::OnSizeGL(int cx, int cy) { glViewport(0,0,cx,cy); + // update the camera glPushMatrix(); glMatrixMode(GL_PROJECTION); @@ -112,8 +112,22 @@ void CMapEditView::OnSizeGL(int cx, int cy) ///////////////////////////////////////////////////////////////////////////// void CMapEditView::SetupPersMatrix() { - gluPerspective(40.0,m_dAspectRatio,0.1f, 100.0f); - glTranslatef(0.0f,0.0f,-4.f); + gluPerspective(40.0,m_dAspectRatio,0.1f, 100.0f); + glTranslatef(0.0f,0.0f,-4.f); + +// GLint viewport[4]; + +// glGetIntegerv( GL_VIEWPORT, viewport ); +// glMatrixMode( GL_PROJECTION ); +// glLoadIdentity(); +// glOrtho( 0.0f, viewport[2]-viewport[0],viewport[3]-viewport[1], 0.0f, 0.1f, 100.0f); +// glOrtho( 0.0f, +30,+20, 0, 0.1f, 100.0f); +// glTranslatef(0.0f,0.0f,-0.f); + +// glMatrixMode( GL_MODELVIEW ); +// glLoadIdentity(); +// glTranslatef( 0.375, 0.375, 0.0 ); + } diff --git a/Utils/MapEdit/TexCache.cpp b/Utils/MapEdit/TexCache.cpp index 5652b2ef5..d6fad2851 100644 --- a/Utils/MapEdit/TexCache.cpp +++ b/Utils/MapEdit/TexCache.cpp @@ -107,13 +107,39 @@ void CTexCache::FreeBMP(sRGBData &RGBData) /**************************************************************************************/ void CTexCache::LoadTex(sTex &ThisTex,sRGBData *TexData) { - ThisTex.Width=TexData->Width; - ThisTex.Height=TexData->Height; +std::vector Buffer; +int Width=TexData->Width; +int Height=TexData->Height; +int Size=Width*Height; +// create RGB & alpha texture + Buffer.resize(Size*4); +u8 *RgbPtr=TexData->RGB; + + for (int i=0;iWidth, TexData->Height, 0, GL_RGB, GL_UNSIGNED_BYTE, TexData->RGB); + glTexImage2D(GL_TEXTURE_2D, 0, 4, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &Buffer[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); diff --git a/Utils/MapEdit/TexCache.h b/Utils/MapEdit/TexCache.h index eaf255bd4..2d1fd0f6d 100644 --- a/Utils/MapEdit/TexCache.h +++ b/Utils/MapEdit/TexCache.h @@ -29,6 +29,8 @@ struct sTex int Width,Height; }; +const RGBQUAD BlankRGB={255,0,255}; + /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ diff --git a/Utils/MapEdit/TileSet.cpp b/Utils/MapEdit/TileSet.cpp index 3042d250e..3f12c41e3 100644 --- a/Utils/MapEdit/TileSet.cpp +++ b/Utils/MapEdit/TileSet.cpp @@ -322,12 +322,67 @@ void CTileSet::Load(CCore *Core) /*****************************************************************************/ void CTileSet::Load2d(CCore *Core) { +char Filename[_MAX_PATH]; +CTexCache &TexCache=Core->GetTexCache(); +sRGBData ThisBmp; +sRGBData NewTex; -// _makepath( Filename, Drive, Path, Name, Ext); - - Tile.push_back(CTile()); // Insert Blank + _makepath( Filename, Drive, Path, Name, Ext); + TexCache.LoadBMP(Filename,ThisBmp); - Tile.push_back(CTile(Core,this,0,0)); +int Width=ThisBmp.Width/16; +int Height=ThisBmp.Height/16; +u8 Buffer[16*16*3]; + + + NewTex.Width=16; + NewTex.Height=16; + NewTex.RGB=Buffer; + + TRACE2("Load 2d TileBank (%i,%i)\n",Width,Height); + Tile.push_back(CTile(0)); // Insert Blank + + for (int Y=0; Y