mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 13:17:00 -04:00
Implement unique IDs and card linking
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <gui/control/card_editor.hpp>
|
||||
#include <gui/value/editor.hpp>
|
||||
#include <gui/set/cards_panel.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <data/field.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
@@ -360,6 +361,16 @@ void DataEditor::onMotion(wxMouseEvent& ev) {
|
||||
}
|
||||
}
|
||||
|
||||
void DataEditor::onMouseEnter(wxMouseEvent& ev) {
|
||||
ev.Skip();
|
||||
if (GetId() == ID_CARD_LINK_EDITOR) {
|
||||
CardsPanel* panel = dynamic_cast<CardsPanel*> (GetParent());
|
||||
if (panel) {
|
||||
panel->refreshCard(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DataEditor::onMouseLeave(wxMouseEvent& ev) {
|
||||
// on mouse leave for editor
|
||||
if (hovered_viewer) {
|
||||
@@ -462,6 +473,13 @@ void DataEditor::onChar(wxKeyEvent& ev) {
|
||||
} else {
|
||||
ev.Skip();
|
||||
}
|
||||
|
||||
if (GetId() == ID_CARD_LINK_EDITOR) {
|
||||
CardsPanel* panel = dynamic_cast<CardsPanel*> (GetParent());
|
||||
if (panel) {
|
||||
panel->refreshCard(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Menu events
|
||||
@@ -503,6 +521,10 @@ void DataEditor::onFocus(wxFocusEvent& ev) {
|
||||
selectFirst();
|
||||
}
|
||||
}
|
||||
CardsPanel* panel = dynamic_cast<CardsPanel*> (GetParent());
|
||||
if (panel) {
|
||||
panel->setFocusedEditor(this);
|
||||
}
|
||||
}
|
||||
void DataEditor::onLoseFocus(wxFocusEvent& ev) {
|
||||
if (current_editor) {
|
||||
@@ -520,6 +542,7 @@ BEGIN_EVENT_TABLE(DataEditor, CardViewer)
|
||||
EVT_RIGHT_DOWN (DataEditor::onRightDown)
|
||||
EVT_MOTION (DataEditor::onMotion)
|
||||
EVT_MOUSEWHEEL (DataEditor::onMouseWheel)
|
||||
EVT_ENTER_WINDOW (DataEditor::onMouseEnter)
|
||||
EVT_LEAVE_WINDOW (DataEditor::onMouseLeave)
|
||||
EVT_CONTEXT_MENU (DataEditor::onContextMenu)
|
||||
EVT_MENU (wxID_ANY, DataEditor::onMenu)
|
||||
|
||||
@@ -111,6 +111,7 @@ private:
|
||||
void onRightDown (wxMouseEvent&);
|
||||
void onMotion (wxMouseEvent&);
|
||||
void onMouseWheel(wxMouseEvent&);
|
||||
void onMouseEnter(wxMouseEvent&);
|
||||
void onMouseLeave(wxMouseEvent&);
|
||||
void onLoseCapture(wxMouseCaptureLostEvent&);
|
||||
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
#include <gui/control/card_list.hpp>
|
||||
#include <gui/control/card_list_column_select.hpp>
|
||||
#include <gui/set/window.hpp> // for sorting all cardlists in a window
|
||||
#include <gui/util.hpp>
|
||||
#include <gui/add_csv_window.hpp>
|
||||
#include <gui/card_link_window.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <gui/add_csv_window.hpp>
|
||||
#include <gui/add_json_window.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/field.hpp>
|
||||
@@ -25,6 +26,7 @@
|
||||
#include <data/action/value.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <wx/clipbrd.h>
|
||||
#include <unordered_set>
|
||||
|
||||
DECLARE_POINTER_TYPE(ChoiceValue);
|
||||
|
||||
@@ -157,6 +159,31 @@ bool CardListBase::doCopy() {
|
||||
wxTheClipboard->Close();
|
||||
return ok;
|
||||
}
|
||||
bool CardListBase::doCopyCardAndLinkedCards() {
|
||||
if (!canCopy()) return false;
|
||||
vector<CardP> cards_selected;
|
||||
getSelection(cards_selected);
|
||||
if (cards_selected.size() < 1) return false;
|
||||
if (!wxTheClipboard->Open()) return false;
|
||||
vector<CardP> cards_to_copy;
|
||||
unordered_set<CardP> cards_already_added;
|
||||
FOR_EACH(card, cards_selected) {
|
||||
if (cards_already_added.find(card) == cards_already_added.end()) {
|
||||
cards_to_copy.push_back(card);
|
||||
cards_already_added.insert(card);
|
||||
}
|
||||
vector<pair<CardP, String>> linked_cards = card->getLinkedCards(*set);
|
||||
FOR_EACH(linked_card, linked_cards) {
|
||||
if (cards_already_added.find(linked_card.first) == cards_already_added.end()) {
|
||||
cards_to_copy.push_back(linked_card.first);
|
||||
cards_already_added.insert(linked_card.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
bool ok = wxTheClipboard->SetData(new CardsOnClipboard(set, cards_to_copy)); // ignore result
|
||||
wxTheClipboard->Close();
|
||||
return ok;
|
||||
}
|
||||
bool CardListBase::doPaste() {
|
||||
// get data
|
||||
if (!canPaste()) return false;
|
||||
@@ -182,7 +209,26 @@ bool CardListBase::doDelete() {
|
||||
set->actions.addAction(make_unique<AddCardAction>(REMOVE, *set, cards_to_delete));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------- : CardListBase : Card linking
|
||||
|
||||
bool CardListBase::canLink() const {
|
||||
vector<CardP> selected_cards;
|
||||
getSelection(selected_cards);
|
||||
return selected_cards.size() == 1;
|
||||
}
|
||||
bool CardListBase::doLink() {
|
||||
CardLinkWindow wnd(this, set, getCard());
|
||||
if (wnd.ShowModal() == wxID_OK) {
|
||||
// The actual linking is done in this window's onOk function
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool CardListBase::doUnlink(CardP unlinked_card) {
|
||||
set->actions.addAction(make_unique<UnlinkCardsAction>(*set, getCard(), unlinked_card));
|
||||
return true;
|
||||
}
|
||||
bool CardListBase::doAddCSV() {
|
||||
AddCSVWindow wnd(this, set, true);
|
||||
if (wnd.ShowModal() == wxID_OK) {
|
||||
@@ -190,8 +236,8 @@ bool CardListBase::doAddCSV() {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool CardListBase::doAddJSON() {
|
||||
AddJSONWindow wnd(this, set, true);
|
||||
if (wnd.ShowModal() == wxID_OK) {
|
||||
@@ -199,7 +245,7 @@ bool CardListBase::doAddJSON() {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardListBase : Building the list
|
||||
|
||||
@@ -412,10 +458,12 @@ void CardListBase::onContextMenu(wxContextMenuEvent&) {
|
||||
wxMenu m;
|
||||
add_menu_item_tr(&m, wxID_CUT, "cut", "cut_card");
|
||||
add_menu_item_tr(&m, wxID_COPY, "copy", "copy_card");
|
||||
add_menu_item_tr(&m, ID_CARD_AND_LINK_COPY, "card_copy", "copy card and links");
|
||||
add_menu_item_tr(&m, wxID_PASTE, "paste", "paste_card");
|
||||
m.AppendSeparator();
|
||||
add_menu_item_tr(&m, ID_CARD_ADD, "card_add", "add card");
|
||||
add_menu_item_tr(&m, ID_CARD_REMOVE, "card_del", "remove card");
|
||||
add_menu_item_tr(&m, ID_CARD_LINK, "card_link", "link card");
|
||||
PopupMenu(&m);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,9 +64,9 @@ public:
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
|
||||
inline CardP getCard() const { return static_pointer_cast<Card>(selected_item); }
|
||||
inline void setCard(const CardP& card) { selectItem(card, true, false); }
|
||||
|
||||
inline CardP getCard() const { return static_pointer_cast<Card>(selected_item); }
|
||||
inline void setCard(const CardP& card, bool event = false) { selectItem(card, true, event); }
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
|
||||
bool canCut() const override;
|
||||
@@ -75,11 +75,18 @@ public:
|
||||
bool canDelete() const override;
|
||||
// Try to perform a clipboard operation, return success
|
||||
bool doCopy() override;
|
||||
bool doCopyCardAndLinkedCards();
|
||||
bool doPaste() override;
|
||||
bool doDelete() override;
|
||||
bool doAddCSV();
|
||||
bool doAddJSON();
|
||||
bool doAddJSON();
|
||||
|
||||
// --------------------------------------------------- : Card linking
|
||||
|
||||
bool canLink() const;
|
||||
bool doLink();
|
||||
bool doUnlink(CardP unlinked_card);
|
||||
|
||||
// --------------------------------------------------- : Set actions
|
||||
|
||||
void onBeforeChangeSet() override;
|
||||
@@ -107,7 +114,7 @@ protected:
|
||||
|
||||
/// Send an 'item selected' event for the currently selected item (selected_item)
|
||||
void sendEvent() override { sendEvent(EVENT_CARD_SELECT); }
|
||||
void sendEvent(int type = EVENT_CARD_SELECT);
|
||||
void sendEvent(int type);
|
||||
/// Compare cards
|
||||
bool compareItems(void* a, void* b) const override;
|
||||
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <gui/control/card_viewer.hpp>
|
||||
#include <gui/control/image_card_list.hpp>
|
||||
#include <gui/set/cards_panel.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/settings.hpp>
|
||||
#include <render/value/viewer.hpp>
|
||||
#include <wx/dcbuffer.h>
|
||||
#include <util/window_id.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
@@ -31,7 +34,11 @@ wxSize CardViewer::DoGetBestSize() const {
|
||||
if (set) {
|
||||
if (!stylesheet) stylesheet = set->stylesheet;
|
||||
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
|
||||
wxSize size(int(stylesheet->card_width * (150.0 / stylesheet->card_dpi) * ss.card_zoom()), int(stylesheet->card_height * (150.0 / stylesheet->card_dpi) * ss.card_zoom()));
|
||||
double dpi_factor = stylesheet->card_dpi <= 150.0 ? 1.0 : 150.0 / stylesheet->card_dpi;
|
||||
double width = stylesheet->card_width * dpi_factor * ss.card_zoom();
|
||||
double height = stylesheet->card_height * dpi_factor * ss.card_zoom();
|
||||
double link_factor = GetId() == ID_CARD_LINK_VIEWER ? (height * 0.5 - 41.0) / height : GetId() == ID_CARD_LINK_EDITOR ? (height * 0.97 - 41.0) / height : 1.0; // Subtract 41 pixels for the link title
|
||||
wxSize size(int(link_factor * width), int(link_factor * height));
|
||||
if (is_sideways(deg_to_rad(ss.card_angle()))) swap(size.x, size.y);
|
||||
return size + ws - cs;
|
||||
}
|
||||
@@ -104,6 +111,16 @@ void CardViewer::onPaint(wxPaintEvent&) {
|
||||
}
|
||||
}
|
||||
|
||||
void CardViewer::onClick(wxMouseEvent& ev) {
|
||||
ev.Skip(); // allow DataEditor::onLeftDown to process this event as well
|
||||
if (GetId() == ID_CARD_LINK_VIEWER) {
|
||||
CardsPanel* panel = dynamic_cast<CardsPanel*> (GetParent());
|
||||
if (panel) {
|
||||
panel->setCard(getCard(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CardViewer::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||
if (shouldDraw(v)) v.draw(dc);
|
||||
}
|
||||
@@ -150,11 +167,15 @@ Rotation CardViewer::getRotation() const {
|
||||
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
|
||||
int dx = CanScroll(wxHORIZONTAL) ? GetScrollPos(wxHORIZONTAL) : 0;
|
||||
int dy = CanScroll(wxVERTICAL) ? GetScrollPos(wxVERTICAL) : 0;
|
||||
return Rotation(deg_to_rad(ss.card_angle()), stylesheet->getCardRect().move(-dx,-dy,0,0), (150.0 / stylesheet->card_dpi) * ss.card_zoom(), 1.0, ROTATION_ATTACH_TOP_LEFT);
|
||||
double dpi_factor = stylesheet->card_dpi <= 150.0 ? 1.0 : 150.0 / stylesheet->card_dpi;
|
||||
double height = stylesheet->card_height * dpi_factor * ss.card_zoom();
|
||||
double link_factor = GetId() == ID_CARD_LINK_VIEWER ? (height * 0.5 - 41.0) / height : GetId() == ID_CARD_LINK_EDITOR ? (height * 0.97 - 41.0) / height : 1.0; // Subtract 41 pixels for the link title
|
||||
return Rotation(deg_to_rad(ss.card_angle()), stylesheet->getCardRect().move(-dx,-dy,0,0), link_factor * dpi_factor * ss.card_zoom(), 1.0, ROTATION_ATTACH_TOP_LEFT);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Event table
|
||||
|
||||
BEGIN_EVENT_TABLE(CardViewer, wxControl)
|
||||
EVT_PAINT(CardViewer::onPaint)
|
||||
EVT_LEFT_DOWN(CardViewer::onClick)
|
||||
END_EVENT_TABLE ()
|
||||
|
||||
@@ -53,9 +53,11 @@ protected:
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
|
||||
void onPaint(wxPaintEvent&);
|
||||
|
||||
|
||||
void onClick(wxMouseEvent&);
|
||||
|
||||
Bitmap buffer; ///< Off-screen buffer we draw to
|
||||
bool up_to_date; ///< Is the buffer up to date?
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ void ItemList::selectItem(const VoidP& item, bool focus, bool event) {
|
||||
focusNone();
|
||||
}
|
||||
selected_item = item;
|
||||
if (event) sendEvent();
|
||||
if (event) sendEvent(); // sending an event will trigger a UI update
|
||||
findSelectedItemPos();
|
||||
if (focus) focusSelectedItem();
|
||||
}
|
||||
@@ -111,6 +111,14 @@ void ItemList::findSelectedItemPos() {
|
||||
}
|
||||
}
|
||||
}
|
||||
long ItemList::findGivenItemPos(const VoidP& item) {
|
||||
long count = GetItemCount();
|
||||
for (long pos = 0; pos < count; ++pos) {
|
||||
if (getItem(pos) == item) {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
void ItemList::focusSelectedItem(bool force_focus) {
|
||||
if (GetItemCount() > 0) {
|
||||
if (selected_item_pos == -1 || (size_t)selected_item_pos > sorted_list.size()) {
|
||||
|
||||
@@ -42,7 +42,9 @@ public:
|
||||
void selectFirst();
|
||||
/// Select all items
|
||||
void doSelectAll();
|
||||
|
||||
/// Find the position for a given item
|
||||
long findGivenItemPos(const VoidP& item);
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
|
||||
virtual bool canCut() const { return canCopy() && canDelete(); }
|
||||
|
||||
Reference in New Issue
Block a user