OSDN Git Service

Fix error of naming rule in Square class.
[deeangband/Deeangband-new.git] / Deeangband / GameSurfaceSDL.cpp
index 5d226a2..fc3f10f 100644 (file)
@@ -36,7 +36,7 @@ namespace Deeangband
                return std::string(&lpa[0]);
        }
 
-       GameSurfaceSDL::GameSurfaceSDL(void)
+       GameSurfaceSDL::GameSurfaceSDL(GameWorld *gameWorld) : GameSurface(gameWorld)
        {
                if(SDL_Init(SDL_INIT_VIDEO) < 0) return;
                window = SDL_CreateWindow(GAME_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_RESIZABLE);
@@ -51,6 +51,8 @@ namespace Deeangband
                viewCreaturePtr = NULL;
                viewFloorPtr = NULL;
 
+               windowSurface = SDL_GetWindowSurface(window);
+
                return;
        }
 
@@ -67,6 +69,7 @@ namespace Deeangband
                SDL_Event event;
                do 
                {
+                       this->Redraw();
                        SDL_PollEvent(&event);
                } while(event.type != SDL_KEYDOWN);
        }
@@ -98,7 +101,6 @@ namespace Deeangband
 
        void GameSurfaceSDL::Redraw()
        {
-               SDL_Surface *windowSurface = SDL_GetWindowSurface(window);
                SDL_Rect rect = {0, 0, 0, 0};
 
                SDL_GetWindowSize(window, &rect.w, &rect.h);
@@ -106,8 +108,10 @@ namespace Deeangband
                SDL_FillRect(windowSurface, &rect, SDL_MapRGBA(windowSurface->format, 50, 20, 10, 255));
                SDL_BlitSurface(titleSurface, &title, windowSurface, &title); 
 
-               if(viewFloorPtr) drawFloor(gameWorld, viewFloorPtr, 0, 0, 20, 20);
-               if(viewCreaturePtr) drawCreatureStatus(viewCreaturePtr);
+               if(this->viewFloorPtr) this->drawFloor(gameWorld, viewFloorPtr, 0, 0, 20, 20);
+               if(this->sideStatusCreatutePtr) this->drawSideCreatureStatus();
+               if(this->viewCreaturePtr) this->drawCreatureStatus(viewCreaturePtr);
+               if(this->currentMessage.size() > 0) this->drawMessage();
 
                SDL_UpdateWindowSurface(window);
 
@@ -116,21 +120,140 @@ namespace Deeangband
 
        void GameSurfaceSDL::ViewCreatureStatus(Creature *creaturePtr)
        {
-               viewCreaturePtr = creaturePtr;
-               Redraw();
+               this->viewCreaturePtr = creaturePtr;
                pushAnyKey();
-               viewCreaturePtr = NULL;
+               this->viewCreaturePtr = NULL;
+       }
+
+       void GameSurfaceSDL::SetSideStatusCreature(Creature *creaturePtr)
+       {
+               this->sideStatusCreatutePtr = creaturePtr;
+               if(creaturePtr) this->updateSideCreatureStatus(creaturePtr);
        }
 
        void GameSurfaceSDL::SetFloor(Floor *floorPtr)
        {
-               viewFloorPtr = floorPtr;
+               this->viewFloorPtr = floorPtr;
+       }
+
+       void GameSurfaceSDL::updateCreatureStatus(Creature *creaturePtr)
+       {
+               int id;
+
+               enum CREATURE_STATUS_VIEW_POSITION
+               {
+                       POS_NAME,
+                       POS_LEVEL,
+                       POS_HP,
+                       POS_MP,
+                       POS_AC,
+                       POS_EV,
+                       POS_VO,
+                       POS_STR,
+                       POS_INT,
+                       POS_WIS,
+                       POS_DEX,
+                       POS_CON,
+                       POS_CHA,
+                       POS_SOUL,
+                       POS_GOOD,
+                       POS_EVIL,
+                       POS_ORDER,
+                       POS_CHAOS,
+                       POS_BALANCE,
+                       POS_HEIGHT,
+                       POS_WEIGHT,
+                       POS_BODY_SIZE,
+                       POS_MAX
+               };
+
+               SDL_Rect CreatureStatusViewPosition[POS_MAX] =
+               {
+                       {10, 10, 0, 0},
+                       {10, 30, 0, 0},
+                       {10, 50, 0, 0},
+                       {10, 70, 0, 0},
+                       {10, 90, 0, 0},
+                       {10, 110, 0, 0},
+                       {10, 130, 0, 0},
+                       {200, 30, 0, 0},
+                       {200, 50, 0, 0},
+                       {200, 70, 0, 0},
+                       {200, 90, 0, 0},
+                       {200, 110, 0, 0},
+                       {200, 130, 0, 0},
+                       {200, 150, 0, 0},
+                       {200, 170, 0, 0},
+                       {200, 190, 0, 0},
+                       {200, 210, 0, 0},
+                       {200, 230, 0, 0},
+                       {200, 250, 0, 0},
+                       {10, 150, 0, 0},
+                       {10, 170, 0, 0},
+                       {10, 190, 0, 0},
+               };
+
+               SDL_Rect CreatureStatusViewRect[POS_MAX];
+
+               const int STATUS_BUFSIZE = 100;
+               char statusBuf[POS_MAX][STATUS_BUFSIZE];
+               SDL_Surface *statusSurface[POS_MAX];
+
+               SDL_Rect masterRect = {0, 0, 490, 450};
+
+               creatureStatusSurface = SDL_CreateRGBSurface(0, 490, 450, 32, 0, 0, 0, 0);
+
+               sprintf_s(statusBuf[POS_NAME], STATUS_BUFSIZE, "\96¼\91O:%s", creaturePtr->GetName().c_str()); 
+               sprintf_s(statusBuf[POS_LEVEL], STATUS_BUFSIZE, "LV:%3d", creaturePtr->GetLevel()); 
+               sprintf_s(statusBuf[POS_HP], STATUS_BUFSIZE, "HP:%5d/%5d", creaturePtr->GetCurHP(), creaturePtr->GetMaxHP()); 
+               sprintf_s(statusBuf[POS_MP], STATUS_BUFSIZE, "MP:%5d/%5d", creaturePtr->GetCurMP(), creaturePtr->GetMaxMP()); 
+               sprintf_s(statusBuf[POS_AC], STATUS_BUFSIZE, "AC:%4d", creaturePtr->GetArmorSaving()); 
+               sprintf_s(statusBuf[POS_EV], STATUS_BUFSIZE, "EV:%4d", creaturePtr->GetEvasionSaving()); 
+               sprintf_s(statusBuf[POS_VO], STATUS_BUFSIZE, "VO:%4d", creaturePtr->GetVolitionSaving()); 
+               sprintf_s(statusBuf[POS_GOOD], STATUS_BUFSIZE, " \91P :%4d", creaturePtr->GetDiscipilneRank(DISCIPLINE_TYPE_GOOD)); 
+               sprintf_s(statusBuf[POS_EVIL], STATUS_BUFSIZE, " \88« :%4d", creaturePtr->GetDiscipilneRank(DISCIPLINE_TYPE_EVIL)); 
+               sprintf_s(statusBuf[POS_ORDER], STATUS_BUFSIZE, "\92\81\8f\98:%4d", creaturePtr->GetDiscipilneRank(DISCIPLINE_TYPE_ORDER)); 
+               sprintf_s(statusBuf[POS_CHAOS], STATUS_BUFSIZE, "\8d¬\93×:%4d", creaturePtr->GetDiscipilneRank(DISCIPLINE_TYPE_CHAOS)); 
+               sprintf_s(statusBuf[POS_BALANCE], STATUS_BUFSIZE, "\93V\94\89:%4d", creaturePtr->GetDiscipilneRank(DISCIPLINE_TYPE_BALANCE)); 
+               sprintf_s(statusBuf[POS_STR], STATUS_BUFSIZE, "\98r\97Í:%4d", creaturePtr->GetCurrentStatus(CS_STR)); 
+               sprintf_s(statusBuf[POS_INT], STATUS_BUFSIZE, "\92m\97Í:%4d", creaturePtr->GetCurrentStatus(CS_INT)); 
+               sprintf_s(statusBuf[POS_WIS], STATUS_BUFSIZE, "\8c«\82³:%4d", creaturePtr->GetCurrentStatus(CS_WIS)); 
+               sprintf_s(statusBuf[POS_DEX], STATUS_BUFSIZE, "\8aí\97p:%4d", creaturePtr->GetCurrentStatus(CS_DEX)); 
+               sprintf_s(statusBuf[POS_CON], STATUS_BUFSIZE, "\91Ï\8bv:%4d", creaturePtr->GetCurrentStatus(CS_CON)); 
+               sprintf_s(statusBuf[POS_CHA], STATUS_BUFSIZE, "\96£\97Í:%4d", creaturePtr->GetCurrentStatus(CS_CHA)); 
+               sprintf_s(statusBuf[POS_SOUL], STATUS_BUFSIZE, "\83\\83E\83\8b:%4d", creaturePtr->GetCurrentSoul()); 
+               sprintf_s(statusBuf[POS_HEIGHT], STATUS_BUFSIZE, "\90g\92·:%6dcm", creaturePtr->GetHeight()); 
+               sprintf_s(statusBuf[POS_WEIGHT], STATUS_BUFSIZE, "\91Ì\8fd:%6dkg", creaturePtr->GetWeight()); 
+               sprintf_s(statusBuf[POS_BODY_SIZE], STATUS_BUFSIZE, "\91Ì\8ai:%3d", creaturePtr->GetSize()); 
+
+               for(id = 0; id < POS_MAX; id++)
+               {
+                       statusSurface[id] = TTF_RenderUTF8_Blended(font, toUTF8(statusBuf[id]).c_str(), color);
+                       CreatureStatusViewRect[id].x = 0;
+                       CreatureStatusViewRect[id].y = 0;
+                       CreatureStatusViewRect[id].w = statusSurface[id]->w;
+                       CreatureStatusViewRect[id].h = statusSurface[id]->h;
+                       CreatureStatusViewPosition[id].x += masterRect.x;
+                       CreatureStatusViewPosition[id].y += masterRect.y;
+               }
+
+               SDL_FillRect(creatureStatusSurface, &masterRect, SDL_MapRGBA(creatureStatusSurface->format, 0, 0, 0, 120));
+
+               for(id = 0; id < POS_MAX; id++)
+               {
+                       SDL_BlitSurface(statusSurface[id], &CreatureStatusViewRect[id], creatureStatusSurface, &CreatureStatusViewPosition[id]); 
+               }
+
+               for(id = 0; id < POS_MAX; id++)
+               {
+                       SDL_FreeSurface(statusSurface[id]);
+               }
+               return;
        }
 
        void GameSurfaceSDL::drawCreatureStatus(Creature *creaturePtr)
        {
                int id;
-               SDL_Surface *windowSurface = SDL_GetWindowSurface(window);
 
                enum CREATURE_STATUS_VIEW_POSITION
                {
@@ -241,6 +364,105 @@ namespace Deeangband
                return;
        }
 
+       void GameSurfaceSDL::updateSideCreatureStatus(Creature *creaturePtr)
+       {
+               int id;
+
+               enum CREATURE_SIDE_STATUS_VIEW_POSITION
+               {
+                       POS_NAME,
+                       POS_LEVEL,
+                       POS_HP,
+                       POS_MP,
+                       POS_AC,
+                       POS_EV,
+                       POS_VO,
+                       POS_STR,
+                       POS_INT,
+                       POS_WIS,
+                       POS_DEX,
+                       POS_CON,
+                       POS_CHA,
+                       POS_SOUL,
+                       POS_MAX
+               };
+
+               SDL_Rect CreatureStatusViewPosition[POS_MAX] =
+               {
+                       {10, 10, 0, 0},
+                       {10, 30, 0, 0},
+                       {10, 50, 0, 0},
+                       {10, 70, 0, 0},
+                       {10, 90, 0, 0},
+                       {10, 110, 0, 0},
+                       {10, 130, 0, 0},
+                       {200, 30, 0, 0},
+                       {200, 50, 0, 0},
+                       {200, 70, 0, 0},
+                       {200, 90, 0, 0},
+                       {200, 110, 0, 0},
+                       {200, 130, 0, 0},
+                       {200, 150, 0, 0},
+               };
+
+               SDL_Rect CreatureStatusViewRect[POS_MAX];
+
+               const int STATUS_BUFSIZE = 100;
+               char statusBuf[POS_MAX][STATUS_BUFSIZE];
+               SDL_Surface *statusSurface[POS_MAX];
+
+               SDL_Rect masterRect = {0, 0, 180, 350};
+
+               creatureStatusSurface = SDL_CreateRGBSurface(0, 490, 450, 32, 0, 0, 0, 0);
+
+               sprintf_s(statusBuf[POS_NAME], STATUS_BUFSIZE, "\96¼\91O:%s", creaturePtr->GetName().c_str()); 
+               sprintf_s(statusBuf[POS_LEVEL], STATUS_BUFSIZE, "LV:%3d", creaturePtr->GetLevel()); 
+               sprintf_s(statusBuf[POS_HP], STATUS_BUFSIZE, "HP:%5d/%5d", creaturePtr->GetCurHP(), creaturePtr->GetMaxHP()); 
+               sprintf_s(statusBuf[POS_MP], STATUS_BUFSIZE, "MP:%5d/%5d", creaturePtr->GetCurMP(), creaturePtr->GetMaxMP()); 
+               sprintf_s(statusBuf[POS_AC], STATUS_BUFSIZE, "AC:%4d", creaturePtr->GetArmorSaving()); 
+               sprintf_s(statusBuf[POS_EV], STATUS_BUFSIZE, "EV:%4d", creaturePtr->GetEvasionSaving()); 
+               sprintf_s(statusBuf[POS_VO], STATUS_BUFSIZE, "VO:%4d", creaturePtr->GetVolitionSaving()); 
+               sprintf_s(statusBuf[POS_STR], STATUS_BUFSIZE, "\98r\97Í:%4d", creaturePtr->GetCurrentStatus(CS_STR)); 
+               sprintf_s(statusBuf[POS_INT], STATUS_BUFSIZE, "\92m\97Í:%4d", creaturePtr->GetCurrentStatus(CS_INT)); 
+               sprintf_s(statusBuf[POS_WIS], STATUS_BUFSIZE, "\8c«\82³:%4d", creaturePtr->GetCurrentStatus(CS_WIS)); 
+               sprintf_s(statusBuf[POS_DEX], STATUS_BUFSIZE, "\8aí\97p:%4d", creaturePtr->GetCurrentStatus(CS_DEX)); 
+               sprintf_s(statusBuf[POS_CON], STATUS_BUFSIZE, "\91Ï\8bv:%4d", creaturePtr->GetCurrentStatus(CS_CON)); 
+               sprintf_s(statusBuf[POS_CHA], STATUS_BUFSIZE, "\96£\97Í:%4d", creaturePtr->GetCurrentStatus(CS_CHA)); 
+               sprintf_s(statusBuf[POS_SOUL], STATUS_BUFSIZE, "\83\\83E\83\8b:%4d", creaturePtr->GetCurrentSoul()); 
+
+               for(id = 0; id < POS_MAX; id++)
+               {
+                       statusSurface[id] = TTF_RenderUTF8_Blended(font, toUTF8(statusBuf[id]).c_str(), color);
+                       CreatureStatusViewRect[id].x = 0;
+                       CreatureStatusViewRect[id].y = 0;
+                       CreatureStatusViewRect[id].w = statusSurface[id]->w;
+                       CreatureStatusViewRect[id].h = statusSurface[id]->h;
+                       CreatureStatusViewPosition[id].x += masterRect.x;
+                       CreatureStatusViewPosition[id].y += masterRect.y;
+               }
+
+               SDL_FillRect(creatureStatusSurface, &masterRect, SDL_MapRGBA(creatureStatusSurface->format, 0, 0, 0, 120));
+
+               for(id = 0; id < POS_MAX; id++)
+               {
+                       SDL_BlitSurface(statusSurface[id], &CreatureStatusViewRect[id], creatureStatusSurface, &CreatureStatusViewPosition[id]); 
+               }
+
+               for(id = 0; id < POS_MAX; id++)
+               {
+                       SDL_FreeSurface(statusSurface[id]);
+               }
+               return;
+
+       }
+
+       void GameSurfaceSDL::drawSideCreatureStatus(void)
+       {
+               SDL_Rect masterRect = {0, 0, 180, 350};
+               SDL_Rect posRect = {10, 120, 0, 0};
+               SDL_BlitSurface(creatureStatusSurface, &masterRect, windowSurface, &posRect); 
+       }
+
        GAME_COMMAND GameSurfaceSDL::GetCommand(void)
        {
                SDL_Event event;
@@ -248,6 +470,7 @@ namespace Deeangband
 
                while (SDL_PollEvent(&event))
                {
+                       this->Redraw();
                        switch(event.type)
                        {
 
@@ -261,6 +484,28 @@ namespace Deeangband
                                                return GAME_COMMAND_EXIT;
                                        case SDLK_c:
                                                return GAME_COMMAND_VIEW_PLAYER_STATUS;
+                                       case SDLK_F11:
+                                               return GAME_COMMAND_DEBUG_XML_SAVE;
+                                       case SDLK_F12:
+                                               return GAME_COMMAND_DEBUG_XML_LOAD;
+                                       case SDLK_j:
+                                               return GAME_COMMAND_NORTH;
+                                       case SDLK_i:
+                                               return GAME_COMMAND_NORTH_EAST;
+                                       case SDLK_l:
+                                               return GAME_COMMAND_EAST;
+                                       case SDLK_m:
+                                               return GAME_COMMAND_SOUTH_EAST;
+                                       case SDLK_k:
+                                               return GAME_COMMAND_SOUTH;
+                                       case SDLK_n:
+                                               return GAME_COMMAND_SOUTH_WEST;
+                                       case SDLK_h:
+                                               return GAME_COMMAND_WEST;
+                                       case SDLK_u:
+                                               return GAME_COMMAND_NORTH_WEST;
+                                       case SDLK_s:
+                                               return GAME_COMMAND_STAY;
                                        }
 
                                }
@@ -278,7 +523,6 @@ namespace Deeangband
 
        void GameSurfaceSDL::drawFloor(GameWorld *gameWorld, Floor *floorPtr, int x, int y, int w, int h)
        {       
-               SDL_Surface *windowSurface = SDL_GetWindowSurface(window);
                SDL_Rect symbolRect = {0, 0, 30, 30};
                SDL_Surface *symbolSurface;
                char symBuf[5];
@@ -290,17 +534,13 @@ namespace Deeangband
                        {
                                if(px < floorPtr->GetWidth() && py < floorPtr->GetHeight())
                                {
-                                       TAG tag = floorPtr->GetSquare(px, py)->getFeatureTag();
-                                       //Color symColor = floorPtr->GetGameWorld()->GetFeature(tag)->GetSymColor();
-                                       //Color backColor = floorPtr->GetGameWorld()->GetFeature(tag)->GetBackColor();
-                                       Color symColor = {100, 100, 100};
-                                       Color backColor = {0, 0, 0};
-                                       SDL_Color sdlSymCol = {(Uint8)symColor.r, (Uint8)symColor.g, (Uint8)symColor.b, (Uint8)symColor.a};
+                                       TAG tag = floorPtr->GetSquare(px, py)->GetFeatureTag();
+                                       Color symColor = gameWorld->GetFeature(tag)->GetSymColor();
+                                       Color backColor = gameWorld->GetFeature(tag)->GetBackColor();
+                                       SDL_Color sdlSymCol = {(Uint8)symColor.GetRed(), (Uint8)symColor.GetGreen(), (Uint8)symColor.GetBlue(), (Uint8)symColor.GetAlpha()};
                                        SDL_Rect blitRect = {240 + px * 24, py * 24 , 24, 24};
-                                       SDL_FillRect(windowSurface, &blitRect, SDL_MapRGBA(windowSurface->format, (Uint8)backColor.r, (Uint8)backColor.g, (Uint8)backColor.b, (Uint8)backColor.a));
-                                       //sprintf_s(symBuf, 5, "%c", floorPtr->GetGameWorld()->GetFeature(tag)->GetSymbol()); 
-                                       sprintf_s(symBuf, 5, "%c", 'X'); 
-
+                                       SDL_FillRect(windowSurface, &blitRect, SDL_MapRGBA(windowSurface->format, (Uint8)backColor.GetRed(), (Uint8)backColor.GetGreen(), (Uint8)backColor.GetBlue(), (Uint8)backColor.GetAlpha()));
+                                       sprintf_s(symBuf, 5, "%s", gameWorld->GetFeature(tag)->GetSymbol().c_str()); 
                                        symbolSurface = TTF_RenderUTF8_Blended(font, toUTF8(symBuf).c_str(), sdlSymCol);
                                        blitRect.x += (24 - symbolSurface->w) / 2;
                                        blitRect.y += (24 - symbolSurface->h) / 2;
@@ -322,4 +562,23 @@ namespace Deeangband
                this->focusPoint.Set(coord.GetX(), coord.GetY());
        }
 
+       void GameSurfaceSDL::drawMessage(void)
+       {
+               SDL_Rect messageRect = {0, 0, 800, 100};
+               SDL_Rect messagePositon = {220, 8, 0, 0}; 
+               SDL_Rect windowRect = {212, 4, 800, 26};
+               SDL_FillRect(windowSurface, &windowRect, SDL_MapRGBA(messageSurface->format, 0, 0, 0, 120));
+               SDL_BlitSurface(messageSurface, &messageRect, windowSurface, &messagePositon); 
+               //SDL_FreeSurface(messageSurface);
+       }
+
+       void GameSurfaceSDL::Message(std::string message)
+       {
+               this->currentMessage = message;
+               messageSurface = TTF_RenderUTF8_Blended(font, toUTF8(this->currentMessage.c_str()).c_str(), color);
+               pushAnyKey();
+               this->currentMessage.erase();
+               SDL_FreeSurface(messageSurface);
+       }
+
 }
\ No newline at end of file