Double-click to join a server

Fixes #228.
This commit is contained in:
Tomoaki Kawada 2016-11-20 18:58:52 +09:00
parent 6a3fa63bff
commit 29c42d950b
2 changed files with 35 additions and 2 deletions

View File

@ -230,6 +230,7 @@ namespace spades {
MainScreenServerItem@[]@ list;
ServerListItemEventHandler@ ItemActivated;
ServerListItemEventHandler@ ItemDoubleClicked;
ServerListModel(spades::ui::UIManager@ manager, MainScreenServerItem@[]@ list) {
@this.manager = manager;
@ -238,15 +239,22 @@ namespace spades {
int NumRows {
get { return int(list.length); }
}
private void ItemClicked(spades::ui::UIElement@ sender){
private void OnItemClicked(spades::ui::UIElement@ sender){
ServerListItem@ item = cast<ServerListItem>(sender);
if(ItemActivated !is null) {
ItemActivated(this, item.item);
}
}
private void OnItemDoubleClicked(spades::ui::UIElement@ sender){
ServerListItem@ item = cast<ServerListItem>(sender);
if(ItemDoubleClicked !is null) {
ItemDoubleClicked(this, item.item);
}
}
spades::ui::UIElement@ CreateElement(int row) {
ServerListItem i(manager, list[row]);
@i.Activated = spades::ui::EventHandler(this.ItemClicked);
@i.Activated = spades::ui::EventHandler(this.OnItemClicked);
@i.DoubleClicked = spades::ui::EventHandler(this.OnItemDoubleClicked);
return i;
}
void RecycleElement(spades::ui::UIElement@ elem) {}
@ -546,6 +554,13 @@ namespace spades {
addressField.SelectAll();
}
void ServerListItemDoubleClicked(ServerListModel@ sender, MainScreenServerItem@ item) {
ServerListItemActivated(sender, item);
// Double-click to connect
Connect();
}
private void SortServerListByPing(spades::ui::UIElement@ sender) {
SortServerList(0);
}
@ -631,6 +646,7 @@ namespace spades {
ServerListModel model(Manager, list2);
@serverList.Model = model;
@model.ItemActivated = ServerListItemEventHandler(this.ServerListItemActivated);
@model.ItemDoubleClicked = ServerListItemEventHandler(this.ServerListItemDoubleClicked);
serverList.ScrollToTop();
}

View File

@ -64,11 +64,16 @@ namespace spades {
bool ActivateOnMouseDown = false;
EventHandler@ Activated;
EventHandler@ DoubleClicked;
string Caption;
string ActivateHotKey;
private Timer@ repeatTimer;
// for double click detection
private float lastActivate = -1.f;
private Vector2 lastActivatePosition = Vector2();
ButtonBase(UIManager@ manager) {
super(manager);
IsMouseInteractive = true;
@ -90,6 +95,12 @@ namespace spades {
}
}
void OnDoubleClicked() {
if(DoubleClicked !is null) {
DoubleClicked(this);
}
}
private void RepeatTimerFired(Timer@ timer) {
OnActivated();
timer.Interval = 0.1f;
@ -139,6 +150,12 @@ namespace spades {
Toggled = not Toggled;
}
OnActivated();
if (Manager.Time < lastActivate + 0.35 &&
(clientPosition - lastActivatePosition).ManhattanLength < 10.0f) {
OnDoubleClicked();
}
lastActivate = Manager.Time;
lastActivatePosition = clientPosition;
}
if(Repeat and Hover){