Filter by server version and forgotten server's CVars window.
Implemented filtering servers by server's version, related to #27.
This combobox is saved-restored across restarts.
Added forgotten bd04870
server_cvars.go, which is responsible for
showing server's CVars window.
This commit is contained in:
parent
7950ab5a1f
commit
bd344fee2e
@ -12,3 +12,9 @@ package common
|
|||||||
const (
|
const (
|
||||||
URTRATOR_VERSION = "0.1.0"
|
URTRATOR_VERSION = "0.1.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Self-named.
|
||||||
|
var SUPPORTED_URT_VERSIONS []string = []string{
|
||||||
|
"4.2.023",
|
||||||
|
"4.3.1",
|
||||||
|
}
|
||||||
|
@ -62,10 +62,14 @@ type MainWindow struct {
|
|||||||
all_servers_hide_offline *gtk.CheckButton
|
all_servers_hide_offline *gtk.CheckButton
|
||||||
// Checkbox for hiding/showing passworded servers in 'Servers' tab list.
|
// Checkbox for hiding/showing passworded servers in 'Servers' tab list.
|
||||||
all_servers_hide_private *gtk.CheckButton
|
all_servers_hide_private *gtk.CheckButton
|
||||||
|
// Combobox for filtering server's versions.
|
||||||
|
all_servers_version *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.
|
||||||
|
fav_servers_version *gtk.ComboBoxText
|
||||||
// Game launch button.
|
// Game launch button.
|
||||||
launch_button *gtk.Button
|
launch_button *gtk.Button
|
||||||
// Server's main information.
|
// Server's main information.
|
||||||
@ -173,6 +177,11 @@ func (m *MainWindow) addToFavorites() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MainWindow) allServersVersionFilterChanged() {
|
||||||
|
ctx.Cfg.Cfg["/serverslist/all_servers/version"] = strconv.Itoa(m.all_servers_version.GetActive())
|
||||||
|
ctx.Eventer.LaunchEvent("loadAllServers", nil)
|
||||||
|
}
|
||||||
|
|
||||||
// Executes when delimiter for two panes is moved, to calculate VALID
|
// Executes when delimiter for two panes is moved, to calculate VALID
|
||||||
// position.
|
// position.
|
||||||
func (m *MainWindow) checkMainPanePosition() {
|
func (m *MainWindow) checkMainPanePosition() {
|
||||||
@ -314,6 +323,11 @@ func (m *MainWindow) editFavorite() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MainWindow) favServersVersionFilterChanged() {
|
||||||
|
ctx.Cfg.Cfg["/serverslist/favorite/version"] = strconv.Itoa(m.all_servers_version.GetActive())
|
||||||
|
ctx.Eventer.LaunchEvent("loadFavoriteServers", nil)
|
||||||
|
}
|
||||||
|
|
||||||
// Executes when "Hide offline servers" checkbox changed it's state on
|
// Executes when "Hide offline servers" checkbox changed it's state on
|
||||||
// "Servers" tab.
|
// "Servers" tab.
|
||||||
func (m *MainWindow) hideOfflineAllServers() {
|
func (m *MainWindow) hideOfflineAllServers() {
|
||||||
@ -375,6 +389,7 @@ func (m *MainWindow) loadAllServers(data map[string]string) {
|
|||||||
iter = server.AllServersIter
|
iter = server.AllServersIter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hide offline servers?
|
||||||
if m.all_servers_hide_offline.GetActive() && (server.Server.Players == "" && server.Server.Maxplayers == "" || ping > 9000) {
|
if m.all_servers_hide_offline.GetActive() && (server.Server.Players == "" && server.Server.Maxplayers == "" || ping > 9000) {
|
||||||
if server.AllServersIterInList && server.AllServersIterSet {
|
if server.AllServersIterInList && server.AllServersIterSet {
|
||||||
m.all_servers_store.Remove(iter)
|
m.all_servers_store.Remove(iter)
|
||||||
@ -383,6 +398,7 @@ func (m *MainWindow) loadAllServers(data map[string]string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hide private servers?
|
||||||
if m.all_servers_hide_private.GetActive() && server.Server.IsPrivate == "1" {
|
if m.all_servers_hide_private.GetActive() && server.Server.IsPrivate == "1" {
|
||||||
if server.AllServersIterInList && server.AllServersIterSet {
|
if server.AllServersIterInList && server.AllServersIterSet {
|
||||||
m.all_servers_store.Remove(iter)
|
m.all_servers_store.Remove(iter)
|
||||||
@ -391,6 +407,16 @@ func (m *MainWindow) loadAllServers(data map[string]string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hide servers that using different version than selected in
|
||||||
|
// filter?
|
||||||
|
if m.all_servers_version.GetActiveText() != "All" && m.all_servers_version.GetActiveText() != server.Server.Version {
|
||||||
|
if server.AllServersIterInList && server.AllServersIterSet {
|
||||||
|
m.all_servers_store.Remove(iter)
|
||||||
|
server.AllServersIterInList = false
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if !server.AllServersIterInList && server.AllServersIterSet {
|
if !server.AllServersIterInList && server.AllServersIterSet {
|
||||||
m.all_servers_store.Append(iter)
|
m.all_servers_store.Append(iter)
|
||||||
server.AllServersIterInList = true
|
server.AllServersIterInList = true
|
||||||
@ -435,6 +461,7 @@ func (m *MainWindow) loadFavoriteServers(data map[string]string) {
|
|||||||
iter = server.FavServersIter
|
iter = server.FavServersIter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hide offline servers?
|
||||||
if m.fav_servers_hide_offline.GetActive() && (server.Server.Players == "" && server.Server.Maxplayers == "" || ping > 9000) {
|
if m.fav_servers_hide_offline.GetActive() && (server.Server.Players == "" && server.Server.Maxplayers == "" || ping > 9000) {
|
||||||
if server.FavServersIterInList {
|
if server.FavServersIterInList {
|
||||||
m.fav_servers_store.Remove(iter)
|
m.fav_servers_store.Remove(iter)
|
||||||
@ -443,6 +470,7 @@ func (m *MainWindow) loadFavoriteServers(data map[string]string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hide private servers?
|
||||||
if m.fav_servers_hide_private.GetActive() && server.Server.IsPrivate == "1" {
|
if m.fav_servers_hide_private.GetActive() && server.Server.IsPrivate == "1" {
|
||||||
if server.FavServersIterInList && server.FavServersIterSet {
|
if server.FavServersIterInList && server.FavServersIterSet {
|
||||||
m.fav_servers_store.Remove(iter)
|
m.fav_servers_store.Remove(iter)
|
||||||
@ -451,6 +479,16 @@ func (m *MainWindow) loadFavoriteServers(data map[string]string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hide servers that using different version than selected in
|
||||||
|
// filter?
|
||||||
|
if m.fav_servers_version.GetActiveText() != "All" && m.fav_servers_version.GetActiveText() != server.Server.Version {
|
||||||
|
if server.FavServersIterInList && server.FavServersIterSet {
|
||||||
|
m.fav_servers_store.Remove(iter)
|
||||||
|
server.FavServersIterInList = false
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// If server on favorites widget, but not favorited (e.g. just
|
// If server on favorites widget, but not favorited (e.g. just
|
||||||
// removed from favorites) - remove it from list.
|
// removed from favorites) - remove it from list.
|
||||||
if server.Server.Favorite != "1" && server.FavServersIterSet && server.FavServersIterInList {
|
if server.Server.Favorite != "1" && server.FavServersIterSet && server.FavServersIterInList {
|
||||||
|
@ -525,8 +525,24 @@ func (m *MainWindow) InitializeTabs() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.AppendText("All")
|
||||||
|
for i := range common.SUPPORTED_URT_VERSIONS {
|
||||||
|
m.all_servers_version.AppendText(common.SUPPORTED_URT_VERSIONS[i])
|
||||||
|
}
|
||||||
|
all_servers_version_val, ok := ctx.Cfg.Cfg["/serverslist/all_servers/version"]
|
||||||
|
if ok {
|
||||||
|
all_servers_version_int, _ := strconv.Atoi(all_servers_version_val)
|
||||||
|
m.all_servers_version.SetActive(all_servers_version_int)
|
||||||
|
} else {
|
||||||
|
m.all_servers_version.SetActive(0)
|
||||||
|
}
|
||||||
|
m.all_servers_version.Connect("changed", m.allServersVersionFilterChanged)
|
||||||
|
tab_all_srv_ctl_vbox.PackStart(m.all_servers_version, false, true, 5)
|
||||||
|
|
||||||
// Final separator.
|
// Final separator.
|
||||||
ctl_sep := gtk.NewVSeparator()
|
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)
|
||||||
|
|
||||||
// Favorites servers
|
// Favorites servers
|
||||||
@ -621,8 +637,24 @@ func (m *MainWindow) InitializeTabs() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.fav_servers_version = gtk.NewComboBoxText()
|
||||||
|
m.fav_servers_version.SetTooltipText("Show only servers which uses selected version of Urban Terror")
|
||||||
|
m.fav_servers_version.AppendText("All")
|
||||||
|
for i := range common.SUPPORTED_URT_VERSIONS {
|
||||||
|
m.fav_servers_version.AppendText(common.SUPPORTED_URT_VERSIONS[i])
|
||||||
|
}
|
||||||
|
fav_servers_version_val, ok := ctx.Cfg.Cfg["/serverslist/favorite/version"]
|
||||||
|
if ok {
|
||||||
|
fav_servers_version_int, _ := strconv.Atoi(fav_servers_version_val)
|
||||||
|
m.fav_servers_version.SetActive(fav_servers_version_int)
|
||||||
|
} else {
|
||||||
|
m.fav_servers_version.SetActive(0)
|
||||||
|
}
|
||||||
|
m.fav_servers_version.Connect("changed", m.favServersVersionFilterChanged)
|
||||||
|
tab_fav_srv_ctl_vbox.PackStart(m.fav_servers_version, false, true, 5)
|
||||||
|
|
||||||
// Final separator.
|
// Final separator.
|
||||||
ctl_fav_sep := gtk.NewVSeparator()
|
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)
|
||||||
|
|
||||||
// Add tab_widget widget to window.
|
// Add tab_widget widget to window.
|
||||||
|
104
ui/server_cvars.go
Normal file
104
ui/server_cvars.go
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
// URTator - Urban Terror server browser and game launcher, written in
|
||||||
|
// Go.
|
||||||
|
//
|
||||||
|
// Copyright (c) 2016, Stanslav N. a.k.a pztrn (or p0z1tr0n)
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under Terms and Conditions of GNU General Public License
|
||||||
|
// version 3 or any higher.
|
||||||
|
// ToDo: put full text of license here.
|
||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
// stdlib
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
// Local
|
||||||
|
"github.com/pztrn/urtrator/ioq3dataparser"
|
||||||
|
|
||||||
|
// Other
|
||||||
|
"github.com/mattn/go-gtk/gtk"
|
||||||
|
"github.com/mattn/go-gtk/glib"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServerCVarsDialog struct {
|
||||||
|
// Window.
|
||||||
|
window *gtk.Window
|
||||||
|
// Main Vertical Box.
|
||||||
|
vbox *gtk.VBox
|
||||||
|
// Treeview for CVars.
|
||||||
|
treeview *gtk.TreeView
|
||||||
|
// Store for treeview.
|
||||||
|
treeview_store *gtk.ListStore
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scd *ServerCVarsDialog) Close() {
|
||||||
|
scd.window.Destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scd *ServerCVarsDialog) fill(srv_address string) {
|
||||||
|
server_info := ctx.Cache.Servers[srv_address].Server
|
||||||
|
parsed_general_data := ioq3dataparser.ParseInfoToMap(server_info.ExtendedConfig)
|
||||||
|
|
||||||
|
// Sort it!
|
||||||
|
general_data_keys := make([]string, 0, len(parsed_general_data))
|
||||||
|
for k := range parsed_general_data {
|
||||||
|
general_data_keys = append(general_data_keys, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(general_data_keys)
|
||||||
|
|
||||||
|
for k := range general_data_keys {
|
||||||
|
iter := new(gtk.TreeIter)
|
||||||
|
scd.treeview_store.Append(iter)
|
||||||
|
scd.treeview_store.SetValue(iter, 0, general_data_keys[k])
|
||||||
|
scd.treeview_store.SetValue(iter, 1, parsed_general_data[general_data_keys[k]])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scd *ServerCVarsDialog) Initialize(w *gtk.Window, srv_address string) {
|
||||||
|
fmt.Println("Showing server's CVars...")
|
||||||
|
|
||||||
|
scd.initializeStorages()
|
||||||
|
|
||||||
|
scd.window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||||
|
scd.window.SetTitle("URTrator - Server CVars")
|
||||||
|
scd.window.Connect("destroy", scd.Close)
|
||||||
|
scd.window.SetTransientFor(w)
|
||||||
|
scd.window.SetDefaultSize(300, 400)
|
||||||
|
|
||||||
|
scd.vbox = gtk.NewVBox(false, 0)
|
||||||
|
scd.window.Add(scd.vbox)
|
||||||
|
|
||||||
|
// CVars scrolls.
|
||||||
|
si := gtk.NewScrolledWindow(nil, nil)
|
||||||
|
scd.vbox.PackStart(si, true, true, 5)
|
||||||
|
|
||||||
|
// CVars list.
|
||||||
|
scd.treeview = gtk.NewTreeView()
|
||||||
|
scd.treeview.SetModel(scd.treeview_store)
|
||||||
|
si.Add(scd.treeview)
|
||||||
|
|
||||||
|
scd.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Key", gtk.NewCellRendererText(), "markup", 0))
|
||||||
|
scd.treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Value", gtk.NewCellRendererText(), "markup", 1))
|
||||||
|
|
||||||
|
// Close button.
|
||||||
|
hbox := gtk.NewHBox(false, 0)
|
||||||
|
scd.vbox.PackStart(hbox, false, true, 5)
|
||||||
|
|
||||||
|
sep := gtk.NewHBox(false, 0)
|
||||||
|
hbox.PackStart(sep, true, true, 5)
|
||||||
|
|
||||||
|
close_button := gtk.NewButtonWithLabel("Close")
|
||||||
|
close_button.Clicked(scd.Close)
|
||||||
|
hbox.PackStart(close_button, false, true, 5)
|
||||||
|
|
||||||
|
scd.fill(srv_address)
|
||||||
|
|
||||||
|
scd.window.ShowAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scd *ServerCVarsDialog) initializeStorages() {
|
||||||
|
scd.treeview_store = gtk.NewListStore(glib.G_TYPE_STRING, glib.G_TYPE_STRING)
|
||||||
|
}
|
Reference in New Issue
Block a user