(card *Card)
| 2538 | } |
| 2539 | |
| 2540 | func NewMapContents(card *Card) *MapContents { |
| 2541 | |
| 2542 | mc := &MapContents{ |
| 2543 | DefaultContents: newDefaultContents(card), |
| 2544 | Buttons: []*IconButton{}, |
| 2545 | PatternButtons: map[int]*Button{}, |
| 2546 | } |
| 2547 | |
| 2548 | mc.MapData = NewMapData(mc) |
| 2549 | |
| 2550 | toolButtons := []*sdl.FRect{ |
| 2551 | {368, 160, 32, 32}, // MapEditToolColors |
| 2552 | |
| 2553 | {368, 0, 32, 32}, // MapEditToolNone |
| 2554 | {368, 32, 32, 32}, // MapEditToolPencil |
| 2555 | {368, 64, 32, 32}, // MapEditToolEraser |
| 2556 | {368, 96, 32, 32}, // MapEditToolBucket |
| 2557 | {368, 128, 32, 32}, // MapEditToolLine |
| 2558 | } |
| 2559 | |
| 2560 | for index, iconSrc := range toolButtons { |
| 2561 | i := index |
| 2562 | button := NewIconButtonTintless(0, 0, iconSrc, globals.GUITexture, true, func() { |
| 2563 | if i != MapEditToolColors { |
| 2564 | mc.Tool = i |
| 2565 | } else { |
| 2566 | globals.MenuSystem.Get("map palette menu").Open() |
| 2567 | } |
| 2568 | }) |
| 2569 | mc.Buttons = append(mc.Buttons, button) |
| 2570 | } |
| 2571 | |
| 2572 | mc.container.AddRow(AlignLeft).Add("icon", NewGUIImage(nil, &sdl.FRect{112, 96, 32, 32}, globals.GUITexture.Texture, true)) |
| 2573 | |
| 2574 | cardWidth := mc.Card.Rect.W |
| 2575 | cardHeight := mc.Card.Rect.H |
| 2576 | |
| 2577 | // New cards have no width or height set yet because the contents have |
| 2578 | // to be set first to get the default width or height |
| 2579 | if cardWidth == 0 || cardHeight == 0 { |
| 2580 | size := mc.DefaultSize() |
| 2581 | cardWidth = size.X |
| 2582 | cardHeight = size.Y |
| 2583 | } |
| 2584 | |
| 2585 | mc.MapData.Resize(int(cardWidth/globals.GridSize), int(cardHeight/globals.GridSize)) |
| 2586 | |
| 2587 | if mc.Card.Properties.Get("contents").AsString() != "" { |
| 2588 | mc.MapData.Deserialize(mc.Card.Properties.Get("contents").AsString()) |
| 2589 | } else { |
| 2590 | mc.Card.Properties.Get("contents").SetRaw(mc.MapData.Serialize()) |
| 2591 | } |
| 2592 | |
| 2593 | paletteMenu := globals.MenuSystem.Get("map palette menu") |
| 2594 | mc.PatternButtons[MapPatternSolid] = paletteMenu.Pages["root"].FindElement("pattern solid", false).(*Button) |
| 2595 | mc.PatternButtons[MapPatternDotted] = paletteMenu.Pages["root"].FindElement("pattern dotted", false).(*Button) |
| 2596 | mc.PatternButtons[MapPatternChecked] = paletteMenu.Pages["root"].FindElement("pattern checked", false).(*Button) |
| 2597 | mc.PatternButtons[MapPatternCrossed] = paletteMenu.Pages["root"].FindElement("pattern crossed", false).(*Button) |
no test coverage detected