/** * \brief Updates the animation of the hero's sprites if necessary. */ void HeroSprites::update() { // Keep the current sprites here in case they change from a script during the operation. SpritePtr tunic_sprite = this->tunic_sprite; SpritePtr sword_sprite = this->sword_sprite; // update the frames tunic_sprite->update(); if (is_sword_visible()) { sword_sprite->update(); sword_sprite->set_current_frame(tunic_sprite->get_current_frame()); hero.check_collision_with_detectors(*sword_sprite); } hero.check_collision_with_detectors(*tunic_sprite); if (is_sword_stars_visible()) { // the stars are not synchronized with the other sprites sword_stars_sprite->update(); } if (is_shield_visible()) { shield_sprite->update(); if (walking) { shield_sprite->set_current_frame(tunic_sprite->get_current_frame()); } } if (is_trail_visible()) { trail_sprite->update(); } if (is_ground_visible()) { ground_sprite->update(); } if (lifted_item != nullptr && walking) { lifted_item->get_sprite().set_current_frame(tunic_sprite->get_current_frame() % 3); } // blinking if (is_blinking() && end_blink_date != 0 && System::now() >= end_blink_date) { stop_blinking(); } // Lua callback. if (tunic_sprite->is_animation_finished() && !animation_callback_ref.is_empty()) { animation_callback_ref.clear_and_call("hero animation callback"); } }
/** * \brief Updates the animation of the hero's sprites if necessary. */ void HeroSprites::update() { // update the frames tunic_sprite->update(); if (is_sword_visible()) { sword_sprite->update(); sword_sprite->set_current_frame(tunic_sprite->get_current_frame()); hero.check_collision_with_detectors(*sword_sprite); } hero.check_collision_with_detectors(*tunic_sprite); if (is_sword_stars_visible()) { // the stars are not synchronized with the other sprites sword_stars_sprite->update(); } if (is_shield_visible()) { shield_sprite->update(); if (walking) { shield_sprite->set_current_frame(tunic_sprite->get_current_frame()); } } if (is_trail_visible()) { trail_sprite->update(); } if (is_ground_visible()) { ground_sprite->update(); } if (lifted_item != NULL && walking) { lifted_item->get_sprite().set_current_frame(tunic_sprite->get_current_frame() % 3); } // blinking if (tunic_sprite->is_blinking() && System::now() >= end_blink_date) { stop_blinking(); } }
static gboolean maybe_change_state (DrWright *dr) { gint elapsed_time; gint elapsed_idle_time; if (debug) { drw_timer_start (dr->idle_timer); } elapsed_time = drw_timer_elapsed (dr->timer) + dr->save_last_time; elapsed_idle_time = drw_timer_elapsed (dr->idle_timer); if (elapsed_time > dr->last_elapsed_time + dr->warn_time) { /* If the timeout is delayed by the amount of warning time, then * we must have been suspended or stopped, so we just start * over. */ dr->state = STATE_START; } switch (dr->state) { case STATE_START: if (dr->break_window) { gtk_widget_destroy (dr->break_window); dr->break_window = NULL; } #ifndef HAVE_APP_INDICATOR gtk_status_icon_set_from_pixbuf (dr->icon, dr->neutral_bar); #endif /* HAVE_APP_INDICATOR */ dr->save_last_time = 0; drw_timer_start (dr->timer); drw_timer_start (dr->idle_timer); if (dr->enabled) { dr->state = STATE_RUNNING; } update_status (dr); stop_blinking (dr); break; case STATE_RUNNING: case STATE_WARN: if (elapsed_idle_time >= dr->break_time) { dr->state = STATE_BREAK_DONE_SETUP; } else if (elapsed_time >= dr->type_time) { dr->state = STATE_BREAK_SETUP; } else if (dr->state != STATE_WARN && elapsed_time >= dr->type_time - dr->warn_time) { dr->state = STATE_WARN; start_blinking (dr); } break; case STATE_BREAK_SETUP: /* Don't allow more than one break window to coexist, can happen * if a break is manually enforced. */ if (dr->break_window) { dr->state = STATE_BREAK; break; } stop_blinking (dr); #ifndef HAVE_APP_INDICATOR gtk_status_icon_set_from_pixbuf (dr->icon, dr->red_bar); #endif /* HAVE_APP_INDICATOR */ drw_timer_start (dr->timer); dr->break_window = drw_break_window_new (); g_signal_connect (dr->break_window, "map_event", G_CALLBACK (break_window_map_event_cb), dr); g_signal_connect (dr->break_window, "done", G_CALLBACK (break_window_done_cb), dr); g_signal_connect (dr->break_window, "postpone", G_CALLBACK (break_window_postpone_cb), dr); g_signal_connect (dr->break_window, "destroy", G_CALLBACK (break_window_destroy_cb), dr); dr->secondary_break_windows = create_secondary_break_windows (); gtk_widget_show (dr->break_window); dr->save_last_time = elapsed_time; dr->state = STATE_BREAK; break; case STATE_BREAK: if (elapsed_time - dr->save_last_time >= dr->break_time) { dr->state = STATE_BREAK_DONE_SETUP; } break; case STATE_BREAK_DONE_SETUP: stop_blinking (dr); #ifndef HAVE_APP_INDICATOR gtk_status_icon_set_from_pixbuf (dr->icon, dr->green_bar); #endif /* HAVE_APP_INDICATOR */ dr->state = STATE_BREAK_DONE; break; case STATE_BREAK_DONE: dr->state = STATE_START; if (dr->break_window) { gtk_widget_destroy (dr->break_window); dr->break_window = NULL; } break; } dr->last_elapsed_time = elapsed_time; #ifdef HAVE_APP_INDICATOR update_app_indicator (dr); #else update_icon (dr); #endif /* HAVE_APP_INDICATOR */ return TRUE; }
static gboolean maybe_change_state (DrWright *dr) { gint elapsed_time; gint elapsed_idle_time; if (debug) { g_timer_reset (dr->idle_timer); } elapsed_time = g_timer_elapsed (dr->timer, NULL); elapsed_idle_time = g_timer_elapsed (dr->idle_timer, NULL); if (elapsed_time > dr->last_elapsed_time + dr->warn_time) { /* If the timeout is delayed by the amount of warning time, then * we must have been suspended or stopped, so we just start * over. */ dr->state = STATE_START; } switch (dr->state) { case STATE_START: if (dr->break_window) { gtk_widget_destroy (dr->break_window); dr->break_window = NULL; } gtk_status_icon_set_from_pixbuf (dr->icon, dr->neutral_bar); g_timer_start (dr->timer); g_timer_start (dr->idle_timer); if (dr->enabled) { dr->state = STATE_IDLE; } update_tooltip (dr); stop_blinking (dr); break; case STATE_IDLE: if (elapsed_idle_time >= dr->break_time) { g_timer_start (dr->timer); g_timer_start (dr->idle_timer); } else if (dr->is_active) { dr->state = STATE_TYPE; } break; case STATE_TYPE: if (elapsed_time >= dr->type_time - dr->warn_time) { dr->state = STATE_WARN_TYPE; g_timer_start (dr->timer); start_blinking (dr); } else if (elapsed_time >= dr->type_time) { dr->state = STATE_BREAK_SETUP; } else if (!dr->is_active) { dr->state = STATE_IDLE; g_timer_start (dr->idle_timer); } break; case STATE_WARN_TYPE: if (elapsed_time >= dr->warn_time) { dr->state = STATE_BREAK_SETUP; } else if (!dr->is_active) { dr->state = STATE_WARN_IDLE; } break; case STATE_WARN_IDLE: if (elapsed_idle_time >= dr->break_time) { dr->state = STATE_BREAK_DONE_SETUP; } else if (dr->is_active) { dr->state = STATE_WARN_TYPE; } break; case STATE_BREAK_SETUP: /* Don't allow more than one break window to coexist, can happen * if a break is manually enforced. */ if (dr->break_window) { dr->state = STATE_BREAK; break; } stop_blinking (dr); gtk_status_icon_set_from_pixbuf (dr->icon, dr->red_bar); g_timer_start (dr->timer); dr->break_window = drw_break_window_new (); g_signal_connect (dr->break_window, "map_event", G_CALLBACK (break_window_map_event_cb), dr); g_signal_connect (dr->break_window, "done", G_CALLBACK (break_window_done_cb), dr); g_signal_connect (dr->break_window, "postpone", G_CALLBACK (break_window_postpone_cb), dr); g_signal_connect (dr->break_window, "destroy", G_CALLBACK (break_window_destroy_cb), dr); dr->secondary_break_windows = create_secondary_break_windows (); gtk_widget_show (dr->break_window); dr->state = STATE_BREAK; break; case STATE_BREAK: if (elapsed_time >= dr->break_time) { dr->state = STATE_BREAK_DONE_SETUP; } break; case STATE_BREAK_DONE_SETUP: stop_blinking (dr); gtk_status_icon_set_from_pixbuf (dr->icon, dr->green_bar); dr->state = STATE_BREAK_DONE; break; case STATE_BREAK_DONE: if (dr->is_active) { dr->state = STATE_START; if (dr->break_window) { gtk_widget_destroy (dr->break_window); dr->break_window = NULL; } } break; } dr->is_active = FALSE; dr->last_elapsed_time = elapsed_time; update_icon (dr); return TRUE; }