Remove the old editor.

This includes removing sources, cfg files, editor targets in build
systems (scons was done already), and removing old-editor only parts
from several other files under data/ and src/. There probably are some
remains of the old editor left.
This commit is contained in:
Tomasz Śniatowski 2008-10-04 12:24:35 +01:00
parent 2136d9eff1
commit 6022234caa
30 changed files with 17 additions and 5994 deletions

View file

@ -70,7 +70,6 @@ set(FIFO_DIR "/var/run/wesnothd" CACHE STRING "Directory for the wesnothd fifo s
option(ENABLE_GAME "Enable compilation of the game" ON)
option(ENABLE_CAMPAIGN_SERVER "Enable compilation of campaign server")
option(ENABLE_SERVER "Enable compilation of server" ON)
option(ENABLE_EDITOR "Enable compilation of map editor")
option(ENABLE_EDITOR2 "Enable compilation of the new map editor into the game executable" ON)
option(ENABLE_TOOLS "Enable building and installation of tools for artists and WML maintainers")
option(ENABLE_TESTS "Build unit tests")
@ -138,10 +137,10 @@ endif()
# Libraries that are only required by some targets
#
if(ENABLE_TOOLS OR ENABLE_GAME OR ENABLE_EDITOR OR ENABLE_TESTS)
if(ENABLE_TOOLS OR ENABLE_GAME OR ENABLE_TESTS)
find_package( SDL_image 1.2 REQUIRED )
endif()
if(ENABLE_GAME OR ENABLE_EDITOR OR ENABLE_TESTS)
if(ENABLE_GAME OR ENABLE_TESTS)
find_package( SDL_mixer 1.2 REQUIRED )
find_package( SDL_ttf 2.0.8 REQUIRED )
endif()

View file

@ -12,5 +12,9 @@ The release team should empty this file after each release.
*** 1.5.4+svn
The old editor, wesnoth-editor, has been removed. Map editor functionality is
now provided by "Editor2" via the "Editor" in-game main menu option, or directly
by using wesnoth -e.
***

View file

@ -38,7 +38,7 @@ def OptionalPath(key, val, env):
opts.AddOptions(
ListOption('default_targets', 'Targets that will be built if no target is specified in command line.',
"wesnoth,wesnothd,test", Split("wesnoth wesnothd wesnoth_editor campaignd cutter exploder test")),
"wesnoth,wesnothd,test", Split("wesnoth wesnothd campaignd cutter exploder test")),
EnumOption('build', 'Build variant: debug, release profile or base (no subdirectory)', "release", ["release", "debug", "profile","base"]),
('extra_flags_base', 'Extra compiler and linker flags to use for release builds', ""),
('extra_flags_release', 'Extra compiler and linker flags to use for release builds', ""),
@ -132,11 +132,11 @@ Important switches include:
With no arguments, the recipe builds wesnoth and wesnothd. Available
build targets include the individual binaries:
wesnoth wesnoth_editor wesnothd campaignd exploder cutter test
wesnoth wesnothd campaignd exploder cutter test
You can make the following special build targets:
all = wesnoth wesnoth_editor exploder cutter wesnothd campaignd (*).
all = wesnoth exploder cutter wesnothd campaignd (*).
TAGS = build tags for Emacs (*).
wesnoth-deps.png = project dependency graph
install = install all executables that currently exist, and any data needed
@ -154,7 +154,6 @@ You can make the following special build targets:
data-dist = make data tarball as wesnoth-data.tar.bz2 (*).
binary-dist = make data tarball as wesnoth-binaries.tar.bz2 (*).
wesnoth-bundle = make Mac OS application bundle from game (*)
wesnoth-editor-bundle = make Mac OS application bundle from editor (*).
sanity-check = run a pre-release sanity check on the distribution.
manual = regenerate English-language manual and, possibly, localized manuals if appropriate xmls exist.

View file

@ -22,6 +22,8 @@ Version 1.5.4+svn:
unit/unit_type's gender (feature #11982).
* updated translations: Czech, Finnish, French, Galician, German,
Hungarian, Lithuanian, Polish, Slovak, Valencian
* Map editor:
* Removed wesnoth-editor. Use editor2.
* Multiplayer:
* Revised maps: Fallenstar Lake, 2p Hamlets, Hornshark Island, The Freelands,
Castle Hopping Isle.

View file

@ -222,11 +222,6 @@ AC_ARG_ENABLE([campaign_server],
[campaignserver=$enableval],
[campaignserver=no])
AC_ARG_ENABLE([editor],
AS_HELP_STRING([--enable-editor], [enable compilation of map editor]),
[editor=$enableval],
[editor=no])
AC_ARG_ENABLE([editor2],
AS_HELP_STRING([--enable-editor2], [build the new map editor in the game executable]),
[editor2=$enableval],
@ -293,13 +288,12 @@ AM_CONDITIONAL([GAME], [test x$game = xyes])
AM_CONDITIONAL([SERVER], [test x$server = xyes])
AM_CONDITIONAL([CAMPAIGNSERVER], [test x$campaignserver = xyes])
AM_CONDITIONAL([TESTS], [test x$tests = xyes])
AM_CONDITIONAL([EDITOR], [test x$editor = xyes])
AM_CONDITIONAL([EDITOR2], [test x$editor2 = xyes])
AM_CONDITIONAL([BANDWIDTH_MONITOR], [test x$bandwidth_monitor = xyes])
AM_CONDITIONAL([TOOLS], [test x$tools = xyes])
AM_CONDITIONAL([GCC], [test x$GXX = xyes])
AM_CONDITIONAL([INCLUDEDINTL], [test x$nls_cv_use_gnu_gettext = xyes])
AM_CONDITIONAL([INSTALLDATA], [test [ x$game = xyes || test x$editor = xyes || test x$editor2 = xyes ]])
AM_CONDITIONAL([INSTALLDATA], [test [ x$game = xyes || test x$editor2 = xyes ]])
AM_CONDITIONAL([DUMMYLOCALES], [test x$dummylocales = xyes])
if test x$editor2 = xno
@ -989,7 +983,6 @@ AC_SUBST([SOUND_FILES])
AC_CONFIG_FILES([Makefile
po/Makefile
po/wesnoth/Makefile.in
po/wesnoth-editor/Makefile.in
po/wesnoth-test/Makefile.in
po/wesnoth-lib/Makefile.in
po/wesnoth-units/Makefile.in

View file

@ -14,15 +14,10 @@
[textdomain]
name="wesnoth-editor"
[/textdomain]
# This enables UMC to define their custom terrains inside an EDITOR ifdef,
# so the terrains become available in the editor by default
{~campaigns/}
#endif
#ifdef OLD_EDITOR
# The editor needs to know of the default multiplayer random map generator
{multiplayer/scenarios/Random_Scenario.cfg}
#else
{scenario-test.cfg}
{scenario-formula.cfg}
{scenario-formula-recruitment.cfg}
@ -39,7 +34,6 @@
[textdomain]
name="wesnoth-tutorial"
[/textdomain]
#endif
# Include the terrain-graphics definitions after the campaigns so campaign specific
# terrains work properly.

View file

@ -3,12 +3,6 @@
# wmlscope: set export=yes
#ifdef OLD_EDITOR
{core/macros/}
{core/terrain.cfg}
{core/terrain-graphics/}
{core/editor-groups.cfg}
#else
{core/macros/}
{core/about.cfg}
{core/fonts.cfg}
@ -27,4 +21,3 @@
{core/editor2-tods.cfg}
{core/editor2-tool-hints.cfg}
#endif
#endif

View file

@ -3,6 +3,7 @@
# All editor_group entries in terrain.cfg should have a corresponding id here.
# Name is shown in the tooltip in the editor.
# Icon is the button icon name.
# Note: Used by editor2. Do not remove.
#The all entry shows all terrains and must be available
[editor_group]

View file

@ -1,647 +0,0 @@
#textdomain wesnoth-editor
[theme]
name=null
[resolution]
width=1
height=1
[/resolution]
[/theme]
[theme]
name=editor
# description attributes are not used by the game engine;
# they're here to enable generating a correct keybing list.
# The following are canned bindings to be prepended to the list.
#! Arrow keys=Scroll (if map scrolling is enabled)
#! Left click=On map: Paint foreground terrain. On right panel: select foreground terrain
#! Right click=On map: Paint background terrain. On right panel: select background terrain
#! shift-left click=Mark terrain
#! shift-alt-left click=Mark connected terrain
#! ctrl-left click=Select the terrain under the cursor as foreground terrain
#! ctrl-right click=Select the terrain under the cursor as background terrain
#! Click and drag marked terrain=Move the marked terrain
# Common key definitions
[hotkey]
command="zoomin"
description="Zoom in"
key="+"
cmd=no
alt=no
shift=no
[/hotkey]
[hotkey]
command="zoomout"
description="Zoom out"
key="-"
cmd=no
alt=no
shift=no
[/hotkey]
[hotkey]
command="zoomdefault"
description="Zoom default"
key="0"
cmd=no
alt=no
shift=no
[/hotkey]
[hotkey]
command="undo"
description="Undo"
key="u"
cmd=no
alt=no
shift=no
[/hotkey]
[hotkey]
command="redo"
description="Redo"
key="r"
cmd=no
alt=no
shift=no
[/hotkey]
[hotkey]
command="togglegrid"
description="Toggle hex grid"
key="g"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="mousescroll"
description="Toggle mouse scrolling"
key="l"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editsavemap"
description="Save map"
key="s"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editsaveas"
description="Save map as"
key="s"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=yes
shift=no
[/hotkey]
[hotkey]
command="editquit"
description="Quit map editor"
key="q"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editsetstartpos"
description="Set the starting position of a player"
key="t"
cmd=no
alt=no
shift=no
[/hotkey]
[hotkey]
command="editnewmap"
description="New map"
key="n"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editloadmap"
description="Load map from file"
key="l"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editfloodfill"
description="Flood fill with selected terrain"
key="f"
cmd=no
alt=no
shift=no
[/hotkey]
[hotkey]
command="editfillselection"
description="Flood map selection with selected terrain"
key="f"
cmd=no
alt=yes
shift=no
[/hotkey]
[hotkey]
command="editrotateselection"
description="Rotate selected map terrain"
key="r"
cmd=no
alt=no
shift=yes
[/hotkey]
[hotkey]
command="editcut"
description="Cut selection from map"
key="x"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editcopy"
description="Copy selection from map"
key="c"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editpaste"
description="Paste selection to map"
key="v"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editrevert"
description="Revert map from file"
key="r"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="preferences"
description="Set map preferences"
key="p"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editresize"
description="Resize map"
key="r"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=yes
shift=no
[/hotkey]
[hotkey]
command="fullscreen"
description="Toggle fullscreen"
key="f"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editselectall"
description="Select entire map"
key="a"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editflip"
description="Flip the map"
key="f"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=yes
shift=no
[/hotkey]
[hotkey]
command="editdraw"
description="Set draw mode"
key="d"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editrefresh"
description="Refresh map display"
key="e"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="editupdate"
description="Redraw/update terrain transitions"
key="b"
cmd=no
alt=no
shift=no
[/hotkey]
[hotkey]
command="editautoupdate"
description="Delay terrain transitions"
key="t"
#ifdef APPLE
cmd=yes
#else
ctrl=yes
#endif
alt=no
shift=no
[/hotkey]
[hotkey]
command="changelanguage"
description="Change editor language"
key="l"
cmd=no
alt=yes
shift=no
[/hotkey]
[resolution]
#everywhere in here 1024x768 is seen as basic reference due to some hardcoded values
id=800x600
width=800
height=600
[screen]
# this is only useful as a ref for other rects
id=screen
rect="0,0,1024,768"
[/screen]
# top panel
[panel]
id=top-panel
image=themes/top-bg.png
ref=screen
rect="=,=,882,+26"
xanchor=top
yanchor=fixed
[/panel]
[main_map]
id=main-map
rect="=,+0,+882,768"
xanchor=left
yanchor=top
[/main_map]
# use a more transparent set for the borders than is used ingame
[main_map_border]
border_size = 0.5
background_image = "terrain/off-map/background.png"
# this image is processed by the terrain matching code so should be
# in the terrains directory and should ommit the 'terrain/' prefix
# and the '.png' suffix
tile_image = "off-map/alpha"
corner_image_top_left = "terrain/off-map/fade_corner_top_left_editor.png"
corner_image_bottom_left = "terrain/off-map/fade_corner_bottom_left_editor.png"
# odd means the corner is on a tile with an odd x value,
# the tile is the ingame tile not the odd in C++
corner_image_top_right_odd = "terrain/off-map/fade_corner_top_right_odd_editor.png"
corner_image_top_right_even = "terrain/off-map/fade_corner_top_right_even_editor.png"
corner_image_bottom_right_odd = "terrain/off-map/fade_corner_bottom_right_odd_editor.png"
corner_image_bottom_right_even = "terrain/off-map/fade_corner_bottom_right_even_editor.png"
border_image_left = "terrain/off-map/fade_border_left_editor.png"
border_image_right = "terrain/off-map/fade_border_right_editor.png"
border_image_top_odd = "terrain/off-map/fade_border_top_odd_editor.png"
border_image_top_even = "terrain/off-map/fade_border_top_even_editor.png"
border_image_bottom_odd = "terrain/off-map/fade_border_bottom_odd_editor.png"
border_image_bottom_even = "terrain/off-map/fade_border_bottom_even_editor.png"
[/main_map_border]
# rightside panel
[panel]
id=top-right-panel
image=themes/rightside-editor.png
rect="+0,0,1024,+304"
xanchor=right
yanchor=fixed
[/panel]
[panel]
id=middle-right-panel
image=themes/rightside-bg.png
rect="=,+0,1024,+464"
xanchor=right
yanchor=top
[/panel]
# ain't working anyway in the way it should, the space can be better used otherwise
# [panel]
# id=bottom-right-panel
# image=themes/rightside-bottom.png
# rect=882,722,1024,768
# xanchor=right
# yanchor=bottom
# [/panel]
[menu]
id=file-menu
title=_"File"
image=lite
items=editnewmap,editloadmap,editsaveas,editsavemap,editrevert,editquit
ref=top-panel
rect="=+3,=+1,+100,=-4"
xanchor=fixed
yanchor=fixed
[/menu]
[menu]
id=edit-menu
title=_"Edit"
image=lite
items=undo,redo,editcut,editcopy,editpaste,editselectall,editfillselection,editrotateselection,editresize,editflip,editrefresh,editupdate,
rect="+2,=,+100,="
xanchor=fixed
yanchor=fixed
[/menu]
[menu]
id=settings-menu
title=_"Settings"
image=lite
items=changelanguage,preferences,editautoupdate
rect="+2,=,+100,="
xanchor=fixed
yanchor=fixed
[/menu]
[panel]
id=villages-panel
image=themes/status-bg.png
ref=settings-menu
rect="+2,=+1,+65,+19"
xanchor=fixed
yanchor=fixed
[/panel]
[label]
id=villages-icon
icon=themes/villages.png
text= _ "villages"
ref=villages-panel
rect="=+5,=+1,+17,+17"
xanchor=fixed
yanchor=fixed
[/label]
[mini_map]
ref=top-right-panel
rect="=+10,=+7,=-7,+143"
#rect=892,32,1017,175
xanchor=right
yanchor=fixed
[/mini_map]
# The toolbar.
[menu]
id=draw_button_editor
image=draw_button_editor
items=editdraw
ref=top-right-panel
#harcoded since the brushes are above, which are hardcoded in src/editor/editor_layout.cpp
rect="=+27,200,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=flood_button_editor
image=flood_button_editor
items=editfloodfill
rect="+10,=,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=start_position_button_editor
image=start_position_button_editor
items=editsetstartpos
rect="+10,=,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=resize_button_editor
image=resize_button_editor
items=editresize
ref=draw_button_editor
rect="=,+10,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=flip_map_button_editor
image=flip_map_button_editor
items=editflip
rect="+10,=,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=toggle_grid_button_editor
image=toggle_grid_button_editor
items=togglegrid
rect="+10,=,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=undo_button_editor
image=undo_button_editor
items=undo
ref=resize_button_editor
rect="=-9,+10,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=redo_button_editor
image=redo_button_editor
items=redo
rect="+4,=,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=zoom_in_button_editor
image=zoom_in_button_editor
items=zoomin
rect="+4,=,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[menu]
id=zoom_out_button_editor
image=zoom_out_button_editor
items=zoomout
rect="+4,=,+24,+24"
xanchor=right
yanchor=fixed
[/menu]
[status]
[villages]
id=villages
ref=villages-icon
rect="+2,=+1,+41,+16"
font_size=12
xanchor=fixed
yanchor=fixed
[/villages]
[terrain]
id=status-terrain
ref=villages-panel
font_size=12
rect="+10,=+1,+200,+16"
xanchor=fixed
yanchor=fixed
[/terrain]
[position]
id=status-position
font_size=12
ref=status-terrain
rect="822,=,+60,="
xanchor=right
yanchor=fixed
[/position]
#what is this supposed to do? seems to do *nothing* regarding the theme
#->commenting out
#[edit_left_button_function]
# font_size=10
# rect=900,330,1024,345
# xanchor=right
# yanchor=fixed
#[/edit_left_button_function]
#broken since I don't know when, commenting out
#[selected_terrain]
# font_size=10
# rect=890,730,1024,20
# xanchor=right
# yanchor=bottom
#[/selected_terrain]
[/status]
[/resolution]
[/theme]

View file

@ -15,6 +15,9 @@ Version 1.5.4+svn:
works much more reliably.
* Added --load support for -e command line option. Loads the map file
with the given filename.
* Map editor
* Removed wesnoth-editor. Use editor2.
* Language and translations
* updated translations: Czech, Finnish, French, Galician, German,

View file

@ -48,14 +48,6 @@ set( server-external-libs
${SDLNET_LIBRARY}
)
set( editor-external-libs
${common-external-libs}
${SDLIMAGE_LIBRARY}
${SDLMIXER_LIBRARY}
${SDLTTF_LIBRARY}
${FONTCONFIG_LDFLAGS}
)
set( tools-external-libs
${common-external-libs}
${SDLIMAGE_LIBRARY}
@ -69,13 +61,11 @@ endif(ENABLE_PYTHON AND PYTHON_LIBRARY)
if(ENABLE_FRIBIDI AND FRIBIDI_LIBRARIES)
include_directories( ${FRIBIDI_INCLUDE_PATH} )
set(game-external-libs ${game-external-libs} ${FRIBIDI_LIBRARIES})
set(editor-external-libs ${editor-external-libs} ${FRIBIDI_LIBRARIES})
endif(ENABLE_FRIBIDI AND FRIBIDI_LIBRARIES)
if(X11_FOUND)
include_directories( ${X11_INCLUDE_DIR} )
set(game-external-libs ${game-external-libs} ${X11_LIBRARIES})
set(editor-external-libs ${editor-external-libs} ${X11_LIBRARIES})
endif(X11_FOUND)
#
# Create targets for revision.hpp
@ -360,32 +350,6 @@ install(TARGETS wesnoth DESTINATION ${BINDIR})
ENDIF(ENABLE_GAME)
########### Editor ###############
IF(ENABLE_EDITOR)
SET(wesnoth_editor_SRC
editor/editor.cpp
editor/editor_layout.cpp
editor/map_manip.cpp
editor/editor_display.cpp
editor/editor_palettes.cpp
editor/editor_main.cpp
editor/editor_dialogs.cpp
editor/editor_undo.cpp
animated_editor.cpp
generic_event.cpp
tooltips.cpp
)
add_executable(wesnoth_editor ${wesnoth_editor_SRC})
target_link_libraries(wesnoth_editor wesnoth-core wesnoth-game ${editor-external-libs})
set_target_properties(wesnoth_editor PROPERTIES OUTPUT_NAME ${BINARY_PREFIX}wesnoth_editor${BINARY_SUFFIX})
install(TARGETS wesnoth_editor DESTINATION ${BINDIR})
ENDIF(ENABLE_EDITOR)
########### Wesnothd Server ###############
IF(ENABLE_SERVER)

View file

@ -27,10 +27,6 @@ bin_SCRIPTS += wmlscope wmllint wmlindent wesnoth_addon_manager
CLEANFILES += $(bin_SCRIPTS)
endif
if EDITOR
bin_PROGRAMS += wesnoth_editor
endif
noinst_LIBRARIES = libwesnoth-core.a libwesnoth.a
pkgdatadir=$(datadir)/@DATADIR@
@ -193,25 +189,6 @@ wesnoth_SOURCES = \
wesnoth_LDADD = $(INTERNALLIBS) $(THELIBS) $(PANGO_LIBS) $(FONTCONFIG_LIBS)
wesnoth_DEPENDENCIES=libwesnoth-core.a libwesnoth.a
#############################################################################
# Editor #
#############################################################################
wesnoth_editor_SOURCES = \
editor/editor.cpp \
editor/editor_layout.cpp \
editor/map_manip.cpp \
editor/editor_display.cpp \
editor/editor_palettes.cpp \
editor/editor_main.cpp \
editor/editor_dialogs.cpp \
editor/editor_undo.cpp \
animated_editor.cpp \
generic_event.cpp \
tooltips.cpp
wesnoth_editor_LDADD = $(INTERNALLIBS) $(THELIBS) $(FONTCONFIG_LIBS)
wesnoth_editor_DEPENDENCIES=libwesnoth-core.a libwesnoth.a
#############################################################################
# Wesnothd Server #
@ -480,7 +457,7 @@ endif
CLEANFILES += TAGS
TAGS:
etags -l c++ $(wesnoth_SOURCES) $(wesnoth_editor_SOURCES) $(wesnothd_SOURCES) $(campaignd_SOURCES) $(exploder_SOURCES) $(cutter_SOURCES) $(libwesnoth_core_a_SOURCES) $(libwesnoth__a_SOURCES)
etags -l c++ $(wesnoth_SOURCES) $(wesnothd_SOURCES) $(campaignd_SOURCES) $(exploder_SOURCES) $(cutter_SOURCES) $(libwesnoth_core_a_SOURCES) $(libwesnoth__a_SOURCES)
#############################################################################
# Scripts

View file

@ -1,28 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2007 - 2008 by Jeremy Rosen <jeremy.rosen@enst-bretagne.fr>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* @file animated_editor.cpp
* Template instantiations for wesnoth-editor.
*/
#include "animated.i"
// Force compilation of the following template instantiations
#include "unit_frame.hpp"
#include "image.hpp"
template class animated< image::locator >;
template class animated< std::string >;

File diff suppressed because it is too large Load diff

View file

@ -1,353 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/editor.hpp
//!
#ifndef EDITOR_H_INCLUDED
#define EDITOR_H_INCLUDED
#include "global.hpp"
#include "SDL.h"
#include "editor_display.hpp"
#include "editor_palettes.hpp"
#include "editor_layout.hpp"
#include "editor_undo.hpp"
#include "map_manip.hpp"
#include "../display.hpp"
#include "../events.hpp"
#include "../font.hpp"
#include "../hotkeys.hpp"
#include "../preferences_display.hpp"
#include "../theme.hpp"
#include "../tooltips.hpp"
//#include "gui/key_listener.hpp"
//#include "gui/mouse_listener.hpp"
#include <map>
#include <queue>
#include <set>
#include <vector>
namespace map_editor {
bool check_data(std::string &data, std::string &filename, bool &from_scenario, config &game_cfg);
//! A map editor. Receives SDL events and can execute hotkey commands.
class map_editor : public events::handler,
public hotkey::command_executor {
public:
map_editor(editor_display &gui, editormap &map, config &theme, config &game_config);
virtual ~map_editor();
//! Enter the main loop. The loop runs until set_abort() is called
//! to set an abort mode which makes the loop exit.
void main_loop();
//! Set the filename that map should be saved as.
void set_file_to_save_as(const std::string, bool from_scenario);
//! How to abort the map editor.
//! DONT_ABORT is set during normal operation.
//! When ABORT_NORMALLY is set, the editor asks for confirmation and
//! if save is desired before it exits.
//! When ABORT_HARD is set, the editor exists without asking any
//! questions or saving.
enum ABORT_MODE {DONT_ABORT, ABORT_NORMALLY, ABORT_HARD};
//! Set the abort flag, which indicates if the editor should exit in
//! some way after the current iteration of the main loop.
void set_abort(const ABORT_MODE abort=ABORT_NORMALLY);
//! Save the current map. If filename is an empty string, use the
//! filename that is set with set_file_to_save_as(). A message box
//! that shows confirmation that the map was saved is shown if
//! display_confirmation is true. Return false if the save failed.
bool save_map(const std::string filename="",
const bool display_confirmation=true);
//! Exception thrown when the loading of a map failed.
struct load_map_exception {};
virtual void handle_event(const SDL_Event &event);
//! Handle a keyboard event. mousex and mousey is the current
//! position of the mouse.
void handle_keyboard_event(const SDL_KeyboardEvent &event,
const int mousex, const int mousey);
//! Handle a mouse button event. mousex and mousey is the current
//! position of the mouse.
void handle_mouse_button_event(const SDL_MouseButtonEvent &event,
const int mousex, const int mousey);
//! Return true if the map has changed since the last time it was
//! saved.
bool changed_since_save() const;
//! Recalculate layout and redraw everything.
void redraw_everything();
// Change the language in_game
virtual void change_language();
// Methods inherited from command_executor. Used to perform
// operations on menu/hotkey commands.
virtual void toggle_grid();
virtual void undo();
virtual void redo();
virtual void preferences();
virtual void edit_quit();
virtual void edit_new_map();
virtual void edit_load_map();
virtual void edit_save_map();
virtual void edit_save_as();
//! Display a dialog asking for a player number and set the starting
//! position of the given player to the currently selected hex.
virtual void edit_set_start_pos();
virtual void edit_flood_fill();
virtual void edit_fill_selection();
virtual void edit_rotate_selection();
virtual void edit_cut();
virtual void edit_copy();
virtual void edit_paste();
virtual void edit_revert();
virtual void edit_resize();
virtual void edit_flip();
//! Either select or deselect all hexes on the map depending on if
//! this operations has been invoked before or not.
virtual void edit_select_all();
virtual void edit_draw();
virtual void edit_refresh();
virtual void edit_update();
virtual void edit_auto_update();
void perform_flood_fill(const t_translation::t_terrain fill_with);
void perform_paste();
void perform_set_starting_pos();
virtual bool can_execute_command(hotkey::HOTKEY_COMMAND command, int) const;
//Does the action control a toggle switch? If so, return the state of the action (on or off)
virtual hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command) const;
//! Exception thrown when new map is to be loaded.
struct new_map_exception {
new_map_exception(const std::string &map, const std::string filename="", const bool scenario = false)
: new_map(map), new_filename(filename), from_scenario(scenario) {}
const std::string new_map;
const std::string new_filename;
const bool from_scenario;
};
private:
//! What to perform while the left button is held down.
enum LEFT_BUTTON_HELD_FUNC {DRAW_TERRAIN, DRAW_TERRAIN_LAYER, ADD_SELECTION, REMOVE_SELECTION,
MOVE_SELECTION, NONE};
//! What to perform on a left button click.
enum LEFT_BUTTON_FUNC {DRAW, SELECT_HEXES, FLOOD_FILL,
SET_STARTING_POSITION, PASTE, NUM_L_BUTTON_FUNC};
//! Called in every iteration when the left mouse button is held
//! down. Note that this differs from a click.
void left_button_down(const int mousex, const int mousey);
//! Handle a left click on the location.
void left_click(const gamemap::location loc);
//! Called in every iteration when the right mouse button is held
//! down. Note that this differs from a click.
void right_button_down(const int mousex, const int mousey);
//! Handle a right click on the location.
void right_click(const gamemap::location loc);
//! Called in every iteration when the middle mouse button is held
//! down. Note that this differs from a click.
void middle_button_down(const int mousex, const int mousey);
//! Confirm that exiting is desired and ask for saving of the map.
//! Return true if exit is confirmed and the save is successful or not
//! wanted. Return false if exit is cancelled or the requested save
//! failed.
bool confirm_exit_and_save();
//! Set the starting position for the given player to the location
//! given.
void set_starting_position(const int player, const gamemap::location loc);
//! Check whether the filename contains illegal characters.
bool verify_filename(const std::string& filename, bool show_error) const;
//! Display a menu with given items and at the given location.
void show_menu(const std::vector<std::string>& items_arg, const int xloc,
const int yloc, const bool context_menu=false);
//! Pass the command onto the hotkey handling system. Quit requests
//! are intercepted because the editor does not want the default
//! behavior of those.
void execute_command(const hotkey::HOTKEY_COMMAND command);
//! Draw terrain at a location. The operation is saved in the undo
//! stack. Update the map to reflect the change.
void draw_terrain(const t_translation::t_terrain terrain,
const std::vector<gamemap::location> &hexes, const bool one_layer_only);
//! Re-set the labels for the starting positions of the
//! players. Should be called when the terrain has changed, which
//! may have changed the starting positions.
void recalculate_starting_pos_labels();
//! Update the selection and highlightning of the hexes the mouse
//! currently is over.
void update_mouse_over_hexes(const gamemap::location mouse_over_hex);
//! Insert the currently selected locations in the clipboard.
void insert_selection_in_clipboard();
//! Commit hexes filling.
void perform_fill_hexes(std::set<gamemap::location> &fill_hexes,
const t_translation::t_terrain terrain, map_undo_action &undo_action);
//! Commit the movement of a selection.
void perform_selection_move();
//! Highlight the currently selected hexes. If clear_old is true the
//! old highlighting is cleared, otherwise the current selection is
//! only added, which may leave old selected terrain still
//! highlighted.
void highlight_selected_hexes(const bool clear_old=true);
//! Clear the highlighted hexes in the gui and set a variable to
//! indicate this so that the brush size highlighting may be
//! refreshed.
void clear_highlighted_hexes_in_gui();
// Sets the special overlay with the selection of fore and background
void set_mouseover_overlay();
// Clears the special overlay
void reset_mouseover_overlay() { gui_.clear_mouseover_hex_overlay(); }
//! Terrain has changed at the specified hex through user drawing
//! (not undo/redo or other special things).
void terrain_changed(const gamemap::location &hex);
// void terrain_changed(const std::vector<gamemap::location> &hexes);
// void terrain_changed(const std::set<gamemap::location> &hexes);
//! Save an action so that it may be undone. Add an operation to the
//! number done since save.
void save_undo_action(const map_undo_action &action);
//! Call when the left mouse button function has changed. Updated
//! the report indicating what will be performed. New_function is
//! the hotkey-string describing the action.
void left_button_func_changed(const LEFT_BUTTON_FUNC func);
//! Draw black squares around the buttons that are used to select
//! the left button function and draw a read square around the
//! currently selected function.
void update_l_button_palette();
//! Return the hotkey-string representing the left button
//! function. The "action_" is left out.
std::string get_action_name(const LEFT_BUTTON_FUNC func) const;
//! Return true if the menu is a button used for setting the left
//! mouse button function.
bool is_left_button_func_menu(const theme::menu &menu) const;
//! Draw the terrain on the hexes the mouse is over, taking account
//! for brush size.
void draw_on_mouseover_hexes(const t_translation::t_terrain t, const bool one_layer_only = false);
// Load the tooltips for each button
void load_tooltips(void);
//! An item in the buffer. Consists of the copied terrain and an
//! offset. When pasting stuff, the offset is used to calculate
//! where to put the pasted hex
struct buffer_item {
buffer_item(const gamemap::location &o, t_translation::t_terrain t, int start_side) :
offset(o), terrain(t), starting_side(start_side) {}
gamemap::location offset;
t_translation::t_terrain terrain;
int starting_side;
};
// map_buffer is used for clipboard and other map operations
typedef std::vector<buffer_item> map_buffer;
void copy_buffer(map_buffer& buffer, const std::set<gamemap::location> &locs,
const gamemap::location &origin);
void paste_buffer(const map_buffer& buffer, const gamemap::location &loc,
map_undo_action &undo_action);
void clear_buffer(map_buffer& buffer) {buffer.clear();};
editor_display &gui_;
editormap &map_;
std::string filename_, original_filename_;
bool from_scenario_;
ABORT_MODE abort_;
// Keep track of the number of operations performed since the last
// save. If this is zero when the editor is exited there is no need
// to ask the user to save.
static int num_operations_since_save_;
size_specs size_specs_;
config &theme_;
config &game_config_;
CKey key_;
gamemap::location selected_hex_;
// When map_dirty_ is true, schedule redraw of the minimap and
// perform some updates like recalculating labels of starting
// positions. But only it the option auto_update is enabled
bool map_dirty_;
bool auto_update_;
bool l_button_palette_dirty_;
bool everything_dirty_;
terrain_palette palette_;
brush_bar brush_;
std::vector<gamemap::location> starting_positions_;
std::set<gamemap::location> mouse_over_hexes_;
std::set<gamemap::location> selected_hexes_;
map_buffer clipboard_;
LEFT_BUTTON_HELD_FUNC l_button_held_func_;
gamemap::location selection_move_start_;
tooltips::manager tooltip_manager_;
font::floating_label_context floating_label_manager_;
// mouse_moved_ will be true if the mouse have moved between two
// cycles.
bool mouse_moved_;
bool highlighted_locs_cleared_;
const hotkey::manager hotkey_manager_;
const preferences::display_manager prefs_disp_manager_;
static config prefs_;
static config hotkeys_;
static bool first_time_created_;
static LEFT_BUTTON_FUNC l_button_func_;
static t_translation::t_terrain old_fg_terrain_, old_bg_terrain_;
static int old_brush_size_;
bool all_hexes_selected_;
};
}
#endif // EDITOR_H_INCLUDED

View file

@ -1,705 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/editor_dialogs.cpp
//!
#include "SDL.h"
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "../config.hpp"
#include "../construct_dialog.hpp"
#include "../display.hpp"
#include "../events.hpp"
#include "../filesystem.hpp"
#include "../game_config.hpp"
#include "../gettext.hpp"
#include "../language.hpp"
#include "../map.hpp"
#include "../mapgen.hpp"
#include "../map_create.hpp"
#include "../marked-up_text.hpp"
#include "../preferences_display.hpp"
#include "../video.hpp"
#include "../widgets/slider.hpp"
#include "editor_dialogs.hpp"
namespace {
const int map_min_height = 1;
const int map_min_width = 1;
const int map_max_height = 200;
const int map_max_width = 200;
}
namespace map_editor {
bool confirm_modification_disposal(display& disp) {
const int res = gui::dialog(disp, "",
_("Your modifications to the map will be lost. Continue?"),
gui::OK_CANCEL).show();
return res == 0;
}
std::string new_map_dialog(display& disp, const t_translation::t_terrain fill_terrain,
const bool confirmation_needed, const config &game_config)
{
const resize_lock prevent_resizing;
const events::event_context dialog_events_context;
const gui::dialog_manager dialog_mgr;
int map_width(40), map_height(40);
const int width = 600;
const int height = 400;
const int xpos = disp.w()/2 - width/2;
const int ypos = disp.h()/2 - height/2;
const int horz_margin = 5;
const int vertical_margin = 20;
SDL_Rect dialog_rect = {xpos-10,ypos-10,width+20,height+20};
surface_restorer restorer(&disp.video(),dialog_rect);
gui::dialog_frame frame(disp.video());
frame.layout(xpos,ypos,width,height);
frame.draw_background();
frame.draw_border();
SDL_Rect title_rect = font::draw_text(NULL,screen_area(),24,font::NORMAL_COLOUR,
_("Create New Map"),0,0);
const std::string& width_label = _("Width:");
const std::string& height_label = _("Height:");
SDL_Rect width_rect = font::draw_text(NULL, screen_area(), 14, font::NORMAL_COLOUR,
width_label, 0, 0);
SDL_Rect height_rect = font::draw_text(NULL, screen_area(), 14, font::NORMAL_COLOUR,
height_label, 0, 0);
const int text_right = xpos + horz_margin +
std::max<int>(width_rect.w,height_rect.w);
width_rect.x = text_right - width_rect.w;
height_rect.x = text_right - height_rect.w;
width_rect.y = ypos + title_rect.h + vertical_margin*2;
height_rect.y = width_rect.y + width_rect.h + vertical_margin;
gui::button new_map_button(disp.video(), _("Generate New Map"));
gui::button random_map_button(disp.video(), _("Generate Random Map"));
gui::button random_map_setting_button(disp.video(), _("Random Generator Settings"));
gui::button cancel_button(disp.video(), _("Cancel"));
new_map_button.set_location(xpos + horz_margin,height_rect.y + height_rect.h + vertical_margin);
random_map_button.set_location(xpos + horz_margin,ypos + height - random_map_button.height()-14*2-vertical_margin);
random_map_setting_button.set_location(random_map_button.location().x + random_map_button.width() + horz_margin,
ypos + height - random_map_setting_button.height()
- 14*2 - vertical_margin);
cancel_button.set_location(xpos + width - cancel_button.width() - horz_margin,
ypos + height - cancel_button.height()-14);
const int right_space = 100;
const int slider_left = text_right + 10;
const int slider_right = xpos + width - horz_margin - right_space;
SDL_Rect slider_rect = { slider_left,width_rect.y,slider_right-slider_left,width_rect.h};
slider_rect.y = width_rect.y;
gui::slider width_slider(disp.video());
width_slider.set_location(slider_rect);
width_slider.set_min(map_min_width);
width_slider.set_max(map_max_width);
width_slider.set_value(map_width);
slider_rect.y = height_rect.y;
gui::slider height_slider(disp.video());
height_slider.set_location(slider_rect);
height_slider.set_min(map_min_height);
height_slider.set_max(map_max_height);
height_slider.set_value(map_height);
static util::scoped_ptr<map_generator> random_map_generator(NULL);
if (random_map_generator == NULL) {
// Initialize the map generator if this is the first call,
// otherwise keep the settings and such.
const config* const toplevel_cfg = game_config.find_child("multiplayer","id","multiplayer_Random_Map");
const config* const cfg = toplevel_cfg == NULL ? NULL : toplevel_cfg->child("generator");
if (cfg == NULL) {
config dummy_cfg;
random_map_generator.assign(create_map_generator("", &dummy_cfg));
}
else {
random_map_generator.assign(create_map_generator("", cfg));
}
}
for(bool draw = true;; draw = false) {
if(cancel_button.pressed()) {
return "";
}
if(new_map_button.pressed()) {
draw = true;
if ((confirmation_needed &&
confirm_modification_disposal(disp))
|| !confirmation_needed) {
return map_editor::new_map(width_slider.value() + 2 * gamemap::default_border,
height_slider.value() + 2 * gamemap::default_border, fill_terrain);
}
}
if(random_map_setting_button.pressed()) {
draw = true;
if (random_map_generator.get()->allow_user_config()) {
random_map_generator.get()->user_config(disp);
}
}
if(random_map_button.pressed()) {
draw = true;
if ((confirmation_needed
&& confirm_modification_disposal(disp))
|| !confirmation_needed) {
const std::string map =
random_map_generator.get()->create_map(std::vector<std::string>());
if (map == "") {
gui::message_dialog(disp, "",
_("Map creation failed.")).show();
}
return map;
}
}
if (width_slider.value() != map_width
|| height_slider.value() != map_height) {
draw = true;
}
if (draw) {
map_width = width_slider.value();
map_height = height_slider.value();
frame.draw_background();
frame.draw_border();
title_rect = font::draw_text(&disp.video(),screen_area(),24,font::NORMAL_COLOUR,
_("Create New Map"),
xpos+(width-title_rect.w)/2,ypos+10);
font::draw_text(&disp.video(),screen_area(),14,font::NORMAL_COLOUR,
width_label,width_rect.x,width_rect.y);
font::draw_text(&disp.video(),screen_area(),14,font::NORMAL_COLOUR,
height_label,height_rect.x,height_rect.y);
std::stringstream width_str;
width_str << map_width;
font::draw_text(&disp.video(),screen_area(),14,font::NORMAL_COLOUR,width_str.str(),
slider_right+horz_margin,width_rect.y);
std::stringstream height_str;
height_str << map_height;
font::draw_text(&disp.video(),screen_area(),14,font::NORMAL_COLOUR,height_str.str(),
slider_right+horz_margin,height_rect.y);
}
new_map_button.set_dirty();
random_map_button.set_dirty();
random_map_setting_button.set_dirty();
cancel_button.set_dirty();
width_slider.set_dirty();
height_slider.set_dirty();
events::raise_process_event();
events::raise_draw_event();
if (draw) {
update_rect(xpos,ypos,width,height);
}
disp.update_display();
SDL_Delay(20);
events::pump();
}
}
void preferences_dialog(display &disp, config &prefs) {
const events::event_context dialog_events_context;
const gui::dialog_manager dialog_mgr;
const int width = 600;
const int height = 400;
const int xpos = disp.w()/2 - width/2;
const int ypos = disp.h()/2 - height/2;
SDL_Rect clip_rect = disp.screen_area();
gui::button close_button(disp.video(),_("Close Window"));
std::vector<gui::button*> buttons;
buttons.push_back(&close_button);
gui::dialog_frame frame(disp.video(),_("Preferences"),gui::dialog_frame::default_style,true,&buttons);
frame.layout(xpos,ypos,width,height);
frame.draw();
const std::string& scroll_label = _("Scroll Speed:");
SDL_Rect scroll_rect = {0,0,0,0};
scroll_rect = font::draw_text(NULL,clip_rect,14,font::NORMAL_COLOUR,
scroll_label,0,0);
const int text_right = xpos + scroll_rect.w + 5;
const int scroll_pos = ypos + 20;
scroll_rect.x = text_right - scroll_rect.w;
scroll_rect.y = scroll_pos;
const int slider_left = text_right + 10;
const int slider_right = xpos + width - 5;
if(slider_left >= slider_right)
return;
SDL_Rect slider_rect = { slider_left, scroll_pos, slider_right - slider_left, 10 };
slider_rect.y = scroll_pos;
gui::slider scroll_slider(disp.video());
scroll_slider.set_location(slider_rect);
scroll_slider.set_min(1);
scroll_slider.set_max(100);
scroll_slider.set_value(preferences::scroll_speed());
gui::button fullscreen_button(disp.video(),_("Toggle Full Screen"),
gui::button::TYPE_CHECK);
fullscreen_button.set_check(preferences::fullscreen());
fullscreen_button.set_location(slider_left,scroll_pos + 80);
gui::button grid_button(disp.video(),_("Show Grid"),
gui::button::TYPE_CHECK);
grid_button.set_check(preferences::grid());
grid_button.set_location(slider_left + fullscreen_button.width() + 100,
scroll_pos + 80);
gui::button resolution_button(disp.video(),_("Video Mode"));
resolution_button.set_location(slider_left,scroll_pos + 80 + 50);
gui::button hotkeys_button (disp.video(),_("Hotkeys"));
hotkeys_button.set_location(slider_left + fullscreen_button.width() + 100,
scroll_pos + 80 + 50);
// Time of Day lighting level sliders, etc.
const std::string& lighting_header_label = _("Lighting levels (time of day):");
SDL_Rect lighting_header_rect = font::draw_text(NULL,clip_rect,14,font::NORMAL_COLOUR,
lighting_header_label,0,0
);
lighting_header_rect.x = scroll_rect.x;
lighting_header_rect.y = resolution_button.location().y + resolution_button.height() + 40;
const std::string& lighting_r_label = _("light_level^Red:");
const std::string& lighting_g_label = _("light_level^Green:");
const std::string& lighting_b_label = _("light_level^Blue:");
SDL_Rect lighting_r_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_r_label,0,0);
SDL_Rect lighting_g_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_g_label,0,0);
SDL_Rect lighting_b_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_b_label,0,0);
lighting_r_rect.x = resolution_button.location().x;
lighting_r_rect.y = lighting_header_rect.y + 40;
lighting_g_rect.x = resolution_button.location().x;
lighting_g_rect.y = lighting_r_rect.y + 40;
lighting_b_rect.x = resolution_button.location().x;
lighting_b_rect.y = lighting_g_rect.y + 40;
gui::slider lighting_r_slider(disp.video());
gui::slider lighting_g_slider(disp.video());
gui::slider lighting_b_slider(disp.video());
const int rgb_sliders_ref_x = lighting_r_rect.x +
std::max<int>(std::max<int>(lighting_r_rect.w, lighting_g_rect.w), lighting_b_rect.w);
const int rgb_sliders_ref_width = hotkeys_button.location().x + hotkeys_button.location().w - rgb_sliders_ref_x;
SDL_Rect r_rect = { rgb_sliders_ref_x, lighting_r_rect.y, rgb_sliders_ref_width, 10};
SDL_Rect g_rect = { rgb_sliders_ref_x, lighting_g_rect.y, rgb_sliders_ref_width, 10};
SDL_Rect b_rect = { rgb_sliders_ref_x, lighting_b_rect.y, rgb_sliders_ref_width, 10};
lighting_r_slider.set_value(preferences::editor_r());
lighting_g_slider.set_value(preferences::editor_g());
lighting_b_slider.set_value(preferences::editor_b());
lighting_r_slider.set_min(-255);
lighting_g_slider.set_min(-255);
lighting_b_slider.set_min(-255);
lighting_r_slider.set_max(255);
lighting_g_slider.set_max(255);
lighting_b_slider.set_max(255);
lighting_r_slider.set_location(r_rect);
lighting_g_slider.set_location(g_rect);
lighting_b_slider.set_location(b_rect);
// NOTE: padding
std::string lighting_value_r = "0000";
std::string lighting_value_g = "0000";
std::string lighting_value_b = "0000";
SDL_Rect lighting_value_r_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_value_r,0,0);
SDL_Rect lighting_value_g_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_value_g,0,0);
SDL_Rect lighting_value_b_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_value_b,0,0);
lighting_value_r_rect.x = rgb_sliders_ref_x + rgb_sliders_ref_width + 20;
lighting_value_g_rect.x = rgb_sliders_ref_x + rgb_sliders_ref_width + 20;
lighting_value_b_rect.x = rgb_sliders_ref_x + rgb_sliders_ref_width + 20;
lighting_value_r_rect.y = r_rect.y;
lighting_value_g_rect.y = g_rect.y;
lighting_value_b_rect.y = b_rect.y;
bool redraw_all = true;
bool redraw_slider_values = false;
for(;;) {
if(close_button.pressed()) {
break;
}
if(fullscreen_button.pressed()) {
preferences::set_fullscreen(fullscreen_button.checked());
redraw_all = true;
}
if(redraw_all) {
frame.draw();
fullscreen_button.set_dirty();
close_button.set_dirty();
resolution_button.set_dirty();
grid_button.set_dirty();
hotkeys_button.set_dirty();
scroll_slider.set_dirty();
lighting_r_slider.set_dirty();
lighting_g_slider.set_dirty();
lighting_b_slider.set_dirty();
font::draw_text(&disp.video(),clip_rect,14,font::NORMAL_COLOUR,scroll_label,
scroll_rect.x,scroll_rect.y);
font::draw_text(&disp.video(),clip_rect,14,font::NORMAL_COLOUR,lighting_header_label,lighting_header_rect.x,lighting_header_rect.y);
font::draw_text(&disp.video(),clip_rect,12,font::NORMAL_COLOUR,lighting_r_label,lighting_r_rect.x,lighting_r_rect.y);
font::draw_text(&disp.video(),clip_rect,12,font::NORMAL_COLOUR,lighting_g_label,lighting_g_rect.x,lighting_g_rect.y);
font::draw_text(&disp.video(),clip_rect,12,font::NORMAL_COLOUR,lighting_b_label,lighting_b_rect.x,lighting_b_rect.y);
update_rect(screen_area());
redraw_all = false;
redraw_slider_values = true;
}
if(grid_button.pressed()) {
preferences::set_grid(grid_button.checked());
}
if(resolution_button.pressed()) {
preferences::show_video_mode_dialog(disp);
break;
}
if(hotkeys_button.pressed()) {
preferences::show_hotkeys_dialog(disp, &prefs);
break;
}
events::pump();
events::raise_process_event();
events::raise_draw_event();
//!@todo FIXME: this could be made simpler with gui::label widgets, but I'm too lazy to go
//! and learn how to use them, thus I'll concentrate on the real feature -- shadowmaster
if (lighting_r_slider.value_change() || redraw_slider_values) {
draw_solid_tinted_rectangle(
lighting_value_r_rect.x-2, lighting_value_r_rect.y-2,
lighting_value_r_rect.w+4, lighting_value_r_rect.h+4,
30, 30, 30,
1.0,
disp.video().getSurface()
);
lighting_value_r = str_cast<int>(lighting_r_slider.value());
font::draw_text(&disp.video(), clip_rect, 12, font::NORMAL_COLOUR,
lighting_value_r, lighting_value_r_rect.x, lighting_value_r_rect.y);
update_rect(lighting_value_r_rect);
}
if (lighting_g_slider.value_change() || redraw_slider_values) {
draw_solid_tinted_rectangle(
lighting_value_g_rect.x-2, lighting_value_g_rect.y-2,
lighting_value_g_rect.w+4, lighting_value_g_rect.h+4,
30, 30, 30,
1.0,
disp.video().getSurface()
);
lighting_value_g = str_cast<int>(lighting_g_slider.value());
font::draw_text(&disp.video(), clip_rect, 12, font::NORMAL_COLOUR,
lighting_value_g, lighting_value_g_rect.x, lighting_value_g_rect.y
);
update_rect(lighting_value_g_rect);
}
if (lighting_b_slider.value_change() || redraw_slider_values) {
draw_solid_tinted_rectangle(
lighting_value_b_rect.x-2, lighting_value_b_rect.y-2,
lighting_value_b_rect.w+4, lighting_value_b_rect.h+4,
30, 30, 30,
1.0,
disp.video().getSurface()
);
lighting_value_b = str_cast<int>(lighting_b_slider.value());
font::draw_text(&disp.video(), clip_rect, 12, font::NORMAL_COLOUR,
lighting_value_b, lighting_value_b_rect.x, lighting_value_b_rect.y
);
update_rect(lighting_value_b_rect);
}
redraw_slider_values = false;
preferences::set_scroll_speed(scroll_slider.value());
preferences::set_editor_r(lighting_r_slider.value());
preferences::set_editor_g(lighting_g_slider.value());
preferences::set_editor_b(lighting_b_slider.value());
disp.update_display();
SDL_Delay(20);
}
}
bool resize_dialog(display &disp, unsigned& width, unsigned& height,
int& x_offset, int& y_offset, bool& do_expand)
{
const resize_lock prevent_resizing;
const events::event_context dialog_events_context;
const gui::dialog_manager dialog_mgr;
const int dlg_width = 600;
const int dlg_height = 350;
const int xpos = disp.w() / 2 - dlg_width / 2;
const int ypos = disp.h() / 2 - dlg_height / 2;
const int horz_margin = 5;
const int vertical_margin = 20;
const int button_padding = 20;
SDL_Rect dialog_rect = {xpos - 10,
ypos - 10, dlg_width + 20, dlg_height + 20};
surface_restorer restorer(&disp.video(), dialog_rect);
gui::dialog_frame frame(disp.video());
frame.layout(xpos,ypos,dlg_width, dlg_height);
frame.draw_background();
frame.draw_border();
SDL_Rect title_rect = font::draw_text(NULL, screen_area(), 24,
font::NORMAL_COLOUR, _("Resize Map"), 0, 0);
const std::string& width_label = _("Width:");
const std::string& height_label = _("Height:");
const std::string& x_offset_label = _("X offset:");
const std::string& y_offset_label = _("Y offset:");
SDL_Rect width_rect = font::draw_text(NULL, screen_area(), 14,
font::NORMAL_COLOUR, width_label, 0, 0);
SDL_Rect height_rect = font::draw_text(NULL, screen_area(), 14,
font::NORMAL_COLOUR, height_label, 0, 0);
SDL_Rect x_offset_rect = font::draw_text(NULL, screen_area(), 14,
font::NORMAL_COLOUR, x_offset_label, 0, 0);
SDL_Rect y_offset_rect = font::draw_text(NULL, screen_area(), 14,
font::NORMAL_COLOUR, y_offset_label, 0, 0);
// store the width of all labels in an array to determine the maximum
const int label_arr_size = 4;
int label_arr[label_arr_size] =
{ width_rect.w, height_rect.w, x_offset_rect.w, y_offset_rect.w };
// use the biggest label to deterimine the right side for the labels
const int text_right = xpos + horz_margin +
*std::max_element(label_arr, label_arr + label_arr_size);
width_rect.x = text_right - width_rect.w;
height_rect.x = text_right - height_rect.w;
x_offset_rect.x = text_right - x_offset_rect.w;
y_offset_rect.x = text_right - y_offset_rect.w;
width_rect.y = ypos + title_rect.h + vertical_margin * 2;
height_rect.y = width_rect.y + width_rect.h + vertical_margin;
x_offset_rect.y = height_rect.y + height_rect.h + vertical_margin * 2;
y_offset_rect.y = x_offset_rect.y + x_offset_rect.h + vertical_margin;
gui::button cancel_button(disp.video(), _("Cancel"));
gui::button ok_button(disp.video(), _("OK"));
cancel_button.set_location(
xpos + dlg_width - cancel_button.width() - horz_margin,
ypos + dlg_height - cancel_button.height() - 14);
ok_button.set_location(
xpos + dlg_width - cancel_button.width() - horz_margin - ok_button.width() - button_padding,
ypos + dlg_height - ok_button.height()-14);
const int right_space = 100;
const int slider_left = text_right + 10;
const int slider_right = xpos + dlg_width - horz_margin - right_space;
SDL_Rect slider_rect =
{ slider_left, width_rect.y, slider_right-slider_left, width_rect.h};
slider_rect.y = width_rect.y;
gui::slider width_slider(disp.video());
width_slider.set_location(slider_rect);
width_slider.set_min(map_min_width);
width_slider.set_max(map_max_width);
width_slider.set_value(width);
slider_rect.y = height_rect.y;
gui::slider height_slider(disp.video());
height_slider.set_location(slider_rect);
height_slider.set_min(map_min_height);
height_slider.set_max(map_max_height);
height_slider.set_value(height);
slider_rect.y = x_offset_rect.y;
gui::slider x_offset_slider(disp.video());
x_offset_slider.set_location(slider_rect);
x_offset_slider.set_min(-map_max_height);
x_offset_slider.set_max(map_max_height);
x_offset_slider.set_value(x_offset);
slider_rect.y = y_offset_rect.y;
gui::slider y_offset_slider(disp.video());
y_offset_slider.set_location(slider_rect);
y_offset_slider.set_min(-map_max_height);
y_offset_slider.set_max(map_max_height);
y_offset_slider.set_value(y_offset);
slider_rect.y += y_offset_rect.h + vertical_margin * 2;
gui::button do_expand_button(disp.video(), _("Smart expand"), gui::button::TYPE_CHECK);
// assume the width will be correct for this widget
do_expand_button.set_location(slider_rect);
do_expand_button.set_check(do_expand);
for(bool draw = true;; draw = false) {
if(cancel_button.pressed()) {
return false;
}
if (static_cast<unsigned>(width_slider.value()) != width
|| static_cast<unsigned>(height_slider.value()) != height
|| x_offset_slider.value() != x_offset
|| y_offset_slider.value() != y_offset
|| do_expand_button.checked() != do_expand) {
draw = true;
}
if (draw) {
width = width_slider.value();
height = height_slider.value();
x_offset = x_offset_slider.value();
y_offset = y_offset_slider.value();
do_expand = do_expand_button.checked();
frame.draw_background();
frame.draw_border();
title_rect = font::draw_text(&disp.video(), screen_area(), 24,
font::NORMAL_COLOUR, _("Resize Map"),
xpos + (dlg_width - title_rect.w) / 2, ypos + 10);
font::draw_text(&disp.video(), screen_area(), 14, font::NORMAL_COLOUR,
width_label, width_rect.x, width_rect.y);
font::draw_text(&disp.video(), screen_area(), 14, font::NORMAL_COLOUR,
height_label, height_rect.x, height_rect.y);
font::draw_text(&disp.video(), screen_area(), 14, font::NORMAL_COLOUR,
x_offset_label, x_offset_rect.x, x_offset_rect.y);
font::draw_text(&disp.video(),screen_area(),14,font::NORMAL_COLOUR,
y_offset_label, y_offset_rect.x, y_offset_rect.y);
font::draw_text(&disp.video(), screen_area(), 14,
font::NORMAL_COLOUR, lexical_cast<std::string>(width),
slider_right + horz_margin, width_rect.y);
font::draw_text(&disp.video(), screen_area(), 14,
font::NORMAL_COLOUR, lexical_cast<std::string>(height),
slider_right + horz_margin, height_rect.y);
font::draw_text(&disp.video(), screen_area(), 14,
font::NORMAL_COLOUR, lexical_cast<std::string>(x_offset),
slider_right + horz_margin, x_offset_rect.y);
font::draw_text(&disp.video(), screen_area(), 14,
font::NORMAL_COLOUR, lexical_cast<std::string>(y_offset),
slider_right + horz_margin, y_offset_rect.y);
}
if (ok_button.pressed()) {
return true;
}
// make sure the all elements are redrawn
cancel_button.set_dirty();
ok_button.set_dirty();
width_slider.set_dirty();
height_slider.set_dirty();
x_offset_slider.set_dirty();
y_offset_slider.set_dirty();
do_expand_button.set_dirty();
events::raise_process_event();
events::raise_draw_event();
if (draw) {
update_rect(xpos, ypos, dlg_width, dlg_height);
}
disp.update_display();
SDL_Delay(20);
events::pump();
}
}
FLIP_AXIS flip_dialog(display &disp) {
std::vector<std::string> items;
items.push_back(_("X-Axis"));
items.push_back(_("Y-Axis"));
const std::string msg = _("Flip around (this may change the dimensions of the map):");
gui::dialog flipmenu = gui::dialog(disp, "",
font::word_wrap_text(msg, 12, 180),
gui::OK_CANCEL);
flipmenu.set_menu(items);
switch (flipmenu.show()) {
case 0:
return FLIP_X;
case 1:
return FLIP_Y;
default:
return NO_FLIP;
}
}
}

View file

@ -1,59 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/editor_dialogs.hpp
//!
#include "../display.hpp"
#include "../config.hpp"
#include "../map.hpp"
#include "map_manip.hpp"
#include <map>
#ifndef EDITOR_DIALOGS_H_INCLUDED
#define EDITOR_DIALOGS_H_INCLUDED
namespace map_editor {
//! Notify the user that the map is changed and ask if the user wants to
//! proceed. Return true if yes is answered.
bool confirm_modification_disposal(display &disp);
//! Show a dialog to create new map. If confirmation_needed is true, the
//! user will be asked if she wants to continue even though the changes
//! to the current map is lost. fill_terrain will be used to fill the
//! map if a new one is created. Return the string representation of the
//! new map, or the empty string if the operation failed or was
//! cancelled.
std::string new_map_dialog(display &disp, const t_translation::t_terrain fill_terrain,
const bool confirmation_needed, const config &gconfig);
//! Show a dialog where the user may set the preferences used in the
//! editor.
void preferences_dialog(display &disp, config &prefs);
//! Show a dialog asking for the new size of the map. Return the chosen
//! width and height. Checks are made to see that the desired values
//! will result in a feasible map.
bool resize_dialog(display &disp, unsigned& width, unsigned& height,
int& x_offset, int& y_offset, bool& do_expand);
FLIP_AXIS flip_dialog(display &disp);
}
#endif // DIALOGS_H_INCLUDED

View file

@ -1,103 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/editor_display.cpp
//! Draw the screen for the map-editor.
#include "global.hpp"
#include "editor_display.hpp"
#include "game_config.hpp"
#include "gamestatus.hpp"
#include "gettext.hpp"
#include "hotkeys.hpp"
#include "language.hpp"
#include "preferences.hpp"
#include "sdl_utils.hpp"
#include "theme.hpp"
#include "tooltips.hpp"
#include "util.hpp"
#include "SDL_image.h"
#include <cassert>
editor_display::editor_display(CVideo& video, const gamemap& map,
const config& theme_cfg, const config& cfg,
const config& level) :
display(video, map, theme_cfg, cfg, level)
{
clear_screen();
}
void editor_display::pre_draw()
{
//!@todo FIXME: this should be done from the preferences dialog as well,
//! to reflect changes for the user before closing it
this->update_light_levels();
image::set_colour_adjustment(lr_, lg_, lb_);
}
image::TYPE editor_display::get_image_type(const gamemap::location& loc)
{
if(loc == mouseoverHex_ && map_.on_board_with_border(mouseoverHex_)) {
return image::BRIGHTENED;
} else if (highlighted_locations_.find(loc) != highlighted_locations_.end()) {
return image::SEMI_BRIGHTENED;
}
return image::SCALED_TO_HEX;
}
const SDL_Rect& editor_display::get_clip_rect()
{
return map_outside_area();
}
void editor_display::draw_sidebar()
{
// Fill in the terrain report
if(map_.on_board_with_border(mouseoverHex_)) {
const t_translation::t_terrain terrain = map_.get_terrain(mouseoverHex_);
const t_translation::t_list& underlying = map_.underlying_union_terrain(terrain);
std::stringstream str;
str << map_.get_terrain_info(terrain).name();
if(underlying.size() != 1 || underlying.front() != terrain) {
str << " (";
for(t_translation::t_list::const_iterator i =
underlying.begin(); i != underlying.end(); ++i) {
str << map_.get_terrain_info(*i).name();
if(i+1 != underlying.end()) {
str << ",";
}
}
str << ")";
}
refresh_report(reports::TERRAIN, reports::report(str.str()));
std::stringstream str2;
str2 << mouseoverHex_;
refresh_report(reports::POSITION, reports::report(str2.str()));
}
refresh_report(reports::VILLAGES, reports::report(lexical_cast<std::string>(map_.villages().size())));
}
void editor_display::update_light_levels(void)
{
this->lr_ = preferences::editor_r();
this->lg_ = preferences::editor_g();
this->lb_ = preferences::editor_b();
}

View file

@ -1,46 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//** @file editor_display.hpp */
#ifndef EDITOR_DISPLAY_H_INCLUDED
#define EDITOR_DISPLAY_H_INCLUDED
#include "../display.hpp"
class editor_display : public display
{
public:
editor_display(CVideo& video, const gamemap& map, const config& theme_cfg,
const config& cfg, const config& level);
bool in_editor() const { return true; }
/** Rebuild the dynamic terrain at the given location. */
void rebuild_terrain(const gamemap::location &loc) {
builder_.rebuild_terrain(loc);
}
protected:
void pre_draw();
image::TYPE get_image_type(const gamemap::location& loc);
const SDL_Rect& get_clip_rect();
void draw_sidebar();
/** Updates editor light levels from preferences */
void update_light_levels();
private:
int lr_, lg_, lb_;
};
#endif

View file

@ -1,57 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/editor_layout.cpp
//! Set various sizes for the screen-layout of the map editor.
#include "editor_layout.hpp"
#include "util.hpp"
namespace {
const size_t default_terrain_size = 36;
const size_t default_palette_width = 3;
}
namespace map_editor {
size_specs::size_specs() {
terrain_size = default_terrain_size;
terrain_padding = 2;
terrain_space = terrain_size + terrain_padding;
terrain_width = default_palette_width;
brush_x = 0;
brush_y = 0;
brush_padding = 5;
palette_x = 0;
palette_y = 0;
palette_w = 10;
palette_h = 20;
}
void adjust_sizes(const display &disp, size_specs &sizes) {
//! @todo Hardcoded coordinates for brush selection, make it themeable
sizes.brush_x = disp.map_outside_area().w + 22;
sizes.brush_y = 165;
//! @todo Hardcoded coordinates for terrain palette, make it themeable
sizes.palette_x = disp.map_outside_area().w + 16;
sizes.palette_y = sizes.brush_y + 132 + 10;
sizes.palette_w = sizes.terrain_space * default_palette_width;
//the '-5' make sure that the scroll down button can not be outside of
//the window, this is probably a bug in placement anyway...
sizes.palette_h = disp.h() - sizes.palette_y - 5;
}
} // end namespace map_editor

View file

@ -1,51 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/editor_layout.hpp
//!
#ifndef EDITOR_LAYOUT_H_INCLUDED
#define EDITOR_LAYOUT_H_INCLUDED
#include "global.hpp"
#include "display.hpp"
namespace map_editor {
//! Size specifications for the map editor.
struct size_specs {
//! Initialize the values to dummie-values that will
//! avoid floating point errors if calculations are made
//! before the sizes are adjusted through adjust_sizes().
size_specs();
size_t terrain_size;
size_t terrain_padding;
size_t terrain_space;
size_t terrain_width;
size_t palette_x;
size_t palette_y;
size_t palette_h;
size_t palette_w;
size_t brush_x;
size_t brush_y;
size_t brush_padding;
};
//! Adjust the internal size specifications to fit the display.
void adjust_sizes(const display &disp, size_specs &sizes);
}
#endif // EDITOR_LAYOUT_H_INCLUDED

View file

@ -1,369 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/editor_main.cpp
//!
#include "editor.hpp"
#include "../config.hpp"
#include "../cursor.hpp"
#include "../filesystem.hpp"
#include "../font.hpp"
#include "../game_config.hpp"
#include "../gettext.hpp"
#include "../image.hpp"
#include "../language.hpp"
#include "../log.hpp"
#include "../map.hpp"
#include "../minimap.hpp"
#include "../preferences.hpp"
#include "../random.hpp"
#include "../util.hpp"
#include "../video.hpp"
#include "../wesconfig.h"
#include "../wml_exception.hpp"
#include "serialization/parser.hpp"
#include "serialization/preprocessor.hpp"
#include "serialization/string_utils.hpp"
#include <cctype>
#include <clocale>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
namespace {
static std::string wm_title_string;
}
int main(int argc, char** argv)
{
const std::string rev = game_config::revision.empty() ? "" :
" (" + game_config::revision + ")";
std::cerr << "Battle for Wesnoth Map Editor v" << VERSION << rev << '\n';
time_t t = time(NULL);
std::cerr << "Started on " << ctime(&t) << "\n";
game_config::editor = true;
rand_rng::rng generator;
const rand_rng::set_random_generator generator_setter(&generator);
int arg;
for(arg = 1; arg != argc; ++arg) {
const std::string val(argv[arg]);
if(val.empty()) {
continue;
}
if(val == "--help" || val == "-h") {
std::cout << "usage: " << argv[0]
<< " [options] [map]\n"
<< " --bpp Set the bits per pixel.\n"
<< " --datadir Select the data directory to use.\n"
<< " -f, --fullscreen Runs the editor in full screen mode.\n"
<< " -h, --help Prints this message and exits.\n"
<< " --log-<level>=<domain1>,<domain2>,...\n"
<< " Sets the severity level of the log domains.\n"
<< " 'all' can be used to match any log domain.\n"
<< " Available levels: error, warning, info, debug.\n"
<< " By default the 'error' level is used.\n"
<< " --logdomains List defined log domains and exit.\n"
<< " --path Prints the name of the game data directory and exits.\n"
<< " -r, --resolution XxY Sets the screen resolution. Example: -r 800x600.\n"
<< " -v, --version Prints the game's version number and exits.\n"
<< " -w, --windowed Runs the editor in windowed mode.\n"
;
return 0;
} else if(val == "--version" || val == "-v") {
std::cout << "Battle for Wesnoth "
<< game_config::version
#if defined(SVNREV) && defined(DO_DISPLAY_REVISION)
<< " (" << game_config::revision << ")"
#endif /* defined(SVNREV) and defined(DO_DISPLAY_REVISION) */
<< "\n";
return 0;
} else if(val == "--path") {
std::cout << game_config::path
<< "\n";
return 0;
} else if(val == "--logdomains") {
std::cout << lg::list_logdomains() << "\n";
return 0;
}
}
CVideo video;
const font::manager font_manager;
const preferences::base_manager prefs_manager;
const image::manager image_manager;
resize_monitor resize_monitor_;
binary_paths_manager paths_manager;
std::string filename = "";
std::string mapdata;
bool from_scenario;
int choosen_bpp = 0;
for(arg = 1; arg != argc; ++arg) {
const std::string val(argv[arg]);
if(val.empty()) {
continue;
}
if(val == "--bpp" && arg + 1 != argc) {
++arg;
choosen_bpp = lexical_cast_default<int>(argv[arg]);
}
else if(val == "--resolution" || val == "-r") {
if(arg+1 != argc) {
++arg;
const std::string val(argv[arg]);
const std::vector<std::string> res = utils::split(val, 'x');
if(res.size() == 2) {
const int xres = lexical_cast_default<int>(res.front());
const int yres = lexical_cast_default<int>(res.back());
if(xres > 0 && yres > 0) {
const std::pair<int,int> resolution(xres,yres);
preferences::set_resolution(resolution);
}
}
}
} else if(val == "--windowed" || val == "-w") {
preferences::set_fullscreen(false);
} else if(val == "--fullscreen" || val == "-f") {
preferences::set_fullscreen(true);
} else if(val == "--datadir") {
if (arg+1 != argc) {
const std::string val(argv[++arg]);
const std::string cwd = get_cwd();
if(val[0] == '/') {
game_config::path = val;
} else if(cwd != "") {
game_config::path = cwd + '/' + val;
} else {
std::cerr << "Could not get working directory\n";
return 0;
}
if(!is_directory(game_config::path)) {
std::cerr << "Could not find directory '" << game_config::path << "'\n";
return 0;
}
}
} else if (val.substr(0, 6) == "--log-") {
size_t p = val.find('=');
if (p == std::string::npos) {
std::cerr << "unknown option: " << val << '\n';
return 0;
}
std::string s = val.substr(6, p - 6);
int severity;
if (s == "error") severity = 0;
else if (s == "warning") severity = 1;
else if (s == "info") severity = 2;
else if (s == "debug") severity = 3;
else {
std::cerr << "unknown debug level: " << s << '\n';
return 0;
}
while (p != std::string::npos) {
size_t q = val.find(',', p + 1);
s = val.substr(p + 1, q == std::string::npos ? q : q - (p + 1));
if (!lg::set_log_domain_severity(s, severity)) {
std::cerr << "unknown debug domain: " << s << '\n';
return 0;
}
p = q;
}
} else if(val[0] == '-') {
std::cerr << "unknown option: " << val << "\n";
return 0;
} else {
filename = val;
try {
mapdata = read_file(filename);
}
catch (io_exception) {
std::cerr << "Could not read the map file, sorry." << std::endl;
return 1;
}
}
}
setlocale (LC_ALL, "");
const std::string& intl_dir = get_intl_dir();
bindtextdomain (PACKAGE "-editor", intl_dir.c_str());
bind_textdomain_codeset (PACKAGE "-editor", "UTF-8");
bindtextdomain (PACKAGE "-lib", intl_dir.c_str());
bind_textdomain_codeset (PACKAGE "-lib", "UTF-8");
textdomain (PACKAGE "-editor");
// Blatant cut and paste from game.cpp
image::set_wm_icon();
int video_flags = preferences::fullscreen() ? FULL_SCREEN : 0;
std::pair<int,int> resolution = preferences::resolution();
std::cerr << "checking mode possible...\n";
const int default_bpp = 24;
int bpp = default_bpp;
if(choosen_bpp == 0) {
bpp = video.modePossible(resolution.first,resolution.second,default_bpp,video_flags);
std::cerr << bpp << "\n";
if(bpp == 0) {
//Video mode not supported, maybe from bad prefs.
std::cerr << "The video mode, " << resolution.first
<< "x" << resolution.second << "x" << default_bpp <<
"is not supported\nAttempting 1024x768x" << default_bpp << "...\n";
//Attempt 1024x768.
resolution.first = 1024;
resolution.second = 768;
bpp = video.modePossible(resolution.first,resolution.second,default_bpp,video_flags);
if(bpp == 0) {
//Attempt 1024x768.
resolution.first = 1024;
resolution.second = 768;
std::cerr << "1024x768x" << default_bpp << " is not possible.\nAttempting 800x600x" << default_bpp << "...\n";
resolution.first = 800;
resolution.second = 600;
bpp = video.modePossible(resolution.first,resolution.second,default_bpp,video_flags);
}
if(bpp == 0) {
//couldn't do 1024x768 or 800x600
std::cerr << "The required video mode, " << resolution.first
<< "x" << resolution.second << "x" << default_bpp <<
"is not supported\n";
return 0;
}
}
} else {
bpp = choosen_bpp;
}
std::cerr << "setting mode to " << resolution.first << "x" << resolution.second << "\n";
const int res = video.setMode(resolution.first,resolution.second,bpp,video_flags);
video.setBpp(bpp);
if(res == 0) {
std::cerr << "required video mode, " << resolution.first << "x"
<< resolution.second << "x" << bpp << " is not supported\n";
return 0;
}
preproc_map defines_map;
// define editor to do conditionnal loading in the main cfg
defines_map["EDITOR"] = preproc_define();
defines_map["OLD_EDITOR"] = preproc_define();
defines_map["MEDIUM"] = preproc_define();
defines_map["NORMAL"] = preproc_define();
#if defined(__APPLE__)
defines_map["APPLE"] = preproc_define();
#endif
//Set the locale first, then read the configuration, or else WML
//strings are not correctly translated. Does this work on on the win32
//platform?
load_language_list();
const bool lang_res = ::set_language(get_locale());
if(!lang_res) {
std::cerr << "No translation for locale '" << get_locale().language
<< "', default to system locale\n";
const bool lang_res = ::set_language(get_languages()[0]);
if(!lang_res) {
std::cerr << "Language data not found\n";
}
}
// Set the caption of the window
wm_title_string = _("Battle for Wesnoth Map Editor");
wm_title_string += " - " + game_config::revision;
SDL_WM_SetCaption(wm_title_string.c_str(), NULL);
//Read the configuration af
config cfg;
try {
scoped_istream stream = preprocess_file("data/", &defines_map);
read(cfg, *stream);
}
catch (config::error e) {
std::cerr << "Error when reading game config: '" << e.message << "'" << std::endl;
}
font::load_font_config();
paths_manager.set_paths(cfg);
::init_textdomains(cfg);
if(mapdata.empty()) {
mapdata = map_editor::new_map(22, 22, t_translation::GRASS_LAND);
}
srand(time(NULL));
bool done = false;
config* theme_cfg = cfg.find_child("theme", "name", "editor");
config dummy_theme;
if (!theme_cfg) {
std::cerr << "Editor theme could not be loaded." << std::endl;
theme_cfg = &dummy_theme;
}
std::cerr << "entering while...\n";
events::event_context ec;
map_editor::check_data(mapdata, filename, from_scenario, cfg);
while (!done) {
try {
std::cerr << "creating map...\n";
//! @todo Allow the editor to also create mask maps
editormap map(cfg, mapdata);
const config dummy_cfg;
editor_display gui(video, map, *theme_cfg, cfg, dummy_cfg);
map_editor::map_editor editor(gui, map, *theme_cfg, cfg);
editor.set_file_to_save_as(filename, from_scenario);
editor.main_loop();
done = true;
}
catch (map_editor::map_editor::new_map_exception &e) {
mapdata = e.new_map;
filename = e.new_filename;
from_scenario = e.from_scenario;
}
catch (gamemap::incorrect_format_exception) {
std::cerr << "The map is not in a correct format, sorry." << std::endl;
return 1;
} catch(twml_exception& e) {
std::cerr << "WML exception:\nUser message: "
<< e.user_message << "\nDev message: " << e.dev_message << '\n';
return 1;
} catch (CVideo::quit&) {
return 0;
}
}
return 0;
}

View file

@ -1,614 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/editor_palettes.cpp
//! Manage the terrain-palette in the editor.
#include "SDL.h"
#include "SDL_keysym.h"
#include "editor_palettes.hpp"
#include "editor_layout.hpp"
#include "../config.hpp"
#include "../sdl_utils.hpp"
#include "../serialization/string_utils.hpp"
#include "../image.hpp"
#include "../reports.hpp"
#include "../gettext.hpp"
#include "../tooltips.hpp"
#include "../video.hpp"
#include <cassert>
namespace map_editor {
static bool is_invalid_terrain(t_translation::t_terrain c) {
return (c == t_translation::VOID_TERRAIN || c == t_translation::FOGGED);
}
terrain_group::terrain_group(const config& cfg, display& gui):
id(cfg["id"]), name(cfg["name"]),
button(gui.video(), "", gui::button::TYPE_CHECK, cfg["icon"])
{
}
terrain_palette::terrain_palette(display &gui, const size_specs &sizes,
const gamemap &map, const config& cfg)
: gui::widget(gui.video()), size_specs_(sizes), gui_(gui), tstart_(0),
checked_group_btn_(0), map_(map),
top_button_(gui.video(), "", gui::button::TYPE_PRESS, "uparrow-button"),
bot_button_(gui.video(), "", gui::button::TYPE_PRESS, "downarrow-button")
{
// Get the available terrains temporary in terrains_
terrains_ = map_.get_terrain_list();
terrains_.erase(std::remove_if(terrains_.begin(), terrains_.end(), is_invalid_terrain),
terrains_.end());
// Get the available groups and add them to the structure
const config::child_list& groups = cfg.get_children("editor_group");
config::child_list::const_iterator g_itor = groups.begin();
for(; g_itor != groups.end(); ++ g_itor) {
terrain_groups_.push_back(terrain_group(**g_itor, gui));
// By default the 'all'-button is pressed
if(terrain_groups_.back().id == "all") {
terrain_groups_.back().button.set_check(true);
checked_group_btn_ = &terrain_groups_.back().button;
}
}
// The rest of the code assumes this is a valid pointer
assert(checked_group_btn_ != 0);
// add the groups for all terrains to the map
t_translation::t_list::const_iterator t_itor = terrains_.begin();
for(; t_itor != terrains_.end(); ++t_itor) {
const terrain_type& t_info = map_.get_terrain_info(*t_itor);
// don't display terrains that were automatically created from base+overlay
if (t_info.is_combined())
continue;
// nor display terrains that have hide_in_editor=true
if (t_info.hide_in_editor())
continue;
// add the terrain to the requested groups
const std::vector<std::string>& key =
utils::split(t_info.editor_group());
for(std::vector<std::string>::const_iterator k_itor = key.begin();
k_itor != key.end(); ++k_itor)
{
terrain_map_[*k_itor].push_back(*t_itor);
}
// Add the terrain to the default group
terrain_map_["all"].push_back(*t_itor);
}
// Set the default group
terrains_ = terrain_map_["all"];
if(terrains_.empty()) {
std::cerr << "No terrain found.\n";
}
else {
selected_fg_terrain_ = terrains_[0];
selected_bg_terrain_ = terrains_[0];
}
update_report();
//adjust_size();
}
void terrain_palette::adjust_size() {
scroll_top();
const size_t button_height = 24;
const size_t button_palette_padding = 8;
// Values for the group buttons fully hardcoded for now
//! @todo will be fixed later
const size_t group_button_height = 24;
const size_t group_button_padding = 2;
const size_t group_buttons_per_row = 5;
// Determine number of theme button rows
size_t group_rows = terrain_groups_.size() / group_buttons_per_row;
if(terrain_groups_.size() % group_buttons_per_row != 0) {
++group_rows;
}
const size_t group_height = group_rows * (group_button_height + group_button_padding);
SDL_Rect rect = { size_specs_.palette_x, size_specs_.palette_y, size_specs_.palette_w, size_specs_.palette_h };
set_location(rect);
top_button_y_ = size_specs_.palette_y + group_height ;
button_x_ = size_specs_.palette_x + size_specs_.palette_w/2 - button_height/2;
terrain_start_ = top_button_y_ + button_height + button_palette_padding;
const size_t space_for_terrains = size_specs_.palette_h - (button_height + button_palette_padding) * 2 - group_height;
rect.y = terrain_start_;
rect.h = space_for_terrains;
bg_register(rect);
const unsigned terrains_fitting =
static_cast<unsigned> (space_for_terrains / size_specs_.terrain_space) *
size_specs_.terrain_width;
const unsigned total_terrains = num_terrains();
nterrains_ = std::min<int>(terrains_fitting, total_terrains);
bot_button_y_ = size_specs_.palette_y + (nterrains_ / size_specs_.terrain_width) * size_specs_.terrain_space + \
button_palette_padding * size_specs_.terrain_width + button_height + group_height;
top_button_.set_location(button_x_, top_button_y_);
bot_button_.set_location(button_x_, bot_button_y_);
size_t top = size_specs_.palette_y;
size_t left = size_specs_.palette_x - 8;
for(size_t i = 0; i < terrain_groups_.size(); ++i) {
terrain_groups_[i].button.set_location(left, top);
if(i % group_buttons_per_row == (group_buttons_per_row - 1)) {
left = size_specs_.palette_x - 8;
top += group_button_height + group_button_padding;
} else {
left += group_button_height + group_button_padding;
}
}
set_dirty();
}
void terrain_palette::set_dirty(bool dirty) {
widget::set_dirty(dirty);
if (dirty) {
top_button_.set_dirty();
bot_button_.set_dirty();
for(size_t i = 0; i < terrain_groups_.size(); ++i) {
terrain_groups_[i].button.set_dirty();
}
}
}
void terrain_palette::scroll_down() {
if(tstart_ + nterrains_ + size_specs_.terrain_width <= num_terrains()) {
tstart_ += size_specs_.terrain_width;
bg_restore();
set_dirty();
}
else if (tstart_ + nterrains_ + (num_terrains() % size_specs_.terrain_width) <= num_terrains()) {
tstart_ += num_terrains() % size_specs_.terrain_width;
bg_restore();
set_dirty();
}
}
void terrain_palette::scroll_up() {
unsigned int decrement = size_specs_.terrain_width;
if (tstart_ + nterrains_ == num_terrains() && num_terrains() % size_specs_.terrain_width != 0) {
decrement = num_terrains() % size_specs_.terrain_width;
}
if(tstart_ >= decrement) {
bg_restore();
set_dirty();
tstart_ -= decrement;
}
}
void terrain_palette::scroll_top() {
tstart_ = 0;
bg_restore();
set_dirty();
}
void terrain_palette::scroll_bottom() {
unsigned int old_start = num_terrains();
while (old_start != tstart_) {
old_start = tstart_;
scroll_down();
}
}
void terrain_palette::set_group(const std::string& id)
{
terrains_ = terrain_map_[id];
if(terrains_.empty()) {
std::cerr << "No terrain found.\n";
}
scroll_top();
}
t_translation::t_terrain terrain_palette::selected_fg_terrain() const
{
return selected_fg_terrain_;
}
t_translation::t_terrain terrain_palette::selected_bg_terrain() const
{
return selected_bg_terrain_;
}
void terrain_palette::select_fg_terrain(t_translation::t_terrain terrain)
{
if (selected_fg_terrain_ != terrain) {
set_dirty();
selected_fg_terrain_ = terrain;
update_report();
}
}
void terrain_palette::select_bg_terrain(t_translation::t_terrain terrain)
{
if (selected_bg_terrain_ != terrain) {
set_dirty();
selected_bg_terrain_ = terrain;
update_report();
}
}
//! After the language is changed, the selected terrains needs an update.
void terrain_palette::update_selected_terrains(void)
{
set_dirty();
update_report();
}
std::string terrain_palette::get_terrain_string(const t_translation::t_terrain t)
{
std::stringstream str;
const std::string& name = map_.get_terrain_info(t).name();
const t_translation::t_list& underlying = map_.underlying_union_terrain(t);
str << name;
if(underlying.size() != 1 || underlying[0] != t) {
str << " (";
for(t_translation::t_list::const_iterator i = underlying.begin();
i != underlying.end(); ++i) {
str << map_.get_terrain_info(*i).name();
if(i+1 != underlying.end()) {
str << ",";
}
}
str << ")";
}
return str.str();
}
void terrain_palette::left_mouse_click(const int mousex, const int mousey) {
int tselect = tile_selected(mousex, mousey);
if(tselect >= 0) {
select_fg_terrain(terrains_[tstart_+tselect]);
gui_.invalidate_game_status();
}
}
void terrain_palette::right_mouse_click(const int mousex, const int mousey) {
int tselect = tile_selected(mousex, mousey);
if(tselect >= 0) {
select_bg_terrain(terrains_[tstart_+tselect]);
gui_.invalidate_game_status();
}
}
size_t terrain_palette::num_terrains() const {
return terrains_.size();
}
void terrain_palette::draw() {
draw(false);
}
void terrain_palette::handle_event(const SDL_Event& event) {
if (event.type == SDL_MOUSEMOTION) {
// If the mouse is inside the palette, give it focus.
if (point_in_rect(event.button.x, event.button.y, location())) {
if (!focus(&event)) {
set_focus(true);
}
}
// If the mouse is outside, remove focus.
else {
if (focus(&event)) {
set_focus(false);
}
}
}
if (!focus(&event)) {
return;
}
int mousex, mousey;
SDL_GetMouseState(&mousex,&mousey);
const SDL_MouseButtonEvent mouse_button_event = event.button;
if (mouse_button_event.type == SDL_MOUSEBUTTONDOWN) {
if (mouse_button_event.button == SDL_BUTTON_LEFT) {
left_mouse_click(mousex, mousey);
}
if (mouse_button_event.button == SDL_BUTTON_RIGHT) {
right_mouse_click(mousex, mousey);
}
if (mouse_button_event.button == SDL_BUTTON_WHEELUP) {
scroll_up();
}
if (mouse_button_event.button == SDL_BUTTON_WHEELDOWN) {
scroll_down();
}
}
if (mouse_button_event.type == SDL_MOUSEBUTTONUP) {
if (mouse_button_event.button == SDL_BUTTON_LEFT) {
}
}
}
void terrain_palette::draw(bool force) {
if (top_button_.pressed()) {
scroll_up();
}
if (bot_button_.pressed()) {
scroll_down();
}
for(size_t i = 0; i < terrain_groups_.size(); ++i) {
if(terrain_groups_[i].button.pressed()) {
if(&terrain_groups_[i].button == checked_group_btn_) {
checked_group_btn_->set_check(true);
} else {
checked_group_btn_->set_check(false);
checked_group_btn_ = &terrain_groups_[i].button;
set_group(terrain_groups_[i].id);
}
break;
}
}
if (!dirty() && !force) {
return;
}
unsigned int starting = tstart_;
unsigned int ending = starting + nterrains_;
SDL_Surface* const screen = gui_.video().getSurface();
if(ending > num_terrains()){
ending = num_terrains();
}
const SDL_Rect &loc = location();
int y = terrain_start_;
for(unsigned int counter = starting; counter < ending; counter++){
const t_translation::t_terrain terrain = terrains_[counter];
const t_translation::t_terrain base_terrain = map_.get_terrain_info(terrain).default_base();
const int counter_from_zero = counter - starting;
SDL_Rect dstrect;
dstrect.x = loc.x + (counter_from_zero % size_specs_.terrain_width) * size_specs_.terrain_space;
dstrect.y = y;
dstrect.w = size_specs_.terrain_size;
dstrect.h = size_specs_.terrain_size;
//Draw default base for overlay terrains
if(base_terrain != t_translation::NONE_TERRAIN) {
const std::string base_filename = "terrain/" + map_.get_terrain_info(base_terrain).editor_image() + ".png";
surface base_image(image::get_image(base_filename));
if(base_image == NULL) {
std::cerr << "image for terrain " << counter << ": '" << base_filename << "' not found\n";
return;
}
if(static_cast<unsigned>(base_image->w) != size_specs_.terrain_size ||
static_cast<unsigned>(base_image->h) != size_specs_.terrain_size) {
base_image.assign(scale_surface(base_image,
size_specs_.terrain_size, size_specs_.terrain_size));
}
SDL_BlitSurface(base_image, NULL, screen, &dstrect);
}
const std::string filename = "terrain/" + map_.get_terrain_info(terrain).editor_image() + ".png";
surface image(image::get_image(filename));
if(image == NULL) {
std::cerr << "image for terrain " << counter << ": '" << filename << "' not found\n";
return;
}
if(static_cast<unsigned>(image->w) != size_specs_.terrain_size ||
static_cast<unsigned>(image->h) != size_specs_.terrain_size) {
image.assign(scale_surface(image,
size_specs_.terrain_size, size_specs_.terrain_size));
}
SDL_BlitSurface(image, NULL, screen, &dstrect);
SDL_Surface* const screen = gui_.video().getSurface();
Uint32 color;
if (terrain == selected_bg_terrain() && terrain == selected_fg_terrain()) {
color = SDL_MapRGB(screen->format,0xFF,0x00,0xFF);
}
else if (terrain == selected_bg_terrain()) {
color = SDL_MapRGB(screen->format,0x00,0x00,0xFF);
}
else if (terrain == selected_fg_terrain()) {
color = SDL_MapRGB(screen->format,0xFF,0x00,0x00);
}
else {
color = SDL_MapRGB(screen->format,0x00,0x00,0x00);
}
draw_rectangle(dstrect.x, dstrect.y, image->w, image->h, color, screen);
if (counter_from_zero % size_specs_.terrain_width == size_specs_.terrain_width - 1)
y += size_specs_.terrain_space;
}
update_rect(loc);
set_dirty(false);
}
int terrain_palette::tile_selected(const int x, const int y) const {
for(unsigned int i = 0; i != nterrains_; i++) {
const int px = size_specs_.palette_x + (i % size_specs_.terrain_width) * size_specs_.terrain_space;
const int py = terrain_start_ + (i / size_specs_.terrain_width) * size_specs_.terrain_space;
const int pw = size_specs_.terrain_space;
const int ph = size_specs_.terrain_space;
if(x > px && x < px + pw && y > py && y < py + ph) {
return i;
}
}
return -1;
}
void terrain_palette::update_report() {
const std::string msg = std::string(_("FG")) + ": "
+ get_terrain_string(selected_fg_terrain()) + "\n"
+ std::string(_("BG")) +
": " + get_terrain_string(selected_bg_terrain());
gui_.set_report_content(reports::SELECTED_TERRAIN, msg);
}
void terrain_palette::load_tooltips()
{
for(size_t i = 0; i < terrain_groups_.size(); ++i) {
const std::string& text = terrain_groups_[i].name;
if(text !="") {
const SDL_Rect tooltip_rect = terrain_groups_[i].button.location();
tooltips::add_tooltip(tooltip_rect, text);
}
}
}
// void terrain_palette::bg_backup() {
// restorer_ = surface_restorer(&gui_.video(), get_rect());
// }
// void terrain_palette::bg_restore() {
// restorer_.restore();
// }
brush_bar::brush_bar(display &gui, const size_specs &sizes)
: gui::widget(gui.video()), size_specs_(sizes), gui_(gui), selected_(0), total_brush_(3),
size_(30) {
adjust_size();
}
void brush_bar::adjust_size() {// TODO
set_location(size_specs_.brush_x, size_specs_.brush_y);
set_measurements(size_ * total_brush_ + (total_brush_ - 1) * size_specs_.brush_padding, size_);
set_dirty();
}
unsigned int brush_bar::selected_brush_size() {
return selected_ + 1;
}
void brush_bar::select_brush_size(int new_size) {
assert(new_size > 0 && new_size <= total_brush_);
selected_ = new_size - 1;
}
void brush_bar::left_mouse_click(const int mousex, const int mousey) {
int index = selected_index(mousex, mousey);
if(index >= 0) {
if (static_cast<unsigned>(index) != selected_) {
set_dirty();
selected_ = index;
}
}
}
void brush_bar::handle_event(const SDL_Event& event) {
if (event.type == SDL_MOUSEMOTION) {
// If the mouse is inside the palette, give it focus.
if (point_in_rect(event.button.x, event.button.y, location())) {
if (!focus(&event)) {
set_focus(true);
}
}
// If the mouse is outside, remove focus.
else {
if (focus(&event)) {
set_focus(false);
}
}
}
if (!focus(&event)) {
return;
}
int mousex, mousey;
SDL_GetMouseState(&mousex,&mousey);
const SDL_MouseButtonEvent mouse_button_event = event.button;
if (mouse_button_event.type == SDL_MOUSEBUTTONDOWN) {
if (mouse_button_event.button == SDL_BUTTON_LEFT) {
left_mouse_click(mousex, mousey);
}
}
}
void brush_bar::draw() {
draw(false);
}
void brush_bar::draw(bool force) {
if (!dirty() && !force) {
return;
}
const SDL_Rect loc = location();
int x = loc.x;
// Everything will be redrawn even though only one little part may
// have changed, but that happens so seldom so we'll settle with this.
SDL_Surface* const screen = gui_.video().getSurface();
for (int i = 1; i <= total_brush_; i++) {
std::stringstream filename;
filename << "editor/brush-" << i << ".png";
surface image(image::get_image(filename.str()));
if (image == NULL) {
std::cerr << "Image " << filename.str() << " not found." << std::endl;
continue;
}
if (static_cast<unsigned>(image->w) != size_ ||
static_cast<unsigned>(image->h) != size_) {
image.assign(scale_surface(image, size_, size_));
}
SDL_Rect dstrect;
dstrect.x = x;
dstrect.y = size_specs_.brush_y;
dstrect.w = image->w;
dstrect.h = image->h;
SDL_BlitSurface(image, NULL, screen, &dstrect);
const Uint32 color = static_cast<unsigned>(i) == selected_brush_size() ?
SDL_MapRGB(screen->format,0xFF,0x00,0x00) :
SDL_MapRGB(screen->format,0x00,0x00,0x00);
draw_rectangle(dstrect.x, dstrect.y, image->w, image->h, color, screen);
x += image->w + size_specs_.brush_padding;
}
update_rect(loc);
set_dirty(false);
}
int brush_bar::selected_index(const int x, const int y) const {
const int bar_x = size_specs_.brush_x;
const int bar_y = size_specs_.brush_y;
if ((x < bar_x || static_cast<unsigned>(x) > bar_x + size_ * total_brush_ +
total_brush_ * size_specs_.brush_padding) ||
(y < bar_y || static_cast<unsigned>(y) > bar_y + size_)) {
return -1;
}
for(int i = 0; i < total_brush_; i++) {
const int px = bar_x + size_ * i + i * size_specs_.brush_padding;
if(x >= px && static_cast<unsigned>(x) <= px + size_ &&
y >= bar_y && static_cast<unsigned>(y) <= bar_y + size_) {
return i;
}
}
return -1;
}
} // end namespace map_editor

View file

@ -1,189 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/editor_palettes.hpp
//!
#ifndef EDITOR_PALETTES_H_INCLUDED
#define EDITOR_PALETTES_H_INCLUDED
#include "global.hpp"
#include "SDL.h"
#include "../sdl_utils.hpp"
#include "../display.hpp"
#include "../map.hpp"
#include "../widgets/widget.hpp"
#include "editor_layout.hpp"
#include <vector>
class config;
namespace map_editor {
//! Stores the info about the data in editor-groups.cfg in a nice format.
// Helper struct which for some reason can't be moved to the cpp file.
struct terrain_group
{
terrain_group(const config& cfg, display& gui);
std::string id;
t_string name;
gui::button button;
};
//! Palette where the terrain to be drawn can be selected.
class terrain_palette : public gui::widget {
public:
terrain_palette(display &gui, const size_specs &sizes,
const gamemap &map, const config& cfg);
//! Scroll the terrain-palette up one step if possible.
void scroll_up();
//! Scroll the terrain-palette down one step if possible.
void scroll_down();
//! Scroll the terrain-palette to the top.
void scroll_top();
//! Scroll the terrain-palette to the bottom.
void scroll_bottom();
//! Sets a group active id == terrain_map_->first
//! The selected terrains remain the same,
//! this can result in no visible selected items.
void set_group(const std::string& id);
//! Return the currently selected foreground terrain.
t_translation::t_terrain selected_fg_terrain() const;
//! Return the currently selected background terrain.
t_translation::t_terrain selected_bg_terrain() const;
//! Select a foreground terrain.
void select_fg_terrain(t_translation::t_terrain);
void select_bg_terrain(t_translation::t_terrain);
//! Update the selected terrains strings
void update_selected_terrains(void);
//! Draw the palette.
//! If force is true everything will be redrawn,
//! even though it is not invalidated.
void draw(bool force=false);
virtual void draw();
virtual void handle_event(const SDL_Event& event);
void set_dirty(bool dirty=true);
//! Return the number of terrains in the palette.
size_t num_terrains() const;
//! Update the size of this widget.
//! Use if the size_specs have changed.
void adjust_size();
//! Sets the tooltips used in the palette
void load_tooltips();
private:
void draw_old(bool);
//! To be called when a mouse click occurs.
//! Check if the coordinates is a terrain that may be chosen,
//! and select the terrain if that is the case.
void left_mouse_click(const int mousex, const int mousey);
void right_mouse_click(const int mousex, const int mousey);
//! Return the number of the tile that is at coordinates (x, y) in the panel.
int tile_selected(const int x, const int y) const;
//! Return a string represeting the terrain and the underlying ones.
std::string get_terrain_string(const t_translation::t_terrain);
//! Update the report with the currently selected terrains.
void update_report();
const size_specs &size_specs_;
display &gui_;
unsigned int tstart_;
//! This map contains all editor_group as defined in terrain.cfg
//! and associate with the group there.
//! The group 'all' is added automatically, and all terrains
//! are also automatically stored in this group.
std::map<std::string, t_translation::t_list> terrain_map_;
//! A copy from the terrain_map_->second for the current active group.
t_translation::t_list terrains_;
//! The editor_groups as defined in editor-groups.cfg
//! Note the user must make sure the id's here are the same
//! as the editor_group in terrain.cfg
std::vector<terrain_group> terrain_groups_;
//! The group buttons behave like a radio group.
//! This one points to the selected button, this value should not be 0
//! otherwise things will fail. Thus should be set in constructor.
gui::button *checked_group_btn_;
t_translation::t_terrain selected_fg_terrain_, selected_bg_terrain_;
const gamemap &map_;
gui::button top_button_, bot_button_;
size_t button_x_, top_button_y_, bot_button_y_;
size_t nterrains_, terrain_start_;
};
//! A bar where the brush is drawn
class brush_bar : public gui::widget {
public:
brush_bar(display &gui, const size_specs &sizes);
//! Return the size of currently selected brush.
unsigned int selected_brush_size();
//! Select a brush size.
void select_brush_size(int new_size);
//! Draw the palette. If force is true, everything
//! will be redrawn, even though it is not dirty.
void draw(bool force=false);
virtual void draw();
virtual void handle_event(const SDL_Event& event);
//! Update the size of this widget.
//! Use if the size_specs have changed.
void adjust_size();
private:
//! To be called when a mouse click occurs.
//! Check if the coordinates is a terrain that may be chosen,
//! and select the terrain if that is the case.
void left_mouse_click(const int mousex, const int mousey);
//! Return the index of the brush that is at coordinates (x, y) in the panel.
int selected_index(const int x, const int y) const;
const size_specs &size_specs_;
display &gui_;
unsigned int selected_;
const int total_brush_;
const size_t size_;
};
}
#endif // EDITOR_PALETTES_H_INCLUDED

View file

@ -1,165 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/editor_undo.cpp
//!
#include "editor_undo.hpp"
namespace {
const unsigned int undo_limit = 100;
map_editor::map_undo_list undo_stack;
map_editor::map_undo_list redo_stack;
}
namespace map_editor {
map_undo_action::map_undo_action() {
terrain_set_ = false;
selection_set_ = false;
map_data_set_ = false;
starting_locations_set_ = false;
}
const std::map<gamemap::location, t_translation::t_terrain>& map_undo_action::undo_terrains() const
{
return old_terrain_;
}
const std::map<gamemap::location, t_translation::t_terrain>& map_undo_action::redo_terrains() const
{
return new_terrain_;
}
const std::set<gamemap::location> map_undo_action::undo_selection() const {
return old_selection_;
}
const std::set<gamemap::location> map_undo_action::redo_selection() const {
return new_selection_;
}
std::string map_undo_action::old_map_data() const {
return old_map_data_;
}
std::string map_undo_action::new_map_data() const {
return new_map_data_;
}
const std::map<gamemap::location, int>& map_undo_action::undo_starting_locations() const {
return old_starting_locations_;
}
const std::map<gamemap::location, int>& map_undo_action::redo_starting_locations() const {
return new_starting_locations_;
}
void map_undo_action::add_terrain(const t_translation::t_terrain& old_tr,
const t_translation::t_terrain& new_tr,
const gamemap::location& lc)
{
old_terrain_[lc] = old_tr;
new_terrain_[lc] = new_tr;
terrain_set_ = true;
}
bool map_undo_action::terrain_set() const {
return terrain_set_;
}
void map_undo_action::set_selection(const std::set<gamemap::location> &old_selection,
const std::set<gamemap::location> &new_selection) {
old_selection_ = old_selection;
new_selection_ = new_selection;
selection_set_ = true;
}
bool map_undo_action::selection_set() const {
return selection_set_;
}
void map_undo_action::set_map_data(const std::string &old_data,
const std::string &new_data) {
old_map_data_ = old_data;
new_map_data_ = new_data;
map_data_set_ = true;
}
bool map_undo_action::map_data_set() const {
return map_data_set_;
}
void map_undo_action::add_starting_location(const int old_side, const int new_side,
const gamemap::location &old_loc,
const gamemap::location &new_loc) {
old_starting_locations_[old_loc] = old_side;
new_starting_locations_[new_loc] = new_side;
starting_locations_set_ = true;
}
bool map_undo_action::starting_location_set() const {
return starting_locations_set_;
}
bool map_undo_action::something_set() const {
return terrain_set_ || selection_set_ || map_data_set_ || starting_locations_set_;
}
void add_undo_action(const map_undo_action &action) {
undo_stack.push_back(action);
if (undo_stack.size() > undo_limit) {
undo_stack.pop_front();
}
// Adding an undo action means that an operations was performed,
// which in turns means that no further redo may be performed.
redo_stack.clear();
}
bool exist_undo_actions() {
return !undo_stack.empty();
}
bool exist_redo_actions() {
return !redo_stack.empty();
}
map_undo_action pop_undo_action() {
map_undo_action action = undo_stack.back();
undo_stack.pop_back();
redo_stack.push_back(action);
if (redo_stack.size() > undo_limit) {
redo_stack.pop_front();
}
return action;
}
map_undo_action pop_redo_action() {
map_undo_action action = redo_stack.back();
redo_stack.pop_back();
undo_stack.push_back(action);
if (undo_stack.size() > undo_limit) {
undo_stack.pop_front();
}
return action;
}
void clear_undo_actions() {
undo_stack.clear();
redo_stack.clear();
}
}

View file

@ -1,128 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
// This module is used to manage actions that may be undone in the map
// editor.
//! @file editor/editor_undo.hpp
//!
#ifndef EDITOR_UNDO_H_INCLUDED
#define EDITOR_UNDO_H_INCLUDED
#include "global.hpp"
#include "map.hpp"
#include <queue>
#include <vector>
#include <set>
namespace map_editor {
//! A saved action that may be undone.
class map_undo_action {
public:
map_undo_action();
const std::map<gamemap::location, t_translation::t_terrain>& undo_terrains() const;
const std::map<gamemap::location, t_translation::t_terrain>& redo_terrains() const;
const std::set<gamemap::location> undo_selection() const;
const std::set<gamemap::location> redo_selection() const;
std::string new_map_data() const;
std::string old_map_data() const;
const std::map<gamemap::location, int>& undo_starting_locations() const;
const std::map<gamemap::location, int>& redo_starting_locations() const;
void add_terrain(const t_translation::t_terrain& old_tr,
const t_translation::t_terrain& new_tr,
const gamemap::location& lc);
//! Return true if a terrain change has been saved in this undo
//! action.
bool terrain_set() const;
void set_selection(const std::set<gamemap::location> &old_selection,
const std::set<gamemap::location> &new_selection);
//! Return true if a selection change has been saved in this undo
//! action.
bool selection_set() const;
void set_map_data(const std::string &old_data,
const std::string &new_data);
//! Return true if a map data change has been saved in this undo
//! action.
bool map_data_set() const;
void add_starting_location(const int old_side, const int new_side,
const gamemap::location &old_loc,
const gamemap::location &new_loc);
//! Return true if starting locations have been saved in this undo
//! action.
bool starting_location_set() const;
//! Return true if something have been saved in this undo
bool something_set() const;
private:
std::map<gamemap::location, t_translation::t_terrain> old_terrain_;
std::map<gamemap::location, t_translation::t_terrain> new_terrain_;
bool terrain_set_;
std::set<gamemap::location> old_selection_;
std::set<gamemap::location> new_selection_;
bool selection_set_;
std::string old_map_data_;
std::string new_map_data_;
bool map_data_set_;
std::map<gamemap::location,int> old_starting_locations_;
std::map<gamemap::location,int> new_starting_locations_;
bool starting_locations_set_;
};
typedef std::deque<map_undo_action> map_undo_list;
//! Add an undo action to the undo stack. Resize the stack if it gets
//! larger than the maximum size. Add an operation to the number done
//! since save. If keep_selection is true, it indicates that the
//! selection has not changed and the currently selected terrain should
//! be kept if this action is redone/undone. Also clear the redo stack.
void add_undo_action(const map_undo_action &action);
//! Return true if there exist any undo actions in the undo stack.
bool exist_undo_actions();
//! Return true if there exist any redo actions in the redo stack.
bool exist_redo_actions();
//! Remove, store in the redo stack and return the last undo action
//! stored.
map_undo_action pop_undo_action();
//! Remove, store in the undo stack and return the last redo action
//! stored.
map_undo_action pop_redo_action();
//! Clear all stored information about performed actions.
void clear_undo_actions();
}
#endif // EDITOR_UNDO_H_INCLUDED

View file

@ -1,423 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/map_manip.cpp
//! Operations on a game-map.
#include "map_manip.hpp"
#include "../gettext.hpp"
#include "../map.hpp"
#include "../config.hpp"
#include "../construct_dialog.hpp"
#include "../util.hpp"
#include "../wml_exception.hpp"
#include "serialization/string_utils.hpp"
#include <algorithm>
#include <cassert>
#include <map>
#include <set>
#include <sstream>
#include <vector>
std::string editormap::resize(const size_t width, const size_t height,
const int x_offset, const int y_offset,
const bool do_expand, t_translation::t_terrain filler)
{
const unsigned old_w = static_cast<unsigned>(w());
const unsigned old_h = static_cast<unsigned>(h());
// no changes leave
if(old_w == width && old_h == height && x_offset == 0 && y_offset == 0 ) {
return "";
}
if(do_expand) {
filler = t_translation::NONE_TERRAIN;
}
// Determine the amount of resizing is required
const int left_resize = -x_offset;
const int right_resize = (width - old_w) + x_offset;
const int top_resize = -y_offset;
const int bottom_resize = (height - old_h) + y_offset;
// std::cerr << "resize y " << left_resize << " x " << right_resize
// << " top " << top_resize << " bottom " << bottom_resize << '\n';
if(right_resize > 0) {
add_tiles_right(right_resize, filler);
} else if(right_resize < 0) {
remove_tiles_right(-right_resize);
}
if(bottom_resize > 0) {
add_tiles_bottom(bottom_resize, filler);
} else if(bottom_resize < 0) {
remove_tiles_bottom(-bottom_resize);
}
if(left_resize > 0) {
add_tiles_left(left_resize, filler);
} else if(left_resize < 0) {
remove_tiles_left(-left_resize);
}
if(top_resize > 0) {
add_tiles_top(top_resize, filler);
} else if(top_resize < 0) {
remove_tiles_top(-top_resize);
}
// fix the starting positions
if(x_offset || y_offset) {
for(size_t i = 0; i < MAX_PLAYERS+1; ++i) {
if(startingPositions_[i] != gamemap::location()) {
startingPositions_[i].x -= x_offset;
startingPositions_[i].y -= y_offset;
}
}
}
return write();
}
std::string editormap::flip(const map_editor::FLIP_AXIS axis)
{
if(axis != map_editor::FLIP_X && axis != map_editor::FLIP_Y) {
return "";
}
if(axis == map_editor::FLIP_X) {
// Due to the hexes we need some mirror tricks when mirroring over the
// X axis. We resize the map and fill it. The odd columns will be extended
// with the data in row 0 the even columns are extended with the data in
// the last row
const size_t middle = (tiles_[0].size() / 2); // the middle if reached we flipped all
const size_t end = tiles_[0].size() - 1; // the last row _before_ resizing
for(size_t x = 0; x < tiles_.size(); ++x) {
if(x % 2) {
// odd lines
tiles_[x].resize(tiles_[x].size() + 1, tiles_[x][0]);
for(size_t y1 = 0, y2 = end; y1 < middle; ++y1, --y2) {
swap_starting_position(x, y1, x, y2);
std::swap(tiles_[x][y1], tiles_[x][y2]);
}
} else {
// even lines
tiles_[x].resize(tiles_[x].size() + 1, tiles_[x][end]);
for(size_t y1 = 0, y2 = end + 1; y1 < middle; ++y1, --y2) {
swap_starting_position(x, y1, x, y2);
std::swap(tiles_[x][y1], tiles_[x][y2]);
}
}
}
} else { // FLIP_Y
// Flipping on the Y axis requires no resize,
// so the code is much simpler.
const size_t middle = (tiles_.size() / 2);
const size_t end = tiles_.size() - 1;
for(size_t y = 0; y < tiles_[0].size(); ++y) {
for(size_t x1 = 0, x2 = end; x1 < middle; ++x1, --x2) {
swap_starting_position(x1, y, x2, y);
std::swap(tiles_[x1][y], tiles_[x2][y]);
}
}
}
return write();
}
void editormap::set_starting_position(const int pos, const location loc) {
startingPositions_[pos] = loc;
}
void editormap::swap_starting_position(const size_t x1, const size_t y1,
const size_t x2, const size_t y2)
{
const int pos1 = is_starting_position(location(x1, y1));
const int pos2 = is_starting_position(location(x2, y2));
if(pos1 != -1) {
set_starting_position(pos1 + 1, location(x2, y2));
}
if(pos2 != -1) {
set_starting_position(pos2 + 1, location(x1, y1));
}
}
void editormap::add_tiles_right(
const unsigned count, const t_translation::t_terrain& filler)
{
for(size_t x = 1; x <= count; ++x) {
t_translation::t_list one_row(tiles_[1].size());
for(size_t y = 0; y < tiles_[1].size(); ++y) {
one_row[y] =
filler != t_translation::NONE_TERRAIN ?
filler :
tiles_[x - 1][y];
assert(one_row[y] != t_translation::NONE_TERRAIN);
}
tiles_.push_back(one_row);
}
}
void editormap::add_tiles_left(
const unsigned count, const t_translation::t_terrain& filler)
{
for(size_t i = 1; i <= count; ++i) {
t_translation::t_list one_row(tiles_[1].size());
for(size_t y = 0; y < tiles_[1].size(); ++y) {
one_row[y] =
filler != t_translation::NONE_TERRAIN ?
filler :
tiles_[0][y];
assert(one_row[y] != t_translation::NONE_TERRAIN);
}
tiles_.insert(tiles_.begin(), 1, one_row);
clear_border_cache();
}
}
void editormap::remove_tiles_right(const unsigned count)
{
if(count > tiles_.size()) {
std::stringstream sstr;
sstr << _("Can't resize the map, the requested size is bigger "
"than the maximum, size=") << count << _(" maximum=")
<< tiles_.size();
throw incorrect_format_exception(sstr.str().c_str());
}
tiles_.resize(tiles_.size() - count);
}
void editormap::remove_tiles_left(const unsigned count)
{
if(count > tiles_.size()) {
std::stringstream sstr;
sstr << _("Can't resize the map, the requested size is bigger "
"than the maximum, size=") << count << _(" maximum=")
<< tiles_.size();
throw incorrect_format_exception(sstr.str().c_str());
}
tiles_.erase(tiles_.begin(), tiles_.begin() + count);
}
void editormap::add_tiles_top(
const unsigned count, const t_translation::t_terrain& filler)
{
for(size_t i = 1; i <= count; ++i) {
for(size_t y = 0; y < tiles_.size(); ++y) {
t_translation::t_terrain terrain =
filler != t_translation::NONE_TERRAIN ?
filler :
tiles_[y][0];
assert(terrain != t_translation::NONE_TERRAIN);
tiles_[y].insert(tiles_[y].begin(), 1, terrain);
clear_border_cache();
}
}
}
void editormap::add_tiles_bottom(
const unsigned count, const t_translation::t_terrain& filler)
{
for(size_t i = 1; i <= count; ++i) {
for(size_t x = 0; x < tiles_.size(); ++x) {
t_translation::t_terrain terrain =
filler != t_translation::NONE_TERRAIN ?
filler :
tiles_[x][i - 1];
assert(terrain != t_translation::NONE_TERRAIN);
tiles_[x].push_back(terrain);
}
}
}
void editormap::remove_tiles_top(const unsigned count)
{
if(count > tiles_[0].size()) {
std::stringstream sstr;
sstr << _("Can't resize the map, the requested size is bigger "
"than the maximum, size=") << count << _(" maximum=")
<< tiles_[0].size();
throw incorrect_format_exception(sstr.str().c_str());
}
for(size_t x = 0; x < tiles_.size(); ++x) {
tiles_[x].erase(tiles_[x].begin(), tiles_[x].begin() + count);
}
}
void editormap::remove_tiles_bottom(const unsigned count)
{
if(count > tiles_[0].size()) {
std::stringstream sstr;
sstr << _("Can't resize the map, the requested size is bigger "
"than the maximum, size=") << count << _(" maximum=")
<< tiles_[0].size();
throw incorrect_format_exception(sstr.str().c_str());
}
for(size_t x = 0; x < tiles_.size(); ++x) {
tiles_[x].erase(tiles_[x].end() - count, tiles_[x].end());
}
}
namespace map_editor {
std::vector<gamemap::location> get_tiles(const gamemap &map,
const gamemap::location& a,
const unsigned int radius) {
const unsigned int distance = radius - 1;
std::vector<gamemap::location> res;
res.push_back(a);
for (unsigned int d = 1; d <= distance; d++) {
gamemap::location loc = a;
unsigned int i;
// Get the starting point.
for (i = 1; i <= d; i++) {
loc = loc.get_direction(gamemap::location::NORTH, 1);
}
// Get all the tiles clockwise with distance d.
const gamemap::location::DIRECTION direction[6] =
{gamemap::location::SOUTH_EAST, gamemap::location::SOUTH, gamemap::location::SOUTH_WEST,
gamemap::location::NORTH_WEST, gamemap::location::NORTH, gamemap::location::NORTH_EAST};
for (i = 0; i < 6; i++) {
for (unsigned int j = 1; j <= d; j++) {
loc = loc.get_direction(direction[i], 1);
if (map.on_board_with_border(loc)) {
res.push_back(loc);
}
}
}
}
return res;
}
void flood_fill(gamemap &map, const gamemap::location &start_loc,
const t_translation::t_terrain fill_with, terrain_log *log)
{
t_translation::t_terrain terrain_to_fill = map.get_terrain(start_loc);
if (fill_with == terrain_to_fill) {
return;
}
std::set<gamemap::location> to_fill = get_component(map, start_loc);
std::set<gamemap::location>::iterator it;
for (it = to_fill.begin(); it != to_fill.end(); it++) {
gamemap::location loc = *it;
if (log != NULL) {
log->push_back(std::make_pair(loc, terrain_to_fill));
}
if (fill_with.base == t_translation::NO_LAYER) {
map.set_terrain(loc, fill_with, gamemap::OVERLAY);
}
else {
map.set_terrain(loc, fill_with);
}
}
}
std::set<gamemap::location> get_component(const gamemap &map,
const gamemap::location &start_loc)
{
t_translation::t_terrain terrain_to_fill = map.get_terrain(start_loc);
std::set<gamemap::location> to_fill;
std::set<gamemap::location> filled;
std::set<gamemap::location>::iterator it;
// Insert the start location in a set.
// Chose an element in the set, mark this element,
// and add all adjacent elements that are not marked.
// Continue until the set is empty.
to_fill.insert(start_loc);
while (!to_fill.empty()) {
it = to_fill.begin();
gamemap::location loc = *it;
to_fill.erase(it);
filled.insert(loc);
// Find all adjacent tiles with the terrain that should
// be filled and add these to the to_fill vector.
std::vector<gamemap::location> adj = get_tiles(map, loc, 2);
for (std::vector<gamemap::location>::iterator it2 = adj.begin();
it2 != adj.end(); it2++) {
if (map.on_board_with_border(*it2) && map.get_terrain(*it2) == terrain_to_fill
&& filled.find(*it2) == filled.end()) {
to_fill.insert(*it2);
}
}
}
return filled;
}
std::string resize_map(editormap &map, const unsigned new_w,
const unsigned new_h, const int off_x, const int off_y,
const bool do_expand, const t_translation::t_terrain fill_with)
{
return map.resize(new_w, new_h, off_x, off_y, do_expand, fill_with);
}
std::string flip_map(editormap &map, const FLIP_AXIS axis) {
return map.flip(axis);
}
bool valid_mapdata(const std::string &data, const config &cfg) {
bool res = data.size() != 0;
// Create a map and see if we get an exception. Not very efficient,
// but simple as things are implemented now.
try {
const gamemap m(cfg, data);
// Having a zero size map may cause floating point exceptions
// at some places later on.
res = m.w() != 0 && m.h() != 0;
}
catch (gamemap::incorrect_format_exception) {
res = false;
} catch(twml_exception& e) {
std::cerr << "WML exception:\nUser message: "
<< e.user_message << "\nDev message: " << e.dev_message << '\n';
return false;
}
return res;
}
std::string new_map(const size_t width, const size_t height, const t_translation::t_terrain filler)
{
const t_translation::t_list column(height, filler);
const t_translation::t_map map(width, column);
return gamemap::default_map_header + t_translation::write_game_map(map);
}
} // end namespace map_editor

View file

@ -1,211 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
//! @file editor/map_manip.hpp
//!
#ifndef MAP_MANIP_H_INCLUDED
#define MAP_MANIP_H_INCLUDED
#include "global.hpp"
#include "../map.hpp"
#include <vector>
#include <set>
namespace map_editor {
enum FLIP_AXIS {NO_FLIP, FLIP_X, FLIP_Y};
}
// This object modifies the internal structure of a map,
// most of the time this is done on the real map data.
// This means that the display and mapdata are heavily out of sync.
// Our callers throw a new_map_exception which will invalide the entire
// map object. These callers expect a string with the new raw map data.
// So it's "save" but really not clean. -- Mordante
class editormap : public gamemap
{
public:
editormap(const config& terrain_cfg, const std::string& data) :
gamemap(terrain_cfg, data)
{}
~editormap(){}
/**
* Resizes the map.
*
* @param width the new width
* @param height the new height
* @param x_offset the offset in x direction (the x coordinate specified will be the new 0 location)
* @param y_offset the offset in y direction (the y coordinate specified will be the new 0 location)
* @param do_expand try to expand the map depending on the current tiles
* @param filler if the map is enlarged the new tiles are set to this terrain,
* unless expand is set
*
* @return if there's been a modification to the map: the new map data as string,
* else an empty string
*/
std::string resize(const size_t width, const size_t height,
const int x_offset, const int y_offset,
const bool do_expand, t_translation::t_terrain filler);
/**
* Flips the map over an axis
*
* @param axis the axis to flip the map over
*
* @return if there's been a modification to the map the new map data as string
* else an empty string
*/
std::string flip(const map_editor::FLIP_AXIS axis);
/**
* Sets the starting position of a player
*
* @param pos the starting position, 1 = player 1
* @param loc a location (same as gamemap location)
*/
void set_starting_position(const int pos, const location loc);
private:
/**
* Exchanges starting positions,
* If there's a starting location on x1, y1 it will be moved to x2, y2.
* If x2, y2 contains a starting location this is moved to x1, y1.
* The function also works if both locations contain
* a starting position.
*/
void swap_starting_position(
const size_t x1, const size_t y1,
const size_t x2, const size_t y2);
/**
* Adds column(s) at the right side.
*
* @param count the number of columns to add
* @param filler the terrain to draw, if equal to NONE_TERRAIN
* the enigne will determine the terrain by itself
*/
void add_tiles_right(const unsigned count,
const t_translation::t_terrain& filler);
/**
* Adds column(s) at the left side
*
* @param count the number of columns to add
* @param filler the terrain to draw, if equal to NONE_TERRAIN
* the enigne will determine the terrain by itself
*/
void add_tiles_left(const unsigned count,
const t_translation::t_terrain& filler);
/**
* Removes column(s) at the right side.
*
* @param count the number of columns to remove
*/
void remove_tiles_right(const unsigned count);
/**
* Removes column(s) at the left side.
*
* @param count the number of columns to remove
*/
void remove_tiles_left(const unsigned count);
/**
* Adds row(s) at the top side.
*
* @param count the number of rows to add
* @param filler the terrain to draw, if equal to NONE_TERRAIN
* the enigne will determine the terrain by itself
*/
void add_tiles_top(const unsigned count,
const t_translation::t_terrain& filler);
/**
* Adds row(s) at the bottom side.
*
* @param count the number of rows to add
* @param filler the terrain to draw, if equal to NONE_TERRAIN
* the enigne will determine the terrain by itself
*/
void add_tiles_bottom(const unsigned count,
const t_translation::t_terrain& filler);
/**
* Removes row(s) at the top side.
*
* @param count the number of rows to remove
*/
void remove_tiles_top(const unsigned count);
/**
* Removes row(s) at the bottom side.
*
* @param count the number of rows to remove
*/
void remove_tiles_bottom(const unsigned count);
};
namespace map_editor {
//! Return the tiles that are within radius from the location.
std::vector<gamemap::location> get_tiles(const gamemap &map,
const gamemap::location& a,
const unsigned int radius);
typedef std::vector<std::pair<gamemap::location, t_translation::t_terrain> > terrain_log;
/// Flood fill the map with the terrain fill_with
/// starting from the location start_loc.
/// If log is non-null it will contain the positions of the changed tiles
/// and the terrains they had before the filling started.
void flood_fill(gamemap &map, const gamemap::location &start_loc,
const t_translation::t_terrain fill_with, terrain_log *log = NULL);
/// Return the area that would be flood filled
/// if a flood fill was requested.
std::set<gamemap::location>
get_component(const gamemap &map, const gamemap::location &start_loc);
/// Return the string representation of the map after it has been
/// resized to new_w X new_h. If the new dimensions are smaller than the
/// current ones, the map will be cropped from the bottom and from the
/// right. If the map becomes larger than the current dimensions, the
/// new map area appeard at the bottom and/or the right and is filled
/// with the terrain fill_with.
std::string resize_map(editormap &map, const unsigned new_w,
const unsigned new_h, const int off_x, const int off_y,
const bool do_expand, const t_translation::t_terrain fill_with);
/// Return the string representation of the map
/// after it has been flipped around the axis.
std::string flip_map(editormap &map, const FLIP_AXIS axis);
//! Return true if the data is valid to create a map with,
//! othwerwise false.
bool valid_mapdata(const std::string &data, const config &cfg);
//! Returns a string representating a new empty map
//! of width by height of the terrain filler
std::string new_map(const size_t width, const size_t height, const t_translation::t_terrain filler);
} // end namespace map_editor
#endif // MAP_MANIP_H_INCLUDED

View file

@ -108,28 +108,6 @@ const struct {
N_("Team 1"), false, hotkey::SCOPE_GAME },
{ hotkey::HOTKEY_REPLAY_SKIP_ANIMATION, "replayskipanimation", N_("Skip animation"), false, hotkey::SCOPE_GAME },
{ hotkey::HOTKEY_EDIT_SET_TERRAIN, "editsetterrain", N_("Set Terrain"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_QUIT, "editquit", N_("Quit Editor"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_NEW_MAP, "editnewmap", N_("New Map"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_LOAD_MAP, "editloadmap", N_("Load Map"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_SAVE_MAP, "editsavemap", N_("Save Map"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_SAVE_AS, "editsaveas", N_("Save As"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_SET_START_POS, "editsetstartpos", N_("Set Player's keep"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_FLOOD_FILL, "editfloodfill", N_("Flood Fill"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_FILL_SELECTION, "editfillselection", N_("Fill Selection"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_ROTATE_SELECTION, "editrotateselection", N_("Rotate Selection"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_CUT, "editcut", N_("Cut"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_COPY, "editcopy", N_("Copy"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_PASTE, "editpaste", N_("Paste"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_REVERT, "editrevert", N_("Revert from Disk"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_RESIZE, "editresize", N_("Resize Map"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_FLIP, "editflip", N_("Flip Map"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_SELECT_ALL, "editselectall", N_("Select All"),true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_DRAW, "editdraw", N_("Draw Terrain"), true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_REFRESH, "editrefresh", N_("Refresh Image Cache"), true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_AUTO_UPDATE, "editautoupdate", N_("Delay transition updates"), true, hotkey::SCOPE_GENERAL },
{ hotkey::HOTKEY_EDIT_UPDATE, "editupdate", N_("Update transitions"), true, hotkey::SCOPE_GENERAL },
#ifndef DISABLE_EDITOR2
{ hotkey::HOTKEY_EDITOR_QUIT_TO_DESKTOP, "editor-quit-to-desktop", N_("Quit to Desktop"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_SETTINGS, "editor-settings", N_("Editor Settings"), false, hotkey::SCOPE_EDITOR },
@ -847,70 +825,6 @@ bool command_executor::execute_command(HOTKEY_COMMAND command, int /*index*/)
break;
#endif
case HOTKEY_EDIT_SET_TERRAIN:
edit_set_terrain();
break;
case HOTKEY_EDIT_QUIT:
edit_quit();
break;
case HOTKEY_EDIT_NEW_MAP:
edit_new_map();
break;
case HOTKEY_EDIT_LOAD_MAP:
edit_load_map();
break;
case HOTKEY_EDIT_SAVE_MAP:
edit_save_map();
break;
case HOTKEY_EDIT_SAVE_AS:
edit_save_as();
break;
case HOTKEY_EDIT_SET_START_POS:
edit_set_start_pos();
break;
case HOTKEY_EDIT_FLOOD_FILL:
edit_flood_fill();
break;
case HOTKEY_EDIT_FILL_SELECTION:
edit_fill_selection();
break;
case HOTKEY_EDIT_ROTATE_SELECTION:
edit_rotate_selection();
break;
case HOTKEY_EDIT_CUT:
edit_cut();
break;
case HOTKEY_EDIT_PASTE:
edit_paste();
break;
case HOTKEY_EDIT_COPY:
edit_copy();
break;
case HOTKEY_EDIT_REVERT:
edit_revert();
break;
case HOTKEY_EDIT_RESIZE:
edit_resize();
break;
case HOTKEY_EDIT_FLIP:
edit_flip();
break;
case HOTKEY_EDIT_SELECT_ALL:
edit_select_all();
break;
case HOTKEY_EDIT_DRAW:
edit_draw();
break;
case HOTKEY_EDIT_REFRESH:
edit_refresh();
break;
case HOTKEY_EDIT_UPDATE:
edit_update();
break;
case HOTKEY_EDIT_AUTO_UPDATE:
edit_auto_update();
break;
case HOTKEY_LANGUAGE:
change_language();
break;

View file

@ -59,16 +59,6 @@ enum HOTKEY_COMMAND {
HOTKEY_REPLAY_NEXT_SIDE, HOTKEY_REPLAY_SHOW_EVERYTHING,
HOTKEY_REPLAY_SHOW_EACH, HOTKEY_REPLAY_SHOW_TEAM1,
HOTKEY_REPLAY_SKIP_ANIMATION,
//editing specific commands
HOTKEY_EDIT_SET_TERRAIN,
HOTKEY_EDIT_QUIT, HOTKEY_EDIT_SAVE_MAP,
HOTKEY_EDIT_SAVE_AS, HOTKEY_EDIT_SET_START_POS,
HOTKEY_EDIT_NEW_MAP, HOTKEY_EDIT_LOAD_MAP, HOTKEY_EDIT_FLOOD_FILL,
HOTKEY_EDIT_FILL_SELECTION, HOTKEY_EDIT_ROTATE_SELECTION, HOTKEY_EDIT_CUT, HOTKEY_EDIT_COPY,
HOTKEY_EDIT_PASTE, HOTKEY_EDIT_REVERT, HOTKEY_EDIT_RESIZE,
HOTKEY_EDIT_FLIP, HOTKEY_EDIT_SELECT_ALL, HOTKEY_EDIT_DRAW,
HOTKEY_EDIT_REFRESH, HOTKEY_EDIT_UPDATE, HOTKEY_EDIT_AUTO_UPDATE,
#ifndef DISABLE_EDITOR2
HOTKEY_EDITOR_QUIT_TO_DESKTOP,
@ -301,29 +291,6 @@ public:
virtual void replay_show_team1() {}
virtual void replay_skip_animation() {}
// Map editor stuff.
virtual void edit_set_terrain() {}
virtual void edit_quit() {}
virtual void edit_new_map() {}
virtual void edit_load_map() {}
virtual void edit_save_map() {}
virtual void edit_save_as() {}
virtual void edit_set_start_pos() {}
virtual void edit_flood_fill() {}
virtual void edit_fill_selection() {}
virtual void edit_rotate_selection() {}
virtual void edit_cut() {}
virtual void edit_copy() {}
virtual void edit_paste() {}
virtual void edit_revert() {}
virtual void edit_resize() {}
virtual void edit_flip() {}
virtual void edit_select_all() {}
virtual void edit_draw() {}
virtual void edit_refresh() {}
virtual void edit_update() {}
virtual void edit_auto_update() {}
//Gets the action's image (if any). Displayed left of the action text in menus.
virtual std::string get_action_image(hotkey::HOTKEY_COMMAND /*command*/, int /*index*/) const { return ""; }
//Does the action control a toggle switch? If so, return the state of the action (on or off)