editor is now in src/. First step.

This commit is contained in:
zas 2003-10-23 21:02:30 +00:00
parent 4f952ba9e4
commit 3c6fee0fa5
3 changed files with 173 additions and 0 deletions

1
src/editor/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.swp

12
src/editor/Makefile Normal file
View file

@ -0,0 +1,12 @@
SDL_CFLAGS = `sdl-config --cflags` `freetype-config --cflags`
SDL_LIBS = `sdl-config --libs` -lSDL_ttf -lSDL_mixer -lSDL_image -lSDL_net `freetype-config --libs`
OBJS= editor.o ../actions.o ../ai.o ../ai_attack.o ../ai_move.o ../config.o ../dialogs.o ../display.o ../events.o ../filesystem.o ../font.o ../game_config.o ../game_events.o ../gamestatus.o ../hotkeys.o ../intro.o ../key.o ../language.o ../log.o ../map.o ../show_dialog.o ../mouse.o ../network.o ../pathfind.o ../playlevel.o ../playturn.o ../preferences.o ../replay.o ../sdl_utils.o ../sound.o ../team.o ../terrain.o ../tooltips.o ../unit.o ../unit_types.o ../video.o ../widgets/button.o ../widgets/menu.o ../widgets/textbox.o ../widgets/slider.o
editor: $(OBJS)
gcc -lstdc++ ${SDL_CFLAGS} -o $@ ${OBJS} ${SDL_LIBS}
.cpp.o:
gcc ${SDL_CFLAGS} -c $< -o $*.o
clean:
-rm -f *.o ../*.o editor

160
src/editor/editor.cpp Normal file
View file

@ -0,0 +1,160 @@
/*
Copyright (C) 2003 by David White <davidnwhite@optusnet.com.au>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "SDL.h"
#include "../actions.hpp"
#include "../ai.hpp"
#include "../config.hpp"
#include "../dialogs.hpp"
#include "../display.hpp"
#include "../font.hpp"
#include "../game_config.hpp"
#include "../gamestatus.hpp"
#include "../key.hpp"
#include "../language.hpp"
#include "../menu.hpp"
#include "../pathfind.hpp"
#include "../playlevel.hpp"
#include "../team.hpp"
#include "../unit_types.hpp"
#include "../unit.hpp"
#include "../video.hpp"
#include <cctype>
#include <iostream>
#include <map>
#include <string>
int main(int argc, char** argv)
{
const double scroll_speed = 30.0;
const double zoom_amount = 5.0;
if(argc == 1) {
std::cout << "usage: " << argv[0] << " map-name\n";
return 0;
}
std::map<std::string,std::string> defines_map;
defines_map["MEDIUM"] = "";
config cfg(preprocess_file("data/game.cfg",&defines_map));
set_language("English", cfg);
std::cout << "a\n";
std::string mapdata = read_file(argv[1]);
if(mapdata.empty()) {
for(int i = 0; i != 30; ++i) {
mapdata = mapdata + "gggggggggggggggggggggggggggggggggggggg\n";
}
}
std::cout << "b\n";
gamemap map(cfg,mapdata);
CVideo video;
video.setMode(1024,768,16,0);
CKey key;
gamestatus status(cfg,0);
std::vector<team> teams;
std::map<gamemap::location,unit> units;
display gui(units,video,map,status,teams);
gui.draw_terrain_palette(gui.mapx()+10,150,0);
gamemap::TERRAIN selected_terrain = 0;
bool first_time = true;
const font::manager font_manager;
std::cerr << "starting for(;;)\n";
for(;;) {
if(key[KEY_ESCAPE])
break;
int mousex, mousey;
const int mouse_flags = SDL_GetMouseState(&mousex,&mousey);
const bool new_left_button = mouse_flags & SDL_BUTTON_LMASK;
const bool new_right_button = mouse_flags & SDL_BUTTON_RMASK;
if(key[KEY_UP] || mousey == 0)
gui.scroll(0.0,-scroll_speed);
if(key[KEY_DOWN] || mousey == gui.y()-1)
gui.scroll(0.0,scroll_speed);
if(key[KEY_LEFT] || mousex == 0)
gui.scroll(-scroll_speed,0.0);
if(key[KEY_RIGHT] || mousex == gui.x()-1)
gui.scroll(scroll_speed,0.0);
if(key[KEY_Z])
gui.zoom(zoom_amount);
if(key[KEY_X])
gui.zoom(-zoom_amount);
if(key[KEY_D])
gui.default_zoom();
gui.highlight_hex(gui.hex_clicked_on(mousex,mousey));
if(new_left_button) {
const gamemap::TERRAIN terrain_on =
gui.get_terrain_on(gui.mapx()+10,150,mousex,mousey);
if(terrain_on && terrain_on != selected_terrain) {
selected_terrain = terrain_on;
gui.draw_terrain_palette(gui.mapx()+10,150,selected_terrain);
}
const gamemap::location hex = gui.hex_clicked_on(mousex,mousey);
if(map.on_board(hex)) {
const gamemap::TERRAIN terrain = map[hex.x][hex.y];
if(selected_terrain && selected_terrain != terrain) {
map.set_terrain(hex,selected_terrain);
gui.recalculate_minimap();
gamemap::location locs[7];
locs[0] = hex;
get_adjacent_tiles(hex,locs+1);
for(int i = 0; i != 7; ++i) {
gui.draw_tile(locs[i].x,locs[i].y);
}
}
}
}
gui.draw();
if(first_time) {
std::cerr << "drawing terrain pallette...\n";
gui.draw_terrain_palette(gui.mapx()+10,150,0);
first_time = false;
}
SDL_Delay(20);
pump_events();
}
system("pwd");
int res = gui::show_dialog(gui,NULL,"Save?","Do you want to save changes?",
gui::YES_NO);
if(res == 0) {
write_file(argv[1],map.write());
}
return 0;
}