Hostname's colorizing is here. Added stub for server info window.

This commit is contained in:
Stanislav Nikitin 2016-10-05 20:46:02 +05:00
parent 98598e41e3
commit dd41537106
5 changed files with 162 additions and 20 deletions

View File

@ -0,0 +1,62 @@
// 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 colorizer
import (
// stdlib
"fmt"
"html"
"strings"
)
type Colorizer struct {
// RAW colors to Pango relation.
colors map[string]string
}
func (c *Colorizer) Fix(data string) string {
result := ""
data_splitted := strings.Split(data, "^")
if len(data_splitted) > 1 {
for item := range data_splitted {
if len(data_splitted[item]) > 0 {
colorcode_raw := string([]rune(data_splitted[item])[0])
colorcode, ok := c.colors[colorcode_raw]
if !ok {
colorcode = "#000000"
}
result += "<span foreground=\"" + colorcode + "\">" + html.EscapeString(string([]rune(data_splitted[item])[1:])) + "</span>"
} else {
result += data_splitted[item]
}
}
} else {
result = data_splitted[0]
}
return "<markup>" + result + "</markup>"
}
func (c *Colorizer) Initialize() {
fmt.Println("Initializing colorizer...")
c.initializeStorages()
}
func (c *Colorizer) initializeStorages() {
c.colors = map[string]string{
"1": "#cc0000",
"2": "#00cc00",
"3": "#eeee00",
"4": "#1c86ee",
"5": "#00eeee",
"6": "#ee00ee",
"7": "#000000",
"8": "#000000",
}
}

15
colorizer/exported.go Normal file
View File

@ -0,0 +1,15 @@
// 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 colorizer
func New() *Colorizer {
c := Colorizer {}
return &c
}

View File

@ -14,6 +14,7 @@ import (
"fmt"
// local
"github.com/pztrn/urtrator/colorizer"
"github.com/pztrn/urtrator/configuration"
"github.com/pztrn/urtrator/database"
"github.com/pztrn/urtrator/eventer"
@ -25,6 +26,8 @@ import (
)
type Context struct {
// Colors parser and prettifier.
Colorizer *colorizer.Colorizer
// Configuration.
Cfg *configuration.Config
// Database.
@ -46,6 +49,11 @@ func (ctx *Context) Close() {
gtk.MainQuit()
}
func (ctx *Context) initializeColorizer() {
ctx.Colorizer = colorizer.New()
ctx.Colorizer.Initialize()
}
func (ctx *Context) initializeConfig() {
ctx.Cfg = configuration.New()
ctx.Cfg.Initialize()
@ -74,6 +82,7 @@ func (ctx *Context) initializeRequester() {
func (ctx *Context) Initialize() {
fmt.Println("Initializing application context...")
ctx.initializeColorizer()
ctx.initializeConfig()
ctx.initializeDatabase()
ctx.initializeEventer()

View File

@ -14,6 +14,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"runtime"
"strconv"
"strings"
@ -277,11 +278,21 @@ func (m *MainWindow) editFavorite() {
func (m *MainWindow) hideOfflineAllServers() {
fmt.Println("(Un)Hiding offline servers in 'Servers' tab...")
if m.all_servers_hide_offline.GetActive() {
ctx.Cfg.Cfg["/serverslist/all_servers/hide_offline"] = "1"
} else {
ctx.Cfg.Cfg["/serverslist/all_servers/hide_offline"] = "0"
}
ctx.Eventer.LaunchEvent("loadAllServers")
}
func (m *MainWindow) hideOfflineFavoriteServers() {
fmt.Println("(Un)Hiding offline servers in 'Favorite' tab...")
if m.fav_servers_hide_offline.GetActive() {
ctx.Cfg.Cfg["/serverslist/favorite/hide_offline"] = "1"
} else {
ctx.Cfg.Cfg["/serverslist/favorite/hide_offline"] = "0"
}
ctx.Eventer.LaunchEvent("loadFavoriteServers")
}
@ -548,7 +559,7 @@ func (m *MainWindow) InitializeTabs() {
m.all_servers.SetModel(m.all_servers_store)
m.all_servers.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Status", gtk.NewCellRendererPixbuf(), "pixbuf", 0))
all_srv_name_column := gtk.NewTreeViewColumnWithAttributes("Name", gtk.NewCellRendererText(), "text", 1)
all_srv_name_column := gtk.NewTreeViewColumnWithAttributes("Name", gtk.NewCellRendererText(), "markup", 1)
all_srv_name_column.SetSortColumnId(1)
m.all_servers.AppendColumn(all_srv_name_column)
@ -590,6 +601,9 @@ func (m *MainWindow) InitializeTabs() {
m.all_servers_hide_offline.SetTooltipText("Hide offline servers on Servers tab")
tab_all_srv_ctl_vbox.PackStart(m.all_servers_hide_offline, false, true, 5)
m.all_servers_hide_offline.Clicked(m.hideOfflineAllServers)
if ctx.Cfg.Cfg["/serverslist/all_servers/hide_offline"] == "1" {
m.all_servers_hide_offline.SetActive(true)
}
// Final separator.
ctl_sep := gtk.NewVSeparator()
@ -606,7 +620,7 @@ func (m *MainWindow) InitializeTabs() {
m.fav_servers.SetModel(m.fav_servers_store)
m.fav_servers.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Status", gtk.NewCellRendererPixbuf(), "pixbuf", 0))
fav_name_column := gtk.NewTreeViewColumnWithAttributes("Name", gtk.NewCellRendererText(), "text", 1)
fav_name_column := gtk.NewTreeViewColumnWithAttributes("Name", gtk.NewCellRendererText(), "markup", 1)
fav_name_column.SetSortColumnId(1)
m.fav_servers.AppendColumn(fav_name_column)
@ -643,6 +657,9 @@ func (m *MainWindow) InitializeTabs() {
m.fav_servers_hide_offline.SetTooltipText("Hide offline servers on Favorites tab")
tab_fav_srv_ctl_vbox.PackStart(m.fav_servers_hide_offline, false, true, 5)
m.fav_servers_hide_offline.Clicked(m.hideOfflineFavoriteServers)
if ctx.Cfg.Cfg["/serverslist/favorite/hide_offline"] == "1" {
m.fav_servers_hide_offline.SetActive(true)
}
// Final separator.
ctl_fav_sep := gtk.NewVSeparator()
@ -704,26 +721,30 @@ func (m *MainWindow) initializeTrayIcon() {
m.tray_icon.SetTitle("URTrator")
m.tray_icon.SetTooltipText("URTrator is ready")
m.tray_menu = gtk.NewMenu()
// Tray menu is still buggy on windows, so skipping initialization,
// if OS is Windows.
if runtime.GOOS != "windows" {
m.tray_menu = gtk.NewMenu()
// Open/Close URTrator menu item.
open_close_item := gtk.NewMenuItemWithLabel("Show / Hide URTrator")
open_close_item.Connect("activate", m.showHide)
m.tray_menu.Append(open_close_item)
// Open/Close URTrator menu item.
open_close_item := gtk.NewMenuItemWithLabel("Show / Hide URTrator")
open_close_item.Connect("activate", m.showHide)
m.tray_menu.Append(open_close_item)
// Separator
sep1 := gtk.NewSeparatorMenuItem()
m.tray_menu.Append(sep1)
// Separator
sep1 := gtk.NewSeparatorMenuItem()
m.tray_menu.Append(sep1)
// Exit menu item.
exit_item := gtk.NewMenuItemWithLabel("Exit")
exit_item.Connect("activate", m.window.Destroy)
m.tray_menu.Append(exit_item)
// Exit menu item.
exit_item := gtk.NewMenuItemWithLabel("Exit")
exit_item.Connect("activate", m.window.Destroy)
m.tray_menu.Append(exit_item)
// Connect things.
m.tray_icon.Connect("activate", m.showHide)
m.tray_icon.Connect("popup-menu", m.showTrayMenu)
m.tray_menu.ShowAll()
// Connect things.
m.tray_icon.Connect("activate", m.showHide)
m.tray_icon.Connect("popup-menu", m.showTrayMenu)
m.tray_menu.ShowAll()
}
}
func (m *MainWindow) launchGame() error {
@ -857,7 +878,8 @@ func (m *MainWindow) loadAllServers() {
} else {
m.all_servers_store.Set(&iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
}
m.all_servers_store.Set(&iter, 1, srv.Name)
srv_name := ctx.Colorizer.Fix(srv.Name)
m.all_servers_store.Set(&iter, 1, srv_name)
m.all_servers_store.Set(&iter, 2, m.gamemodes[srv.Gamemode])
m.all_servers_store.Set(&iter, 3, srv.Map)
m.all_servers_store.Set(&iter, 4, srv.Players + "/" + srv.Maxplayers)
@ -890,7 +912,8 @@ func (m *MainWindow) loadFavoriteServers() {
} else {
m.fav_servers_store.Set(&iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
}
m.fav_servers_store.Set(&iter, 1, srv.Name)
srv_name := ctx.Colorizer.Fix(srv.Name)
m.fav_servers_store.Set(&iter, 1, srv_name)
m.fav_servers_store.Set(&iter, 2, m.gamemodes[srv.Gamemode])
m.fav_servers_store.Set(&iter, 3, srv.Map)
m.fav_servers_store.Set(&iter, 4, srv.Players + "/" + srv.Maxplayers)

33
ui/server_info.go Normal file
View File

@ -0,0 +1,33 @@
// 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"
// Local
//"github.com/pztrn/urtrator/datamodels"
// Other
"github.com/mattn/go-gtk/gtk"
//"github.com/mattn/go-gtk/glib"
)
type ServerInfoDialog struct {
// Window.
window *gtk.Window
// Main Vertical Box.
vbox *gtk.VBox
}
func (sid *ServerInfoDialog) Initialize() {
fmt.Println("Showing server's information...")
}