/* * Copyright 2008 Ben Boeckel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ // Header include #include "MapUI.h" // PokeModr includes #include "TilemapModel.h" // Pokemod includes #include "../pokemod/Map.h" #include "../pokemod/MapWarp.h" #include "../pokemod/Pokemod.h" #include "../pokemod/Tile.h" // Qt includes #include MapUI::MapUI(Map* map, QWidget* parent) : ObjectUI(parent) { setupUi(this); setObjects(map, new Map(*map)); } MapUI::~MapUI() { } void MapUI::initGui() { varType->addItems(Map::TypeStr); varTilemap->horizontalHeader()->setResizeMode(QHeaderView::Fixed); varTilemap->verticalHeader()->setResizeMode(QHeaderView::Fixed); varTilemap->horizontalHeader()->setDefaultSectionSize(64); varTilemap->verticalHeader()->setDefaultSectionSize(64); varTilemap->setModel(new TilemapModel(static_cast(modified())->map(), pokemod())); } void MapUI::refreshGui() { varFlyWarp->clear(); for (int i = 0; i < static_cast(original())->warpCount(); ++i) { const MapWarp* warp = static_cast(original())->warp(i); varFlyWarp->addItem(warp->name(), warp->id()); } varTile->clear(); for (int i = 0; i < pokemod()->tileCount(); ++i) { const Tile* tile = pokemod()->tile(i); varTile->addItem(tile->sprite(), tile->name(), tile->id()); } varTile->setEnabled(false); } void MapUI::setGui() { varName->setText(static_cast(modified())->name()); boxFlyWarp->setChecked((static_cast(modified())->flyWarp() == INT_MAX) ? Qt::Unchecked : Qt::Checked); // varFlyWarp->setCurrentIndex(varFlyWarp->findData(static_cast(modified())->flyWarp())); varType->setCurrentIndex(static_cast(modified())->type()); // buttonDeleteColumn->setEnabled(0 < m_model->columnCount()); // buttonDeleteRow->setEnabled(0 < m_model->rowCount()); } void MapUI::apply() { *static_cast(original()) = *static_cast(modified()); emit(changed(false)); } void MapUI::discard() { *static_cast(modified()) = *static_cast(original()); setGui(); emit(changed(false)); } void MapUI::on_varName_textChanged(const QString& name) { const int cursor = varName->cursorPosition(); static_cast(modified())->setName(name); varName->setCursorPosition(cursor); } void MapUI::on_boxFlyWarp_toggled() { static_cast(modified())->setFlyWarp(-1); } void MapUI::on_varFlyWarp_activated(const int flyWarp) { static_cast(modified())->setFlyWarp(varFlyWarp->itemData(flyWarp).toInt()); } void MapUI::on_varType_activated(const int type) { static_cast(modified())->setType(type); } void MapUI::on_varTilemap_clicked(const QModelIndex& index) { m_index = index; varTile->setEnabled(true); varTile->setCurrentIndex(varTile->findData(varTilemap->model()->data(m_index, Qt::EditRole))); } void MapUI::on_buttonAddColumn_pressed() { varTilemap->model()->insertColumns(varTilemap->model()->columnCount(), 1); emit(changed(true)); } void MapUI::on_buttonAddRow_pressed() { varTilemap->model()->insertRows(varTilemap->model()->rowCount(), 1); emit(changed(true)); } void MapUI::on_buttonDeleteColumn_pressed() { varTilemap->model()->removeColumns(m_index.column(), 1); emit(changed(true)); } void MapUI::on_buttonDeleteRow_pressed() { varTilemap->model()->removeRows(m_index.row(), 1); emit(changed(true)); } void MapUI::on_buttonInsertColumn_pressed() { varTilemap->model()->insertColumns(m_index.column(), 1); emit(changed(true)); } void MapUI::on_buttonInsertRow_pressed() { varTilemap->model()->insertRows(m_index.row(), 1); emit(changed(true)); } void MapUI::on_varTile_activated(const int tile) { varTilemap->model()->setData(m_index, varTile->itemData(tile), Qt::EditRole); emit(changed(true)); setGui(); }