Skip to content

Commit

Permalink
Add 'Copy Item Server Id', 'Copy Item Client Id' and 'Copy Item Name'…
Browse files Browse the repository at this point in the history
… menus. Closes #251
  • Loading branch information
Mignari committed Oct 14, 2018
1 parent e805d3d commit c79c232
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 9 deletions.
3 changes: 3 additions & 0 deletions source/gui_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ enum
MAP_POPUP_MENU_PASTE,
MAP_POPUP_MENU_DELETE,

MAP_POPUP_MENU_COPY_SERVER_ID,
MAP_POPUP_MENU_COPY_CLIENT_ID,
MAP_POPUP_MENU_COPY_NAME,
MAP_POPUP_MENU_BROWSE_TILE,

MAP_POPUP_MENU_SWITCH_DOOR,
Expand Down
86 changes: 77 additions & 9 deletions source/map_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ BEGIN_EVENT_TABLE(MapCanvas, wxGLCanvas)
EVT_MENU(MAP_POPUP_MENU_PASTE, MapCanvas::OnPaste)
EVT_MENU(MAP_POPUP_MENU_DELETE, MapCanvas::OnDelete)
//----
EVT_MENU(MAP_POPUP_MENU_BROWSE_TILE, MapCanvas::OnBrowseTile)
EVT_MENU(MAP_POPUP_MENU_COPY_SERVER_ID, MapCanvas::OnCopyServerId)
EVT_MENU(MAP_POPUP_MENU_COPY_CLIENT_ID, MapCanvas::OnCopyClientId)
EVT_MENU(MAP_POPUP_MENU_COPY_NAME, MapCanvas::OnCopyName)
// ----
EVT_MENU(MAP_POPUP_MENU_ROTATE, MapCanvas::OnRotateItem)
EVT_MENU(MAP_POPUP_MENU_GOTO, MapCanvas::OnGotoDestination)
Expand All @@ -82,6 +84,8 @@ BEGIN_EVENT_TABLE(MapCanvas, wxGLCanvas)
EVT_MENU(MAP_POPUP_MENU_SELECT_HOUSE_BRUSH, MapCanvas::OnSelectHouseBrush)
// ----
EVT_MENU(MAP_POPUP_MENU_PROPERTIES, MapCanvas::OnProperties)
// ----
EVT_MENU(MAP_POPUP_MENU_BROWSE_TILE, MapCanvas::OnBrowseTile)
END_EVENT_TABLE()

bool MapCanvas::processed[] = {0};
Expand Down Expand Up @@ -1836,6 +1840,63 @@ void MapCanvas::OnCopyPosition(wxCommandEvent& WXUNUSED(event))
}
}

void MapCanvas::OnCopyServerId(wxCommandEvent& WXUNUSED(event))
{
ASSERT(editor.selection.size() == 1)

if(wxTheClipboard->Open()) {
Tile* tile = editor.selection.getSelectedTile();
ItemVector selected_items = tile->getSelectedItems();
ASSERT(selected_items.size() == 1)

const Item* item = selected_items.front();

wxTextDataObject* obj = new wxTextDataObject();
obj->SetText(i2ws(item->getID()));
wxTheClipboard->SetData(obj);

wxTheClipboard->Close();
}
}

void MapCanvas::OnCopyClientId(wxCommandEvent& WXUNUSED(event))
{
ASSERT(editor.selection.size() == 1)

if(wxTheClipboard->Open()) {
Tile* tile = editor.selection.getSelectedTile();
ItemVector selected_items = tile->getSelectedItems();
ASSERT(selected_items.size() == 1)

const Item* item = selected_items.front();

wxTextDataObject* obj = new wxTextDataObject();
obj->SetText(i2ws(item->getClientID()));
wxTheClipboard->SetData(obj);

wxTheClipboard->Close();
}
}

void MapCanvas::OnCopyName(wxCommandEvent& WXUNUSED(event))
{
ASSERT(editor.selection.size() == 1)

if(wxTheClipboard->Open()) {
Tile* tile = editor.selection.getSelectedTile();
ItemVector selected_items = tile->getSelectedItems();
ASSERT(selected_items.size() == 1)

const Item* item = selected_items.front();

wxTextDataObject* obj = new wxTextDataObject();
obj->SetText(wxstr(item->getName()));
wxTheClipboard->SetData(obj);

wxTheClipboard->Close();
}
}

void MapCanvas::OnBrowseTile(wxCommandEvent& WXUNUSED(event))
{
if(editor.selection.size() != 1)
Expand Down Expand Up @@ -2184,23 +2245,16 @@ void MapPopupMenu::Update()
wxMenuItem* deleteItem = Append( MAP_POPUP_MENU_DELETE, "&Delete\tDEL", "Removes all seleceted items");
deleteItem->Enable(anything_selected);

AppendSeparator();

wxMenuItem* browseTile = Append(MAP_POPUP_MENU_BROWSE_TILE, "Browse Field", "Navigate from tile items");
browseTile->Enable(anything_selected);

if(anything_selected) {
if(editor.selection.size() == 1) {
Tile* tile = editor.selection.getSelectedTile();

AppendSeparator();
ItemVector selected_items = tile->getSelectedItems();

bool hasWall = false;
bool hasCarpet = false;
bool hasTable = false;
Item* topItem = nullptr;
Item* topSelectedItem = (selected_items.size() == 1? selected_items.back() : nullptr);
Item* topSelectedItem = (selected_items.size() == 1 ? selected_items.back() : nullptr);
Creature* topCreature = tile->creature;
Spawn* topSpawn = tile->spawn;

Expand All @@ -2226,6 +2280,15 @@ void MapPopupMenu::Update()
topItem = tile->ground;
}

AppendSeparator();

if(topSelectedItem) {
Append(MAP_POPUP_MENU_COPY_SERVER_ID, "Copy Item Server Id", "Copy the server id of this item");
Append(MAP_POPUP_MENU_COPY_CLIENT_ID, "Copy Item Client Id", "Copy the client id of this item");
Append(MAP_POPUP_MENU_COPY_NAME, "Copy Item Name", "Copy the name of this item");
AppendSeparator();
}

if(topSelectedItem || topCreature || topItem) {
Teleport* teleport = dynamic_cast<Teleport*>(topSelectedItem);
if(topSelectedItem && (topSelectedItem->isBrushDoor() || topSelectedItem->isRoteable() || teleport)) {
Expand Down Expand Up @@ -2300,6 +2363,11 @@ void MapPopupMenu::Update()
Append( MAP_POPUP_MENU_PROPERTIES, "&Properties", "Properties for the current object");
}
}

AppendSeparator();

wxMenuItem* browseTile = Append(MAP_POPUP_MENU_BROWSE_TILE, "Browse Field", "Navigate from tile items");
browseTile->Enable(anything_selected);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions source/map_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class MapCanvas : public wxGLCanvas {
void OnCut(wxCommandEvent& event);
void OnCopy(wxCommandEvent& event);
void OnCopyPosition(wxCommandEvent& event);
void OnCopyServerId(wxCommandEvent& event);
void OnCopyClientId(wxCommandEvent& event);
void OnCopyName(wxCommandEvent& event);
void OnBrowseTile(wxCommandEvent& event);
void OnPaste(wxCommandEvent& event);
void OnDelete(wxCommandEvent& event);
Expand Down

0 comments on commit c79c232

Please sign in to comment.