/*********************/ /*** TileSet Stuph ***/ /*********************/ #include "stdafx.h" #include "gl3d.h" #include #include #include #include "GLEnabledView.h" #include #include "Core.h" #include "TileSet.h" #include "GinTex.h" #include "utils.h" #include "MapEdit.h" #include "MapEditDoc.h" #include "MapEditView.h" #include "MainFrm.h" #include "TileSetDlg.h" /*****************************************************************************/ /*****************************************************************************/ /*** TileBank ****************************************************************/ /*****************************************************************************/ const float TileBrowserGap=0.2f; const float TileBrowserX0=0-TileBrowserGap/2; const float TileBrowserX1=1+TileBrowserGap/2; const float TileBrowserY0=0-TileBrowserGap/2; const float TileBrowserY1=1+TileBrowserGap/2; /*****************************************************************************/ CTileBank::CTileBank() { LoadFlag=FALSE; CurrentSet=0; LTile.Set=-1; RTile.Set=-1; AddTileSet("c:/temp/rockp/rockp.gin"); LTile.Set=0; LTile.Tile=1; RTile.Set=0; RTile.Tile=2; } /*****************************************************************************/ CTileBank::~CTileBank() { } /*****************************************************************************/ void CTileBank::AddTileSet(char *Filename) { TileSet.push_back(CTileSet(Filename)); LoadFlag=TRUE; } /*****************************************************************************/ void CTileBank::LoadTileSets(CCore *Core) { int ListSize=TileSet.size(); for (int i=0;iIsGridOn()); glDisable(GL_DEPTH_TEST); } else { TileSet[CurrentSet].Render2d(CamPos,LT,RT,CursorPos,Core->IsGridOn()); } } /*****************************************************************************/ void CTileBank::FindCursorPos(CCore *Core,CMapEditView *View,Vec &CamPos,CPoint &MousePos) { if (!TileSet.size()) return; // No tiles, return CursorPos=TileSet[CurrentSet].FindCursorPos(Core,View,CamPos,MousePos); } /*****************************************************************************/ /*** Gui *********************************************************************/ /*****************************************************************************/ void CTileBank::UpdateGUI(CCore *Core,BOOL IsTileView) { CMainFrame *Frm=(CMainFrame*)AfxGetApp()->GetMainWnd(); CTileSetDlg *TileSetDlg=(CTileSetDlg*)Frm->GetDialog(IDD_TILESET_DIALOG); int ListSize=TileSet.size(); TileSetDlg->TileSetList.ResetContent(); if (ListSize) { for (int i=0; iTileSetList.AddString(TileSet[i].GetName()); } TileSetDlg->TileSetList.SetCurSel(CurrentSet); // IsTileView=TRUE; } else { IsTileView=FALSE; } TileSetDlg->TileSetList.EnableWindow(IsTileView); } /*****************************************************************************/ /*** Functions ***************************************************************/ /*****************************************************************************/ BOOL CTileBank::TileSelect(sMapElem &ThisTile,sMapElem &OtherTile) { if (CursorPos==-1) return(FALSE); if (CurrentSet==OtherTile.Set && OtherTile.Tile==CursorPos) { // Dont assign if same as other Tile return(FALSE); } ThisTile.Set=CurrentSet; ThisTile.Tile=CursorPos; if (ThisTile.Tile==0) ThisTile.Set=0; // Always make zero tile, bank 0 (dunno why, just seems handy) return(TRUE); } /*****************************************************************************/ /*****************************************************************************/ /*** TileSet *****************************************************************/ /*****************************************************************************/ /*****************************************************************************/ CTileSet::CTileSet(char *_Filename) { char Drive[_MAX_DRIVE]; char Dir[_MAX_DIR]; char Fname[_MAX_FNAME]; char Ext[_MAX_EXT]; _splitpath(_Filename,Drive,Dir,Fname,Ext); sprintf(Path,"%s%s",Drive,Dir); sprintf(Name,"%s",Fname); Loaded=FALSE; } /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ CTileSet::~CTileSet() { } /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ void CTileSet::Load(CCore *Core) { CScene Scene; char Filename[256+64]; sprintf(Filename,"%s%s.%s",Path,Name,"Gin"); Scene.Load(Filename); CNode &ThisNode=Scene.GetSceneNode(0); int ChildCount=ThisNode.GetPruneChildCount(); Tile.push_back(CTile()); // Insert Blank for (int Child=0; ChildSetupPersMatrix(); glMatrixMode(GL_MODELVIEW); while(TileID!=ListSize) { int XPos=TileID%TileBrowserWidth; int YPos=TileID/TileBrowserWidth; glLoadIdentity(); glTranslatef(CamPos.x+XPos*(1+TileBrowserGap),CamPos.y-YPos*(1+TileBrowserGap),CamPos.z); glLoadName (TileID); glBegin (GL_QUADS); BuildGLQuad(TileBrowserX0,TileBrowserX1,TileBrowserY0,TileBrowserY1,0); glEnd(); TileID++; } HitCount= glRenderMode (GL_RENDER); glMatrixMode(GL_PROJECTION); glPopMatrix(); // Process hits GLuint *HitPtr=SelectBuffer; TileID=-1; if (HitCount) // Just take 1st { TileID=HitPtr[3]; } glMatrixMode(GL_MODELVIEW); // <-- Prevent arse GL assert return(TileID); }