Skip to content
This repository has been archived by the owner on May 7, 2018. It is now read-only.

Commit

Permalink
Show animation in $SF_PhoneMailReciveNew and cleanup some phone code
Browse files Browse the repository at this point in the history
  • Loading branch information
krofna committed Jul 30, 2014
1 parent 80d5375 commit eab3f3e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
33 changes: 28 additions & 5 deletions src/phone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,21 @@ const char* HeaderString[] =
const int16_t WALLPAPER_WIDTH = 220;
const int16_t WALLPAPER_HEIGHT = 244;

static const sf::IntRect OverlayContentTexRect[] =
{
sf::IntRect(717, 9, 49, 29),
sf::IntRect(880, 576, 50, 38)
};

Phone::Phone(sf::Drawable* pDrawable, sf::Window* pWindow) :
DrawableBase(pDrawable, -1, DRAWABLE_TEXTURE),
State(PHONE_CLOSED),
ShowSD(false),
ShowOverlay(false),
MailReceived(false),
Mode(MODE_POWER_OFF),
pWindow(pWindow),
pMode(nullptr)
pMode(nullptr),
OverlayAnimProgress(0)
{
pWallpaper = LoadTextureFromFile("cg/sys/phone/pwcg101.png", sf::IntRect());
pPhoneTex = LoadTextureFromFile("cg/sys/phone/phone_01.png", sf::IntRect());
Expand All @@ -77,6 +84,7 @@ pMode(nullptr)
Overlay.setTexture(*pPhoneTex);
Overlay.setPosition(PHONE_OVERLAY_POS_X, PHONE_OVERLAY_POS_Y);
Overlay.setTextureRect(sf::IntRect(PHONE_NEW_MAIL_TEX_X, PHONE_NEW_MAIL_TEX_Y, PHONE_NEW_MAIL_WIDTH, PHONE_NEW_MAIL_HEIGHT));
OverlayContent.setTexture(*pPhoneTex);
Header.setTexture(*pPhoneTex);
Header.setPosition(PHONE_HEADER_POS_X, PHONE_HEADER_POS_Y);
Header.setTextureRect(sf::IntRect(PHONE_HEADER_TEX_X, PHONE_HEADER_TEX_Y, PHONE_HEADER_WIDTH, PHONE_HEADER_HEIGHT));
Expand Down Expand Up @@ -127,6 +135,9 @@ void Phone::Draw(sf::RenderWindow* pWindow)
AnimClock.restart();
}

if (OverlayClock.getElapsedTime().asMilliseconds() > 500)
UpdateOverlayAnim();

// Draw
DrawableBase::Draw(pWindow);
if (State == PHONE_OPEN)
Expand All @@ -135,8 +146,11 @@ void Phone::Draw(sf::RenderWindow* pWindow)
{
pWindow->draw(Wallpaper);
pWindow->draw(Header);
if (ShowOverlay)
if (MailReceived)
{
pWindow->draw(Overlay);
pWindow->draw(OverlayContent);
}
}
if (Mode == MODE_ADDRESS_CONFIRM_DIAL)
PhoneModes[MODE_ADDRESS_BOOK]->Draw(pWindow);
Expand Down Expand Up @@ -212,6 +226,15 @@ void Phone::UpdateAnim()
}
}

void Phone::UpdateOverlayAnim()
{
const sf::IntRect& TexRect = OverlayContentTexRect[OverlayAnimProgress];
OverlayContent.setTextureRect(TexRect);
OverlayContent.setPosition(834 - TexRect.width / 2, 208 - TexRect.height / 2);
OverlayAnimProgress = !OverlayAnimProgress;
OverlayClock.restart();
}

void Phone::UpdateMode(uint8_t NewMode)
{
if (NewMode == Mode || NewMode == MODE_INVALID)
Expand All @@ -235,8 +258,8 @@ void Phone::MailReceive(int32_t Show)
{
switch (Show)
{
case PHONE_CLOSING: ShowOverlay = false; break;
case PHONE_OPENING: ShowOverlay = true; break;
case PHONE_CLOSING: MailReceived = false; break;
case PHONE_OPENING: MailReceived = true; UpdateOverlayAnim(); break;
default: assert(false); break;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/phone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,22 @@ class Phone : public DrawableBase

private:
void UpdateAnim();
void UpdateOverlayAnim();

bool ShowSD;
bool ShowOverlay;
bool MailReceived;
uint8_t Mode;
uint8_t State;
int8_t AnimRow;
int8_t AnimColumn;
sf::Clock AnimClock;
int8_t OverlayAnimProgress;
sf::Clock AnimClock, OverlayClock;
sf::Texture* pWallpaper;
sf::Texture* pPhoneOpenTex; // Open/Close animation frames
sf::Texture* pPhoneTex;
sf::Sprite Wallpaper;
sf::Sprite Header;
sf::Sprite Overlay;
sf::Sprite Overlay, OverlayContent;
sf::Sprite BlueHeader;
sf::Window* pWindow; // Needed to move mouse pointer
PhoneMode* pMode;
Expand Down
4 changes: 1 addition & 3 deletions src/phonemodereceivingmail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ PhoneModeReceivingMail::PhoneModeReceivingMail(Phone* pPhone) : PhoneMode(pPhone
RecMailText.setFont(Text::Font);
RecMailText.setString(sf::String::fromUtf8(RecMailStr, RecMailStr + strlen(RecMailStr)));
// TODO: position and size are a guess
RecMailText.setPosition(780 + 2 * 8, 150 + 2 * 8);
RecMailText.setPosition(780 + 28, 150 + 18);
RecMailText.setCharacterSize(20);
UpdateAnim();
}
Expand All @@ -51,7 +51,6 @@ void PhoneModeReceivingMail::OnOpen(uint8_t OldMode)

void PhoneModeReceivingMail::Draw(sf::RenderWindow* pWindow)
{
// TODO: animation time is a guess
if (AnimClock.getElapsedTime().asMilliseconds() > 100)
UpdateAnim();

Expand All @@ -71,7 +70,6 @@ void PhoneModeReceivingMail::UpdateAnim()
{
AnimClock.restart();

// TODO: animation flow is a guess
for (int i = 0; i < 4; ++i)
HDots[i].setTextureRect(sf::IntRect(1000, 720 + AnimStep * 10, 48, 8));
for (int i = 0; i < 2; ++i)
Expand Down

0 comments on commit eab3f3e

Please sign in to comment.