Skip to content

Commit

Permalink
[view] Progress bars and wind support in Room #19
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaudic committed Jan 3, 2020
1 parent 766c1b8 commit 97cc4ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/views/roomview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Uint16 RoomView::MAX_POWER;
*/
RoomView::RoomView(const GameMode mode, GameMap *map) : Context(ContextName::ROOM),
btn_1("1"), btn_2("2"), btn_supershot("SS"),
pb_power(0, MAX_POWER, 0), pb_motion(0, MOTION_LIMIT, MOTION_LIMIT),
currentMode(InteractionMode::IDLE), gameMode(mode),
currentMap(map) {

Expand All @@ -51,6 +52,14 @@ currentMap(map) {
tf_chat.setActionEventId("text");
tf_chat.addActionListener(this);

pb_motion.setHeight(15);
pb_motion.setForegroundColor(gcn::Color(0x0, 0x77, 0x73));
pb_motion.setVisible(false); // only shows up when moving
pb_motion.setWidth(getWidth() / 2);
pb_power.setHeight(20);
pb_power.setForegroundColor(gcn::Color(0xff, 0, 0));
pb_power.setWidth(getWidth() - 100 - 10);

currentMap->load();

}
Expand Down Expand Up @@ -94,10 +103,14 @@ void RoomView::drawBackground(SDL_Renderer *screen) {

// Draw map background
SDL_RenderCopy(screen, currentMap->getBackground(), &bg_rect, &fullScreen);
// Draw weather effects if any

// Draw map foreground
SDL_RenderCopy(screen, currentMap->getForeground(), &fg_rect, &fullScreen);
// Draw mobiles

// Draw flying weapons if any

SDL_RenderSetClipRect(screen, NULL);
}

Expand All @@ -111,6 +124,7 @@ void RoomView::processEvent(SDL_Event &event) {
if (event.key.keysym.sym == SDLK_SPACE && !tf_chat.isFocused() && currentMode == InteractionMode::TURN) {
currentPower += POWER_INCREMENT;
currentPower = min(currentPower, MAX_POWER);
pb_power.setValue(currentPower);
}
} else if (event.type == SDL_KEYUP) {
if (event.key.keysym.sym == SDLK_SPACE && !tf_chat.isFocused() && currentMode == InteractionMode::TURN) {
Expand Down Expand Up @@ -160,6 +174,22 @@ void RoomView::addWidgets() {
addWidget(&btn_supershot, 40, getHeight() - 5 - btn_supershot.getHeight());
addWidget(&btn_2, 40, btn_supershot.getY() - 5 - btn_2.getHeight());
addWidget(&btn_1, 40, btn_2.getY() - 5 - btn_1.getHeight());
addWidget(&lbl_wind, 20, getHeight() - 20);

addWidget(&pb_power, 70, getHeight() - pb_power.getHeight() - 10);
addWidget(&pb_motion, 70, pb_power.getY() - 20);
}

/**
* \brief React on wind update
* \param newPower new power value (0-25)
* \param newAngle new angle value (0-360), in degrees
*/
void RoomView::setWind(Uint8 newPower, Uint16 newAngle) {
windPower = newPower;
windAngle = newAngle;
lbl_wind.setCaption(to_string(windPower));
// TODO play a sound
}

/**
Expand All @@ -169,6 +199,8 @@ void RoomView::setTurn() {
currentMode = InteractionMode::TURN;
currentPower = 0;
motionLeft = MOTION_LIMIT;
pb_power.setValue(currentPower);
pb_motion.setValue(motionLeft);
// TODO play a sound once to wake up player
}

Expand Down
6 changes: 6 additions & 0 deletions src/views/roomview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class RoomView: public Context, public gcn::ActionListener {
gcn::Label lbl_lastAngle;
gcn::Label lbl_currentAngle;
gcn::Label lbl_wind;
gcn::ProgressBar pb_power;
gcn::ProgressBar pb_motion;

Uint16 turnCount = 0;
InteractionMode currentMode;
Expand All @@ -70,6 +72,9 @@ class RoomView: public Context, public gcn::ActionListener {
Uint16 currentPower = 0;
Uint16 motionLeft = 0;

Uint8 windPower = 0;
Uint16 windAngle = 0;

static const Uint32 AUTOSCROLL_DELAY = 2000; // in ms
static const Uint16 SCROLL_DELTA = 4; // in pixels, for the foreground
static const Uint16 MAX_POWER = 1000;
Expand All @@ -78,6 +83,7 @@ class RoomView: public Context, public gcn::ActionListener {
static const Uint16 MAGIC_EDGE_WIDTH = 20; // in pixels

void addWidgets();
void setWind(Uint8 newPower, Uint16 newAngle);
void updateMagicEdge(const int coordinate, Uint32 &target);
void moveViewport(const int xDelta, const int yDelta);
void moveViewportTo(const int x, const int y);
Expand Down

0 comments on commit 97cc4ed

Please sign in to comment.