Skip to content

Commit

Permalink
feat: zones
Browse files Browse the repository at this point in the history
  • Loading branch information
luan committed Oct 19, 2023
1 parent 47d8f4f commit 34fcdbc
Show file tree
Hide file tree
Showing 44 changed files with 1,283 additions and 328 deletions.
14 changes: 7 additions & 7 deletions data/creatures/monsters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<monster name="Abyssador" looktype="495" />
<monster name="Abyssal Calamary" looktype="451" />
<monster name="Achad" looktype="146" lookhead="93" lookbody="93" looklegs="57" lookfeet="97" lookaddons="3" />
<monster name="Acid Blob" looktype="314" />
<monster name="Acid Blob" looktype="315" />
<monster name="Acolyte Of Darkness" looktype="9" />
<monster name="Acolyte Of The Cult" looktype="194" lookhead="114" lookbody="121" looklegs="121" lookfeet="57" lookaddons="0" />
<monster name="Adept Of The Cult" looktype="194" lookhead="114" lookbody="94" looklegs="94" lookfeet="57" lookaddons="0" />
Expand Down Expand Up @@ -228,7 +228,7 @@
<monster name="Cult Believer" looktype="132" lookhead="98" lookbody="77" looklegs="39" lookfeet="57" lookaddons="1" />
<monster name="Cult Enforcer" looktype="134" lookhead="114" lookbody="19" looklegs="76" lookfeet="76" lookaddons="1" />
<monster name="Cult Scholar" looktype="145" />
<monster name="Cursed Ape" looktype="1592" />
<monster name="Cursed Ape" looktype="1506" />
<monster name="Cursed Book" looktype="1061" lookhead="79" lookbody="83" looklegs="113" lookfeet="0" lookaddons="0" />
<monster name="Cursed Gladiator" looktype="100" />
<monster name="Cursed Prospector" looktype="1268" />
Expand Down Expand Up @@ -616,11 +616,10 @@
<monster name="Ice Witch" looktype="149" />
<monster name="Icecold Book" looktype="1061" lookhead="87" lookbody="85" looklegs="79" lookfeet="0" lookaddons="0" />
<monster name="Icicle" looktype="904" />
<monster name="Iks Ahpututu" looktype="1590" />
<monster name="Iks Aucar" looktype="1587" />
<monster name="Iks Chuka" looktype="1588" />
<monster name="Iks Churrascan" looktype="1587" />
<monster name="Iks Pututu" looktype="1589" />
<monster name="Iks Ahpututu" looktype="1509" />
<monster name="Iks Aucar" looktype="1507" />
<monster name="Iks Chuka" looktype="1508" />
<monster name="Iks Pututu" looktype="1508" />
<monster name="Imp Intruder" looktype="237" />
<monster name="Incineron" looktype="243" />
<monster name="Incredibly Old Witch" looktype="54" />
Expand Down Expand Up @@ -1408,4 +1407,5 @@
<monster name="Zugurosh" looktype="12" lookhead="2" lookbody="35" looklegs="57" lookfeet="91" lookaddons="0" />
<monster name="Zulazza The Corruptor" looktype="334" />
<monster name="Zushuka" looktype="149" lookhead="86" lookbody="12" looklegs="31" lookfeet="60" lookaddons="0" />
<monster name="Elf Overseer" looktype="159" lookhead="57" lookbody="95" looklegs="114" lookfeet="116" lookaddons="0" />
</monsters>
2 changes: 2 additions & 0 deletions data/menubar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<item name="Replace Items on Selection" action="REPLACE_ON_SELECTION_ITEMS" help="Replace items on selected area."/>
<item name="Find Item on Selection" action="SEARCH_ON_SELECTION_ITEM" help="Find items on selected area."/>
<item name="Remove Item on Selection" action="REMOVE_ON_SELECTION_ITEM" help="Remove item on selected area."/>
<item name="Remove Monsters on Selection" action="REMOVE_ON_SELECTION_MONSTER" help="Remove monsters on selected area."/>
<separator/>
<menu name="$Find on Selection">
<item name="Find $Everything" action="SEARCH_ON_SELECTION_EVERYTHING" help="Find all unique/action/text/container items."/>
Expand Down Expand Up @@ -157,6 +158,7 @@
<item name="$Creature Palette" hotkey="C" action="SELECT_MONSTER" help="Select the Creature palette."/>
<item name="$Npc Palette" hotkey="N" action="SELECT_NPC" help="Select the Npc palette."/>
<item name="$Waypoint Palette" hotkey="W" action="SELECT_WAYPOINT" help="Select the Waypoint palette."/>
<item name="$Zones Palette" hotkey="Z" action="SELECT_ZONES" help="Select the Zones palette."/>
<item name="$RAW Palette" hotkey="R" action="SELECT_RAW" help="Select the RAW palette."/>
</menu>
<!--
Expand Down
8 changes: 5 additions & 3 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(remeres)

find_package(asio CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(GLUT REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(OpenGL REQUIRED)
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -171,6 +171,7 @@ target_sources(${PROJECT_NAME}
palette_house.cpp
palette_npc.cpp
palette_waypoints.cpp
palette_zones.cpp
palette_window.cpp
pngfiles.cpp
preferences.cpp
Expand Down Expand Up @@ -199,20 +200,21 @@ target_sources(${PROJECT_NAME}
waypoint_brush.cpp
waypoints.cpp
welcome_dialog.cpp
zone_brush.cpp
zones.cpp
)

target_include_directories(${PROJECT_NAME}
PRIVATE
${CMAKE_SOURCE_DIR}/source
${OPENGL_INCLUDE_DIR}
${GLUT_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIR}
)

target_link_libraries(${PROJECT_NAME}
PRIVATE
${OPENGL_LIBRARIES}
${GLUT_LIBRARIES}
glfw
${ZLIB_LIBRARIES}
fmt::fmt
asio::asio
Expand Down
2 changes: 2 additions & 0 deletions source/brush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "table_brush.h"
#include "wall_brush.h"
#include "waypoint_brush.h"
#include "zone_brush.h"

#include "settings.h"

Expand Down Expand Up @@ -87,6 +88,7 @@ void Brushes::init() {
addBrush(g_gui.rook_brush = newd FlagBrush(TILESTATE_NOPVP));
addBrush(g_gui.nolog_brush = newd FlagBrush(TILESTATE_NOLOGOUT));
addBrush(g_gui.pvp_brush = newd FlagBrush(TILESTATE_PVPZONE));
addBrush(g_gui.zone_brush = newd ZoneBrush());

GroundBrush::init();
WallBrush::init();
Expand Down
7 changes: 7 additions & 0 deletions source/brush.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class HouseExitBrush;
class WaypointBrush;
class FlagBrush;
class EraserBrush;
class ZoneBrush;

//=============================================================================
// Brushes, holds all brushes
Expand Down Expand Up @@ -188,6 +189,9 @@ class Brush {
virtual bool isWaypoint() const {
return false;
}
virtual bool isZone() const {
return false;
}
virtual bool isFlag() const {
return false;
}
Expand Down Expand Up @@ -252,6 +256,9 @@ class Brush {
virtual EraserBrush* asEraser() {
return nullptr;
}
virtual ZoneBrush* asZone() {
return nullptr;
}

bool visibleInPalette() const {
return visible;
Expand Down
30 changes: 15 additions & 15 deletions source/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ bool posFromClipboard(int &x, int &y, int &z) {
std::vector<int> values;
wxTextDataObject data;
wxTheClipboard->GetData(data);
wxString text = data.GetText();
auto text = data.GetText().ToStdString();

if (text.size() < 50) {
bool r = false;
Expand Down Expand Up @@ -254,26 +254,26 @@ bool posToClipboard(int x, int y, int z, int format) {
return true;
}

bool posToClipboard(int fromx, int fromy, int fromz, int tox, int toy, int toz) {
bool posToClipboard(int fromx, int fromy, int fromz, int tox, int toy, int toz, int format) {
if (!wxTheClipboard->Open()) {
return false;
}

std::ostringstream clip;
clip << "{";
clip << "fromx = " << fromx << ", ";
clip << "tox = " << tox << ", ";
clip << "fromy = " << fromy << ", ";
clip << "toy = " << toy << ", ";
if (fromz != toz) {
clip << "fromz = " << fromz << ", ";
clip << "toz = " << toz;
} else {
clip << "z = " << fromz;
wxTextDataObject* data = new wxTextDataObject();

switch (format) {
case 0:
data->SetText(wxString::Format("{fromx = %d, tox = %d, fromy = %d, toy = %d, fromz = %d, toz = %d}", fromx, tox, fromy, toy, fromz, toz));
break;
case 1:
data->SetText(wxString::Format("{ x = %d, y = %d, z = %d }, { x = %d, y = %d, z = %d }", fromx, fromy, fromz, tox, toy, toz));
break;
case 2:
data->SetText(wxString::Format("Position(%d, %d, %d), Position(%d, %d, %d)", fromx, fromy, fromz, tox, toy, toz));
break;
}
clip << "}";

wxTheClipboard->SetData(new wxTextDataObject(clip.str()));
wxTheClipboard->SetData(data);
wxTheClipboard->Close();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ std::string wstring2string(const std::wstring &widestring);
// Gets position values from ClipBoard
bool posFromClipboard(int &x, int &y, int &z);
bool posToClipboard(int x, int y, int z, int format);
bool posToClipboard(int fromx, int fromy, int fromz, int tox, int toy, int toz);
bool posToClipboard(int fromx, int fromy, int fromz, int tox, int toy, int toz, int format);

// Returns 'yes' if the defined value is true or 'no' if it is false.
wxString b2yn(bool v);
Expand Down
8 changes: 6 additions & 2 deletions source/common_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ MapPropertiesWindow::MapPropertiesWindow(wxWindow* parent, MapTab* view, Editor
house_filename_ctrl = newd wxTextCtrl(this, wxID_ANY, wxstr(map.getHouseFilename())), 1, wxEXPAND
);

grid_sizer->Add(
zone_filename_ctrl = newd wxTextCtrl(this, wxID_ANY, wxstr(map.getZoneFilename())), 1, wxEXPAND
);

grid_sizer->Add(
newd wxStaticText(this, wxID_ANY, "External monster file")
);
Expand Down Expand Up @@ -341,6 +345,7 @@ void MapPropertiesWindow::OnClickOK(wxCommandEvent &WXUNUSED(event)) {
map.setHouseFilename(nstr(house_filename_ctrl->GetValue()));
map.setSpawnMonsterFilename(nstr(spawn_filename_ctrl->GetValue()));
map.setSpawnNpcFilename(nstr(spawn_npc_filename_ctrl->GetValue()));
map.setZoneFilename(nstr(zone_filename_ctrl->GetValue()));

// Only resize if we have to
int new_map_width = width_spin->GetValue();
Expand Down Expand Up @@ -1028,12 +1033,11 @@ wxCoord FindDialogListBox::OnMeasureItem(size_t n) const {
// wxListBox that can be sorted

SortableListBox::SortableListBox(wxWindow* parent, wxWindowID id, const wxPoint &pos, const wxSize &size) :
wxListBox(parent, id, pos, size, 0, nullptr, wxLB_SINGLE | wxLB_NEEDED_SB) { }
wxCheckListBox(parent, id, pos, size, 0, nullptr, wxLB_SINGLE | wxLB_NEEDED_SB) { }

SortableListBox::~SortableListBox() { }

void SortableListBox::Sort() {

if (GetCount() == 0) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion source/common_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class MapPropertiesWindow : public wxDialog {
wxTextCtrl* house_filename_ctrl;
wxTextCtrl* spawn_filename_ctrl;
wxTextCtrl* spawn_npc_filename_ctrl;
wxTextCtrl* zone_filename_ctrl;

DECLARE_EVENT_TABLE();
};
Expand Down Expand Up @@ -177,7 +178,7 @@ class FindDialogListBox : public wxVListBox {
* A wxListBox that can be sorted without using style wxLB_SORT.
* wxLB_SORT does not work properly on Windows and causes errors on macOS.
*/
class SortableListBox : public wxListBox {
class SortableListBox : public wxCheckListBox {
public:
SortableListBox(wxWindow* parent, wxWindowID id, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize);
~SortableListBox();
Expand Down
24 changes: 23 additions & 1 deletion source/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Editor::Editor(CopyBuffer &copybuffer) :
map.spawnmonsterfile = sname + "-monster.xml";
map.spawnnpcfile = sname + "-npc.xml";
map.housefile = sname + "-house.xml";
map.zonefile = sname + "-zones.xml";
map.description = "No map description available.";
map.unnamed = true;

Expand Down Expand Up @@ -278,6 +279,8 @@ void Editor::saveMap(FileName filename, bool showdialog) {
map.spawnnpcfile = nstr(_name.GetFullName());
_name.SetName(filename.GetName() + "-house");
map.housefile = nstr(_name.GetFullName());
_name.SetName(filename.GetName() + "-zones");
map.zonefile = nstr(_name.GetFullName());

map.unnamed = false;
}
Expand All @@ -289,7 +292,7 @@ void Editor::saveMap(FileName filename, bool showdialog) {

// Make temporary backups
// converter.Assign(wxstr(savefile));
std::string backup_otbm, backup_house, backup_spawn, backup_spawn_npc;
std::string backup_otbm, backup_house, backup_spawn, backup_spawn_npc, backup_zones;

if (converter.GetExt() == "otgz") {
save_otgz = true;
Expand Down Expand Up @@ -325,6 +328,13 @@ void Editor::saveMap(FileName filename, bool showdialog) {
std::remove(backup_spawn_npc.c_str());
std::rename((map_path + map.spawnnpcfile).c_str(), backup_spawn_npc.c_str());
}

converter.SetFullName(wxstr(map.zonefile));
if (converter.FileExists()) {
backup_zones = map_path + nstr(converter.GetName()) + ".xml~";
std::remove(backup_zones.c_str());
std::rename((map_path + map.zonefile).c_str(), backup_zones.c_str());
}
}

// Save the map
Expand Down Expand Up @@ -383,6 +393,12 @@ void Editor::saveMap(FileName filename, bool showdialog) {
std::rename(backup_spawn_npc.c_str(), std::string(spawnnpc_filename + ".xml").c_str());
}

if (!backup_zones.empty()) {
converter.SetFullName(wxstr(map.zonefile));
std::string zones_filename = map_path + nstr(converter.GetName());
std::rename(backup_zones.c_str(), std::string(zones_filename + ".xml").c_str());
}

// Display the error
g_gui.PopupDialog("Error", "Could not save, unable to open target for writing.", wxOK);
}
Expand Down Expand Up @@ -442,6 +458,12 @@ void Editor::saveMap(FileName filename, bool showdialog) {
std::string spawnnpc_filename = map_path + nstr(converter.GetName());
std::rename(backup_spawn_npc.c_str(), std::string(spawnnpc_filename + "." + date.str() + ".xml").c_str());
}

if (!backup_zones.empty()) {
converter.SetFullName(wxstr(map.zonefile));
std::string zones_filename = map_path + nstr(converter.GetName());
std::rename(backup_zones.c_str(), std::string(zones_filename + "." + date.str() + ".xml").c_str());
}
} else {
// Delete the temporary files
std::remove(backup_otbm.c_str());
Expand Down
2 changes: 2 additions & 0 deletions source/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "map_tab.h"
#include "palette_window.h"
#include "client_version.h"
#include "zone_brush.h"

class BaseMap;
class Map;
Expand Down Expand Up @@ -443,6 +444,7 @@ class GUI {
FlagBrush* rook_brush;
FlagBrush* nolog_brush;
FlagBrush* pvp_brush;
ZoneBrush* zone_brush;

protected:
//=========================================================================
Expand Down
7 changes: 7 additions & 0 deletions source/gui_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ enum EditorActionID {
PALETTE_WAYPOINT_ADD_WAYPOINT,
PALETTE_WAYPOINT_REMOVE_WAYPOINT,

PALETTE_ZONES_LISTBOX,
PALETTE_ZONES_ADD_ZONE,
PALETTE_ZONES_REMOVE_ZONE,

PALETTE_DOODAD_USE_THICKNESS,
PALETTE_DOODAD_SLIDER,
PALETTE_BRUSHSHAPE_SQUARE,
Expand All @@ -122,13 +126,16 @@ enum EditorActionID {
PALETTE_TERRAIN_NOPVP_TOOL,
PALETTE_TERRAIN_NOLOGOUT_TOOL,
PALETTE_TERRAIN_PVPZONE_TOOL,
PALETTE_TERRAIN_ZONE_TOOL,

PALETTE_MONSTER_TILESET_CHOICE,
PALETTE_MONSTER_LISTBOX,
PALETTE_MONSTER_SEARCH,
PALETTE_MONSTER_BRUSH_BUTTON,
PALETTE_SPAWN_MONSTER_BRUSH_BUTTON,
PALETTE_MONSTER_SPAWN_TIME,
PALETTE_MONSTER_SPAWN_SIZE,
PALETTE_MONSTER_SPAWN_DENSITY,

PALETTE_NPC_TILESET_CHOICE,
PALETTE_NPC_LISTBOX,
Expand Down
Loading

0 comments on commit 34fcdbc

Please sign in to comment.