1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-09-29 22:56:07 -04:00

code cleanup

This commit is contained in:
M. Sz 2020-11-26 12:25:47 +01:00
parent 570d71845e
commit 640a9e043d
3 changed files with 8 additions and 10 deletions

View File

@ -135,11 +135,6 @@ func SplitIntoLinesWithMaxWidth(fullSentence string, maxChars int) []string {
return lines
}
// SplitIntoLinesWithMaxWidthOneLine does the same as SplitIntoLinesWithMaxWidth but return string with newline char
func SplitIntoLinesWithMaxWidthOneLine(s string, l int) string {
return strings.Join(SplitIntoLinesWithMaxWidth(s, l), "\n")
}
func splitCjkIntoChunks(str string, chars int) []string {
chunks := make([]string, chars/len(str))
i, count := 0, 0

View File

@ -5,6 +5,7 @@ import (
"math"
"os"
"strconv"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
@ -229,7 +230,7 @@ func (v *CharacterSelect) loadHeroTitle() {
func (v *CharacterSelect) loadDeleteCharConfirm() {
v.deleteCharConfirmLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits)
lines := d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateLabel(delCharConfLabel), 30)
lines := strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateLabel(delCharConfLabel), 30), "\n")
v.deleteCharConfirmLabel.SetText(lines)
v.deleteCharConfirmLabel.Alignment = d2ui.HorizontalAlignCenter
deleteConfirmX, deleteConfirmY := 400, 185
@ -292,17 +293,18 @@ func rgbaColor(rgba uint32) color.RGBA {
}
func (v *CharacterSelect) createButtons(loading d2screen.LoadingState) {
v.newCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateString("#831"), 13))
v.newCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, strings.Join(
d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateString("#831"), 13), "\n"))
v.newCharButton.SetPosition(newCharBtnX, newCharBtnY)
v.newCharButton.OnActivated(func() { v.onNewCharButtonClicked() })
v.convertCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall,
d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateString("#825"), 13))
strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateString("#825"), 13), "\n"))
v.convertCharButton.SetPosition(convertCharBtnX, convertCharBtnY)
v.convertCharButton.SetEnabled(false)
v.deleteCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall,
d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateString("#832"), 13))
strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateString("#832"), 13), "\n"))
v.deleteCharButton.OnActivated(func() { v.onDeleteCharButtonClicked() })
v.deleteCharButton.SetPosition(deleteCharBtnX, deleteCharBtnY)

View File

@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"runtime"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
@ -344,7 +345,7 @@ func (v *MainMenu) createLabels(loading d2screen.LoadingState) {
v.tcpJoinGameLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits)
v.tcpJoinGameLabel.Alignment = d2ui.HorizontalAlignCenter
v.tcpJoinGameLabel.SetText(d2util.SplitIntoLinesWithMaxWidthOneLine(v.asset.TranslateLabel(tcpIPEnterHostIPLabel), 27))
v.tcpJoinGameLabel.SetText(strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateLabel(tcpIPEnterHostIPLabel), 27), "\n"))
v.tcpJoinGameLabel.Color[0] = rgbaColor(gold)
v.tcpJoinGameLabel.SetPosition(joinGameX, joinGameY)