* GUI: added card popup info in choose dialog (example: choose dungeon, #8012);

* GUI: added texts popup info in choose dialog (example: choose from any list);
This commit is contained in:
Oleg Agafonov 2021-08-14 09:18:50 +04:00
parent b73f10a0ab
commit d587cc9151
12 changed files with 322 additions and 36 deletions

View file

@ -0,0 +1,134 @@
package mage.client.cards;
import mage.abilities.icon.CardIconRenderSettings;
import mage.cards.MageCard;
import mage.cards.action.TransferData;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.client.dialog.PreferencesDialog;
import mage.client.plugins.adapters.MageActionCallback;
import mage.client.plugins.impl.Plugins;
import mage.client.util.ClientDefaultSettings;
import mage.view.CardView;
import java.awt.*;
import java.util.UUID;
/**
* GUI: virtual card component for popup hint (move mouse over card to show a hint)
* <p>
* Use case: you don't have a real card but want to show a popup card hint.
* Howto use:
* - call "init" on new card;
* - call "onMouseXXX" on start, update and close
*
* @author JayDi85
*/
public class VirtualCardInfo {
CardView cardView;
MageCard cardComponent;
BigCard bigCard;
MageActionCallback actionCallback;
TransferData data = new TransferData();
Dimension cardDimension = null;
public VirtualCardInfo() {
super();
}
private void clear() {
this.cardView = null;
this.cardComponent = null;
}
public void init(String cardName, BigCard bigCard, UUID gameId) {
CardInfo cardInfo = CardRepository.instance.findCards(cardName).stream().findFirst().orElse(null);
if (cardInfo == null) {
clear();
return;
}
this.init(new CardView(cardInfo.getCard()), bigCard, gameId);
}
public void init(CardView cardView, BigCard bigCard, UUID gameId) {
clear();
this.bigCard = bigCard != null ? bigCard : new BigCard();
this.cardDimension = new Dimension(ClientDefaultSettings.dimensions.getFrameWidth(), ClientDefaultSettings.dimensions.getFrameHeight());
this.actionCallback = (MageActionCallback) Plugins.instance.getActionCallback();
this.cardView = cardView;
this.cardComponent = Plugins.instance.getMageCard(
this.cardView,
this.bigCard,
new CardIconRenderSettings(),
this.cardDimension,
null,
true,
true,
PreferencesDialog.getRenderMode(),
true
);
this.cardComponent.update(cardView);
data.setComponent(this.cardComponent);
data.setCard(this.cardView);
data.setGameId(gameId);
}
public boolean prepared() {
return this.cardView != null
&& this.cardComponent != null
&& this.actionCallback != null;
}
private void updateLocation(Point point) {
Point newPoint = new Point(point);
if (this.cardComponent != null) {
// offset popup
newPoint.translate(50, 50);
}
data.setLocationOnScreen(newPoint);
}
public void onMouseEntered() {
onMouseMoved(null);
}
public void onMouseEntered(Point newLocation) {
if (!prepared()) {
return;
}
if (newLocation != null) {
updateLocation(newLocation);
}
this.actionCallback.mouseEntered(null, this.data);
}
public void onMouseMoved() {
onMouseMoved(null);
}
public void onMouseMoved(Point newLocation) {
if (!prepared()) {
return;
}
if (newLocation != null) {
updateLocation(newLocation);
}
this.actionCallback.mouseMoved(null, this.data);
}
public void onMouseExited() {
if (!prepared()) {
return;
}
this.actionCallback.mouseExited(null, this.data);
}
}