/** * @brief Notifies this entity that another sprite is overlapping it. * * This function is called by check_collision(MapEntity*, Sprite*) when another entity's * sprite overlaps a sprite of this detector. * * @param other_entity the entity overlapping this detector * @param other_sprite the sprite of other_entity that is overlapping this detector * @param this_sprite the sprite of this detector that is overlapping the other entity's sprite */ void Destructible::notify_collision(MapEntity& other_entity, Sprite& other_sprite, Sprite& this_sprite) { if (features[subtype].can_be_cut && !is_being_cut && !is_disabled() && !is_regenerating && other_entity.is_hero() && other_sprite.contains("sword")) { Hero& hero = static_cast<Hero&>(other_entity); if (hero.is_striking_with_sword(*this)) { play_destroy_animation(); hero.check_position(); // to update the ground under the hero create_pickable(); if (can_explode()) { explode(); } } } // TODO use dynamic dispatch if (other_entity.get_type() == EXPLOSION && can_explode() && !is_being_cut && !is_disabled() && !is_regenerating) { play_destroy_animation(); create_pickable(); explode(); } }
void HSlider::on_mouse_button_down(int mx, int my) { if (is_disabled()) return; this->on_mouse_button_hold(mx, my); }
void Button::draw() { const Theme & theme = this->dialog->get_theme(); ALLEGRO_COLOR fg; ALLEGRO_COLOR bg; SaveState state; double y; if (this->pushed) { fg = theme.bg; bg = theme.fg; } else { fg = theme.fg; bg = theme.bg; } if (is_disabled()) { bg = al_map_rgb(64, 64, 64); } al_draw_filled_rectangle(this->x1, this->y1, this->x2, this->y2, bg); al_draw_rectangle(this->x1 + 0.5, this->y1 + 0.5, this->x2 - 0.5, this->y2 - 0.5, fg, 0); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); /* Center the text vertically in the button, taking the font size * into consideration. */ y = (this->y1 + this->y2 - al_get_font_line_height(theme.font) - 1) / 2; al_draw_text(theme.font, fg, (this->x1 + this->x2 + 1)/2, y, ALLEGRO_ALIGN_CENTRE, this->text.c_str()); }
void List::draw() { const Theme & theme = dialog->get_theme(); SaveState state; ALLEGRO_COLOR bg = theme.bg; if (is_disabled()) { bg = al_map_rgb(64, 64, 64); } al_draw_filled_rectangle(x1 + 1, y1 + 1, x2 - 1, y2 - 1, bg); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); const int font_height = al_get_font_line_height(theme.font); for (unsigned i = 0; i < items.size(); i++) { int yi = y1 + i * font_height; if (i == selected_item) { al_draw_filled_rectangle(x1 + 1, yi, x2 - 1, yi + font_height - 1, theme.highlight); } al_draw_text(theme.font, theme.fg, x1, yi, 0, items.at(i).c_str()); } }
/** * @brief Updates the item. */ void Destructible::update() { MapEntity::update(); if (suspended) { return; } if (is_being_cut && get_sprite().is_animation_finished()) { if (!features[subtype].can_regenerate) { // remove the item from the map destruction_callback(); remove_from_map(); } else { is_being_cut = false; regeneration_date = System::now() + 10000; } } else if (is_disabled() && System::now() >= regeneration_date && !overlaps(get_hero())) { get_sprite().set_current_animation("regenerating"); is_regenerating = true; regeneration_date = 0; } else if (is_regenerating && get_sprite().is_animation_finished()) { get_sprite().set_current_animation("on_ground"); is_regenerating = false; } }
static void draw_row(int y, int sel, int top, int sbtop, int sbbot) { int i = (y - 4 - VSHIFT) + top; int dis = (i < cm->nentries) && is_disabled(cm->menu_entries[i]); printf("\033[%d;%dH\1#1\016x\017%s ", y, MARGIN + 1 + HSHIFT, (i == sel) ? "\1#5" : dis ? "\2#17" : "\1#3"); if (i >= cm->nentries) { fputs(pad_line("", 0, WIDTH - 2 * MARGIN - 4), stdout); } else { display_entry(cm->menu_entries[i], (i == sel) ? "\1#5" : dis ? "\2#17" : "\1#3", (i == sel) ? "\1#6" : dis ? "\2#17" : "\1#4", WIDTH - 2 * MARGIN - 4); } if (cm->nentries <= MENU_ROWS) { printf(" \1#1\016x\017"); } else if (sbtop > 0) { if (y >= sbtop && y <= sbbot) printf(" \1#7\016a\017"); else printf(" \1#1\016x\017"); } else { putchar(' '); /* Don't modify the scrollbar */ } }
void ToggleButton::on_mouse_button_up(int mx, int my) { (void)mx; (void)my; if (is_disabled()) return; }
void tap_log_post_suite(struct criterion_suite_stats *stats) { for (struct criterion_test_stats *ts = stats->tests; ts; ts = ts->next) { if (is_disabled(ts->test, stats->suite)) { criterion_important("ok - %s::%s %s # SKIP %s is disabled\n", ts->test->category, ts->test->name, ts->test->data->description ?: "", ts->test->data->disabled ? "test" : "suite"); } }
void ToggleButton::on_mouse_button_down(int mx, int my) { (void)mx; (void)my; if (is_disabled()) return; set_pushed(!this->pushed); }
/** * \brief Notifies this detector that the player is interacting with it by * pressing the action command. * * This function is called when the player presses the action command * while the hero is facing this detector, and the action command effect lets * him do this. */ void Destructible::notify_action_command_pressed() { KeysEffect::ActionKeyEffect effect = get_keys_effect().get_action_key_effect(); if ((effect == KeysEffect::ACTION_KEY_LIFT || effect == KeysEffect::ACTION_KEY_LOOK) && features[subtype].can_be_lifted && !is_being_cut && !is_disabled() && !is_regenerating) { int weight = features[subtype].weight; if (get_equipment().has_ability("lift", weight)) { uint32_t explosion_date = can_explode() ? System::now() + 6000 : 0; get_hero().start_lifting(new CarriedItem( get_hero(), *this, get_animation_set_id(), get_destruction_sound_id(), get_damage_on_enemies(), explosion_date) ); // play the sound Sound::play("lift"); // create the pickable item create_pickable(); // remove the item from the map if (!features[subtype].can_regenerate) { destruction_callback(); remove_from_map(); } else { // the item can actually regenerate play_destroy_animation(); } } else { if (features[subtype].can_be_cut && !features[subtype].can_explode && !get_equipment().has_ability("sword", 1)) { get_game().start_dialog("_cannot_lift_should_cut", LUA_REFNIL); } else if (!get_equipment().has_ability("lift", 1)) { get_game().start_dialog("_cannot_lift_too_heavy", LUA_REFNIL); } else { get_game().start_dialog("_cannot_lift_still_too_heavy", LUA_REFNIL); } } } }
void Button::on_mouse_button_up(int mx, int my) { (void)mx; (void)my; if (is_disabled()) return; this->pushed = false; dialog->request_draw(); }
void VSlider::on_mouse_button_hold(int mx, int my) { if (is_disabled()) return; double r = (double) (this->y2 - 1 - my) / (this->height() - 2); r = CLAMP(0.0, r, 1.0); cur_value = (int) (r * max_value); dialog->request_draw(); (void)mx; }
void HSlider::on_mouse_button_hold(int mx, int my) { if (is_disabled()) return; double r = (double) (mx - 1 - this->x1) / (this->width() - 2); r = CLAMP(0.0, r, 1.0); cur_value = (int) (r * max_value); dialog->request_draw(); (void)my; }
void hotkey_base::save(config& item) const { item["command"] = get_command(); item["disabled"] = is_disabled(); item["shift"] = !!(mod_ & KMOD_SHIFT); item["ctrl"] = !!(mod_ & KMOD_CTRL); item["cmd"] = !!(mod_ & KMOD_GUI); item["alt"] = !!(mod_ & KMOD_ALT); save_helper(item); }
static CR_INLINE const char *get_status_string(struct criterion_test_stats *ts, struct criterion_suite_stats *ss) { const char *status = "PASSED"; if (ts->crashed || ts->timed_out) status = "ERRORED"; else if (ts->failed) status = "FAILED"; else if (is_disabled(ts->test, ss->suite)) status = "SKIPPED"; return status; }
void MenuButton::_unhandled_key_input(InputEvent p_event) { if (p_event.is_pressed() && !p_event.is_echo() && (p_event.type==InputEvent::KEY || p_event.type==InputEvent::ACTION || p_event.type==InputEvent::JOYSTICK_BUTTON)) { if (!get_parent() || !is_visible() || is_disabled()) return; if (popup->activate_item_by_event(p_event)) accept_event(); } }
void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) { if (p_event->is_pressed() && !p_event->is_echo() && (Object::cast_to<InputEventKey>(p_event.ptr()) || Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventAction>(*p_event))) { if (!get_parent() || !is_visible_in_tree() || is_disabled()) return; bool global_only = (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)); if (popup->activate_item_by_event(p_event, global_only)) accept_event(); } }
static void print_test(FILE *f, struct criterion_test_stats *ts, struct criterion_suite_stats *ss) { fprintf(f, JSON_TEST_TEMPLATE_BEGIN, ts->test->name, (size_t) (ts->passed_asserts + ts->failed_asserts), get_status_string(ts, ss) ); if (is_disabled(ts->test, ss->suite)) { fprintf(f, JSON_SKIPPED_MSG_ENTRY); } else if (ts->crashed) { fprintf(f, JSON_CRASH_MSG_ENTRY); } else if (ts->timed_out) { fprintf(f, JSON_TIMEOUT_MSG_ENTRY); } else if (ts->failed) { fprintf(f, JSON_TEST_FAILED_TEMPLATE_BEGIN); bool first = true; for (struct criterion_assert_stats *asrt = ts->asserts; asrt; asrt = asrt->next) { if (!asrt->passed) { if (!first) { fprintf(f, ",\n"); } else { first = false; } bool sf = criterion_options.short_filename; char *dup = strdup(*asrt->message ? asrt->message : ""); char *saveptr = NULL; char *line = strtok_r(dup, "\n", &saveptr); fprintf(f, JSON_FAILURE_MSG_ENTRY, sf ? basename_compat(asrt->file) : asrt->file, asrt->line, line ); while ((line = strtok_r(NULL, "\n", &saveptr))) { fprintf(f, ",\n \" %s\"", line); } free(dup); } } fprintf(f, JSON_TEST_FAILED_TEMPLATE_END); } fprintf(f, JSON_TEST_TEMPLATE_END); }
bool is_cobra(void) { sysFSStat stat; bool ret = false; if(is_disabled("/dev_blind/habib/cobra/stage2_disabled.cex", "/dev_blind/habib/cobra/stage2.cex")) return true; if(is_disabled("/dev_blind/sys/stage2_disabled.bin", "/dev_blind/sys/stage2.bin")) return true; if(is_disabled("/dev_blind/sys/stage2.bin.bak", "/dev_blind/sys/stage2.bin")) return true; if(is_disabled("/dev_blind/rebug/cobra/stage2.cex.bak", "/dev_blind/rebug/cobra/stage2.cex")) ret = true; if(is_disabled("/dev_blind/rebug/cobra/stage2.dex.bak", "/dev_blind/rebug/cobra/stage2.dex")) ret = true; if(sysLv2FsStat("/dev_flash/sys/stage2.bin", &stat) == SUCCESS) return true; if(sysLv2FsStat("/dev_hdd0/boot_plugins.txt", &stat) == SUCCESS) return true; if(sysLv2FsStat("/dev_flash/rebug/cobra", &stat) == SUCCESS) return true; if (is_mamba()) return false; u32 version = 0x99999999; if (sys_get_version(&version) < 0) return false; if ((version & 0xFF00FF) == 0x04000F || (version & 0xFFFFFF) == 0x03550F) return true; return ret; }
void List::on_click(int mx, int my) { if (is_disabled()) return; const Theme & theme = dialog->get_theme(); unsigned int i = (my - this->y1) / al_get_font_line_height(theme.font); if (i < this->items.size()) { this->selected_item = i; dialog->request_draw(); } (void)mx; (void)my; }
bool hotkey_base::matches(const SDL_Event &event) const { unsigned int mods = sdl_get_mods(); if (!hotkey::is_scope_active(hotkey::get_hotkey_command(get_command()).scope) || !active() || is_disabled()) { return false; } if ((mods != mod_)) { return false; } return matches_helper(event); }
void BaseButton::_unhandled_input(InputEvent p_event) { if (!is_disabled() && is_visible() && p_event.is_pressed() && !p_event.is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { if (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)) return; //ignore because of modal window if (is_toggle_mode()) { set_pressed(!is_pressed()); emit_signal("toggled",is_pressed()); } emit_signal("pressed"); } }
void normal_log_post_suite(struct criterion_suite_stats *stats) { for (struct criterion_test_stats *ts = stats->tests; ts; ts = ts->next) { if (is_disabled(ts->test, stats->suite)) { const char *format = ts->test->data->disabled ? _(msg_post_suite_test) : _(msg_post_suite_suite); criterion_pinfo(CRITERION_PREFIX_SKIP, format, ts->test->category, ts->test->name); if (ts->test->data->description) criterion_pinfo(CRITERION_PREFIX_DASHES, msg_desc, ts->test->data->description); } } }
void TextEntry::draw() { const Theme & theme = dialog->get_theme(); SaveState state; ALLEGRO_COLOR bg = theme.bg; if (is_disabled()) { bg = al_map_rgb(64, 64, 64); } al_draw_filled_rectangle(x1, y1, x2, y2, bg); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); if (!focused) { al_draw_ustr(theme.font, theme.fg, x1, y1, 0, UString(text, left_pos)); } else { int x = x1; if (cursor_pos > 0) { UString sub(text, left_pos, cursor_pos); al_draw_ustr(theme.font, theme.fg, x1, y1, 0, sub); x += al_get_ustr_width(theme.font, sub); } if ((unsigned) cursor_pos == al_ustr_size(text)) { al_draw_filled_rectangle(x, y1, x + CURSOR_WIDTH, y1 + al_get_font_line_height(theme.font), theme.fg); } else { int post_cursor = cursor_pos; al_ustr_next(text, &post_cursor); UString sub(text, cursor_pos, post_cursor); int subw = al_get_ustr_width(theme.font, sub); al_draw_filled_rectangle(x, y1, x + subw, y1 + al_get_font_line_height(theme.font), theme.fg); al_draw_ustr(theme.font, theme.bg, x, y1, 0, sub); x += subw; al_draw_ustr(theme.font, theme.fg, x, y1, 0, UString(text, post_cursor)); } } }
void HSlider::draw() { const Theme & theme = dialog->get_theme(); const int cy = (y1 + y2) / 2; SaveState state; ALLEGRO_COLOR bg = theme.bg; if (is_disabled()) { bg = al_map_rgb(64, 64, 64); } al_draw_filled_rectangle(x1, y1, x2, y2, bg); al_draw_line(x1, cy, x2, cy, theme.fg, 0); double ratio = (double) this->cur_value / (double) this->max_value; int xpos = x1 + (int) (ratio * (width() - 2)); al_draw_filled_rectangle(xpos - 2, y1, xpos + 2, y2, theme.fg); }
void VSlider::draw() { const Theme & theme = dialog->get_theme(); ALLEGRO_COLOR bg = theme.fg; float left = x1 + 0.5, top = y1 + 0.5; float right = x2 + 0.5, bottom = y2 + 0.5; SaveState state; if (is_disabled()) { bg = al_map_rgb(64, 64, 64); } al_draw_rectangle(left, top, right, bottom, bg, 1); double ratio = (double) this->cur_value / (double) this->max_value; int ypos = (int) (bottom - 0.5 - (int) (ratio * (height() - 7))); al_draw_filled_rectangle(left + 0.5, ypos - 5, right - 0.5, ypos, theme.fg); }
/** * \brief This function is called when this entity detects a collision with the hero. * \param hero the hero * \param collision_mode the collision mode that detected the collision */ void Destructible::notify_collision_with_hero(Hero& hero, CollisionMode collision_mode) { if (features[subtype].can_be_lifted && !is_being_cut && !is_disabled() && !is_regenerating && get_keys_effect().get_action_key_effect() == KeysEffect::ACTION_KEY_NONE && hero.is_free()) { int weight = features[subtype].weight; if (get_equipment().has_ability("lift", weight)) { get_keys_effect().set_action_key_effect(KeysEffect::ACTION_KEY_LIFT); } else { get_keys_effect().set_action_key_effect(KeysEffect::ACTION_KEY_LOOK); } } }
void MenuButton::_unhandled_key_input(InputEvent p_event) { //check accelerators if (p_event.type==InputEvent::KEY && p_event.key.pressed) { if (!get_parent() || !is_visible() || is_disabled()) return; uint32_t code=p_event.key.scancode; if (code==0) code=p_event.key.unicode; if (p_event.key.mod.control) code|=KEY_MASK_CTRL; if (p_event.key.mod.alt) code|=KEY_MASK_ALT; if (p_event.key.mod.meta) code|=KEY_MASK_META; if (p_event.key.mod.shift) code|=KEY_MASK_SHIFT; int item = popup->find_item_by_accelerator(code); if (item>=0 && ! popup->is_item_disabled(item)) popup->activate_item(item); /* for(int i=0;i<items.size();i++) { if (items[i].accel==0) continue; if (items[i].accel==code) { emit_signal("item_pressed",items[i].ID); } }*/ } }
void Label::draw() { const Theme & theme = this->dialog->get_theme(); SaveState state; ALLEGRO_COLOR fg = theme.fg; if (is_disabled()) { fg = al_map_rgb(64, 64, 64); } al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); if (centred) { al_draw_text(theme.font, fg, (this->x1 + this->x2 + 1)/2, this->y1, ALLEGRO_ALIGN_CENTRE, this->text.c_str()); } else { al_draw_text(theme.font, fg, this->x1, this->y1, 0, this->text.c_str()); } }
void TextEntry::on_key_down(const ALLEGRO_KEYBOARD_EVENT & event) { if (is_disabled()) return; switch (event.keycode) { case ALLEGRO_KEY_LEFT: al_ustr_prev(text, &cursor_pos); break; case ALLEGRO_KEY_RIGHT: al_ustr_next(text, &cursor_pos); break; case ALLEGRO_KEY_HOME: cursor_pos = 0; break; case ALLEGRO_KEY_END: cursor_pos = al_ustr_size(text); break; case ALLEGRO_KEY_DELETE: al_ustr_remove_chr(text, cursor_pos); break; case ALLEGRO_KEY_BACKSPACE: if (al_ustr_prev(text, &cursor_pos)) al_ustr_remove_chr(text, cursor_pos); break; default: if (event.unichar >= ' ') { al_ustr_insert_chr(text, cursor_pos, event.unichar); cursor_pos += al_utf8_width(event.unichar); } break; } maybe_scroll(); dialog->request_draw(); }