自作 Quick Look View 画像ボタンの作成 – FlyWithLua

2023年8月24日

X-Planeのデフォルトで使えるQuick Look Viewを簡単につかえるようにした。
画像を希望の位置に移動させM0〜M19までのメモリーボタンをクリックすることにより、その画面を保存して、画像ボタンをクリックしたら記憶されて位置に簡単に移動できるようになる。

-- 画像県警の初期設定 ----
image_B_1 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-1.png") --3-5
image_B_2 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-2.png") --2-4
image_B_3 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-3.png") --1-4
image_B_4 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-4.png") --1-5
image_B_5 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/unknown.png")
image_B_6 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/unknown.png")
image_B_7 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/unknown.png")
image_B_8 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-8.png")   --3-3
image_B_9 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-9.png")   --2-3
image_B_10 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-10.png") --1-3
image_B_11 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-11.png") --3-2
image_B_12 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-12.png") --ウインドウ左45度
image_B_13 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-13.png") --4-3
image_B_14 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-14.png") --4-4
image_B_15 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-15.png") --3-4
image_B_16 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-16.png") --2-2
image_B_17 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-17.png") --5-2
image_B_18 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-18.png") --5-3
image_B_19 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/B-19.png") --5-4
image_B_20 = float_wnd_load_image(SCRIPT_DIRECTORY .. "/tab_img/unknown.png")
image_B = { image_B_1, image_B_2, image_B_3, image_B_4, image_B_5, image_B_6, image_B_7, image_B_8, image_B_9,
	image_B_10, image_B_11, image_B_12, image_B_13, image_B_14, image_B_15, image_B_16, image_B_17, image_B_18,
	image_B_19, image_B_20 }

-- Quick Look 記憶ボタン用(1〜5段と2〜5列)
local quick_look_Memory_Command = {
	"sim/view/quick_look_0_mem", "sim/view/quick_look_1_mem", "sim/view/quick_look_2_mem", "sim/view/quick_look_3_mem",
	"sim/view/quick_look_4_mem", "sim/view/quick_look_5_mem", "sim/view/quick_look_6_mem", "sim/view/quick_look_7_mem",
	"sim/view/quick_look_8_mem", "sim/view/quick_look_9_mem", "sim/view/quick_look_10_mem", "sim/view/quick_look_11_mem",
	"sim/view/quick_look_12_mem", "sim/view/quick_look_13_mem", "sim/view/quick_look_14_mem",
	"sim/view/quick_look_15_mem",
	"sim/view/quick_look_16_mem", "sim/view/quick_look_17_mem", "sim/view/quick_look_18_mem",
	"sim/view/quick_look_19_mem"
}
local quick_look_Command = { "sim/view/quick_look_0", "sim/view/quick_look_1", "sim/view/quick_look_2",
	"sim/view/quick_look_3", "sim/view/quick_look_4",
	"sim/view/quick_look_5", "sim/view/quick_look_6", "sim/view/quick_look_7", "sim/view/quick_look_8",
	"sim/view/quick_look_9", "sim/view/quick_look_10",
	"sim/view/quick_look_11", "sim/view/quick_look_12", "sim/view/quick_look_13", "sim/view/quick_look_14",
	"sim/view/quick_look_15", "sim/view/quick_look_16",
	"sim/view/quick_look_17", "sim/view/quick_look_18", "sim/view/quick_look_19"
}
local Image_Button_posX = { "10", "145", "280", "415", "550", "10", "145", "280", "415", "550", "10", "145", "280",
	"415",
	"550", "10", "145", "280", "415", "550", "10", "145", "280", "415", "550" } --左のボタンからの位置 +135
local Image_Button_posY = { "52", "52", "52", "52", "52", "147", "147", "147", "147", "147", "242", "242", "242", "242",
	"242", "337", "337", "337", "337", "337" }                               --上のボタンからの位置 +95
local memory_Button_posX = { "10", "145", "280", "415", "550", "10", "145", "280", "415", "550", "10", "145", "280",
	"415",
	"550", "10", "145", "280", "415", "550", "10", "145", "280", "415", "550" }
local memory_Button_posY = { "123", "123", "123", "123", "123", "218", "218", "218", "218", "218", "313", "313", "313",
	"313", "313", "408", "408", "408", "408", "408" }
local number_Button_posX = { "15", "150", "285", "420", "555", "15", "150", "285", "420", "555", "15", "150", "285",
	"420", "555",
	"15", "150", "285", "420", "555", "15", "150", "285", "420", "555" }
local number_Button_posY = { "54", "54", "54", "54", "54", "149", "149", "149", "149", "149", "244", "244", "244",
	"244", "244", "339", "339", "339", "339", "339" }
local Quick_View_label_text = { "Cockpit Door", "Guest Room", "Left Wing", "Right Wing", "quick_look_4", "quick_look_5",
	"quick_look_6", "Head Panel-1", "Head Panel-2", "Head Panel-3", "Left 90 Deg", "Left 45 Deg", "Cockpit Front",
	"Right 45 Deg", "Right 90 Deg", "TWKSTER", "FMS", "Throttle", "Frequency", "quick_look_19", }

---------------------------------------------------------------------------------
view_selector_wnd = float_wnd_create(825, 442, 1, true)
float_wnd_set_position(view_selector_wnd, 300, 100)
float_wnd_set_title(view_selector_wnd, "X-Plane View Selector")
float_wnd_set_imgui_builder(view_selector_wnd, "view_selector_build_wnd")
float_wnd_set_onclose(view_selector_wnd, "on_close")
---------------------------------------------------------------------------------

function view_selector_build_wnd(view_selector_wnd, x, y)
	if imgui.BeginTabBar("KF_Select_flight_view_tabs") then -- flag NoToolTip flag ツールヒントなし
		if imgui.BeginTabItem("B_Quick View") then
			----------タブの内容を入れるスペース---------------
			for i = 1, 20, 1 do
				imgui.SetCursorPosX(Image_Button_posX[i])
				imgui.SetCursorPosY(Image_Button_posY[i])
				imgui.PushStyleColor(imgui.constant.Col.Button, "0xFF228B22") --紫
				if imgui.ImageButton(image_B[i], 120, 65) then
					command_once("SRS/X-Camera/Disable_X-Camera") --有効無効のトグル
					command_once(quick_look_Command[i])
				end
				imgui.PopStyleColor()
				--メモリーボタン
				imgui.SetCursorPosX(memory_Button_posX[i])
				imgui.SetCursorPosY(memory_Button_posY[i])
				if imgui.Button("M" .. (i - 1)) then
					command_once(quick_look_Memory_Command[i])
				end
				imgui.SameLine() --以下を横に入れる
				--ボタン下のテキスト(中心に入れる設定)
				local Quick_View_label = Quick_View_label_text[i]
				local text_size = imgui.CalcTextSize(Quick_View_label)                     --テキストのサイズを取得
				--68はボタンの中心位置、テキストサイズを半分にして引くとボタンに対してテキストが中心になる。
				imgui.SetCursorPos(80 + Image_Button_posX[i] - (text_size / 2), imgui.GetCursorPosY()) --パラメーターは、Xの位置と、Yの位置
				imgui.TextUnformatted(Quick_View_label)
				--ボタンナンバーの位置とラベル
				imgui.SetCursorPosX(number_Button_posX[i])
				imgui.SetCursorPosY(number_Button_posY[i])
				imgui.TextUnformatted("B-" .. i)
			end
			--円を作成してX-Cameraのオンオフ表示する。--------------------------
			dataref("XCamera_Enabled", "SRS/X-Camera/integration/X-Camera_enabled") --1か0かの判定用
			if XCamera_Enabled == 1 then                                   --0のとき黄緑ONを表示
				imgui.DrawList_AddCircleFilled(690, 67, 7, 0xFF00FF00)     -- +95 円を作成 1段目 黄緑ONの色 1-2、1-3、1-4、1-5
			else
				imgui.DrawList_AddCircleFilled(690, 67, 7, 0x50FFFFFF)     -- +95 円を作成 1段目 グレー 1-2、1-3、1-4、1-5
			end
			imgui.SetCursorPosX(705)
			imgui.SetCursorPosY(60)
			imgui.TextUnformatted("X-Camera ON/OFF")
			----------タブの内容を入れる END---------------
			imgui.EndTabItem()
		end
		imgui.EndTabBar()
	end
end