Filtering by game mode implemented.

This commit is contained in:
Stanislav Nikitin 2016-11-26 16:20:57 +05:00
parent f0ddda1af5
commit 979de8d858
2 changed files with 84 additions and 3 deletions

View File

@ -64,12 +64,16 @@ type MainWindow struct {
all_servers_hide_private *gtk.CheckButton all_servers_hide_private *gtk.CheckButton
// Combobox for filtering server's versions. // Combobox for filtering server's versions.
all_servers_version *gtk.ComboBoxText all_servers_version *gtk.ComboBoxText
// Combobox for filtering by gamemode.
all_servers_gamemode *gtk.ComboBoxText
// Checkbox for hiding/showing offline servers in 'Favorites' tab list. // Checkbox for hiding/showing offline servers in 'Favorites' tab list.
fav_servers_hide_offline *gtk.CheckButton fav_servers_hide_offline *gtk.CheckButton
// Checkbox for hiding/showing passworded servers in 'Favorites' tab list. // Checkbox for hiding/showing passworded servers in 'Favorites' tab list.
fav_servers_hide_private *gtk.CheckButton fav_servers_hide_private *gtk.CheckButton
// Combobox for filtering server's versions. // Combobox for filtering server's versions.
fav_servers_version *gtk.ComboBoxText fav_servers_version *gtk.ComboBoxText
// Combobox for filtering by gamemode.
fav_servers_gamemode *gtk.ComboBoxText
// Game launch button. // Game launch button.
launch_button *gtk.Button launch_button *gtk.Button
// Server's main information. // Server's main information.
@ -177,6 +181,11 @@ func (m *MainWindow) addToFavorites() {
} }
} }
func (m *MainWindow) allServersGamemodeFilterChanged() {
ctx.Cfg.Cfg["/serverslist/all_servers/gamemode"] = strconv.Itoa(m.all_servers_gamemode.GetActive())
ctx.Eventer.LaunchEvent("loadAllServers", nil)
}
func (m *MainWindow) allServersVersionFilterChanged() { func (m *MainWindow) allServersVersionFilterChanged() {
ctx.Cfg.Cfg["/serverslist/all_servers/version"] = strconv.Itoa(m.all_servers_version.GetActive()) ctx.Cfg.Cfg["/serverslist/all_servers/version"] = strconv.Itoa(m.all_servers_version.GetActive())
ctx.Eventer.LaunchEvent("loadAllServers", nil) ctx.Eventer.LaunchEvent("loadAllServers", nil)
@ -323,8 +332,13 @@ func (m *MainWindow) editFavorite() {
} }
} }
func (m *MainWindow) favServersGamemodeFilterChanged() {
ctx.Cfg.Cfg["/serverslist/favorite/gamemode"] = strconv.Itoa(m.fav_servers_gamemode.GetActive())
ctx.Eventer.LaunchEvent("loadFavoriteServers", nil)
}
func (m *MainWindow) favServersVersionFilterChanged() { func (m *MainWindow) favServersVersionFilterChanged() {
ctx.Cfg.Cfg["/serverslist/favorite/version"] = strconv.Itoa(m.all_servers_version.GetActive()) ctx.Cfg.Cfg["/serverslist/favorite/version"] = strconv.Itoa(m.fav_servers_version.GetActive())
ctx.Eventer.LaunchEvent("loadFavoriteServers", nil) ctx.Eventer.LaunchEvent("loadFavoriteServers", nil)
} }
@ -409,7 +423,18 @@ func (m *MainWindow) loadAllServers(data map[string]string) {
// Hide servers that using different version than selected in // Hide servers that using different version than selected in
// filter? // filter?
if m.all_servers_version.GetActiveText() != "All" && m.all_servers_version.GetActiveText() != server.Server.Version { if m.all_servers_version.GetActiveText() != "All versions" && m.all_servers_version.GetActiveText() != server.Server.Version {
if server.AllServersIterInList && server.AllServersIterSet {
m.all_servers_store.Remove(iter)
server.AllServersIterInList = false
}
continue
}
// Hide servers that using different gamemode than selected in
// filter?
gm_int_as_str := strconv.Itoa(m.all_servers_gamemode.GetActive())
if m.all_servers_gamemode.GetActiveText() != "All gamemodes" && gm_int_as_str != server.Server.Gamemode {
if server.AllServersIterInList && server.AllServersIterSet { if server.AllServersIterInList && server.AllServersIterSet {
m.all_servers_store.Remove(iter) m.all_servers_store.Remove(iter)
server.AllServersIterInList = false server.AllServersIterInList = false
@ -481,7 +506,18 @@ func (m *MainWindow) loadFavoriteServers(data map[string]string) {
// Hide servers that using different version than selected in // Hide servers that using different version than selected in
// filter? // filter?
if m.fav_servers_version.GetActiveText() != "All" && m.fav_servers_version.GetActiveText() != server.Server.Version { if m.fav_servers_version.GetActiveText() != "All versions" && m.fav_servers_version.GetActiveText() != server.Server.Version {
if server.FavServersIterInList && server.FavServersIterSet {
m.fav_servers_store.Remove(iter)
server.FavServersIterInList = false
}
continue
}
// Hide servers that using different gamemode than selected in
// filter?
gm_int_as_str := strconv.Itoa(m.fav_servers_gamemode.GetActive())
if m.fav_servers_gamemode.GetActiveText() != "All gamemodes" && gm_int_as_str != server.Server.Gamemode {
if server.FavServersIterInList && server.FavServersIterSet { if server.FavServersIterInList && server.FavServersIterSet {
m.fav_servers_store.Remove(iter) m.fav_servers_store.Remove(iter)
server.FavServersIterInList = false server.FavServersIterInList = false

View File

@ -5,6 +5,7 @@ import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"runtime" "runtime"
"sort"
"strconv" "strconv"
// local // local
@ -525,6 +526,7 @@ func (m *MainWindow) InitializeTabs() {
} }
} }
// Filtering by version.
m.all_servers_version = gtk.NewComboBoxText() m.all_servers_version = gtk.NewComboBoxText()
m.all_servers_version.SetTooltipText("Show only servers which uses selected version of Urban Terror") m.all_servers_version.SetTooltipText("Show only servers which uses selected version of Urban Terror")
m.all_servers_version.AppendText("All versions") m.all_servers_version.AppendText("All versions")
@ -541,6 +543,30 @@ func (m *MainWindow) InitializeTabs() {
m.all_servers_version.Connect("changed", m.allServersVersionFilterChanged) m.all_servers_version.Connect("changed", m.allServersVersionFilterChanged)
tab_all_srv_ctl_vbox.PackStart(m.all_servers_version, false, true, 5) tab_all_srv_ctl_vbox.PackStart(m.all_servers_version, false, true, 5)
// Filtering by gamemode
m.all_servers_gamemode = gtk.NewComboBoxText()
m.all_servers_gamemode.SetTooltipText("Show only servers which uses selected game mode")
m.all_servers_gamemode.AppendText("All gamemodes")
// Get sorted gamemodes keys.
gm_keys := make([]int, 0, len(m.gamemodes))
for i := range m.gamemodes {
key, _ := strconv.Atoi(i)
gm_keys = append(gm_keys, key)
}
sort.Ints(gm_keys)
for i := range gm_keys {
m.all_servers_gamemode.AppendText(m.gamemodes[strconv.Itoa(gm_keys[i])])
}
all_servers_gamemode_val, ok := ctx.Cfg.Cfg["/serverslist/all_servers/gamemode"]
if ok {
all_servers_gamemode_int, _ := strconv.Atoi(all_servers_gamemode_val)
m.all_servers_gamemode.SetActive(all_servers_gamemode_int)
} else {
m.all_servers_gamemode.SetActive(0)
}
m.all_servers_gamemode.Connect("changed", m.allServersGamemodeFilterChanged)
tab_all_srv_ctl_vbox.PackStart(m.all_servers_gamemode, false, true, 5)
// Final separator. // Final separator.
ctl_sep := gtk.NewVBox(false, 0) ctl_sep := gtk.NewVBox(false, 0)
tab_all_srv_ctl_vbox.PackStart(ctl_sep, true, true, 5) tab_all_srv_ctl_vbox.PackStart(ctl_sep, true, true, 5)
@ -653,6 +679,25 @@ func (m *MainWindow) InitializeTabs() {
m.fav_servers_version.Connect("changed", m.favServersVersionFilterChanged) m.fav_servers_version.Connect("changed", m.favServersVersionFilterChanged)
tab_fav_srv_ctl_vbox.PackStart(m.fav_servers_version, false, true, 5) tab_fav_srv_ctl_vbox.PackStart(m.fav_servers_version, false, true, 5)
// Filtering by gamemode
m.fav_servers_gamemode = gtk.NewComboBoxText()
m.fav_servers_gamemode.SetTooltipText("Show only servers which uses selected game mode")
m.fav_servers_gamemode.AppendText("All gamemodes")
// Gamemode keys already sorted while adding same filter to "Servers"
// tab, so just re-use them.
for i := range gm_keys {
m.fav_servers_gamemode.AppendText(m.gamemodes[strconv.Itoa(gm_keys[i])])
}
fav_servers_gamemode_val, ok := ctx.Cfg.Cfg["/serverslist/favorite/gamemode"]
if ok {
fav_servers_gamemode_int, _ := strconv.Atoi(fav_servers_gamemode_val)
m.fav_servers_gamemode.SetActive(fav_servers_gamemode_int)
} else {
m.fav_servers_gamemode.SetActive(0)
}
m.fav_servers_gamemode.Connect("changed", m.favServersGamemodeFilterChanged)
tab_fav_srv_ctl_vbox.PackStart(m.fav_servers_gamemode, false, true, 5)
// Final separator. // Final separator.
ctl_fav_sep := gtk.NewVBox(false, 0) ctl_fav_sep := gtk.NewVBox(false, 0)
tab_fav_srv_ctl_vbox.PackStart(ctl_fav_sep, true, true, 5) tab_fav_srv_ctl_vbox.PackStart(ctl_fav_sep, true, true, 5)