Show tooltips when hovering
This commit is contained in:
@@ -47,18 +47,10 @@ func main() {
|
|||||||
log.Fatalf("Couldn't load menu %s: %v", *menuName, err)
|
log.Fatalf("Couldn't load menu %s: %v", *menuName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: move i18n, fonts into assetstore
|
|
||||||
if i18n, err := data.LoadI18n(filepath.Join(*gamePath, "Data", data.I18nFile)); err != nil {
|
|
||||||
log.Printf("Failed to load i18n data, skipping internationalization: %v", err)
|
|
||||||
} else {
|
|
||||||
menu.Internationalize(i18n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// loadedFonts, err := loadFonts(menu.FontNames...)
|
// loadedFonts, err := loadFonts(menu.FontNames...)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Fatalf("Failed to load font: %v", err)
|
// log.Fatalf("Failed to load font: %v", err)
|
||||||
// }
|
// }
|
||||||
*/
|
|
||||||
|
|
||||||
iface, err := ui.NewInterface(menu)
|
iface, err := ui.NewInterface(menu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -6,6 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"code.ur.gs/lupine/ordoor/internal/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -32,11 +34,12 @@ type AssetStore struct {
|
|||||||
entries entryMap
|
entries entryMap
|
||||||
|
|
||||||
// These members are used to store things we've already loaded
|
// These members are used to store things we've already loaded
|
||||||
maps map[string]*Map
|
maps map[string]*Map
|
||||||
menus map[string]*Menu
|
menus map[string]*Menu
|
||||||
objs map[string]*Object
|
objs map[string]*Object
|
||||||
sets map[string]*Set
|
sets map[string]*Set
|
||||||
sounds map[string]*Sound
|
sounds map[string]*Sound
|
||||||
|
strings *data.I18n
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new AssetStore
|
// New returns a new AssetStore
|
||||||
@@ -86,6 +89,7 @@ func (a *AssetStore) Refresh() error {
|
|||||||
a.objs = make(map[string]*Object)
|
a.objs = make(map[string]*Object)
|
||||||
a.sets = make(map[string]*Set)
|
a.sets = make(map[string]*Set)
|
||||||
a.sounds = make(map[string]*Sound)
|
a.sounds = make(map[string]*Sound)
|
||||||
|
a.strings = nil
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
29
internal/assetstore/i18n.go
Normal file
29
internal/assetstore/i18n.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package assetstore
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.ur.gs/lupine/ordoor/internal/data"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Internationalisation is completely hidden inside the asset store. Everything
|
||||||
|
// comes out already converted.
|
||||||
|
//
|
||||||
|
// FIXME: Allow the language to be set. Right now, it's hardcoded to USEng
|
||||||
|
// because that's the only copy of Chaos Gate I have.
|
||||||
|
func (a *AssetStore) i18n() (*data.I18n, error) {
|
||||||
|
if a.strings != nil {
|
||||||
|
return a.strings, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
filename, err := a.lookup(data.I18nFile, "", "Data")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
i18n, err := data.LoadI18n(filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
a.strings = i18n
|
||||||
|
return i18n, nil
|
||||||
|
}
|
@@ -54,6 +54,13 @@ func (a *AssetStore) Menu(name string) (*Menu, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i18n, err := a.i18n()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
raw.Internationalize(i18n)
|
||||||
|
|
||||||
obj, err := a.loadMenuObject(raw) // TODO: multiple objects
|
obj, err := a.loadMenuObject(raw) // TODO: multiple objects
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"reflect" // For DeepEqual
|
"reflect" // For DeepEqual
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||||
|
|
||||||
"code.ur.gs/lupine/ordoor/internal/assetstore"
|
"code.ur.gs/lupine/ordoor/internal/assetstore"
|
||||||
"code.ur.gs/lupine/ordoor/internal/menus"
|
"code.ur.gs/lupine/ordoor/internal/menus"
|
||||||
@@ -93,6 +94,11 @@ func (i *Interface) Draw(screen *ebiten.Image) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
do.GeoM = geo
|
do.GeoM = geo
|
||||||
|
|
||||||
|
if widget.hoverState && widget.Tooltip != "" {
|
||||||
|
mouseX, mouseY := ebiten.CursorPosition()
|
||||||
|
ebitenutil.DebugPrintAt(screen, widget.Tooltip, mouseX+16, mouseY-16)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -167,10 +173,11 @@ func (i *Interface) widgetFromRecord(record *menus.Record) (*Widget, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
widget := &Widget{
|
widget := &Widget{
|
||||||
Bounds: sprite.Rect,
|
Bounds: sprite.Rect,
|
||||||
path: path,
|
Tooltip: record.Desc,
|
||||||
record: record,
|
path: path,
|
||||||
sprite: sprite,
|
record: record,
|
||||||
|
sprite: sprite,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch record.Type {
|
switch record.Type {
|
||||||
|
@@ -13,8 +13,8 @@ import (
|
|||||||
// non-interactive areas are not widgets.
|
// non-interactive areas are not widgets.
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
// Position on the screen in original (i.e., unscaled) coordinates
|
// Position on the screen in original (i.e., unscaled) coordinates
|
||||||
Bounds image.Rectangle
|
Bounds image.Rectangle
|
||||||
// Tooltip string // TODO: show the tooltip when hovering?
|
Tooltip string
|
||||||
|
|
||||||
OnHoverEnter func()
|
OnHoverEnter func()
|
||||||
OnHoverLeave func()
|
OnHoverLeave func()
|
||||||
|
Reference in New Issue
Block a user