Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created August 15, 2025 13:46
Show Gist options
  • Select an option

  • Save todorok1/95d25ebc4c67e8e3a00efbd6e967caee to your computer and use it in GitHub Desktop.

Select an option

Save todorok1/95d25ebc4c67e8e3a00efbd6e967caee to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第119回 選択ウィンドウを制御するクラス
/// <summary>
/// 右側の項目を選択します。
/// </summary>
void SelectRightItem()
{
// 左側の項目を選択していない場合は何もしません。
if (!IsLeftColumn())
{
return;
}
// 移動先のインデックスに魔法が存在する場合はカーソルを移動します。
if (IsValidIndex(_selectedIndex + 1))
{
_selectedIndex += 1;
}
PostSelection();
}
/// <summary>
/// 左側の項目を選択します。
/// </summary>
void SelectLeftItem()
{
// 右側の項目を選択していない場合は何もしません。
if (IsLeftColumn())
{
return;
}
// 移動先のインデックスに魔法が存在する場合はカーソルを移動します。
if (IsValidIndex(_selectedIndex - 1))
{
_selectedIndex -= 1;
}
PostSelection();
}
/// <summary>
/// 現在の選択位置が左側のカラムかどうかを確認します。
/// </summary>
bool IsLeftColumn()
{
int currentColmun = _selectedIndex % 2;
int leftColumn = 0;
return currentColmun == leftColumn;
}
/// <summary>
/// ひとつ上の項目を選択します。
/// </summary>
void SelectUpperItem()
{
if (IsUpperRow())
{
if (_page > 0)
{
_page -= 1;
SetPageElement();
_selectedIndex = _page * 4;
}
}
else
{
if (IsValidIndex(_selectedIndex - 2))
{
_selectedIndex -= 2;
}
}
PostSelection();
}
/// <summary>
/// ひとつ下の項目を選択します。
/// </summary>
void SelectLowerItem()
{
if (IsUpperRow())
{
if (IsValidIndex(_selectedIndex + 2))
{
_selectedIndex += 2;
}
}
else
{
if (_page < GetMaxPageNum() - 1)
{
_page += 1;
SetPageElement();
_selectedIndex = _page * 4;
}
}
PostSelection();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment