@@ -167,7 +167,6 @@ void Textures::load() {
167167}
168168/* *********************************************************************************************************************************************/
169169void Screen::start () {
170- /* TODO (Gamerman7799 the Scrub#1#): More Comments Required to continue window32 Folder*/
171170 Screen::window.width = 35 * Global::pic_size;
172171 Screen::window.height = 14 * Global::pic_size;
173172 Screen::blnload.blnMessage = Screen::blnload.blnMessageFont = Screen::blnload.blnTiles = Screen::blnload.blnToolboxFrame = false ;
@@ -189,14 +188,6 @@ void Screen::start() {
189188 if (Global::blnDebugMode) {printf (" TTF init successful\n " );}
190189 }
191190
192- // Start Image (with only png)
193- /* if (!(IMG_Init( IMG_INIT_PNG )) & IMG_INIT_PNG) {
194- Screen::error();
195- return;
196- } else {
197- if (Global::blnDebugMode) {printf("IMG init successful\n");}
198- }*/
199-
200191 Screen::window.MessageFont = TTF_OpenFont (DEFINED_MESSAGE_FONT,16 ); // Opens font and sets size
201192 if ( Screen::window.MessageFont == nullptr ) {
202193 printf (" Font failed to load, messages will not appear." );
@@ -272,7 +263,6 @@ void Screen::cleanup() {
272263 }
273264
274265 TTF_Quit ();
275- // IMG_Quit();
276266 SDL_Quit ();
277267 if (Global::blnDebugMode) {printf (" SDL quit\n " );}
278268}
@@ -281,7 +271,6 @@ void Screen::error() {
281271 Screen::bln_SDL_Started = false ;
282272 printf (" SDL error: %s\n " , SDL_GetError ());
283273 printf (" TTF error: %s\n " , TTF_GetError ());
284- // printf("IMG error: %s\n", IMG_GetError());
285274 getchar ();
286275 Screen::cleanup ();
287276}
@@ -293,29 +282,12 @@ void Screen::show() {
293282 SDL_RenderCopy (Screen::window.ren , Textures::tilemap, &Textures::clips[tileSpace], NULL );
294283 SDL_Rect dst;
295284 dst.h = dst.w = Global::pic_size;
296- // Do a few checks on the offset so we aren't accessing a non-existing part of the map array.
297- /* TODO (Gamerman7799 the Scrub#1#): Get rid of modoffset and replace with just normal offset
298-
299-
300-
301-
302-
303-
304- JUST DO IT! */
305-
306- if (Screen::offset.y < 0 ) {Screen::modoffset.y = 0 ;}
307- else if (Screen::offset.y > (DEFINED_MAP_HEIGHT * Global::pic_size) - Screen::window.height ) {Screen::modoffset.y = (DEFINED_MAP_HEIGHT * Global::pic_size) - Screen::window.height ;}
308- else {Screen::modoffset.y = Screen::offset.y ;}
309-
310- if (Screen::offset.x < 0 ) {Screen::modoffset.x = 0 ;}
311- else if (Screen::offset.x > (DEFINED_MAP_WIDTH * Global::pic_size) - Screen::window.width ) {Screen::modoffset.x = (DEFINED_MAP_WIDTH * Global::pic_size) - Screen::window.width ;}
312- else {Screen::modoffset.x = Screen::offset.x ;}
313285
314286 for (uint y = 0 ; (y < DEFINED_MAP_HEIGHT); y++) {
315287 for (uint x = 0 ; (x < DEFINED_MAP_WIDTH); x++) {
316288 // update where we're trying to put the texture.
317- dst.x = (x * Global::pic_size) - Screen::modoffset .x ;
318- dst.y = (y * Global::pic_size) - Screen::modoffset .y ;
289+ dst.x = (x * Global::pic_size) - Screen::offset .x ;
290+ dst.y = (y * Global::pic_size) - Screen::offset .y ;
319291
320292 switch (Global::map[y][x]) { // Use this to make sure we aren't try to load a non-existing part
321293 case tileCoin:
@@ -441,12 +413,10 @@ char Screen::promptuser(uchar prompttype, std::string message) {
441413void Toolbar::make_buttons () {
442414 uint centerx; // center of the toolbox
443415 centerx = (uint)(Screen::window.width / 2 );
444- // FIXME weird space in toolbar
445416 // Calculate all the places, the tool box frame has a 2 px wide border all the way around.
417+ // Make tile buttons
446418 for (uchar i = 0 ; i < DEFINED_NUM_BUTN_TILES; i++) {
447419 Toolbar::button_xplaces[i] = centerx - ( ( 2 - i ) * 4 ) - ( ( 2 - i ) * Global::pic_size );
448- // if (i <= 2 ) {xplaces[i] -= 2;}
449- // else {xplaces[i] += 2;}
450420 }
451421
452422 for (uchar i = 0 ; i < DEFINED_NUM_BUTN_TILES; i++) {
@@ -456,6 +426,15 @@ void Toolbar::make_buttons() {
456426 Toolbar::tilebuttons[i].box .y = 2 ;
457427 Toolbar::tilebuttons[i].box .x = Toolbar::button_xplaces[i];
458428 }
429+
430+ // Make menu buttons
431+ for (uchar i = 0 ; i < DEFINED_NUM_BUTN_MENU; i++) {
432+ Toolbar::menubuttons[i].buttontype = menuClose + i;
433+ Toolbar::menubuttons[i].clip = &Textures::clips[menuClose + i];
434+ Toolbar::menubuttons[i].box .w = Toolbar::menubuttons[i].box .h = Global::pic_size;
435+ Toolbar::menubuttons[i].box .y = 2 ;
436+ Toolbar::menubuttons[i].box .x = (Screen::window.width - 2 ) - ( (i+1 ) * Global::pic_size);
437+ }
459438}
460439/* *********************************************************************************************************************************************/
461440void Toolbar::draw () {
@@ -469,13 +448,20 @@ void Toolbar::draw() {
469448 SDL_RenderCopy (Screen::window.ren , Textures::toolboxframe, NULL , &dst);
470449 }
471450
472- // Show all the buttons
451+ // Show all the tile buttons
473452 for (uchar i = 0 ; i < DEFINED_NUM_BUTN_TILES; i++) {
474453 SDL_RenderCopy (Screen::window.ren , Textures::tilemap, Toolbar::tilebuttons[i].clip , &Toolbar::tilebuttons[i].box );
475454 if (Toolbar::tilebuttons[i].buttontype == paintbrush.CurrentTile ) {
476455 SDL_RenderCopy (Screen::window.ren , Textures::tilemap, &Textures::clips[menuFrame] , &Toolbar::tilebuttons[i].box );
477456 }
478457 }
458+
459+ // show all the menu buttons
460+ for (uchar i = 0 ; i < DEFINED_NUM_BUTN_MENU; i++) {
461+ // dst.x = (Screen::window.width - 2) - ( (i+1) * Global::pic_size);
462+ // SDL_RenderCopy(Screen::window.ren, Textures::toolboxframe, NULL, &dst);
463+ SDL_RenderCopy (Screen::window.ren , Textures::tilemap, Toolbar::menubuttons[i].clip , &Toolbar::menubuttons[i].box );
464+ }
479465}
480466/* *********************************************************************************************************************************************/
481467void Toolbar::check_events (SDL_Event* e) {
@@ -487,8 +473,7 @@ void Toolbar::check_events(SDL_Event* e) {
487473 int x, y;
488474 SDL_GetMouseState (&x, &y);
489475
490- // check all of the buttons to see if we are on that one.
491-
476+ // check all of the tile buttons to see if we are on that one.
492477 for (uchar i = 0 ; i < DEFINED_NUM_BUTN_TILES; i++) {
493478 if ( x >= Toolbar::tilebuttons[i].box .x && x <= Toolbar::tilebuttons[i].box .x + Toolbar::tilebuttons[i].box .w ) { // In the x range
494479 if ( y >= Toolbar::tilebuttons[i].box .y && y <= Toolbar::tilebuttons[i].box .y + Toolbar::tilebuttons[i].box .h ) { // in the y range
@@ -497,13 +482,31 @@ void Toolbar::check_events(SDL_Event* e) {
497482 } // end if in x
498483 } // end for buttons
499484
485+ // check all of the menu buttons
486+ for (uchar i = 0 ; i < DEFINED_NUM_BUTN_MENU; i++) {
487+ if ( x >= Toolbar::menubuttons[i].box .x && x <= Toolbar::menubuttons[i].box .x + Toolbar::menubuttons[i].box .w ) { // In the x range
488+ if ( y >= Toolbar::menubuttons[i].box .y && y <= Toolbar::menubuttons[i].box .y + Toolbar::menubuttons[i].box .h ) { // in the y range
489+ blnButtonDown = false ;
490+ switch (Toolbar::menubuttons[i].buttontype ) {
491+ case menuSave:
492+ Map::save ();
493+ break ;
494+ case menuClose:
495+ if (Screen::promptuser (promptYesNo, " Do you really want to quit?" ) == ' Y' ) {
496+ e->type = SDL_QUIT;
497+ } // end if yes
498+ break ;
499+ } // end switch
500+ } // end if in y
501+ } // end if in x
502+ } // end for menu buttons
503+
500504
501505 // user did not click on any buttons therefore change the map tile.
502506 // convert to map coordinates
503507 uint mapx, mapy;
504- /* TODO (GamerMan7799#1#): Add drag ability */
505- mapx = (uint) ( (x + Screen::modoffset.x ) / Global::pic_size);
506- mapy = (uint) ( (y + Screen::modoffset.y ) / Global::pic_size);
508+ mapx = (uint) ( (x + Screen::offset.x ) / Global::pic_size);
509+ mapy = (uint) ( (y + Screen::offset.y ) / Global::pic_size);
507510
508511 Global::map[mapy][mapx] = paintbrush.CurrentTile ;
509512 } else if (e->type == SDL_KEYDOWN) {
@@ -513,18 +516,22 @@ void Toolbar::check_events(SDL_Event* e) {
513516 case SDLK_UP:
514517 case SDLK_w:
515518 Screen::offset.y -= Global::pic_size;
519+ if (Screen::offset.y < 0 ) {Screen::offset.y = 0 ;}
516520 break ;
517521 case SDLK_DOWN:
518522 case SDLK_s:
519523 Screen::offset.y += Global::pic_size;
524+ if (Screen::offset.y > (DEFINED_MAP_HEIGHT * Global::pic_size) - Screen::window.height ) {Screen::offset.y = (DEFINED_MAP_HEIGHT * Global::pic_size) - Screen::window.height ;}
520525 break ;
521526 case SDLK_RIGHT:
522527 case SDLK_d:
523528 Screen::offset.x += Global::pic_size;
529+ if (Screen::offset.x > (DEFINED_MAP_WIDTH * Global::pic_size) - Screen::window.width ) {Screen::offset.x = (DEFINED_MAP_WIDTH * Global::pic_size) - Screen::window.width ;}
524530 break ;
525531 case SDLK_LEFT:
526532 case SDLK_a:
527533 Screen::offset.x -= Global::pic_size;
534+ if (Screen::offset.x < 0 ) {Screen::offset.x = 0 ;}
528535 break ;
529536 case SDLK_HOME:
530537 Screen::offset.x = Screen::offset.y = 0 ;
@@ -559,6 +566,7 @@ void Toolbar::check_events(SDL_Event* e) {
559566 case SDLK_l:
560567 Map::load ();
561568 break ;
569+
562570 // Switch tile
563571 case SDLK_1:
564572 Toolbar::paintbrush.CurrentTile = tileSpace;
@@ -622,7 +630,7 @@ void Map::newmap() {
622630 for (uint y = 0 ; y < DEFINED_MAP_HEIGHT; y++) {
623631 for (uint x = 0 ; x < DEFINED_MAP_WIDTH; x++) {
624632 Global::map[y][x] = tileSpace;
625- } // end for xh
633+ } // end for x
626634 } // end for y
627635 } // end if yes
628636}
0 commit comments