Rev 124 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.pingK.common.game;
import com.gebauz.pingK.common.R;
import com.gebauz.pingK.common.framework.MathUtil;
import com.gebauz.pingK.common.framework.ResourceManager;
import com.gebauz.pingK.common.framework.Sprite2D;
import com.gebauz.pingK.common.game.gamestates.GameStateManager;
public class HelpScreen
{
private Sprite2D mBackground =
new Sprite2D
();
private Sprite2D mBlack =
new Sprite2D
();
private float mPopupTimer = -GameConsts.
HELP_MENU_POPUP_TIME;
private boolean mIsActive =
false;
private boolean mIsActiveTarget =
false;
private TextButton mBack
;
private SpriteButton mForward
;
private SpriteButton mBackward
;
private Sprite2D mPage0 =
new Sprite2D
();
private Sprite2D mPage1 =
new Sprite2D
();
private Sprite2D mPage2 =
new Sprite2D
();
private Sprite2D mPage3 =
new Sprite2D
();
private float mBlackHeight = GameConsts.
VIRTUAL_SCREEN_HEIGHT;
static private int NUM_PAGES =
4;
private int mCurrentPage =
0;
public HelpScreen
(float blackHeight
)
{
mBlackHeight = blackHeight
;
mBackground.
init(R.
drawable.
pause_bg,
0, GameConsts.
VIRTUAL_SCREEN_HEIGHT / 2.0f, GameConsts.
VIRTUAL_SCREEN_WIDTH, GameConsts.
HELP_BG_HEIGHT);
mBackground.
pivotX =
0;
mBackground.
pivotY = mBackground.
h / 2.0f
;
mBlack.
init(R.
drawable.
black80,
0,
0, GameConsts.
VIRTUAL_SCREEN_WIDTH, mBlackHeight
);
mBlack.
pivotX =
0;
mBlack.
pivotY =
0;
mBack =
new TextButton
(GameServices.
getFont(), ResourceManager.
getInstance().
getCurrentContext().
getString(R.
string.
help_back));
mBack.
x = GameConsts.
VIRTUAL_SCREEN_WIDTH - 15.0f
;
mBack.
y = GameConsts.
VIRTUAL_SCREEN_HEIGHT / 2.0f + GameConsts.
HELP_BG_HEIGHT / 2.0f - 35.0f
;
mBack.
scale = GameConsts.
HELP_MENU_TEXT_SCALE;
mBack.
setAlignment(TextButton.
HorizontalAlignment.
RIGHT, TextButton.
VerticalAlignment.
BOTTOM);
mBack.
setTouchListener(mBackListener
);
mForward =
new SpriteButton
(R.
drawable.
menu_forward, GameConsts.
VIRTUAL_SCREEN_WIDTH - 10.0f, GameConsts.
VIRTUAL_SCREEN_HEIGHT / 2.0f, GameConsts.
HELP_MENU_NAV_ICON_SIZE, GameConsts.
HELP_MENU_NAV_ICON_SIZE);
mForward.
setAlignment(TextButton.
HorizontalAlignment.
RIGHT, TextButton.
VerticalAlignment.
MIDDLE);
mForward.
setTouchListener(mNavigationListener
);
mBackward =
new SpriteButton
(R.
drawable.
menu_backward, 10.0f, GameConsts.
VIRTUAL_SCREEN_HEIGHT / 2.0f, GameConsts.
HELP_MENU_NAV_ICON_SIZE, GameConsts.
HELP_MENU_NAV_ICON_SIZE);
mBackward.
setAlignment(TextButton.
HorizontalAlignment.
LEFT, TextButton.
VerticalAlignment.
MIDDLE);
mBackward.
setTouchListener(mNavigationListener
);
mPage0.
init(R.
drawable.
help_page0, GameConsts.
HELP_MENU_NAV_ICON_SIZE + 20.0f, GameConsts.
VIRTUAL_SCREEN_HEIGHT/2.0f, 200.0f, 300.0f
);
mPage0.
pivotX =
0;
mPage0.
pivotY = mPage0.
h / 2.0f
;
mPage1.
init(R.
drawable.
help_page1, GameConsts.
HELP_MENU_NAV_ICON_SIZE + 20.0f, GameConsts.
VIRTUAL_SCREEN_HEIGHT/2.0f, 200.0f, 300.0f
);
mPage1.
pivotX =
0;
mPage1.
pivotY = mPage1.
h / 2.0f
;
mPage2.
init(R.
drawable.
help_page2, GameConsts.
HELP_MENU_NAV_ICON_SIZE + 20.0f, GameConsts.
VIRTUAL_SCREEN_HEIGHT/2.0f, 200.0f, 300.0f
);
mPage2.
pivotX =
0;
mPage2.
pivotY = mPage2.
h / 2.0f
;
mPage3.
init(R.
drawable.
help_page3, GameConsts.
HELP_MENU_NAV_ICON_SIZE + 20.0f, GameConsts.
VIRTUAL_SCREEN_HEIGHT/2.0f, 200.0f, 300.0f
);
mPage3.
pivotX =
0;
mPage3.
pivotY = mPage3.
h / 2.0f
;
}
BaseButton.
TouchListener mBackListener =
new BaseButton.
TouchListener()
{
@
Override
public void onTouched
(BaseButton sender,
int tag
)
{
hide
();
}
};
BaseButton.
TouchListener mNavigationListener =
new BaseButton.
TouchListener()
{
@
Override
public void onTouched
(BaseButton sender,
int tag
)
{
if (sender == mBackward
)
{
mCurrentPage--
;
if (mCurrentPage
< 0)
mCurrentPage = NUM_PAGES-
1;
}
else if (sender == mForward
)
{
mCurrentPage++
;
if (mCurrentPage
>= NUM_PAGES
)
mCurrentPage =
0;
}
}
};
public void update
(float deltaTime
)
{
if (!mIsActive
)
return;
float bgsize = 0.0f
;
if (mIsActive
&& mIsActiveTarget
)
{
// fade in
mPopupTimer += deltaTime
;
bgsize = MathUtil.
clamp((mPopupTimer
) / GameConsts.
HELP_MENU_POPUP_TIME, 0.0f, 1.0f
) * GameConsts.
HELP_BG_HEIGHT;
}
else if (mIsActive
&& !mIsActiveTarget
)
{
// fade out
mPopupTimer += deltaTime
;
bgsize =
(1.0f-MathUtil.
clamp(mPopupTimer / GameConsts.
HELP_MENU_POPUP_TIME, 0.0f, 1.0f
)) * GameConsts.
HELP_BG_HEIGHT;
if (mPopupTimer
>= GameConsts.
HELP_MENU_POPUP_TIME)
mIsActive =
false;
}
mBackground.
h = bgsize
;
mBackground.
pivotY = mBackground.
h/2.0f
;
mBackground.
update(deltaTime
);
mBlack.
update(deltaTime
);
mBack.
update(deltaTime
);
mForward.
update(deltaTime
);
mBackward.
update(deltaTime
);
}
public void render
()
{
if (!mIsActive
)
return;
mBlack.
render();
mBackground.
render();
if (mIsActiveTarget
&& (mPopupTimer
>= GameConsts.
HELP_MENU_POPUP_TIME))
{
String text =
String.
format(ResourceManager.
getInstance().
getCurrentContext().
getString(R.
string.
help_page), mCurrentPage+
1, NUM_PAGES
);
float scale = 2.0f
;
GameServices.
getFont().
drawText(text,
(GameConsts.
VIRTUAL_SCREEN_WIDTH -
(text.
length() * Font.
CHARACTER_SIZE * scale
)) /2.0f,
(GameConsts.
VIRTUAL_SCREEN_HEIGHT - GameConsts.
HELP_BG_HEIGHT) / 2.0f + 40.0f, scale
);
renderScreen
(mCurrentPage
);
mBack.
render();
mForward.
render();
mBackward.
render();
}
}
public void renderScreen
(int whichScreen
)
{
if (whichScreen ==
0)
{
mPage0.
render();
renderText
(R.
string.
help_page0_text0, 300.0f, 160.0f, 1.5f
);
renderText
(R.
string.
help_page0_text1, 300.0f, 190f, 1.5f
);
renderText
(R.
string.
help_page0_text2, 300.0f, 250.0f, 1.5f
);
renderText
(R.
string.
help_page0_text3, 300.0f, 280.0f, 1.5f
);
renderText
(R.
string.
help_page0_text4, 300.0f, 310.0f, 1.5f
);
}
else if (whichScreen ==
1)
{
mPage1.
render();
renderText
(R.
string.
help_page1_text0, 300.0f, 160.0f, 1.5f
);
renderText
(R.
string.
help_page1_text1, 300.0f, 200f, 1.5f
);
renderText
(R.
string.
help_page1_text2, 300.0f, 240.0f, 1.5f
);
renderText
(R.
string.
help_page1_text3, 300.0f, 280.0f, 1.5f
);
renderText
(R.
string.
help_page1_text4, 300.0f, 320.0f, 1.5f
);
}
else if (whichScreen ==
2)
{
mPage2.
render();
renderText
(R.
string.
help_page2_text0, 300.0f, 160.0f, 1.5f
);
renderText
(R.
string.
help_page2_text1, 300.0f, 190f, 1.5f
);
renderText
(R.
string.
help_page2_text2, 300.0f, 245.0f, 1.5f
);
renderText
(R.
string.
help_page2_text3, 300.0f, 275.0f, 1.5f
);
renderText
(R.
string.
help_page2_text4, 300.0f, 320.0f, 1.5f
);
}
else if (whichScreen ==
3)
{
mPage3.
render();
renderText
(R.
string.
help_page3_text0, 300.0f, 160.0f, 1.5f
);
renderText
(R.
string.
help_page3_text1, 300.0f, 220f, 1.5f
);
renderText
(R.
string.
help_page3_text2, 300.0f, 250.0f, 1.5f
);
renderText
(R.
string.
help_page3_text3, 300.0f, 280.0f, 1.5f
);
renderText
(R.
string.
help_page3_text4, 300.0f, 310.0f, 1.5f
);
}
}
public void renderText
(int id,
float x,
float y,
float scale
)
{
String text = ResourceManager.
getInstance().
getCurrentContext().
getString(id
);
GameServices.
getFont().
drawText(text, x, y, scale
);
}
public void show
()
{
mIsActive =
true;
mIsActiveTarget =
true;
mPopupTimer = 0.0f
;
mCurrentPage =
0;
}
public void hide
()
{
mIsActiveTarget =
false;
mPopupTimer = 0.0f
;
}
public void hideImmediately
()
{
mIsActiveTarget =
false;
mIsActive =
false;
}
public boolean isActive
()
{
return mIsActive
;
}
}