Skip to content

Commit

Permalink
Finished toolkit open/save. Created a few test maps. Adding more shit…
Browse files Browse the repository at this point in the history
…ty tiles.
  • Loading branch information
LeonBlade committed Oct 8, 2011
1 parent 7d02486 commit 9426c90
Show file tree
Hide file tree
Showing 20 changed files with 236 additions and 51 deletions.
5 changes: 1 addition & 4 deletions Engine/.cproject
Expand Up @@ -53,10 +53,7 @@
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.macosx.exe.debug.option.optimization.level.1214323724" name="Optimization Level" superClass="gnu.c.compiler.macosx.exe.debug.option.optimization.level" valueType="enumerated"/>
<option id="gnu.c.compiler.macosx.exe.debug.option.debugging.level.77223786" name="Debug Level" superClass="gnu.c.compiler.macosx.exe.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option id="gnu.c.compiler.option.misc.other.1531580697" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0" valueType="string"/>
<option id="gnu.c.compiler.option.include.paths.94895685" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="/opt/local/include"/>
<listOptionValue builtIn="false" value=""/>
</option>
<option id="gnu.c.compiler.option.include.paths.94895685" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.2145942875" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
</toolChain>
Expand Down
9 changes: 2 additions & 7 deletions Engine/Game.cpp
Expand Up @@ -29,8 +29,8 @@ Game::~Game()
void Game::onInit()
{
guy->onLoad("../Resources/character.png");
//map->onCreate("New Map", "../Resources/tiles.png", 10, 10);
map->onLoad("../Resources/testing.map");
// map->onCreate("New Map", "../Resources/tiles.png", 10, 10);
map->onLoad("../Resources/faggots.map");
}

void Game::onUpdate()
Expand Down Expand Up @@ -82,11 +82,6 @@ void Game::onKeyDown()
glutDestroyWindow(glWindow);
exit(0);
}

if (Keyboard::isDown('r'))
{
//map->onResize(15, 12);
}
}

void Game::onKeyUp()
Expand Down
57 changes: 46 additions & 11 deletions Engine/Map.cpp
Expand Up @@ -103,19 +103,25 @@ void Map::onSave(std::string file)

void Map::onResize(int width, int height)
{
Log::info("Resizing map w:%i h:%i...", width, height);
Map *map = new Map();
map->onCreate("NAME", "../Resources/tiles.png", width, height);
for (int y = 0; y < map->getHeight(); y++)
Log::info("Resizing map to %ix%i...", width, height);
MapTile *mapTiles = (MapTile*) malloc(width * height * sizeof(MapTile));
int i = 0;
for (int i = 0; i < width * height; i++) mapTiles[i] = ((MapTile){{1,0,0},false});
int _width = (width < this->getWidth()) ? width : this->getWidth();
int _height = (width < this->getHeight()) ? height : this->getHeight();
for (int y = 0; y < _height; y++)
{
for (int x = 0; x < map->getWidth(); x++)
map->setTile(x, y, this->getTile(x, y));
for (int x = 0; x < _width; x++)
{
i = x + (width * y);
mapTiles[i] = this->getTile(x, y);
}
}

this->onCreate("MAP NAME", "../Resources/tiles.png", width, height);
memcpy(this->tiles, map->tiles, sizeof(map->tiles));
// TODO: objects later when they're added
// memcpy(map->objects, this->objects, sizeof(this->objects));
this->header.width = width;
this->header.height = height;
this->tiles = (MapTile*) malloc(width * height * sizeof(MapTile));
memcpy(this->tiles, mapTiles, width * height * sizeof(MapTile));
delete mapTiles;
}

void Map::onUpdate()
Expand Down Expand Up @@ -151,6 +157,35 @@ int Map::getHeight()
return header.height;
}

std::string Map::getName()
{
return std::string(header.name);
}

std::string Map::getTileset()
{
return std::string(header.tileset);
}

Sprite *Map::getTilesetSprite()
{
return sprite;
}

void Map::setName(std::string name)
{
header.name = (char*) malloc(name.length());
strcpy(header.name, name.c_str());
}

void Map::setTileset(std::string tileset)
{
header.tileset = (char*) malloc(tileset.length());
strcpy(header.tileset, tileset.c_str());

sprite = Graphics::addTexture(tileset);
}

void Map::onDraw(MapLayer layer)
{
sprite->bindTexture();
Expand Down
6 changes: 6 additions & 0 deletions Engine/Map.h
Expand Up @@ -63,9 +63,15 @@ class Map
MapTile getTile(int x, int y);
int getTile(int x, int y, MapLayer layer);

std::string getName();
std::string getTileset();
Sprite *getTilesetSprite();
int getWidth();
int getHeight();

void setName(std::string name);
void setTileset(std::string tileset);

private:
MapHeader header;
MapTile *tiles;
Expand Down
Binary file added Resources/faggots.map
Binary file not shown.
Binary file added Resources/fancymap.map
Binary file not shown.
Binary file added Resources/fuck.map
Binary file not shown.
Binary file added Resources/mymap.map
Binary file not shown.
Binary file modified Resources/testing.map
Binary file not shown.
Binary file modified Resources/tiles.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Toolkit/Makefile
@@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: Toolkit.app/Contents/MacOS/Toolkit
# Generated by qmake (2.01a) (Qt 4.7.3) on: Tue Oct 4 15:58:01 2011
# Generated by qmake (2.01a) (Qt 4.7.3) on: Sat Oct 8 05:14:09 2011
# Project: Toolkit.pro
# Template: app
# Command: /Users/LeonBlade/Programming/QtSDK/Desktop/Qt/473/gcc/bin/qmake -spec ../../QtSDK/Desktop/Qt/473/gcc/mkspecs/macx-g++ -o Makefile Toolkit.pro
Expand Down
86 changes: 68 additions & 18 deletions Toolkit/mainwindow.cpp
Expand Up @@ -10,24 +10,30 @@ MainWindow::MainWindow(QWidget *parent) :
{
ui->setupUi(this);

// set up the master widget
masterWidget = new GLWidget(0);

// set up the tileset window
tilesetWindow = new TilesetWindow(ui->widget, masterWidget);

// connext signals to slots
connect(ui->actionNew_Map, SIGNAL(triggered()), this, SLOT(addTab_Slot()));
connect(ui->tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(removeTab_Slot(int)));
connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(mapUpdate_Slot(int)));
connect(ui->actionOpen_Map, SIGNAL(triggered()), this, SLOT(openMap_Slot()));
connect(ui->actionSave_Map, SIGNAL(triggered()), this, SLOT(saveMap_Slot()));

// add one map by default
addTab();
connect(ui->actionProperties, SIGNAL(triggered()), this, SLOT(showProperties_Slot()));
}

MainWindow::~MainWindow()
{
// delete the ui
delete ui;

// remove the masterWidget
delete masterWidget;
// delete the tileset window
delete tilesetWindow;
// remove all textures
Graphics::removeAllTextures();
}

Expand All @@ -36,63 +42,107 @@ MainWindow::~MainWindow()
**/
void MainWindow::addTab_Slot()
{
// call addTab
addTab();
}

void MainWindow::removeTab_Slot(int id)
{
// call removeTab
removeTab(id);
}

void MainWindow::mapUpdate_Slot(int id)
{
// grab the tab at the index
MapWidget *mapWidget = (MapWidget*)ui->tabWidget->widget(id);
mapWidget->onActive();

// if the widget exists then call onActive
if (mapWidget != NULL)
mapWidget->onActive();
}

void MainWindow::mapChangeSelection_Slot(Rectangle newRectangle)
{
// set the selection on the tilsetWindow to the map selection
tilesetWindow->setSelection(newRectangle);
}

void MainWindow::openMap_Slot()
{
// open the map file with QFileDialog returns qstring of file path
QString mapFile = QFileDialog::getOpenFileName(0, tr("Open map"), tr("../Resources"), tr("Map (*.map)"));

// if it's not empty or null ...
if (!mapFile.isNull() && !mapFile.isEmpty())
{
// TODO: either override or pass in option to open map with addTab
MapWidget *mapWidget = new MapWidget(0, masterWidget);
Map *map = mapWidget->getMap();
if (map)
{
map->onLoad(mapFile.toStdString().c_str());
connect(mapWidget, SIGNAL(changedSelection(Rectangle)), this, SLOT(mapChangeSelection_Slot(Rectangle)));
ui->tabWidget->addTab(mapWidget, QString("MAP NAME"));
tilesetWindow->updateGL();
}
// grab the widget of the current tab up
MapWidget *mapWidget = (MapWidget*)ui->tabWidget->currentWidget();

// load the map in the current tab !
mapWidget->loadMap(mapFile);

// set the tab's name to the current map name
ui->tabWidget->setTabText(ui->tabWidget->currentIndex(), tr(mapWidget->getMap()->getName().c_str()));
}
}

void MainWindow::saveMap_Slot()
{
// saving map with QFileDialog and returns qstring of file path
QString mapFile = QFileDialog::getSaveFileName(0, tr("Save map"), tr("../Resources"), tr("Map (*.map)"));

// grab the widget of the current tab up
MapWidget *mapWidget = (MapWidget*)ui->tabWidget->currentWidget();
mapWidget->getMap()->onSave(mapFile.toStdString().c_str());
// save the map :)
mapWidget->saveMap(mapFile);
}

void MainWindow::showProperties_Slot()
{
// get current tab
MapWidget *mapWidget = (MapWidget*) ui->tabWidget->currentWidget();
// show the properties window for that map tab
mapWidget->showProperties();
}

void MainWindow::propertiesAccepted_Slot()
{
// get the current widget
MapWidget *mapWidget = (MapWidget*) ui->tabWidget->currentWidget();
// get the tab name based on new name of map
ui->tabWidget->setTabText(ui->tabWidget->currentIndex(), tr(mapWidget->getMap()->getName().c_str()));
}

/**
* public
**/
void MainWindow::addTab()
{
// create a new mapWidget
MapWidget *mapWidget = new MapWidget(0, masterWidget);
// call add tab with the widget
addTab(mapWidget);
// if we're creating a new tab we will show the properties
mapWidget->showProperties();
}

void MainWindow::addTab(MapWidget *mapWidget)
{
// add the signal slot connection to change selection (could be done with static slots but pointless
connect(mapWidget, SIGNAL(changedSelection(Rectangle)), this, SLOT(mapChangeSelection_Slot(Rectangle)));
ui->tabWidget->addTab(mapWidget, QString("New tab"));
// signal slot for changing tab (could redo this as well?)
connect(mapWidget, SIGNAL(propertiesAccepted()), this, SLOT(propertiesAccepted_Slot()));
// create the new tab and switch the current index to this tab
ui->tabWidget->setCurrentIndex(ui->tabWidget->addTab(mapWidget, QString("New tab")));
// update the tileset window
// TODO: may need to change to grab the map sprite instead
tilesetWindow->updateGL();

}

void MainWindow::removeTab(int id)
{
ui->tabWidget->removeTab(id);
// remove the tab widget at the tab place
ui->tabWidget->removeTab(id);
}
7 changes: 5 additions & 2 deletions Toolkit/mainwindow.h
Expand Up @@ -25,10 +25,13 @@ public slots:
void mapChangeSelection_Slot(Rectangle newRectangle);
void openMap_Slot();
void saveMap_Slot();
void showProperties_Slot();
void propertiesAccepted_Slot();

public:
void addTab();
void removeTab(int id);
void addTab();
void addTab(MapWidget *mapWidget);
void removeTab(int id);

private:
Ui::MainWindow *ui;
Expand Down
16 changes: 16 additions & 0 deletions Toolkit/mainwindow.ui
Expand Up @@ -74,6 +74,7 @@
<property name="title">
<string>Edit</string>
</property>
<addaction name="actionProperties"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
Expand All @@ -88,6 +89,9 @@
<addaction name="actionNew_Map"/>
<addaction name="actionOpen_Map"/>
<addaction name="actionSave_Map"/>
<addaction name="separator"/>
<addaction name="actionProperties"/>
<addaction name="separator"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<widget class="QDockWidget" name="dockWidget">
Expand Down Expand Up @@ -201,6 +205,18 @@
<string>Close Map</string>
</property>
</action>
<action name="actionProperties">
<property name="icon">
<iconset resource="../Resources/resources.qrc">
<normaloff>:/icons/toolkit/stock_preferences.png</normaloff>:/icons/toolkit/stock_preferences.png</iconset>
</property>
<property name="text">
<string>Properties</string>
</property>
<property name="shortcut">
<string>Ctrl+M</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
Expand Down

0 comments on commit 9426c90

Please sign in to comment.