Skip to content

Commit

Permalink
WIP: locales editor
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Apr 20, 2021
1 parent 9d8f8d7 commit 509c9fc
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 7 deletions.
31 changes: 27 additions & 4 deletions hsapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,21 +231,44 @@ func (a *App) render() {

func (a *App) setupFonts() {
// Note: To support other languages we'll have to do something with glyph ranges here...
// ranges := imgui.NewGlyphRanges()
// rb := imgui.NewFontGlyphRangesBuilder()
// rb.AddRanges(imgui.CurrentIO().Fonts().GlyphRangesJapanese())
// ranges := imgui.EmptyGlyphRanges
//rb := &imgui.GlyphRangesBuilder{}
/*switch a.config.Locale {
case hsenum.LocaleChinaTraditional:
// rb.AddExisting(imgui.CurrentIO().Fonts().GlyphRangesChineseFull())
fmt.Println("Load china")
imgui.CurrentIO().Fonts().AddFontFromMemoryTTFV(hsassets.FontNotoSansRegular, 17, 0, imgui.CurrentIO().Fonts().GlyphRangesChineseFull())
imgui.CurrentIO().Fonts().AddFontFromMemoryTTFV(hsassets.FontNotoSansRegular, 17, 0, imgui.CurrentIO().Fonts().GlyphRangesChineseSimplifiedCommon())
}*/
//rb.AddExisiting(imgui.CurrentIO().Fonts().GlyphRangesJapanese())
// rb.AddRanges(imgui.CurrentIO().Fonts().GlyphRangesChineseSimplifiedCommon())
// rb.AddRanges(imgui.CurrentIO().Fonts().GlyphRangesCyrillic())
// rb.AddRanges(imgui.CurrentIO().Fonts().GlyphRangesKorean())
// rb.BuildRanges(ranges)
// rb.Build()
// imgui.CurrentIO().Fonts().AddFontFromFileTTFV("NotoSans-Regular.ttf", 17, 0, imgui.CurrentIO().Fonts().GlyphRangesJapanese())
var builder imgui.GlyphRangesBuilder
builder.AddExisting(imgui.CurrentIO().Fonts().GlyphRangesDefault())
builder.AddExisting(imgui.CurrentIO().Fonts().GlyphRangesChineseSimplifiedCommon())
/* builder.AddExisting(fontAtlas.GlyphRangesKorean())
builder.AddExisting(fontAtlas.GlyphRangesChinese())*/
ranges := builder.Build()
/*fontAtlas.AddFontFromFileTTFV("lihei.ttf", 16, imgui.DefaultFontConfig, ranges.GlyphRanges)
fontAtlas.SetTexDesiredWidth(8192)*/

imgui.CurrentIO().AddInputCharacters("ą")
imgui.CurrentIO().Fonts().AddFontFromMemoryTTF(hsassets.FontNotoSansRegular, 17)
a.fontFixed = imgui.CurrentIO().Fonts().AddFontFromMemoryTTF(hsassets.FontCascadiaCode, 15)
a.fontFixed = imgui.CurrentIO().Fonts().AddFontFromMemoryTTFV(hsassets.FontCascadiaCode, 15, imgui.DefaultFontConfig, ranges.GlyphRanges)
imgui.CurrentIO().Fonts().SetTexDesiredWidth(8192)
a.fontFixedSmall = imgui.CurrentIO().Fonts().AddFontFromMemoryTTF(hsassets.FontCascadiaCode, 12)
a.fontFixedSmall = imgui.CurrentIO().Fonts().AddFontFromMemoryTTFV(hsassets.FontDiabloRegular, 12, 0, imgui.CurrentIO().Fonts().GlyphRangesChineseSimplifiedCommon())
a.diabloRegularFont = imgui.CurrentIO().Fonts().AddFontFromMemoryTTF(hsassets.FontDiabloRegular, 15)
a.diabloBoldFont = imgui.CurrentIO().Fonts().AddFontFromMemoryTTF(hsassets.FontDiabloBold, 30)
imgui.CurrentStyle().ScaleAllSizes(1)

// a.fontFixed = imgui.CurrentIO().Fonts().AddFontFromMemoryTTFV(hsassets.FontDiabloRegular, 15, 0, imgui.CurrentIO().Fonts().GlyphRangesChineseSimplifiedCommon())
// a.diabloRegularFont = imgui.CurrentIO().Fonts().AddFontFromMemoryTTFV(hsassets.FontDiabloRegular, 15, 0, imgui.CurrentIO().Fonts().GlyphRangesChineseFull())

if err := a.setup(); err != nil {
log.Fatal(err)
}
Expand Down
24 changes: 24 additions & 0 deletions hscommon/hsenum/locales.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package hsenum

type Locale byte

const (
LocaleEnglish Locale = iota
LocaleChinaTraditional
LocaleKorean
)

func (l Locale) String() string {
lookup := map[Locale]string{
LocaleEnglish: "English",
LocaleChinaTraditional: "China (Traditional)",
LocaleKorean: "Korean",
}

value, ok := lookup[l]
if !ok {
return "Unknown"
}

return value
}
3 changes: 3 additions & 0 deletions hsconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"strings"

"github.com/OpenDiablo2/HellSpawner/hscommon/hsenum"
"github.com/OpenDiablo2/HellSpawner/hscommon/hsstate"

"github.com/kirsle/configdir"
Expand All @@ -31,6 +32,7 @@ type Config struct {
ExternalListFile string `json:"ExternalListFile"`
OpenMostRecentOnStartup bool `json:"OpenMostRecentOnStartup"`
ProjectStates map[string]hsstate.AppState `json:"ProjectStates"`
Locale hsenum.Locale `json:"Locale"`
}

// GetConfigPath returns default config path
Expand All @@ -49,6 +51,7 @@ func generateDefaultConfig(path string) *Config {
RecentProjects: []string{},
OpenMostRecentOnStartup: true,
ProjectStates: make(map[string]hsstate.AppState),
Locale: hsenum.LocaleEnglish,
}

if err := result.Save(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions hswidget/fonttablewidget/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (p *widget) makeEditRuneLayout() giu.Layout {
state.mode = modeViewer
}, state.editRuneState.editedRune),
),
giu.Label("是"),
}
}

Expand Down
1 change: 0 additions & 1 deletion hswidget/palettegrideditorwidget/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func (p *PaletteGridEditorWidget) Build() {
state := p.getState()

colors := make([]palettegridwidget.PaletteColor, len(*p.colors))

for n := range *(p.colors) {
colors[n] = (*p.colors)[n]
}
Expand Down
1 change: 1 addition & 0 deletions hswindow/hsdialog/hsaboutdialog/aboutdialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (a *AboutDialog) Build() {
g.Label("HellSpawner").Color(&colorWhite).Font(&a.titleFont),
g.Label("The OpenDiablo 2 Toolset").Color(&colorWhite).Font(&a.regularFont),
g.Label("Local Build").Color(&colorWhite).Font(&a.fixedFont),
g.Label("铁憨憨你好").Color(&colorWhite).Font(&a.fixedFont),
g.Separator(),
g.TabBar("AboutHellSpawnerTabBar").Flags(g.TabBarFlagsNoCloseWithMiddleMouseButton).Layout(g.Layout{
g.TabItem("README##AboutHellSpawner").Layout(g.Layout{
Expand Down
4 changes: 2 additions & 2 deletions hswindow/hstoolwindow/hsconsole/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (c *Console) Build() {
g.PushFont(c.fontFixed)
}),
g.InputTextMultiline("", &c.outputText).
Size(lineW, lineH).
Flags(g.InputTextFlagsReadOnly | g.InputTextFlagsNoUndoRedo),
Size(lineW, lineH),
// Flags(g.InputTextFlagsReadOnly | g.InputTextFlagsNoUndoRedo),
g.Custom(func() {
g.PopFont()
}),
Expand Down

0 comments on commit 509c9fc

Please sign in to comment.