Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding open/save functionality into Toolkit! (Open crashes)

  • Loading branch information...
commit 7d0248602ab3f7f2bba3b0391242c17e93721911 1 parent 2eaee00
James Stine authored
6 Engine/.cproject
View
@@ -30,7 +30,7 @@
<listOptionValue builtIn="false" value="glut"/>
<listOptionValue builtIn="false" value="png"/>
</option>
- <option id="macosx.cpp.link.option.paths.924748179" name="Library search path (-L)" superClass="macosx.cpp.link.option.paths" valueType="libPaths"/>
+ <option id="macosx.cpp.link.option.paths.924748179" name="Library search path (-L)" superClass="macosx.cpp.link.option.paths"/>
<option id="macosx.cpp.link.option.userobjs.775236838" name="Other objects" superClass="macosx.cpp.link.option.userobjs"/>
<option id="macosx.cpp.link.option.other.1236217779" name="Other options (-Xlinker [option])" superClass="macosx.cpp.link.option.other"/>
<inputType id="cdt.managedbuild.tool.macosx.cpp.linker.input.1162104054" superClass="cdt.managedbuild.tool.macosx.cpp.linker.input">
@@ -46,9 +46,7 @@
<option id="gnu.cpp.compilermacosx.exe.debug.option.optimization.level.423957979" name="Optimization Level" superClass="gnu.cpp.compilermacosx.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.macosx.exe.debug.option.debugging.level.1754734499" name="Debug Level" superClass="gnu.cpp.compiler.macosx.exe.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.other.other.307545298" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0" valueType="string"/>
- <option id="gnu.cpp.compiler.option.include.paths.2061817821" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
- <listOptionValue builtIn="false" value="/opt/local/include"/>
- </option>
+ <option id="gnu.cpp.compiler.option.include.paths.2061817821" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.752633299" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.2073546321" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug">
8 Engine/Game.cpp
View
@@ -29,7 +29,8 @@ Game::~Game()
void Game::onInit()
{
guy->onLoad("../Resources/character.png");
- map->onCreate("New Map", "../Resources/tiles.png", 20, 15);
+ //map->onCreate("New Map", "../Resources/tiles.png", 10, 10);
+ map->onLoad("../Resources/testing.map");
}
void Game::onUpdate()
@@ -81,6 +82,11 @@ void Game::onKeyDown()
glutDestroyWindow(glWindow);
exit(0);
}
+
+ if (Keyboard::isDown('r'))
+ {
+ //map->onResize(15, 12);
+ }
}
void Game::onKeyUp()
26 Engine/Map.cpp
View
@@ -71,14 +71,21 @@ void Map::onLoad(std::string file)
{
header.name[i] = cc; i++;
}
+ header.name[i] = '\0';
i = 0;
while ((cc = (char)fgetc(f)) != 0x00)
{
header.tileset[i] = cc; i++;
}
+ header.tileset[i] = '\0';
fread(&header.width, 1, 2, f);
fread(&header.height, 1, 2, f);
- fread(tiles, 1, header.width*header.height*sizeof(MapTile), f);
+ int tbs = header.width * header.height * sizeof(MapTile);
+ tiles = (MapTile*) malloc(tbs);
+ fread(tiles, 1, tbs, f);
+
+ sprite = Graphics::addTexture(header.tileset);
+ Map::maps.insert(std::pair<std::string, Map*>(header.name, this));
}
void Map::onSave(std::string file)
@@ -94,6 +101,23 @@ void Map::onSave(std::string file)
fclose(f);
}
+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++)
+ {
+ for (int x = 0; x < map->getWidth(); x++)
+ map->setTile(x, y, 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));
+}
+
void Map::onUpdate()
{
1  Engine/Map.h
View
@@ -54,6 +54,7 @@ class Map
void onCreate(std::string name, std::string tileset, int width, int height);
void onLoad(std::string file);
void onSave(std::string file);
+ void onResize(int width, int height);
void onUpdate();
void onDraw(MapLayer layer);
10 Resources/resources.qrc
View
@@ -0,0 +1,10 @@
+<RCC>
+ <qresource prefix="/icons">
+ <file>toolkit/filenew.png</file>
+ <file>toolkit/fileopen.png</file>
+ <file>toolkit/filesave.png</file>
+ <file>toolkit/filesaveas.png</file>
+ <file>toolkit/stock_preferences.png</file>
+ <file>toolkit/stock_run.png</file>
+ </qresource>
+</RCC>
1  Resources/test.txt
View
@@ -1 +0,0 @@
-YO DAWG I HERD U LIKE FILES WELL FUCK YOU IDC LOL
BIN  Resources/testing.map
View
Binary file not shown
BIN  Resources/tiles.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  Resources/toolkit/filenew.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  Resources/toolkit/fileopen.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  Resources/toolkit/filesave.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  Resources/toolkit/filesaveas.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  Resources/toolkit/stock_preferences.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  Resources/toolkit/stock_run.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 Toolkit/Makefile
View
@@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: Toolkit.app/Contents/MacOS/Toolkit
-# Generated by qmake (2.01a) (Qt 4.7.3) on: Mon Oct 3 19:20:31 2011
+# Generated by qmake (2.01a) (Qt 4.7.3) on: Tue Oct 4 15:58:01 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
@@ -54,7 +54,8 @@ SOURCES = main.cpp \
moc_glwidget.cpp \
moc_tilesetwindow.cpp \
moc_mapwidget.cpp \
- moc_propertieswindow.cpp
+ moc_propertieswindow.cpp \
+ qrc_resources.cpp
OBJECTS = main.o \
mainwindow.o \
glwidget.o \
@@ -66,7 +67,8 @@ OBJECTS = main.o \
moc_glwidget.o \
moc_tilesetwindow.o \
moc_mapwidget.o \
- moc_propertieswindow.o
+ moc_propertieswindow.o \
+ qrc_resources.o
DIST = ../../QtSDK/Desktop/Qt/473/gcc/mkspecs/common/unix.conf \
../../QtSDK/Desktop/Qt/473/gcc/mkspecs/common/mac.conf \
../../QtSDK/Desktop/Qt/473/gcc/mkspecs/common/mac-g++.conf \
@@ -214,7 +216,7 @@ Toolkit.app/Contents/Info.plist:
@sed -e "s,@ICON@,,g" -e "s,@EXECUTABLE@,Toolkit,g" -e "s,@TYPEINFO@,????,g" ../../QtSDK/Desktop/Qt/473/gcc/mkspecs/macx-g++/Info.plist.app >Toolkit.app/Contents/Info.plist
dist:
@$(CHK_DIR_EXISTS) .tmp/Toolkit1.0.0 || $(MKDIR) .tmp/Toolkit1.0.0
- $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Toolkit1.0.0/ && $(COPY_FILE) --parents mainwindow.h glwidget.h tilesetwindow.h mapwidget.h propertieswindow.h tileselection.h .tmp/Toolkit1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp glwidget.cpp tilesetwindow.cpp mapwidget.cpp propertieswindow.cpp tileselection.cpp .tmp/Toolkit1.0.0/ && $(COPY_FILE) --parents mainwindow.ui propertieswindow.ui .tmp/Toolkit1.0.0/ && (cd `dirname .tmp/Toolkit1.0.0` && $(TAR) Toolkit1.0.0.tar Toolkit1.0.0 && $(COMPRESS) Toolkit1.0.0.tar) && $(MOVE) `dirname .tmp/Toolkit1.0.0`/Toolkit1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Toolkit1.0.0
+ $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Toolkit1.0.0/ && $(COPY_FILE) --parents mainwindow.h glwidget.h tilesetwindow.h mapwidget.h propertieswindow.h tileselection.h .tmp/Toolkit1.0.0/ && $(COPY_FILE) --parents ../Resources/resources.qrc .tmp/Toolkit1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp glwidget.cpp tilesetwindow.cpp mapwidget.cpp propertieswindow.cpp tileselection.cpp .tmp/Toolkit1.0.0/ && $(COPY_FILE) --parents mainwindow.ui propertieswindow.ui .tmp/Toolkit1.0.0/ && (cd `dirname .tmp/Toolkit1.0.0` && $(TAR) Toolkit1.0.0.tar Toolkit1.0.0 && $(COMPRESS) Toolkit1.0.0.tar) && $(MOVE) `dirname .tmp/Toolkit1.0.0`/Toolkit1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Toolkit1.0.0
clean:compiler_clean
@@ -262,8 +264,18 @@ moc_mapwidget.cpp: glwidget.h \
moc_propertieswindow.cpp: propertieswindow.h
/Users/LeonBlade/Programming/QtSDK/Desktop/Qt/473/gcc/bin/moc $(DEFINES) $(INCPATH) -D__APPLE__ -D__GNUC__ propertieswindow.h -o moc_propertieswindow.cpp
-compiler_rcc_make_all:
+compiler_rcc_make_all: qrc_resources.cpp
compiler_rcc_clean:
+ -$(DEL_FILE) qrc_resources.cpp
+qrc_resources.cpp: ../Resources/resources.qrc \
+ ../Resources/toolkit/filesaveas.png \
+ ../Resources/toolkit/filesave.png \
+ ../Resources/toolkit/fileopen.png \
+ ../Resources/toolkit/stock_preferences.png \
+ ../Resources/toolkit/stock_run.png \
+ ../Resources/toolkit/filenew.png
+ /Users/LeonBlade/Programming/QtSDK/Desktop/Qt/473/gcc/bin/rcc -name resources ../Resources/resources.qrc -o qrc_resources.cpp
+
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
-$(DEL_FILE) qmake_image_collection.cpp
@@ -286,7 +298,7 @@ compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
-compiler_clean: compiler_moc_header_clean compiler_uic_clean
+compiler_clean: compiler_moc_header_clean compiler_rcc_clean compiler_uic_clean
####### Compile
@@ -309,14 +321,16 @@ glwidget.o: glwidget.cpp glwidget.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o glwidget.o glwidget.cpp
tilesetwindow.o: tilesetwindow.cpp tilesetwindow.h \
- glwidget.h
+ glwidget.h \
+ tileselection.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tilesetwindow.o tilesetwindow.cpp
mapwidget.o: mapwidget.cpp mapwidget.h \
glwidget.h \
propertieswindow.h \
mainwindow.h \
- tilesetwindow.h
+ tilesetwindow.h \
+ tileselection.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o mapwidget.o mapwidget.cpp
propertieswindow.o: propertieswindow.cpp propertieswindow.h \
@@ -341,6 +355,9 @@ moc_mapwidget.o: moc_mapwidget.cpp
moc_propertieswindow.o: moc_propertieswindow.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_propertieswindow.o moc_propertieswindow.cpp
+qrc_resources.o: qrc_resources.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_resources.o qrc_resources.cpp
+
####### Install
install: FORCE
4 Toolkit/Toolkit.pro
View
@@ -31,6 +31,10 @@ LIBS += -L../Engine/Debug -lMap.o -lSprite.o -lGraphics.o -lLog.o -lpng
FORMS += mainwindow.ui \
propertieswindow.ui
+RESOURCES += \
+ ../Resources/resources.qrc
+
+
30 Toolkit/mainwindow.cpp
View
@@ -2,6 +2,8 @@
#include "ui_mainwindow.h"
#include "propertieswindow.h"
+#include <QFileDialog>
+
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
@@ -15,6 +17,8 @@ MainWindow::MainWindow(QWidget *parent) :
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();
@@ -51,6 +55,32 @@ void MainWindow::mapChangeSelection_Slot(Rectangle newRectangle)
tilesetWindow->setSelection(newRectangle);
}
+void MainWindow::openMap_Slot()
+{
+ QString mapFile = QFileDialog::getOpenFileName(0, tr("Open map"), tr("../Resources"), tr("Map (*.map)"));
+
+ 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();
+ }
+ }
+}
+
+void MainWindow::saveMap_Slot()
+{
+ QString mapFile = QFileDialog::getSaveFileName(0, tr("Save map"), tr("../Resources"), tr("Map (*.map)"));
+ MapWidget *mapWidget = (MapWidget*)ui->tabWidget->currentWidget();
+ mapWidget->getMap()->onSave(mapFile.toStdString().c_str());
+}
+
/**
* public
**/
2  Toolkit/mainwindow.h
View
@@ -23,6 +23,8 @@ public slots:
void removeTab_Slot(int id);
void mapUpdate_Slot(int id);
void mapChangeSelection_Slot(Rectangle newRectangle);
+ void openMap_Slot();
+ void saveMap_Slot();
public:
void addTab();
32 Toolkit/mainwindow.ui
View
@@ -85,6 +85,9 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
+ <addaction name="actionNew_Map"/>
+ <addaction name="actionOpen_Map"/>
+ <addaction name="actionSave_Map"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<widget class="QDockWidget" name="dockWidget">
@@ -146,6 +149,10 @@
</widget>
</widget>
<action name="actionNew_Map">
+ <property name="icon">
+ <iconset resource="../Resources/resources.qrc">
+ <normaloff>:/icons/toolkit/filenew.png</normaloff>:/icons/toolkit/filenew.png</iconset>
+ </property>
<property name="text">
<string>New Map</string>
</property>
@@ -154,19 +161,40 @@
</property>
</action>
<action name="actionOpen_Map">
+ <property name="icon">
+ <iconset resource="../Resources/resources.qrc">
+ <normaloff>:/icons/toolkit/fileopen.png</normaloff>:/icons/toolkit/fileopen.png</iconset>
+ </property>
<property name="text">
<string>Open Map</string>
</property>
+ <property name="shortcut">
+ <string>Ctrl+O</string>
+ </property>
</action>
<action name="actionSave_Map">
+ <property name="icon">
+ <iconset resource="../Resources/resources.qrc">
+ <normaloff>:/icons/toolkit/filesave.png</normaloff>:/icons/toolkit/filesave.png</iconset>
+ </property>
<property name="text">
<string>Save Map</string>
</property>
+ <property name="shortcut">
+ <string>Ctrl+S</string>
+ </property>
</action>
<action name="actionSave_Map_As">
+ <property name="icon">
+ <iconset resource="../Resources/resources.qrc">
+ <normaloff>:/icons/toolkit/filesaveas.png</normaloff>:/icons/toolkit/filesaveas.png</iconset>
+ </property>
<property name="text">
<string>Save Map As...</string>
</property>
+ <property name="shortcut">
+ <string>Ctrl+Shift+S</string>
+ </property>
</action>
<action name="actionClose_Map">
<property name="text">
@@ -175,6 +203,8 @@
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
- <resources/>
+ <resources>
+ <include location="../Resources/resources.qrc"/>
+ </resources>
<connections/>
</ui>
Please sign in to comment.
Something went wrong with that request. Please try again.