void SpellView::show_spell_description() { if(get_selected_index() != -1) { uint8 index = (level-1)*16 + get_selected_index(); Game::get_game()->get_magic()->show_spell_description(index); } close_look(); }
/** * @brief Deletes an animation. * * The index of the selection may change, since animations are sorted * alphabetically. * Emits rowsAboutToBeRemoved(), removes the animation * and then emits rowsRemoved(), as required by QAbstractItemModel. * * Then, emits animation_deleted(). * * Except for the deleted animation, the existing selection is preserved, * though the index of many animations can change. * The selection is cleared before the operations and restored after, * updated with the new index. * * @param index Index of the animation to delete. * @throws EditorException in case of error. */ void SpriteModel::delete_animation(const Index &index) { // Make some checks first. if (!animation_exists(index)) { throw EditorException( tr("Animation '%1' don't exists").arg(index.animation_name)); } // Save and clear the selection since a lot of indexes may change. Index selection = get_selected_index(); clear_selection(); int animation_nb = get_animation_nb(index); // Delete the animation in the sprite file. sprite.remove_animation(index.animation_name.toStdString()); // Rebuild indexes in the list model (indexes were shifted). build_index_map(); // Call beginRemoveRows() as requested by QAbstractItemModel. beginRemoveRows(QModelIndex(), animation_nb, animation_nb); // Update our animation model list. animations.removeAt(animation_nb); // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. endRemoveRows(); emit animation_deleted(index); // Restore the selection. set_selected_index(selection); }
/** * @brief Assigns the selected item to a slot. * * The operation does not take effect immediately: the item picture is thrown to * its destination icon, then the assignment is done. * Nothing is done if the item is not assignable. * * @param slot slot to set (0 for X or 1 for V) */ void PauseSubmenuInventory::assign_item(int slot) { int index = get_selected_index(); const std::string &item_name = item_names[index]; // if this item is not assignable, do nothing if (!equipment.get_item_properties(item_name).can_be_assigned()) { return; } // if another item is being assigned, finish it immediately if (is_assigning_item()) { finish_assigning_item(); } // memorize this item this->item_assigned_name = item_name; this->item_assigned_sprite = sprites[index]; this->item_assigned_variant = equipment.has_item(item_assigned_name); this->item_assigned_destination = slot; // play the sound Sound::play("throw"); // compute the movement int x1 = 60 + 32 * cursor_column; int y1 = 75 + 32 * cursor_row; int x2 = (slot == 0) ? 20 : 72; int y2 = 46; item_assigned_movement = new TargetMovement(x2, y2, 500); item_assigned_movement->set_xy(x1, y1); }
/** * @brief Moves a direction. * @param index Index of the direction to move. * @param new_direction_nb The new number of the direction. * @throws EditorException in case of error. */ void SpriteModel::move_direction(const Index& index, int new_direction_nb) { if (new_direction_nb == index.direction_nb) { // Nothing to do. return; } // Make some checks first. if (!direction_exists(index)) { QString nb = std::to_string(index.direction_nb).c_str(); throw EditorException( tr("Direction %1 don't exists in animation '%2'").arg( nb, index.animation_name)); } // Save and clear the selection. Index selection = get_selected_index(); clear_selection(); // Move the direction in the sprite file. get_animation(index).move_direction(index.direction_nb, new_direction_nb); // Call beginMoveRows() as requested by QAbstractItemModel. int above_row = new_direction_nb; if (new_direction_nb > index.direction_nb) { ++above_row; } QModelIndex model_index = get_model_index(Index(index.animation_name)); beginMoveRows(model_index, index.direction_nb, index.direction_nb, model_index, above_row); // Update our animation model list. int animation_nb = get_animation_nb(index); animations[animation_nb].directions.move(index.direction_nb, new_direction_nb); // Update direction model indexes. int num_dir = animations[animation_nb].directions.size(); for (int nb = 0; nb < num_dir; nb++) { animations[animation_nb].directions[nb].index->direction_nb = nb; } endMoveRows(); // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. emit direction_deleted(index); // Restore the selection. if (selection.direction_nb == index.direction_nb) { selection.direction_nb = new_direction_nb; } set_selected_index(selection); }
/** * @brief Shows a message describing the item currently selected. * * The player must have this item. */ void PauseSubmenuInventory::show_info_message() { const std::string &item_name = item_names[get_selected_index()]; int variant = equipment.get_item_variant(item_name); std::ostringstream oss; oss << "_item_description." << item_name << '.' << variant; DialogBox::VerticalPosition vertical_position = (cursor_row >= 2) ? DialogBox::POSITION_TOP : DialogBox::POSITION_BOTTOM; game.get_dialog_box().start_dialog(oss.str(), NULL, vertical_position); }
GUI_status SpellView::move_up() { sint8 index = get_selected_index(); if(index > 0 && index != num_spells_per_page) { spell_container->quality = cur_spells[index-1]; update_display = true; } else move_left(); return GUI_YUM; }
/** * @brief Selects an animation at the specified index. * * If the selection is a direction of the specified animation, * the selection remains unchanged. * * @param index The index of animation to select. */ void SpriteModel::set_selected_animation(const Index& index) { if (!index.is_valid()) { selection_model.clear(); return; } QString selected_name = get_selected_index().animation_name; if (index.is_direction_index() && index.animation_name == selected_name) { return; } // select the animation set_selected_index(index.animation_name); }
/** * @brief Inserts a direction in an animation of this sprite. * @param index Index of the direction to insert. * @param data The direction data to insert. * @return Index of the inserted direction. * @throws EditorException in case of error. */ int SpriteModel::insert_direction( const Index& index, const SpriteAnimationDirectionData& data) { // Make some checks first. if (!animation_exists(index)) { throw EditorException( tr("Animation '%1' don't exists").arg(index.animation_name)); } // Save and clear the selection. Index selection = get_selected_index(); clear_selection(); // Insert the direction to the sprite file. SpriteAnimationData& animation_data = get_animation(index); animation_data.add_direction(data); int last_dir = animation_data.get_num_directions() - 1; animation_data.move_direction(last_dir, index.direction_nb); int direction_nb = std::min(index.direction_nb, last_dir); // Call beginInsertRows() as requested by QAbstractItemModel. QModelIndex model_index = get_model_index(Index(index.animation_name)); beginInsertRows(model_index, direction_nb, direction_nb); // Update our animation model list. int animation_nb = get_animation_nb(index); auto& directions = animations[animation_nb].directions; directions.insert( direction_nb, DirectionModel(index.animation_name, direction_nb)); // Update direction model indexes. for (int nb = direction_nb + 1; nb < directions.size(); nb++) { directions[nb].index->direction_nb = nb; } // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. endInsertRows(); emit direction_added(Index(index.animation_name, direction_nb)); // Restore the selection. set_selected_index(selection); return direction_nb; }
void SpellView::move_right() { sint8 index = get_selected_index(); if(index < 0) index = 0; if(index >= num_spells_per_page || cur_spells[num_spells_per_page] == -1) { set_next_level(); } else { spell_container->quality = cur_spells[num_spells_per_page]; } update_buttons(); update_display = true; }
GUI_status SpellView::move_down() { sint8 index = get_selected_index(); if(index != -1 && index < 15 && index != (num_spells_per_page-1)) { if(cur_spells[index+1] != -1) { spell_container->quality = cur_spells[index+1]; update_display = true; } else move_right(); } else move_right(); return GUI_YUM; }
void SpellView::move_left() { sint8 index = get_selected_index(); if(index < 0) index = 0; if(index >= num_spells_per_page) { spell_container->quality = cur_spells[0]; } else { set_prev_level(); } update_buttons(); update_display = true; }
/** * @brief Inserts an animation in this sprite. * * The index of the selection may change, since animations are sorted * alphabetically. * Emits rowsAboutToBeInserted(), inserts the animation * and then emits rowsInserted(), as required by QAbstractItemModel. * * Then, emits animation_created(). * * The newly created animation is not initially selected. * The existing selection is preserved, though the index of many * animations can change. * The selection is cleared before the operations and restored after, * updated with the new index. * * @param index Index of the animation to insert. * @param data Data of the animation. * @throws EditorException in case of error. */ void SpriteModel::insert_animation( const Index& index, const Solarus::SpriteAnimationData& data) { // Make some checks first. if (index.animation_name.length() <= 0) { throw EditorException(tr("Animation name cannot be empty")); } if (animation_exists(index)) { throw EditorException( tr("Animation '%1' already exists").arg(index.animation_name)); } // Save and clear the selection since a lot of indexes may change. Index selection = get_selected_index(); clear_selection(); // Add the animation to the sprite file. sprite.add_animation(index.animation_name.toStdString(), data); // Rebuild indexes in the list model (indexes were shifted). build_index_map(); // Call beginInsertRows() as requested by QAbstractItemModel. int animation_nb = get_animation_nb(index.animation_name); beginInsertRows(QModelIndex(), animation_nb, animation_nb); // Update our animation model list. animations.insert(animation_nb, AnimationModel(index.animation_name)); int num_directions = data.get_num_directions(); for (int nb = 0; nb < num_directions; nb++) { animations[animation_nb].directions.append( DirectionModel(index.animation_name, nb)); } // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. endInsertRows(); emit animation_created(index); // Restore the selection. set_selected_index(selection); }
/** * @brief Deletes a direction. * @param index Index of the direction to delete. * @throws EditorException in case of error. */ void SpriteModel::delete_direction(const Index &index) { // Make some checks first. if (!direction_exists(index)) { QString nb = std::to_string(index.direction_nb).c_str(); throw EditorException( tr("Direction %1 don't exists in animation '%2'").arg( nb, index.animation_name)); } // Save and clear the selection. Index selection = get_selected_index(); if (selection.animation_name == index.animation_name && selection.direction_nb == index.direction_nb) { selection.direction_nb = -1; } clear_selection(); // Delete the direction in the sprite file. get_animation(index).remove_direction(index.direction_nb); // Call beginRemoveRows() as requested by QAbstractItemModel. QModelIndex model_index = get_model_index(Index(index.animation_name)); beginRemoveRows(model_index, index.direction_nb, index.direction_nb); // Update our direction model list. int animation_nb = get_animation_nb(index); auto& directions = animations[animation_nb].directions; directions.removeAt(index.direction_nb); // Update direction model indexes. for (int nb = index.direction_nb; nb < directions.size(); nb++) { directions[nb].index->direction_nb = nb; } // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. endRemoveRows(); emit direction_deleted(index); // Restore the selection. set_selected_index(selection); }
/** * @brief Adds a direction in an animation of this sprite. * @param index Index of the animation to add the direction. * @param frame The first frame of the direction to create. * @return Index of the created direction. * @throws EditorException in case of error. */ int SpriteModel::add_direction(const Index& index, const QRect& frame) { // Make some checks first. if (!animation_exists(index)) { throw EditorException( tr("Animation '%1' don't exists").arg(index.animation_name)); } // Save and clear the selection. Index selection = get_selected_index(); clear_selection(); // Add the direction to the sprite file. SpriteAnimationData& animation_data = get_animation(index); SpriteAnimationDirectionData direction( Point::to_solarus_point(frame.topLeft()), Size::to_solarus_size(frame.size())); animation_data.add_direction(direction); // Rebuild indexes in the list model (indexes were shifted). int direction_nb = animation_data.get_num_directions() - 1; // Call beginInsertRows() as requested by QAbstractItemModel. QModelIndex model_index = get_model_index(Index(index.animation_name)); beginInsertRows(model_index, direction_nb, direction_nb); // Update our animation model list. int animation_nb = get_animation_nb(index); animations[animation_nb].directions.append( DirectionModel(index.animation_name, direction_nb)); // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. endInsertRows(); emit direction_added(Index(index.animation_name, direction_nb)); // Restore the selection. set_selected_index(selection); return direction_nb; }
void SpellView::display_spell_list_text() { Magic *m = Game::get_game()->get_magic(); sint8 index = get_selected_index(); if(index >= num_spells_per_page) index = num_spells_per_page; else index = 0; for(uint8 i=0;i<num_spells_per_page;i++) { sint16 spell_num = cur_spells[i+index]; if(spell_num != -1) { Spell *spell = m->get_spell((uint8)spell_num); display_spell_text(spell, i, spell_container->quality); } } }
static gboolean scrollable_touch_event(GltkWidget* scrollable, GltkEventTouch* event, GltkSpinner* spinner) { USING_PRIVATE(spinner); if (event->touchType == TOUCH_END) { int level; for (level = 0; level < priv->model->levels; level++) { if (priv->wheels[level].scrollable != scrollable) continue; int index = get_selected_index(spinner, level); GLTK_SCROLLABLE(priv->wheels[level].scrollable)->offset.y = (-index + priv->visibleItems/2) * priv->itemHeight; if (index != priv->wheels[level].index) { priv->wheels[level].index = index; if (level == priv->model->levels - 1) { g_object_ref(spinner); g_signal_emit(spinner, signals[ITEM_SELECTED], 0); g_object_unref(spinner); } else { //load our new items into the next spinner load_items(spinner, level+1, gltk_spinner_model_get_items(priv->model, level, index)); gltk_widget_layout(GLTK_WIDGET(spinner)); } } break; } } return FALSE; }
void SpellView::update_buttons() { show_buttons(); sint8 index = get_selected_index(); if(level == 1 && index <= (num_spells_per_page-1) && left_button) left_button->Hide(); uint8 old_level = level; uint8 num_spells = 0; for(;num_spells == 0;) { level++; if(level == 9) break; num_spells = fill_cur_spell_list(); } level = old_level; fill_cur_spell_list(); if(right_button && ((level < 8 && num_spells == 0) || level == 8) && cur_spells[num_spells_per_page*(1+index/num_spells_per_page)] == -1) right_button->Hide(); }
/** * @brief Changes the name of an animation. * * The index of the selection may change, since animations are sorted * alphabetically. * In this case, emits rowsAboutToBeMoved(), changes the index * and then emits rowsMoved(), as required by QAbstractItemModel. * * Then, emits animation_name_changed(), no matter if the index has also changed. * * The selection is preserved, though the index of many animations can change. * The selection is cleared before the operations and restored after, * updated with the new index. * * @param index Index of an existing animation. * @param new_name The new name to set. * @throws EditorException in case of error. */ void SpriteModel::set_animation_name(const Index& index, const QString& new_name) { if (new_name == index.animation_name) { // Nothing to do. return; } // Make some checks first. if (!animation_exists(index)) { throw EditorException( tr("Animation '%1' don't exists").arg(index.animation_name)); } if (new_name.length() <= 0) { throw EditorException(tr("Animation name cannot be empty")); } if (animation_exists(new_name)) { throw EditorException(tr("Animation '%1' already exists").arg(new_name)); } // Save and clear the selection since a lot of indexes may change. Index selection = get_selected_index(); clear_selection(); int animation_nb = get_animation_nb(index); // Change the name in the sprite file. sprite.set_animation_name( index.animation_name.toStdString(), new_name.toStdString()); // Change the index in the list model (if the order has changed). build_index_map(); int new_animation_nb = get_animation_nb(new_name); // Call beginMoveRows() if the index changes, as requested by // QAbstractItemModel. if (new_animation_nb != animation_nb) { int above_row = new_animation_nb; if (new_animation_nb > animation_nb) { ++above_row; } beginMoveRows(QModelIndex(), animation_nb, animation_nb, QModelIndex(), above_row); // Update our animation model list. animations.move(animation_nb, new_animation_nb); } animations[new_animation_nb].set_animation_name(new_name); // Notify people before restoring the selection, so that they have a // chance to know new indexes before receiving selection signals. if (new_animation_nb != animation_nb) { endMoveRows(); } emit animation_name_changed(index, Index(new_name)); // Restore the selection. if (selection.animation_name == index.animation_name) { selection.animation_name = new_name; } set_selected_index(selection); }
/** * @brief Returns whether an item is selected. * * This function returns whether whether the cursor is on an * item that the player has. * * @return true if an item is currently selected */ bool PauseSubmenuInventory::is_item_selected() { return equipment.has_item(item_names[get_selected_index()]); }
GUI_status SpellView::MouseDown(int x, int y, int button) { y -= area.y; x -= area.x; Event *event = Game::get_game()->get_event(); bool selecting_spell_target, canceling_spell, doing_nothing; if(Game::get_game()->is_original_plus()) { if(Game::get_game()->is_original_plus_full_map()) selecting_spell_target = (x < -7 || y > 194); else selecting_spell_target = (x < -7); canceling_spell = (x > 1 && (y > 101 || x > 137)); doing_nothing = ((x > -8 && x < 16) || (x > -8 && (y < 8 || (y > 71 && y < 195)))); } else { selecting_spell_target = (x < 0 && y > 0 && y < 162); canceling_spell = (x > 1 && (y > 101 || x > 137)); doing_nothing = (y < 8 || y > 71 || x < 16 || x > 134); } if(button == SDL_BUTTON_WHEELUP) return move_up(); if(button == SDL_BUTTON_WHEELDOWN) return move_down(); if(button == SDL_BUTTON_RIGHT) return cancel_spell(); if(selecting_spell_target) // cast selected spell on the map { if(event->is_looking_at_spellbook()) { close_look(); return GUI_YUM; } event->target_spell(); if(event->get_mode() == INPUT_MODE) { y += area.y; x += area.x; Game::get_game()->get_map_window()->select_target(x, y); } return GUI_YUM; } if(canceling_spell) // cancel spell return cancel_spell(); if(doing_nothing) // do nothing return GUI_YUM; // selecting spell index sint8 index = get_selected_index(); if(index >= num_spells_per_page) index = num_spells_per_page; else index = 0; y = (y / num_spells_per_page) - 1; //printf("x = %d, y = %d index=%d\n", x, y, index); if(cur_spells[index+y] != -1) { spell_container->quality = cur_spells[index+y]; update_display = true; if(event->is_looking_at_spellbook()) show_spell_description(); else if(event_mode) event_mode_select_spell(); else Game::get_game()->get_event()->target_spell(); } return GUI_YUM; }