Browse Source

add TitleBar UpdateTimeLocation

cuu 5 years ago
parent
commit
6f4bbe62dd
2 changed files with 32 additions and 0 deletions
  1. 4 0
      Menu/GameShell/10_Settings/TimeZone/time_zone_page.go
  2. 28 0
      sysgo/UI/title_bar.go

+ 4 - 0
Menu/GameShell/10_Settings/TimeZone/time_zone_page.go

@@ -259,6 +259,10 @@ func (self *TimeZoneListPage) Click() {
     err := cpCmd.Run()
     if err != nil{
       fmt.Println(err)
+    }else {
+      
+      self.Screen.TitleBar.UpdateTimeLocation()
+    
     }
     fmt.Println("add ",cur_li.Path)
   }

+ 28 - 0
sysgo/UI/title_bar.go

@@ -8,6 +8,7 @@ import (
 	"bufio"
 	"strings"
   "os/exec"
+  "io/ioutil"
 	gotime "time"
 	
 	"github.com/veandco/go-sdl2/sdl"
@@ -109,6 +110,7 @@ type TitleBar struct {
 	
 	icon_base_path string /// SkinMap("gameshell/titlebar_icons/")
   
+  MyTimeLocation *gotime.Location
   
 	TitleFont *ttf.Font
 	TimeFont  *ttf.Font
@@ -405,6 +407,9 @@ func (self *TitleBar) Init(main_screen *MainScreen) {
     }
 
   }
+  
+  self.UpdateTimeLocation()
+  
 }
 
 func (self *TitleBar) ClearCanvas() {
@@ -421,6 +426,29 @@ func (self *TitleBar) ClearCanvas() {
 }
 
 
+func (self *TitleBar) UpdateTimeLocation()  {
+  
+  d,err := ioutil.ReadFile("/etc/localtime")
+  if err != nil {
+    return
+  }
+  
+  self.MyTimeLocation,err = gotime.LoadLocationFromTZData("local", d)
+  if err != nil {
+    fmt.Println(err)
+    self.MyTimeLocation = nil
+  }
+}
+
+func (self *TitleBar) GetLocalTime() gotime.Time {
+  if self.MyTimeLocation == nil {
+    return gotime.Now()
+  }else {  
+    return gotime.Now().In(self.MyTimeLocation)
+  }
+}
+
+
 func (self *TitleBar) Draw(title string) {
 	self.ClearCanvas()
 	self.Title = title