Hooked the two scenes together
What the hell am I doing?
This commit is contained in:
@@ -109,14 +109,15 @@ void EditorApplication::LoadScene(SceneList sceneIndex) {
|
||||
switch(sceneIndex) {
|
||||
//add scene creation calls here
|
||||
case SceneList::FIRST:
|
||||
// case SceneList::TESTIFICATESCENE:
|
||||
// activeScene = new TestificateScene();
|
||||
// break;
|
||||
|
||||
case SceneList::EDITORSCENE:
|
||||
activeScene = new EditorScene();
|
||||
break;
|
||||
|
||||
case SceneList::TESTIFICATESCENE:
|
||||
activeScene = new TestificateScene();
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
throw(std::logic_error("Failed to recognize the scene index"));
|
||||
}
|
||||
|
||||
+30
-15
@@ -34,22 +34,26 @@ using namespace std;
|
||||
//-------------------------
|
||||
|
||||
EditorScene::EditorScene() {
|
||||
//create the debugging "window"
|
||||
debugInfo.CreateSurface(256, 256);
|
||||
|
||||
//setup the utility objects
|
||||
font.LoadSurface("rsc\\graphics\\fonts\\pk_white_8.bmp");
|
||||
|
||||
buttonImage.LoadSurface("rsc\\graphics\\interface\\button_menu.bmp");
|
||||
buttonImage.SetClipH(buttonImage.GetClipH()/3);
|
||||
|
||||
//setup the menu bar
|
||||
menuBar.SetFont(&font);
|
||||
menuBar.SetImage(&buttonImage);
|
||||
|
||||
menuBar.SetEntries({
|
||||
{"File", "New", "Open", "Save", "Save As...", "Close", "Exit"},
|
||||
{"Edit", "Set Tile", "Load Sheet", "Delete Sheet", "Metadata", "Run Script"},
|
||||
{"Debugging", "Debug On", "Debug Off", "Toggle Debug"}
|
||||
{"File", "-New", "-Open", "-Save", "-Save As...", "-Close", "Exit"},
|
||||
{"Edit", "-Set Tile", "-Load Sheet", "-Delete Sheet", "-Metadata", "-Run Script"},
|
||||
{"Debugging", "Debug On", "Debug Off", "Toggle Debug", "Testificate"}
|
||||
});
|
||||
|
||||
//setup the pager
|
||||
pager.SetOnNew([](Region* const ptr){
|
||||
printf("New Region: %d, %d\n", ptr->GetX(), ptr->GetY());
|
||||
});
|
||||
@@ -62,18 +66,7 @@ EditorScene::EditorScene() {
|
||||
pager.SetWidth(32*4);
|
||||
pager.SetHeight(32*4);
|
||||
|
||||
sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\grass.bmp", 32, 32);
|
||||
sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\longgrass.bmp", 16, 16);
|
||||
|
||||
// loadGameMap("rsc\\maps\\mappy", &pager, &sheetList);
|
||||
// saveGameMap("rsc\\maps\\foo", &pager, &sheetList);
|
||||
|
||||
// cout << "Region Width: " << pager.GetWidth() << endl;
|
||||
// cout << "Region Height: " << pager.GetHeight() << endl;
|
||||
|
||||
// for (auto& it : sheetList) {
|
||||
// cout << it.GetName() << ": " << it.GetBegin() << ", " << it.GetEnd() << endl;
|
||||
// }
|
||||
sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\terrain.bmp", 32, 32);
|
||||
}
|
||||
|
||||
EditorScene::~EditorScene() {
|
||||
@@ -135,6 +128,24 @@ void EditorScene::DrawToDebugInfo(std::string str, int line) {
|
||||
void EditorScene::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
menuBar.MouseMotion(motion);
|
||||
|
||||
if (motion.state & SDL_BUTTON_LMASK && motion.y >= buttonImage.GetClipH()) {
|
||||
Region* regionPtr = pager.GetRegion(
|
||||
snapToBase(pager.GetWidth(), motion.x + camera.x),
|
||||
snapToBase(pager.GetHeight(), motion.y + camera.y)
|
||||
);
|
||||
|
||||
TileSheet* sheetPtr = sheetMgr.GetSheetByIndex(tileCounter);
|
||||
|
||||
regionPtr->NewTileA({
|
||||
snapToBase(sheetPtr->GetTileW(), motion.x + camera.x), //x
|
||||
snapToBase(sheetPtr->GetTileH(), motion.y + camera.y), //y
|
||||
0, //depth
|
||||
sheetPtr->GetTileW(), //width
|
||||
sheetPtr->GetTileH(), //height
|
||||
tileCounter++ //value
|
||||
});
|
||||
}
|
||||
|
||||
if (motion.state & SDL_BUTTON_RMASK) {
|
||||
camera.x -= motion.xrel;
|
||||
camera.y -= motion.yrel;
|
||||
@@ -238,6 +249,10 @@ void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
case 2:
|
||||
debugOpen = !debugOpen;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
SetNextScene(SceneList::TESTIFICATESCENE);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -67,11 +67,11 @@ void TestificateScene::FrameEnd() {
|
||||
|
||||
void TestificateScene::Render(SDL_Surface* const screen) {
|
||||
//dump all tile graphics to the screen
|
||||
// for (int i = 0; i < sheetMgr.GetRangeEnd(); i++) {
|
||||
// sheetMgr.DrawTo(screen, i * 32 % screen->w, i * 32 / screen->w * 32, i);
|
||||
// }
|
||||
for (int i = 0; i < sheetMgr.GetRangeEnd(); i++) {
|
||||
sheetMgr.DrawTo(screen, i * 32 % screen->w, i * 32 / screen->w * 32, i);
|
||||
}
|
||||
|
||||
pager.DrawTo(screen, &sheetMgr, 0, 0);
|
||||
// pager.DrawTo(screen, &sheetMgr, 0, 0);
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
@@ -94,7 +94,8 @@ void TestificateScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
void TestificateScene::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
switch(key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
QuitEvent();
|
||||
// QuitEvent();
|
||||
SetNextScene(SceneList::EDITORSCENE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user