-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace house allies text box with a graphical ally selector window
- Loading branch information
1 parent
53b8cce
commit 20d2e7b
Showing
6 changed files
with
156 additions
and
12 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/TSMapEditor/Config/UI/Windows/ConfigureAlliesWindow.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[ConfigureAlliesWindow] | ||
$CC0=lblDescription:XNALabel | ||
$Width=getRight(lblDescription) + 40 | ||
$CC1=panelCheckBoxes:XNAPanel | ||
$CC2=btnApply:EditorButton | ||
HasCloseButton=yes | ||
|
||
[lblDescription] | ||
$X=EMPTY_SPACE_SIDES | ||
$Y=EMPTY_SPACE_TOP | ||
Text=Select which houses this house is allied to. | ||
|
||
[panelCheckBoxes] | ||
$X=EMPTY_SPACE_SIDES | ||
$Y=getBottom(lblDescription) + VERTICAL_SPACING | ||
$Width=getWidth(ConfigureAlliesWindow) - (EMPTY_SPACE_SIDES * 2) | ||
$Height=0 ; placeholder, dynamically generated | ||
DrawBorders=no | ||
|
||
[btnApply] | ||
$Width=100 | ||
$X=horizontalCenterOnParent() | ||
$Y=0 ; placeholder, dynamically generated | ||
Text=Apply |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using Rampastring.XNAUI; | ||
using Rampastring.XNAUI.XNAControls; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using TSMapEditor.Models; | ||
using TSMapEditor.UI.Controls; | ||
|
||
namespace TSMapEditor.UI.Windows | ||
{ | ||
public class ConfigureAlliesWindow : INItializableWindow | ||
{ | ||
public ConfigureAlliesWindow(WindowManager windowManager, Map map) : base(windowManager) | ||
{ | ||
this.map = map; | ||
} | ||
|
||
public event EventHandler AlliesUpdated; | ||
|
||
private readonly Map map; | ||
|
||
private XNAPanel panelCheckBoxes; | ||
private EditorButton btnApply; | ||
|
||
private List<XNACheckBox> checkBoxes = new List<XNACheckBox>(); | ||
|
||
private House house; | ||
|
||
public override void Initialize() | ||
{ | ||
Name = nameof(ConfigureAlliesWindow); | ||
base.Initialize(); | ||
|
||
panelCheckBoxes = FindChild<XNAPanel>(nameof(panelCheckBoxes)); | ||
|
||
btnApply = FindChild<EditorButton>("btnApply"); | ||
btnApply.LeftClick += BtnApply_LeftClick; | ||
} | ||
|
||
private void BtnApply_LeftClick(object sender, EventArgs e) | ||
{ | ||
string allies = string.Join(',', new string[] { house.ININame }.Concat(checkBoxes.FindAll(chk => chk.Checked).Select(chk => chk.Text))); | ||
house.Allies = allies; | ||
|
||
AlliesUpdated?.Invoke(this, EventArgs.Empty); | ||
|
||
Hide(); | ||
} | ||
|
||
public void Open(House house) | ||
{ | ||
this.house = house; | ||
|
||
RefreshCheckBoxes(); | ||
|
||
Show(); | ||
} | ||
|
||
private void RefreshCheckBoxes() | ||
{ | ||
checkBoxes.ForEach(chk => panelCheckBoxes.RemoveChild(chk)); | ||
checkBoxes.Clear(); | ||
|
||
string[] existingAllies = house.Allies.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
int y = 0; | ||
|
||
bool useTwoColumns = map.Houses.Count > 16; | ||
bool isSecondColumn = false; | ||
|
||
foreach (var otherHouse in map.Houses) | ||
{ | ||
if (otherHouse == house) | ||
continue; | ||
|
||
var checkBox = new XNACheckBox(WindowManager); | ||
checkBox.Name = "chk" + otherHouse.ININame; | ||
checkBox.X = isSecondColumn ? 150 : 0; | ||
checkBox.Y = y; | ||
checkBox.Text = otherHouse.ININame; | ||
checkBox.Checked = Array.Exists(existingAllies, s => s == otherHouse.ININame); | ||
panelCheckBoxes.AddChild(checkBox); | ||
checkBoxes.Add(checkBox); | ||
|
||
if (!useTwoColumns || isSecondColumn) | ||
y = checkBox.Bottom + Constants.UIVerticalSpacing; | ||
|
||
if (useTwoColumns) | ||
isSecondColumn = !isSecondColumn; | ||
} | ||
|
||
panelCheckBoxes.Height = y - Constants.UIVerticalSpacing; | ||
btnApply.Y = panelCheckBoxes.Bottom + Constants.UIEmptyTopSpace; | ||
Height = btnApply.Bottom + Constants.UIEmptyBottomSpace; | ||
|
||
CenterOnParent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters