ボタンクリックでウインドウを表示する。
テキストの編集と保存、読み込みを全て実行できる
これは問題なく読み込みまで機能するので使える。最初のCategory-AとBボタンは消えて、新しいウインドウが表示される。
Category-Aボタンをクリックすると

この画面が出る。ボックスで編集すると、その下に変更テキストがリアルタイムに表示され、「SAVE-A」ボタンをクリックすると

「PoloInput.save」ファイルに以下のように保存される。

X-Planeを再起動しても、このファイルからテキストが再度読み込まれるので同じテキストが表示される。
右下を基準に配置する場合の設定
FileNamePolo = SCRIPT_DIRECTORY .. "PoloInput.save"
Input_A_text = "ABC"
Input_B_text = "123.456"
-- ファイルを開く
backupfile = io.open(FileNamePolo)
if backupfile ~= nil then
bucontent = backupfile:lines()
Fctr = 0
Input_A_text = bucontent(Fctr)
Input_B_text = bucontent(Fctr + 1)
Fctr = Fctr + 2
backupfile:close()
end
scrWidth, scrHeight = XPLMGetScreenSize()
-- ウインドウの作成 ----------------------------------------------------------------------
PoloWindow = float_wnd_create(10, 10, 2, true)
float_wnd_set_title(PoloWindow, "Polo Input Window")
float_wnd_set_position(PoloWindow, 10, 10)
float_wnd_set_onclose(PoloWindow, "closed_PoloWindow")
float_wnd_set_imgui_builder(PoloWindow, "button_window")
float_wnd_set_onclick(PoloWindow, "button_on_click")
float_wnd_set_geometry(PoloWindow, scrWidth - 336, 40, scrWidth, 0)
----------------------------------------------------------------------------------------
-- 最初に表示されるボタンのウインドウを作成
function button_window(PoloWindow, x, y)
imgui.BeginChild("button_window_Child", 450, 24)
imgui.SetWindowFontScale(1) -- フォントのお大きさ
-- ラジオボタン
if imgui.Button("Category-A", 100, 26) then
float_wnd_set_geometry(PoloWindow, scrWidth - 400, 820, scrWidth, 0)
float_wnd_set_imgui_builder(PoloWindow, "window_1")
end
imgui.SameLine()
imgui.SetCursorPosX(110)
-- Navボタン
if imgui.Button("Category-B", 100, 26) then
float_wnd_set_geometry(PoloWindow, scrWidth - 400, 820, scrWidth, 0)
float_wnd_set_imgui_builder(PoloWindow, "window_2")
end
imgui.SameLine()
imgui.SetCursorPosX(220)
imgui.EndChild()
end
-- 1番目のウインドウ
function window_1(PoloWindow, x, y)
imgui.BeginChild("First_window_Child", 400, 800)
imgui.SetWindowFontScale(1)
--imgui.TextUnformatted(" ")
local changed, Input_A_text_new = imgui.InputText("InputA", Input_A_text,18)
if changed then
Input_A_text = Input_A_text_new
end
local changed, Input_B_text_new = imgui.InputText("InputB", Input_B_text,18)
if changed then
Input_B_text = Input_B_text_new
end
imgui.TextUnformatted(Input_A_text)
imgui.TextUnformatted(Input_B_text)
if imgui.Button("SAVE-A", 60, 30) then
Write_and_Save_to_Disk()
float_wnd_set_geometry(PoloWindow, scrWidth - 336, 40, scrWidth, 0)
float_wnd_set_imgui_builder(PoloWindow, "button_window")
end
imgui.EndChild()
end
-- 2番目のウインドウ(内容の記述無し)
function window_2(PoloWindow, x, y)
imgui.BeginChild("Second_window_Child", 400, 800)
imgui.SetWindowFontScale(1)
if imgui.Button("SAVE-B", 60, 30) then
Write_and_Save_to_Disk() -- 入力テキストをディスクに書き込み保存
float_wnd_set_geometry(PoloWindow, scrWidth - 336, 40, scrWidth, 0) -- 位置とサイズを指定、
float_wnd_set_imgui_builder(PoloWindow, "button_window")
end
imgui.EndChild()
end
function button_on_click(PoloWindow, x, y, state) end
function closed_PoloWindow(wnd) end
-- ディsクへの書き込みと保存
function Write_and_Save_to_Disk()
fileES = io.open(FileNamePolo, "w")
fileES:write(Input_A_text .. "\n")
fileES:write(Input_B_text .. "\n")
fileES:close()
end
左下を基準に配置する場合の設定
FileNamePolo = SCRIPT_DIRECTORY .. "PoloInput.save"
-- 初期設定
Input_A_text = "ABC"
Input_B_text = "123.456"
-- ファイルを開く
backupfile = io.open(FileNamePolo)
if backupfile ~= nil then
bucontent = backupfile:lines()
Fctr = 0
Input_A_text = bucontent(Fctr)
Input_B_text = bucontent(Fctr + 1)
Fctr = Fctr + 2
backupfile:close()
end
-- 画面が変化するサイズをリアルタイムにに取得
screen_Width, screen_Height = XPLMGetScreenSize()
-- ウインドウの作成 ----------------------------------------------------------------------
PoloWindow = float_wnd_create(10, 10, 2, true)
float_wnd_set_title(PoloWindow, "Polo Input Window")
float_wnd_set_position(PoloWindow, 10, 10)
float_wnd_set_onclose(PoloWindow, "closed_PoloWindow")
float_wnd_set_imgui_builder(PoloWindow, "button_window")
float_wnd_set_onclick(PoloWindow, "button_on_click")
-- 最初に表示される2つのボタンの位置を設定
--float_wnd_set_geometry(PoloWindow, screen_Width - 336, 40, screen_Width, 0) -- screen_Widthを使うことで、画面の右下が起点になっている。
float_wnd_set_geometry(PoloWindow, 300, 50, 526, 10) -- 最初に2つのボタン表示。
----------------------------------------------------------------------------------------
-- 最初に表示されるボタンのウインドウを作成
function button_window(PoloWindow, x, y)
imgui.BeginChild("button_window_Child", 450, 24) --2つのボタンが入る子ウインドウのサイズ、幅と高さ(右下が起点)
imgui.SetWindowFontScale(1) -- フォントのお大きさ
-- ラジオボタン
if imgui.Button("Category-A", 100, 26) then
--float_wnd_set_geometry(PoloWindow, screen_Width - 400, 820, screen_Width, 0) --右下が基準の場合
float_wnd_set_geometry(PoloWindow, 300, 180, 636, 30) --1番目のウインドウの位置とサイズ(左下が起点)
float_wnd_set_imgui_builder(PoloWindow, "window_1")
end
imgui.SameLine()
imgui.SetCursorPosX(110)
-- Navボタン
if imgui.Button("Category-B", 100, 26) then
--float_wnd_set_geometry(PoloWindow, screen_Width - 400, 820, screen_Width, 0) --右下が基準の場合
float_wnd_set_geometry(PoloWindow, 300, 180, 636, 30) --2番目のウインドウの位置とサイズ(左下が起点)
float_wnd_set_imgui_builder(PoloWindow, "window_2")
end
imgui.SameLine()
imgui.SetCursorPosX(220)
imgui.EndChild()
end
-- 1番目のウインドウ
function window_1(PoloWindow, x, y)
imgui.BeginChild("First_window_Child", 400, 800) --ウインドウの大きさ
imgui.SetWindowFontScale(1)
--imgui.TextUnformatted(" ")
local changed, Input_A_text_new = imgui.InputText("InputA", Input_A_text,18)
if changed then
Input_A_text = Input_A_text_new
end
local changed, Input_B_text_new = imgui.InputText("InputB", Input_B_text,18)
if changed then
Input_B_text = Input_B_text_new
end
imgui.TextUnformatted(Input_A_text)
imgui.TextUnformatted(Input_B_text)
if imgui.Button("SAVE-A", 60, 30) then
Write_and_Save_to_Disk() --SAVEボタンでテキストを保存
--float_wnd_set_geometry(PoloWindow, screen_Width - 336, 40, screen_Width, 0) --右下が基準の場合
float_wnd_set_geometry(PoloWindow, 300, 50, 526, 10) -- SAVEボタンで2つのボタンを入れる枠の再表示。
float_wnd_set_imgui_builder(PoloWindow, "button_window")-- SAVEボタンで2つのボタンを再表示。
end
imgui.EndChild()
end
-- 2番目のウインドウ(内容の記述無し)
function window_2(PoloWindow, x, y)
imgui.BeginChild("Second_window_Child", 400, 800) --ウインドウの大きさ
imgui.SetWindowFontScale(1)
if imgui.Button("SAVE-B", 60, 30) then
Write_and_Save_to_Disk() -- 入力テキストをディスクに書き込み保存
--float_wnd_set_geometry(PoloWindow, screen_Width - 336, 40, screen_Width, 0) --右下が基準の場合
float_wnd_set_geometry(PoloWindow, 300, 50, 526, 10) -- SAVEボタンで2つのボタンを入れる枠の再表示。
float_wnd_set_imgui_builder(PoloWindow, "button_window")
end
imgui.EndChild()
end
function button_on_click(PoloWindow, x, y, state) end
function closed_PoloWindow(wnd) end
-- ディsクへの書き込みと保存
function Write_and_Save_to_Disk()
fileES = io.open(FileNamePolo, "w")
fileES:write(Input_A_text .. "\n")
fileES:write(Input_B_text .. "\n")
fileES:close()
end
変更したファイルを読み込む
— 既にPersistentParking.txtが存在する必要がある。
local file = io.open(SCRIPT_DIRECTORY..”ExtendedStack.save”, “r”)
for line in file:lines() do
imgui.TextUnformatted(line) –ここ「line」に読み込む
end
file:close() — 最後にf:closeでファイルを閉じる
for文を使ったインプットボックス
入力したテキストは再起動しても維持される。問題なく動作しているのを確認。下の分はfor文を使っているが2つまでしか作成できないように設定しているので表示が2つだけになっている。数値を変更するだけで同じパターンをいくつでも作ることができる。


FileNamePolo = SCRIPT_DIRECTORY .. "PoloInput.save"
Input_A_text = {}
Input_B_text = {}
for input_box = 1, 10 do
Input_A_text[input_box] = "ABC" .. input_box
Input_B_text[input_box] = "123.40"
end
-- ファイルを開く
backupfile = io.open(FileNamePolo)
if backupfile ~= nil then
bucontent = backupfile:lines()
Fctr = 0
for input_box = 1, 10 do
Input_A_text[input_box] = bucontent(Fctr + input_box)
Input_B_text[input_box] = bucontent(Fctr + input_box + 1)
Fctr = Fctr + 2
end
backupfile:close()
end
scrWidth, scrHeight = XPLMGetScreenSize()
-- ウインドウの作成 ----------------------------------------------------------------------
PoloWindow = float_wnd_create(10, 10, 2, true)
float_wnd_set_title(PoloWindow, "Polo Input Window")
float_wnd_set_position(PoloWindow, 10, 10)
float_wnd_set_onclose(PoloWindow, "closed_PoloWindow")
float_wnd_set_imgui_builder(PoloWindow, "button_window")
float_wnd_set_onclick(PoloWindow, "button_on_click")
float_wnd_set_geometry(PoloWindow, scrWidth - 336, 40, scrWidth, 0)
----------------------------------------------------------------------------------------
-- 最初に表示されるボタンのウインドウを作成
function button_window (PoloWindow, x, y)
imgui.BeginChild("button_window_Child", 450, 24)
imgui.SetWindowFontScale(1) --フォントのお大きさ
-- ラジオボタン
if imgui.Button("Category-A", 100, 26) then
float_wnd_set_geometry(PoloWindow, scrWidth - 400, 820, scrWidth, 0)
float_wnd_set_imgui_builder(PoloWindow, "window_1")
end
imgui.SameLine()
imgui.SetCursorPosX(110)
-- Navボタン
if imgui.Button("Category-B", 100, 26) then
float_wnd_set_geometry(PoloWindow, scrWidth - 400, 820, scrWidth, 0)
float_wnd_set_imgui_builder(PoloWindow, "window_2")
end
imgui.SameLine()
imgui.SetCursorPosX(220)
imgui.EndChild()
end
-- 1番目のウインドウ
function window_1 (PoloWindow, x, y)
imgui.BeginChild("First_window_Child", 400, 800)
imgui.SetWindowFontScale(1.2)
if imgui.Button("CLOSE", 60, 30) then
Write_and_Save_to_Disk()
float_wnd_set_geometry(PoloWindow, scrWidth - 336, 40, scrWidth, 0)
float_wnd_set_imgui_builder(PoloWindow, "button_window")
end
for input_box = 1, 2 do
imgui.TextUnformatted(" ")
local changed, Input_A_text_new = imgui.InputText("InputA-" .. input_box,Input_A_text[input_box], 18)
if changed then
Input_A_text[input_box] = Input_A_text_new
end
imgui.SameLine()
end
imgui.EndChild()
end
-- 2番目のウインドウ
function window_2 (PoloWindow, x, y)
imgui.BeginChild("Second_window_Child", 400, 800)
imgui.SetWindowFontScale(1.2)
if imgui.Button("CLOSE", 60, 30) then
Write_and_Save_to_Disk() --入力テキストをディスクに書き込み保存
float_wnd_set_geometry(PoloWindow, scrWidth - 336, 40, scrWidth, 0) --位置とサイズを指定、
float_wnd_set_imgui_builder(PoloWindow, "button_window")
end
imgui.EndChild()
end
function button_on_click(PoloWindow, x, y, state) end
function closed_PoloWindow(wnd) end
-- ディsクへの書き込みと保存
function Write_and_Save_to_Disk()
fileES = io.open(FileNamePolo, "w")
for input_box = 1, 10 do
fileES:write(Input_A_text[input_box] .. "\n")
fileES:write(Input_B_text[input_box] .. "\n")
end
fileES:close()
end