Back to Home

ESO Lua File v100031

ingame/housingeditor/housingeditorhud.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
HOUSING_EDITOR_POSITION_AXIS_X1 = 1
HOUSING_EDITOR_POSITION_AXIS_X2 = 2
HOUSING_EDITOR_POSITION_AXIS_Y1 = 3
HOUSING_EDITOR_POSITION_AXIS_Y2 = 4
HOUSING_EDITOR_POSITION_AXIS_Z1 = 5
HOUSING_EDITOR_POSITION_AXIS_Z2 = 6
HOUSING_EDITOR_ROTATION_AXIS_X1 = 7
HOUSING_EDITOR_ROTATION_AXIS_X2 = 8
HOUSING_EDITOR_ROTATION_AXIS_Y1 = 9
HOUSING_EDITOR_ROTATION_AXIS_Y2 = 10
HOUSING_EDITOR_ROTATION_AXIS_Z1 = 11
HOUSING_EDITOR_ROTATION_AXIS_Z2 = 12
local PI = math.pi
local TWO_PI = 2 * PI
local HALF_PI = 0.5 * PI
local QUARTER_PI = 0.25 * PI
local AXIS_INDICATOR_ALPHA_ACTIVE_PERCENTAGE = 0.6
local AXIS_INDICATOR_ALPHA_INACTIVE_PERCENTAGE = 0
local AXIS_INDICATOR_ALPHA_MAX_PERCENTAGE = 0.6
local AXIS_INDICATOR_RGB_WEIGHT_MIN_PERCENTAGE = 1.4
local AXIS_INDICATOR_RGB_WEIGHT_MAX_PERCENTAGE = 3
local AXIS_INDICATOR_SCALE_MAX = 3
local AXIS_INDICATOR_SCALE_MIN = 1
local AXIS_INDICATOR_PICKUP_YAW_OFFSET_ANGLE = math.rad(20)
local AXIS_KEYBIND_RGB_WEIGHT_MIN_PERCENTAGE = 0.3
local AXIS_KEYBIND_RGB_WEIGHT_MAX_PERCENTAGE = 0.7
local AXIS_MAX_DRAW_LEVEL = 100000
local ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M = 2.25
local TRANSLATION_AXIS_RANGE_MAX_CM = 10000
-- Texture height / width, specified in pixels.
local TRANSLATION_AXIS_INDICATOR_LOCAL_X_DIMENSION_M = 1
local TRANSLATION_AXIS_INDICATOR_LOCAL_Y_DIMENSION_M = 0.5
-- Yaw offset, in radians, for the Y-axis indicator while in pickup mode.
-- This slight offset allows the axis to remain visible and interactive
-- while it is rotationally locked to the camera's heading.
local Y_AXIS_INDICATOR_YAW_OFFSET_RAD = -(PI * 15 / 180)
local X_AXIS_NEGATIVE_INDICATOR_COLOR = ZO_ColorDef:New(0, 0.5, 0.9, 1)
local X_AXIS_POSITIVE_INDICATOR_COLOR = ZO_ColorDef:New(0, 0.5, 0.9, 1)
local Y_AXIS_NEGATIVE_INDICATOR_COLOR = ZO_ColorDef:New(1, 0.2, 0, 1)
local Y_AXIS_POSITIVE_INDICATOR_COLOR = ZO_ColorDef:New(1, 0.2, 0, 1)
local Z_AXIS_NEGATIVE_INDICATOR_COLOR = ZO_ColorDef:New(0, 1, 0.2, 1)
local Z_AXIS_POSITIVE_INDICATOR_COLOR = ZO_ColorDef:New(0, 1, 0.2, 1)
local PRESS_AND_HOLD_ACCELERATION_INTERVAL_MS = 1000
local PRECISION_POSITION_OR_ORIENTATION_UPDATE_INTERVAL_MS = 100
local PRECISION_MOVE_UNITS_CM = {1, 10, 100}
local PRECISION_ROTATE_UNITS_DEG = {0.05, 1, 15}
local PRECISION_ROTATE_INTERVALS_MS = {[0.05] = 120000, [1] = 9000, [15] = 1200}
local PICKUP_ROTATE_INTERVALS_MS = 2000
local PICKUP_AXIS_INDICATOR_DISTANCE_CM = 1000
local DEFAULT_PRECISION_MOVE_UNITS_CM = 10
local DEFAULT_PRECISION_ROTATE_UNITS_DEG = math.rad(15)
local PRECISION_UNIT_ADJUSTMENT_INCREMENT = 1
local PRECISION_UNIT_ADJUSTMENT_DECREMENT = 2
local TEXTURE_ARROW_DIRECTION = "EsoUI/Art/Housing/translation_arrow.dds"
local TEXTURE_ARROW_DIRECTION_INVERSE = "EsoUI/Art/Housing/translation_inverse_arrow.dds"
local TEXTURE_ARROW_ROTATION_FORWARD = "EsoUI/Art/Housing/dual_rotation_arrow.dds"
local TEXTURE_ARROW_ROTATION_REVERSE = "EsoUI/Art/Housing/dual_rotation_arrow_reverse.dds"
local TEXTURE_HOUSE_ICON = "EsoUI/Art/Campaign/Gamepad/gp_overview_menuicon_home.dds"
local function AngleDistance(angle1, angle2)
    local delta = math.abs(angle1 - angle2) % TWO_PI
    return delta < PI and delta or (TWO_PI - delta)
end
--------------------
--HousingEditor HUD Fragment
--------------------
ZO_HousingEditorHUDFragment = ZO_SceneFragment:Subclass()
function ZO_HousingEditorHUDFragment:New(control)
    return ZO_SceneFragment.New(self, control)
end
function ZO_HousingEditorHUDFragment:Show()
    ZO_SceneFragment.Show(self)
end
function ZO_HousingEditorHUDFragment:Hide()
    ZO_SceneFragment.Hide(self)
end
function ZO_HousingEditorHUDFragment:UpdateVisibility()
    local fragmentHidden = not self:IsShowing()
    local playerDead = IsUnitDead("player")
    local hiddenOrDead = fragmentHidden or playerDead
    RETICLE:RequestHidden(hiddenOrDead)
    TUTORIAL_SYSTEM:SuppressTutorialType(TUTORIAL_TYPE_HUD_INFO_BOX, fragmentHidden, TUTORIAL_SUPPRESSED_BY_SCENE)
    SHARED_INFORMATION_AREA:SetSupressed(hiddenOrDead)
end
--------------------
--Housing HUD Fragment
--------------------
local HousingHUDFragment = ZO_HUDFadeSceneFragment:Subclass()
function HousingHUDFragment:New(...)
    return ZO_HUDFadeSceneFragment.New(self, ...)
end
function HousingHUDFragment:Initialize(control)
    ZO_HUDFadeSceneFragment.Initialize(self, control)
    self.keybindButton = self.control:GetNamedChild("KeybindButton")
    ZO_KeybindButtonTemplate_Setup(self.keybindButton, "SHOW_HOUSING_PANEL", function(...) self:OnHousingHUDButtonPressed(...) end, GetString(SI_HOUSING_HUD_FRAGMENT_EDITOR_KEYBIND))
    control:RegisterForEvent(EVENT_PLAYER_ACTIVATED, function() self:OnPlayerActivated() end)
    control:RegisterForEvent(EVENT_HOUSING_PLAYER_INFO_CHANGED, function(eventId, ...) self:OnPlayerInfoChanged(...) end)
end
do
    local KEYBOARD_PLATFORM_STYLE =
    {
        keybindButtonTemplate = "ZO_KeybindButton_Keyboard_Template",
        keybindButtonAnchor = ZO_Anchor:New(BOTTOMRIGHT, nil, BOTTOMRIGHT, -80, -25),
    }
    local GAMEPAD_PLATFORM_STYLE =
    {
        keybindButtonTemplate = "ZO_KeybindButton_Gamepad_Template",
        keybindButtonAnchor = ZO_Anchor:New(BOTTOMLEFT, nil, BOTTOMLEFT, 80, -40),
    }
    function HousingHUDFragment:InitializePlatformStyle()
        self.platformStyle = ZO_PlatformStyle:New(function(style) self:ApplyPlatformStyle(style) end, KEYBOARD_PLATFORM_STYLE, GAMEPAD_PLATFORM_STYLE)
    end
end
function HousingHUDFragment:ApplyPlatformStyle(style)
    ApplyTemplateToControl(self.keybindButton, style.keybindButtonTemplate)
    style.keybindButtonAnchor:Set(self.keybindButton)
    self:UpdateKeybind()
end
function HousingHUDFragment:OnShown()
    ZO_HUDFadeSceneFragment.OnShown(self)
    self:UpdateKeybind()
end
function HousingHUDFragment:OnHousingHUDButtonPressed()
    if self:IsShowing() then
        local visitorRole = GetHousingVisitorRole()
        if visitorRole == HOUSING_VISITOR_ROLE_EDITOR then
            local isHouseOwner = IsOwnerOfCurrentHouse()
            local canEditHouse = HasAnyEditingPermissionsForCurrentHouse()
            if not isHouseOwner and not canEditHouse then
                HousingEditorJumpToSafeLocation()
            else
                local result = HousingEditorRequestModeChange(HOUSING_EDITOR_MODE_SELECTION)
                ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, result)
                if isHouseOwner and IsESOPlusSubscriber() then
                    TriggerTutorial(TUTORIAL_TRIGGER_ENTERED_OWNED_HOUSING_EDITOR_AS_SUBSCRIBER)
                end
            end
        elseif visitorRole == HOUSING_VISITOR_ROLE_PREVIEW then
            SYSTEMS:GetObject("HOUSING_PREVIEW"):ShowDialog()
        end
        PlaySound(SOUNDS.HOUSING_EDITOR_OPEN)
    end
end
do
    local KEYBIND_STRINGS =
    {
        [HOUSING_VISITOR_ROLE_EDITOR] = GetString(SI_HOUSING_HUD_FRAGMENT_EDITOR_KEYBIND),
        [HOUSING_VISITOR_ROLE_PREVIEW] = GetString(SI_HOUSING_HUD_FRAGMENT_PURCHASE_KEYBIND),
        [HOUSING_VISITOR_ROLE_HOME_SHOW] = GetString(SI_HOUSING_HUD_FRAGMENT_VOTE_KEYBIND),
    }
    function HousingHUDFragment:UpdateKeybind()
        local visitorRole = GetHousingVisitorRole()
        local isHouseOwner = IsOwnerOfCurrentHouse()
        local canEditHouse = HasAnyEditingPermissionsForCurrentHouse()
        local keybindString = KEYBIND_STRINGS[visitorRole]
        if visitorRole == HOUSING_VISITOR_ROLE_EDITOR and not isHouseOwner and not canEditHouse then
            keybindString = GetString(SI_HOUSING_EDITOR_SAFE_LOC)
        end
        self.keybindButton:SetText(keybindString)
    end
end
function HousingHUDFragment:CheckShowCopyPermissionsDialog()
    local currentZoneHouseId = GetCurrentZoneHouseId()
    local collectibleId = GetCollectibleIdForHouse(currentZoneHouseId)
    local numHousesUnlocked = GetTotalUnlockedCollectiblesByCategoryType(COLLECTIBLE_CATEGORY_TYPE_HOUSE)
    if COLLECTIONS_BOOK_SINGLETON:DoesHousePermissionsDialogNeedToBeShownForCollectible(collectibleId) and numHousesUnlocked > 1 then
        local data = { currentHouse = currentZoneHouseId }
        if IsInGamepadPreferredMode() then
            ZO_Dialogs_ShowGamepadDialog("GAMEPAD_COPY_HOUSE_PERMISSIONS", data)
        else
            ZO_Dialogs_ShowDialog("COPY_HOUSING_PERMISSIONS", data)
        end
        COLLECTIONS_BOOK_SINGLETON:MarkHouseCollectiblePermissionLoadDialogShown(collectibleId)
    end
end
function HousingHUDFragment:OnPlayerActivated()
    self:UpdateKeybind()
end
function HousingHUDFragment:OnPlayerInfoChanged(wasOwner, permissionsChanged)
    self:UpdateKeybind()
    local isHouseOwner = IsOwnerOfCurrentHouse()
    if not isHouseOwner and permissionsChanged then
        ZO_Alert(UI_ALERT_CATEGORY_ERROR, nil, GetString(SI_HOUSING_PLAYER_PERMISSIONS_CHANGED))
    end
end
--------------------
--HousingEditor HUD
--------------------
ZO_HousingEditorHud = ZO_Object:Subclass()
function ZO_HousingEditorHud:New(...)
    local editor = ZO_Object.New(self)
    editor:Initialize(...)
    return editor
end
function ZO_HousingEditorHud:Initialize(control)
    self.control = control
    self.buttonContainer = control:GetNamedChild("ButtonContainer")
    self.precisionMoveButtonContainer = control:GetNamedChild("PrecisionMoveButtonContainer")
    self.precisionMoveButtons = self.precisionMoveButtonContainer:GetNamedChild("PrecisionMoveButtons")
    self.precisionMoveUnitsLabel = self.precisionMoveButtonContainer:GetNamedChild("PrecisionMoveUnitsLabel")
    self.precisionPositionLabel = self.precisionMoveButtonContainer:GetNamedChild("PrecisionPositionLabel")
    self.precisionRotateButtonContainer = control:GetNamedChild("PrecisionRotateButtonContainer")
    self.precisionRotateButtons = self.precisionRotateButtonContainer:GetNamedChild("PrecisionRotateButtons")
    self.precisionRotateUnitsLabel = self.precisionRotateButtonContainer:GetNamedChild("PrecisionRotateUnitsLabel")
    self.precisionOrientationLabel = self.precisionRotateButtonContainer:GetNamedChild("PrecisionOrientationLabel")
    HOUSING_EDITOR_HUD_SCENE = ZO_Scene:New("housingEditorHud", SCENE_MANAGER)
    HOUSING_EDITOR_HUD_SCENE:RegisterCallback("StateChange",  function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:OnDeferredInitialization()
            local currentMode = GetHousingEditorMode()
            if currentMode == HOUSING_EDITOR_MODE_BROWSE then -- If someone cancelled out of the browser without selecting anything.
                HousingEditorRequestModeChange(HOUSING_EDITOR_MODE_SELECTION)
            elseif currentMode == HOUSING_EDITOR_MODE_SELECTION then
                SCENE_MANAGER:AddFragment(ZO_HOUSING_EDITOR_HISTORY_FRAGMENT)
            end
            self:ClearPlacementKeyPresses()
            KEYBIND_STRIP:AddKeybindButtonGroup(self.exitKeybindButtonStripDescriptor)
            KEYBIND_STRIP:RemoveDefaultExit()
            self:UpdateKeybinds()
        elseif newState == SCENE_HIDDEN then
            self:ClearPlacementKeyPresses()
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.currentKeybindDescriptor)
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.pushAndPullEtherealKeybindGroup)
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.pushAndPullVisibleKeybindGroup)
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.exitKeybindButtonStripDescriptor)
            KEYBIND_STRIP:RestoreDefaultExit()
            self.currentKeybindDescriptor = nil
        end
    end)
    HOUSING_EDITOR_HUD_UI_SCENE = ZO_Scene:New("housingEditorHudUI", SCENE_MANAGER)
    HOUSING_EDITOR_HUD_UI_SCENE:RegisterCallback("StateChange",  function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:OnDeferredInitialization()
            if GetHousingEditorMode() ~= HOUSING_EDITOR_MODE_SELECTION then
                -- Add the HUD UI keybinds for any mode other than Selection.
                -- This is to prevent duplicate keybind registration that would result from Selection
                -- and UI mode both sharing the housing editor's tertiary action keybind.
                KEYBIND_STRIP:RemoveDefaultExit()
                KEYBIND_STRIP:AddKeybindButtonGroup(self.UIModeKeybindStripDescriptor)
                KEYBIND_STRIP:AddKeybindButtonGroup(self.pushAndPullEtherealKeybindGroup)
                KEYBIND_STRIP:AddKeybindButtonGroup(self.exitKeybindButtonStripDescriptor)
            end
            self:UnregisterDragMouseAxis()
            self:UpdateAxisIndicators()
        elseif newState == SCENE_HIDDEN then
            self:ClearPlacementKeyPresses()
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.UIModeKeybindStripDescriptor)
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.pushAndPullEtherealKeybindGroup)
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.exitKeybindButtonStripDescriptor)
            KEYBIND_STRIP:RestoreDefaultExit()
            self:UpdateAxisIndicators()
        end
    end)
    SCENE_MANAGER:SetSceneRestoresBaseSceneOnGameMenuToggle("housingEditorHudUI", true)
    local HOUSING_EDITOR_HUD_SCENE_GROUP = ZO_SceneGroup:New("housingEditorHud", "housingEditorHudUI")
    HOUSING_EDITOR_HUD_SCENE_GROUP:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_GROUP_HIDDEN then
            if GetHousingEditorMode() ~= HOUSING_EDITOR_MODE_BROWSE then
                HousingEditorRequestModeChange(HOUSING_EDITOR_MODE_DISABLED)
                PlaySound(SOUNDS.HOUSING_EDITOR_CLOSED)
            end
        end
    end)
    local function OnHousingModeChanged(eventId, oldMode, newMode)
        self:OnHousingModeChanged(oldMode, newMode)
    end
    local function OnGamepadModeChanged(eventId, isGamepadPreferred)
        if GetHousingEditorMode() ~= HOUSING_EDITOR_MODE_DISABLED and not self.isDirty then
            HousingEditorRequestModeChange(HOUSING_EDITOR_MODE_DISABLED)   -- Turn off housing mode if gamepad mode changes while active.
        end
        self.isDirty = true
    end
    local function OnFurnitureChanged()
        self:UpdateKeybinds()
    end
    local function OnAddOnLoaded(event, addOnName)
        if addOnName == "ZO_Ingame" then
            EVENT_MANAGER:UnregisterForEvent("HousingEditor", EVENT_ADD_ON_LOADED)
            local defaults =
            {
                moveUnitsCentimeters = 10,
                rotateUnitsRadians = math.rad(15),
            }
            self.savedOptions = ZO_SavedVars:NewAccountWide("ZO_Ingame_SavedVariables", 1, "ZO_HousingEditor_Options", defaults)
            self:OnSavedOptionsLoaded()
        end
    end
    EVENT_MANAGER:RegisterForEvent("HousingEditor", EVENT_ADD_ON_LOADED, OnAddOnLoaded)
    EVENT_MANAGER:RegisterForEvent("HousingEditor", EVENT_HOUSING_EDITOR_MODE_CHANGED, OnHousingModeChanged)
    EVENT_MANAGER:RegisterForEvent("HousingEditor", EVENT_GAMEPAD_PREFERRED_MODE_CHANGED, OnGamepadModeChanged)
    EVENT_MANAGER:RegisterForEvent("HousingEditor", EVENT_HOUSING_FURNITURE_PLACED, OnFurnitureChanged)
    EVENT_MANAGER:RegisterForEvent("HousingEditor", EVENT_HOUSING_FURNITURE_REMOVED, OnFurnitureChanged)
    EVENT_MANAGER:RegisterForEvent("HousingEditor", EVENT_HOUSING_FURNITURE_MOVED, OnFurnitureChanged)
    EVENT_MANAGER:RegisterForEvent("HousingEditor", EVENT_HOUSING_EDITOR_COMMAND_RESULT, OnFurnitureChanged)
    EVENT_MANAGER:RegisterForEvent("HousingEditor", EVENT_HOUSING_EDITOR_LINK_TARGET_CHANGED, OnFurnitureChanged)
    do
        local EPSILON_CM = 1
        local EPSILON_RAD = math.rad(1)
        local g_previousX, g_previousY, g_previousZ, g_previousPitch, g_previousYaw, g_previousRoll = 0, 0, 0, 0, 0, 0
        self.axisIndicatorUpdateHandler = function()
            if self.translationIndicators then
                local furnitureId = HousingEditorGetSelectedFurnitureId()
                if furnitureId then
                    local pitch, yaw, roll = HousingEditorGetFurnitureOrientation(furnitureId)
                    local centerX, centerY, centerZ = HousingEditorGetFurnitureWorldCenter(furnitureId)
                    if AngleDistance(pitch, g_previousPitch) > EPSILON_RAD or AngleDistance(yaw, g_previousYaw) > EPSILON_RAD or AngleDistance(roll, g_previousRoll) > EPSILON_RAD then
                        g_previousPitch, g_previousYaw, g_previousRoll = pitch, yaw, roll
                    else
                        pitch, yaw, roll = g_previousPitch, g_previousYaw, g_previousRoll
                    end
                    if math.abs(centerX - g_previousX) > EPSILON_CM or math.abs(centerY - g_previousY) > EPSILON_CM or math.abs(centerZ - g_previousZ) > EPSILON_CM then
                        g_previousX, g_previousY, g_previousZ = centerX, centerY, centerZ
                    else
                        centerX, centerY, centerZ = g_previousX, g_previousY, g_previousZ
                    end
                    -- Order here matters:
                    self:MoveAxisIndicators(centerX, centerY, centerZ, pitch, yaw, roll)
                    self.axisIndicatorWindow:SetHidden(false)
                end
            end
        end
    end
    control:SetHandler("OnUpdate", function(_, currentFrameTimeMS) self:OnUpdate(currentFrameTimeMS) end)
    self.isDirty = true
end
function ZO_HousingEditorHud:RefreshConstants()
    self.pushSpeedPerSecond, self.rotationStep, self.numTickForRotationChange = GetHousingEditorConstants()
    if self.yawMovementController then
        self.yawMovementController:SetAccumulationPerSecondForChange(self.numTickForRotationChange)
        self.pitchMovementController:SetAccumulationPerSecondForChange(self.numTickForRotationChange)
        self.rollMovementController:SetAccumulationPerSecondForChange(self.numTickForRotationChange)
    end
end
function ZO_HousingEditorHud:OnSavedOptionsLoaded()
end
function ZO_HousingEditorHud:InitializePlacementSettings()
    HousingEditorSetPlacementType(HOUSING_EDITOR_PLACEMENT_TYPE_PICKUP)
    HousingEditorSetPrecisionMoveUnits(self.savedOptions.moveUnitsCentimeters)
    HousingEditorSetPrecisionRotateUnits(self.savedOptions.rotateUnitsRadians)
end
function ZO_HousingEditorHud:InitializeMovementControllers()
    local function GetButtonDirection(axis)
        return self:GetButtonDirection(axis)
    end
    self.yawMovementController = ZO_MovementController:New(AXIS_TYPE_Y, self.numTickForRotationChange, GetButtonDirection)
    self.pitchMovementController = ZO_MovementController:New(AXIS_TYPE_X, self.numTickForRotationChange, GetButtonDirection)
    self.rollMovementController = ZO_MovementController:New(AXIS_TYPE_Z, self.numTickForRotationChange, GetButtonDirection)
    self.movementControllers = {self.yawMovementController, self.pitchMovementController, self.rollMovementController}
end
function ZO_HousingEditorHud:OnHousingModeEnabled()
    OpenMarket(MARKET_DISPLAY_GROUP_HOUSE_EDITOR)
    self:CleanDirty()
    SCENE_MANAGER:SetHUDScene("housingEditorHud")
    SCENE_MANAGER:SetHUDUIScene("housingEditorHudUI", true)
end
function ZO_HousingEditorHud:OnHousingModeDisabled()
    OnMarketClose()
    SCENE_MANAGER:RestoreHUDScene()
    SCENE_MANAGER:RestoreHUDUIScene()
end
function ZO_HousingEditorHud:OnHousingModeChanged(oldMode, newMode)
    if newMode == HOUSING_EDITOR_MODE_DISABLED then
        self:OnHousingModeDisabled()
    elseif oldMode == HOUSING_EDITOR_MODE_DISABLED then
        self:OnHousingModeEnabled()
    end
    if newMode == HOUSING_EDITOR_MODE_SELECTION then
        SCENE_MANAGER:AddFragment(ZO_HOUSING_EDITOR_HISTORY_FRAGMENT)
    elseif oldMode == HOUSING_EDITOR_MODE_SELECTION then
        SCENE_MANAGER:RemoveFragment(ZO_HOUSING_EDITOR_HISTORY_FRAGMENT)
    end
    if newMode == HOUSING_EDITOR_MODE_BROWSE then
        HousingEditorSetPlacementType(HOUSING_EDITOR_PLACEMENT_TYPE_PICKUP)
        SYSTEMS:PushScene("housing_furniture_browser")
    elseif oldMode == HOUSING_EDITOR_MODE_BROWSE then -- If something external exited the housing mode hide everything.
        if SYSTEMS:IsShowing("housing_furniture_browser") then
            SCENE_MANAGER:HideCurrentScene()
        end
    end
    if oldMode == HOUSING_EDITOR_MODE_PLACEMENT then
        HousingEditorSetPlacementType(HOUSING_EDITOR_PLACEMENT_TYPE_PICKUP)
        self:ClearPlacementKeyPresses()
        self:UpdateAxisIndicators()
    end
    self:UpdateKeybinds()
end
function ZO_HousingEditorHud:OnDeferredInitialization()
    if self.initialized then
        return
    end
    self.initialized = true
end
function ZO_HousingEditorHud:UpdateKeybinds()
    if not HOUSING_EDITOR_HUD_UI_SCENE:IsShowing() then
        local currentMode = GetHousingEditorMode()
        local currentModeKeybindDescriptor = self:GetKeybindStripDescriptorForMode(currentMode)
        if self.currentKeybindDescriptor ~= currentModeKeybindDescriptor then
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.currentKeybindDescriptor)
            self.currentKeybindDescriptor = currentModeKeybindDescriptor
            if currentModeKeybindDescriptor then
                KEYBIND_STRIP:AddKeybindButtonGroup(currentModeKeybindDescriptor)
            end
        else
            KEYBIND_STRIP:UpdateKeybindButtonGroup(self.currentKeybindDescriptor)
        end
    end
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.UIModeKeybindStripDescriptor)
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.exitKeybindButtonStripDescriptor)
    if GetHousingEditorMode() == HOUSING_EDITOR_MODE_PLACEMENT then
        local hideRotate = false
        local hidePrecisionRotate = true
        local hidePrecisionMove = true
        SCENE_MANAGER:AddFragment(HOUSING_EDITOR_HUD_PLACEMENT_MODE_ACTION_LAYER_FRAGMENT)
        if self:IsPrecisionEditingEnabled() then
            hideRotate = true
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.pushAndPullEtherealKeybindGroup)
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.pushAndPullVisibleKeybindGroup)
            if self:IsPrecisionPlacementRotationMode() then
                hidePrecisionRotate = false
            else
                hidePrecisionMove = false
            end
        else
            if HousingEditorIsSurfaceDragModeEnabled() then
                KEYBIND_STRIP:RemoveKeybindButtonGroup(self.pushAndPullVisibleKeybindGroup)
                KEYBIND_STRIP:AddKeybindButtonGroup(self.pushAndPullEtherealKeybindGroup)
            else
                KEYBIND_STRIP:RemoveKeybindButtonGroup(self.pushAndPullEtherealKeybindGroup)
                KEYBIND_STRIP:AddKeybindButtonGroup(self.pushAndPullVisibleKeybindGroup)
            end
        end
        self.buttonContainer:SetHidden(hideRotate)
        self.precisionRotateButtonContainer:SetHidden(hidePrecisionRotate)
        self.precisionMoveButtonContainer:SetHidden(hidePrecisionMove)
    else
        SCENE_MANAGER:RemoveFragment(HOUSING_EDITOR_HUD_PLACEMENT_MODE_ACTION_LAYER_FRAGMENT)
        KEYBIND_STRIP:RemoveKeybindButtonGroup(self.pushAndPullEtherealKeybindGroup)
        KEYBIND_STRIP:RemoveKeybindButtonGroup(self.pushAndPullVisibleKeybindGroup)
    end 
    local rotationHidden = GetHousingEditorMode() ~= HOUSING_EDITOR_MODE_PLACEMENT
    if rotationHidden then
        HOUSING_EDITOR_HUD_SCENE:RemoveFragment(HOUSING_EDITOR_ACTION_BAR_FRAGMENT)
    else
        HOUSING_EDITOR_HUD_SCENE:AddFragment(HOUSING_EDITOR_ACTION_BAR_FRAGMENT)
    end
end
function ZO_HousingEditorHud:IsPrecisionEditingEnabled()
    return HousingEditorGetPlacementType() == HOUSING_EDITOR_PLACEMENT_TYPE_PRECISION
end
function ZO_HousingEditorHud:TogglePrecisionEditing()
end
function ZO_HousingEditorHud:IsPrecisionPlacementMoveMode()
    return HousingEditorGetPrecisionPlacementMode() == HOUSING_EDITOR_PRECISION_PLACEMENT_MODE_MOVE
end
function ZO_HousingEditorHud:IsPrecisionPlacementRotationMode()
    return HousingEditorGetPrecisionPlacementMode() == HOUSING_EDITOR_PRECISION_PLACEMENT_MODE_ROTATE
end
function ZO_HousingEditorHud:TogglePrecisionPlacementMode()
end
function ZO_HousingEditorHud:UpdateMovementControllerUnits()
    local accumulationCoefficient = self:IsPrecisionEditingEnabled() and 2 or 1
    local accumulationPerSecondForChange = accumulationCoefficient * self.numTickForRotationChange
    for _, controller in ipairs(self.movementControllers) do
        controller:SetAccumulationPerSecondForChange(accumulationPerSecondForChange)
    end
end
function ZO_HousingEditorHud:InitializeAxisIndicators()
    local indicatorName = "ZO_HousingEditorAxisIndicators"
    local window = WINDOW_MANAGER:CreateTopLevelWindow(indicatorName)
    self.axisIndicatorWindow = window
    window:SetAnchor(CENTER, GuiRoot, CENTER, 0, 0)
    window:SetMouseEnabled(false)
    window:Create3DRenderSpace()
    window:SetDrawLayer(DL_BACKGROUND)
    window:SetDrawTier(DT_LOW)
    window:SetHidden(true)
    self.cameraControlName = indicatorName .. "CameraControl"
    local cameraControl = WINDOW_MANAGER:CreateControl(self.cameraControlName, window, CT_TEXTURE)
    self.cameraControl = cameraControl
    cameraControl:SetMouseEnabled(false)
    cameraControl:Create3DRenderSpace()
    cameraControl:SetHidden(true)
    -- Array order matters here for visual control ordering.
    self.translationIndicators = {
        {axis = HOUSING_EDITOR_POSITION_AXIS_X1, pairedAxis = HOUSING_EDITOR_POSITION_AXIS_X2, sizeX = TRANSLATION_AXIS_INDICATOR_LOCAL_X_DIMENSION_M, sizeY = TRANSLATION_AXIS_INDICATOR_LOCAL_Y_DIMENSION_M, offsetX = -0.5, color = X_AXIS_NEGATIVE_INDICATOR_COLOR, inactiveAlpha = AXIS_INDICATOR_ALPHA_ACTIVE_PERCENTAGE, yaw = 0},
        {axis = HOUSING_EDITOR_POSITION_AXIS_X2, pairedAxis = HOUSING_EDITOR_POSITION_AXIS_X1, sizeX = TRANSLATION_AXIS_INDICATOR_LOCAL_X_DIMENSION_M, sizeY = TRANSLATION_AXIS_INDICATOR_LOCAL_Y_DIMENSION_M, offsetX =  0.5, color = X_AXIS_POSITIVE_INDICATOR_COLOR, texture = TEXTURE_ARROW_DIRECTION_INVERSE, inactiveAlpha = AXIS_INDICATOR_ALPHA_ACTIVE_PERCENTAGE, yaw = PI},
        {axis = HOUSING_EDITOR_POSITION_AXIS_Y1, pairedAxis = HOUSING_EDITOR_POSITION_AXIS_Y2, sizeX = TRANSLATION_AXIS_INDICATOR_LOCAL_Y_DIMENSION_M, sizeY = TRANSLATION_AXIS_INDICATOR_LOCAL_X_DIMENSION_M, offsetY = -0.5, color = Y_AXIS_NEGATIVE_INDICATOR_COLOR, texture = TEXTURE_ARROW_DIRECTION_INVERSE, inactiveAlpha = AXIS_INDICATOR_ALPHA_ACTIVE_PERCENTAGE, rotation = HALF_PI},
        {axis = HOUSING_EDITOR_POSITION_AXIS_Y2, pairedAxis = HOUSING_EDITOR_POSITION_AXIS_Y1, sizeX = TRANSLATION_AXIS_INDICATOR_LOCAL_Y_DIMENSION_M, sizeY = TRANSLATION_AXIS_INDICATOR_LOCAL_X_DIMENSION_M, offsetY =  0.5, color = Y_AXIS_POSITIVE_INDICATOR_COLOR, inactiveAlpha = AXIS_INDICATOR_ALPHA_ACTIVE_PERCENTAGE, rotation = -HALF_PI},
        {axis = HOUSING_EDITOR_POSITION_AXIS_Z1, pairedAxis = HOUSING_EDITOR_POSITION_AXIS_Z2, sizeX = TRANSLATION_AXIS_INDICATOR_LOCAL_X_DIMENSION_M, sizeY = TRANSLATION_AXIS_INDICATOR_LOCAL_Y_DIMENSION_M, offsetZ = -0.5, color = Z_AXIS_NEGATIVE_INDICATOR_COLOR, inactiveAlpha = AXIS_INDICATOR_ALPHA_ACTIVE_PERCENTAGE, yaw = -HALF_PI},
        {axis = HOUSING_EDITOR_POSITION_AXIS_Z2, pairedAxis = HOUSING_EDITOR_POSITION_AXIS_Z1, sizeX = TRANSLATION_AXIS_INDICATOR_LOCAL_X_DIMENSION_M, sizeY = TRANSLATION_AXIS_INDICATOR_LOCAL_Y_DIMENSION_M, offsetZ =  0.5, color = Z_AXIS_POSITIVE_INDICATOR_COLOR, texture = TEXTURE_ARROW_DIRECTION_INVERSE, inactiveAlpha = AXIS_INDICATOR_ALPHA_ACTIVE_PERCENTAGE, yaw = HALF_PI},
    }
    self.rotationIndicators = {
        {axis = HOUSING_EDITOR_ROTATION_AXIS_X1, sizeX = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, sizeY = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, inactiveAlpha = AXIS_INDICATOR_ALPHA_ACTIVE_PERCENTAGE,   scale = 1.0, color = X_AXIS_NEGATIVE_INDICATOR_COLOR, texture = TEXTURE_ARROW_ROTATION_FORWARD, pitch = HALF_PI, yaw = -HALF_PI},
        {axis = HOUSING_EDITOR_ROTATION_AXIS_X2, sizeX = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, sizeY = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, inactiveAlpha = AXIS_INDICATOR_ALPHA_INACTIVE_PERCENTAGE, scale = 1.0, color = X_AXIS_POSITIVE_INDICATOR_COLOR, texture = TEXTURE_ARROW_ROTATION_REVERSE, pitch = HALF_PI, yaw =  HALF_PI},
        {axis = HOUSING_EDITOR_ROTATION_AXIS_Y1, sizeX = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, sizeY = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, inactiveAlpha = AXIS_INDICATOR_ALPHA_ACTIVE_PERCENTAGE,   scale = 0.66, color = Y_AXIS_NEGATIVE_INDICATOR_COLOR, texture = TEXTURE_ARROW_ROTATION_FORWARD, yaw = 0},
        {axis = HOUSING_EDITOR_ROTATION_AXIS_Y2, sizeX = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, sizeY = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, inactiveAlpha = AXIS_INDICATOR_ALPHA_INACTIVE_PERCENTAGE, scale = 0.66, color = Y_AXIS_POSITIVE_INDICATOR_COLOR, texture = TEXTURE_ARROW_ROTATION_REVERSE, roll = PI, yaw = 0},
        {axis = HOUSING_EDITOR_ROTATION_AXIS_Z1, sizeX = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, sizeY = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, inactiveAlpha = AXIS_INDICATOR_ALPHA_ACTIVE_PERCENTAGE,   scale = 0.44, color = Z_AXIS_NEGATIVE_INDICATOR_COLOR, texture = TEXTURE_ARROW_ROTATION_FORWARD, yaw =  HALF_PI},
        {axis = HOUSING_EDITOR_ROTATION_AXIS_Z2, sizeX = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, sizeY = ROTATION_AXIS_INDICATOR_LOCAL_DIMENSIONS_M, inactiveAlpha = AXIS_INDICATOR_ALPHA_INACTIVE_PERCENTAGE, scale = 0.44, color = Z_AXIS_POSITIVE_INDICATOR_COLOR, texture = TEXTURE_ARROW_ROTATION_REVERSE, yaw = -HALF_PI, roll = PI},
    }
    self.allAxisIndicators = {}
    local axisIndicators = {}
    for _, indicator in ipairs(self.translationIndicators) do
        table.insert(axisIndicators, indicator)
    end
    for _, indicator in ipairs(self.rotationIndicators) do
        table.insert(axisIndicators, indicator)
    end
    local function OnMouseEnter(...)
        self:OnMouseEnterAxis(...)
    end
    local function OnMouseExit(...)
        self:OnMouseExitAxis(...)
    end
    local function OnMouseDown(...)
        self:OnMouseDownAxis(...)
    end
    for _, indicator in ipairs(axisIndicators) do
        local control = WINDOW_MANAGER:CreateControl(indicatorName .. indicator.axis, window, CT_TEXTURE)
        indicator.control = control
        self.allAxisIndicators[indicator.axis] = indicator
        control.axis = indicator
        control:SetAddressMode(TEX_MODE_CLAMP)
        control:SetAnchor(CENTER, window, CENTER, 0, 0)
        control:SetBlendMode(TEX_BLEND_MODE_ALPHA)
        control:SetColor(indicator.color:UnpackRGBA())
        control:SetTexture(indicator.texture or TEXTURE_ARROW_DIRECTION)
        control:SetTextureReleaseOption(RELEASE_TEXTURE_AT_ZERO_REFERENCES)
        control:SetTextureSampleProcessingWeight(TEX_SAMPLE_PROCESSING_RGB, 1)
        self:RotateAndScaleAxisIndicator(indicator.control, indicator.rotation or 0)
        local scale = indicator.scale or 1
        local width = scale * indicator.sizeX
        local height = scale * indicator.sizeY
        local offsetX, offsetY, offsetZ = indicator.offsetX or 0, indicator.offsetY or 0, indicator.offsetZ or 0
        control:Create3DRenderSpace()
        control:Set3DLocalDimensions(width, height)
        control:Set3DRenderSpaceOrigin(width * offsetX, height * offsetY, width * offsetZ)
        control:Set3DRenderSpaceOrientation(indicator.pitch or 0, indicator.yaw or 0, indicator.roll or 0)
        control:SetMouseEnabled(true)
        control:SetHandler("OnMouseEnter", OnMouseEnter)
        control:SetHandler("OnMouseExit", OnMouseExit)
        control:SetHandler("OnMouseDown", OnMouseDown)
    end
end
function ZO_HousingEditorHud:OnMouseEnterAxis(control, ...)
    if not self.focusAxis then
        control:SetTextureSampleProcessingWeight(TEX_SAMPLE_PROCESSING_RGB, AXIS_INDICATOR_RGB_WEIGHT_MAX_PERCENTAGE)
    end
end
function ZO_HousingEditorHud:OnMouseExitAxis(control, ...)
    if not self.focusAxis then
        control:SetTextureSampleProcessingWeight(TEX_SAMPLE_PROCESSING_RGB, AXIS_INDICATOR_RGB_WEIGHT_MIN_PERCENTAGE)
    end
end
function ZO_HousingEditorHud:OnMouseDownAxis(control, mouseButton)
    if mouseButton == MOUSE_BUTTON_INDEX_LEFT then
        local mouseX, mouseY = GetUIMousePosition()
        self:RegisterDragMouseAxis(control.axis, mouseX, mouseY)
    end
end
do
    local function GetVisibleTranslationRange(originX, originY, originZ, horizontalAngleRadians, invertWorldOffsets)
        -- Offset horizontally based on the optional horizontalAngleRadians parameter.
        local worldOffsetX, worldOffsetY, worldOffsetZ = 0, 0, 0
        if horizontalAngleRadians then
            worldOffsetX = math.sin(horizontalAngleRadians) * TRANSLATION_AXIS_RANGE_MAX_CM
            worldOffsetZ = math.cos(horizontalAngleRadians) * TRANSLATION_AXIS_RANGE_MAX_CM
        else
            worldOffsetY = -TRANSLATION_AXIS_RANGE_MAX_CM
        end
        if invertWorldOffsets then
            worldOffsetX, worldOffsetZ = -worldOffsetX, -worldOffsetZ
        end
        -- Clip the translation range's end points at the camera view frustum bounds.
        local worldX1 = originX - 0.5 * worldOffsetX
        local worldY1 = originY - 0.5 * worldOffsetY
        local worldZ1 = originZ - 0.5 * worldOffsetZ
        local worldX2 = originX + 0.5 * worldOffsetX
        local worldY2 = originY + 0.5 * worldOffsetY
        local worldZ2 = originZ + 0.5 * worldOffsetZ
        local clippedX1, clippedY1, clippedZ1, clippedX2, clippedY2, clippedZ2 = HousingEditorClipLineSegmentToViewFrustum(worldX1, worldY1, worldZ1, worldX2, worldY2, worldZ2)
        -- Calculate the normalized base offset of the initial furniture position.
        local translationDistance = zo_distance3D(clippedX1, clippedY1, clippedZ1, clippedX2, clippedY2, clippedZ2)
        local originOffset = zo_distance3D(clippedX1, clippedY1, clippedZ1, originX, originY, originZ)
        local normalizedOffset = originOffset / translationDistance
        -- Check if the translation range is too constrained by the view frustum
        -- by ensuring that the dot product of the two vectors, clippedXYZ2 - clippedXYZ1
        -- and originXYZ - clippedXYZ1, is roughly positive.
        local vecX1, vecY1, vecZ1 = clippedX2 - clippedX1, clippedY2 - clippedY1, clippedZ2 - clippedZ1
        local vecX2, vecY2, vecZ2 = originX - clippedX1, originY - clippedY1, originZ - clippedZ1
        local dotProduct = vecX1 * vecX2 + vecY1 * vecY2 + vecZ1 * vecZ2
        -- The MIN_SQRT_DOT_PRODUCT allows for a slight overshot on any given axis for situations
        -- where the vector extends just beyond the view frustum boundary but is still valid.
        local MIN_SQRT_DOT_PRODUCT = -50
        if math.sqrt(dotProduct) < MIN_SQRT_DOT_PRODUCT then
            return
        end
        local translationRange =
        {
            minX = clippedX1,
            minY = clippedY1,
            minZ = clippedZ1,
            maxX = clippedX2,
            maxY = clippedY2,
            maxZ = clippedZ2,
            deltaX = clippedX2 - clippedX1,
            deltaY = clippedY2 - clippedY1,
            deltaZ = clippedZ2 - clippedZ1,
            baseOffset = normalizedOffset,
        }
        return translationRange
    end
    function ZO_HousingEditorHud:RegisterDragMouseAxis(axis, mouseX, mouseY)
        local selectedFurnitureId = HousingEditorGetSelectedFurnitureId()
        if selectedFurnitureId and not self.focusAxis then
            local cameraX, cameraY, cameraZ, originX, originY, originZ = self:GetCameraAndAxisIndicatorOrigins()
            self.focusAngle = math.atan2(cameraX - originX, cameraZ - originZ)
            self.focusAxis = axis
            self.focusOffset = 0
            self.focusOriginX = mouseX
            self.focusOriginY = mouseY
            self.focusInitialX, self.focusInitialY, self.focusInitialZ = HousingEditorGetFurnitureWorldPosition(selectedFurnitureId)
            self.focusInitialPitch, self.focusInitialYaw, self.focusInitialRoll = HousingEditorGetFurnitureOrientation(selectedFurnitureId)
            -- Calculate the translation range using the selected item's center point.
            local centerX, centerY, centerZ = HousingEditorGetFurnitureWorldCenter(HousingEditorGetSelectedFurnitureId())
            local centerOffsetX, centerOffsetY, centerOffsetZ = centerX - self.focusInitialX, centerY - self.focusInitialY, centerZ - self.focusInitialZ
            local isTranslation = false
            if axis.axis == HOUSING_EDITOR_POSITION_AXIS_X1 or axis.axis == HOUSING_EDITOR_POSITION_AXIS_X2 then
                local horizontalAngleRadians = self.focusInitialYaw + HALF_PI
                local cameraOffsetRadians = (GetPlayerCameraHeading() - horizontalAngleRadians) % TWO_PI
                self.focusRangeAxis = GetVisibleTranslationRange(centerX, centerY, centerZ, horizontalAngleRadians, cameraOffsetRadians < PI)
                isTranslation = true
            elseif axis.axis == HOUSING_EDITOR_POSITION_AXIS_Y1 or axis.axis == HOUSING_EDITOR_POSITION_AXIS_Y2 then
                self.focusRangeAxis = GetVisibleTranslationRange(centerX, centerY, centerZ)
                isTranslation = true
            elseif axis.axis == HOUSING_EDITOR_POSITION_AXIS_Z1 or axis.axis == HOUSING_EDITOR_POSITION_AXIS_Z2 then
                local horizontalAngleRadians = self.focusInitialYaw
                local cameraOffsetRadians = (GetPlayerCameraHeading() - horizontalAngleRadians) % TWO_PI
                self.focusRangeAxis = GetVisibleTranslationRange(centerX, centerY, centerZ, horizontalAngleRadians, cameraOffsetRadians < PI)
                isTranslation = true
            end
            if isTranslation then
                if self.focusRangeAxis then
                    -- Remove the item's center offset from the translation range.
                    local range = self.focusRangeAxis
                    range.minX, range.minY, range.minZ = range.minX - centerOffsetX, range.minY - centerOffsetY, range.minZ - centerOffsetZ
                    range.maxX, range.maxY, range.maxZ = range.maxX - centerOffsetX, range.maxY - centerOffsetY, range.maxZ - centerOffsetZ
                else
                    self.focusAxis, self.focusOffset, self.focusOriginX, self.focusOriginY, self.focusAngle = nil, nil, nil, nil, nil
                    self.focusInitialX, self.focusInitialY, self.focusInitialZ = nil, nil, nil
                    self.focusInitialPitch, self.focusInitialYaw, self.focusInitialRoll = nil, nil, nil
                    return
                end
            end
            for _, indicator in pairs(self.allAxisIndicators) do
                local isActiveAxis = indicator.axis == self.focusAxis.axis or indicator.axis == self.focusAxis.pairedAxis
                if isActiveAxis then
                    indicator.control:SetTextureSampleProcessingWeight(TEX_SAMPLE_PROCESSING_RGB, AXIS_INDICATOR_RGB_WEIGHT_MAX_PERCENTAGE)
                end
                indicator.control:SetHidden(not isActiveAxis)
            end
            EVENT_MANAGER:RegisterForUpdate("ZO_HousingEditorHud_DragMouseAxis", 1, function() self:OnDragMouseAxis() end)
            EVENT_MANAGER:RegisterForEvent("ZO_HousingEditorHud_OnMouseUp", EVENT_GLOBAL_MOUSE_UP, function() self:UnregisterDragMouseAxis() end)
        end
    end
end
function ZO_HousingEditorHud:UnregisterDragMouseAxis()
    if self.focusAxis then
        EVENT_MANAGER:UnregisterForUpdate("ZO_HousingEditorHud_DragMouseAxis")
        EVENT_MANAGER:UnregisterForEvent("ZO_HousingEditorHud_OnMouseUp", EVENT_GLOBAL_MOUSE_UP)
        for _, indicator in pairs(self.allAxisIndicators) do
            local isActiveAxis = indicator.axis == self.focusAxis.axis or indicator.axis == self.focusAxis.pairedAxis
            if isActiveAxis then
                indicator.control:SetTextureSampleProcessingWeight(TEX_SAMPLE_PROCESSING_RGB, AXIS_INDICATOR_RGB_WEIGHT_MIN_PERCENTAGE)
            end
            indicator.control:SetHidden(false)
        end
        self.focusOffset, self.focusAxis, self.focusOriginX, self.focusOriginY = nil, nil, nil, nil
        self.focusInitialX, self.focusInitialY, self.focusInitialZ = nil, nil, nil
        self.focusInitialPitch, self.focusInitialYaw, self.focusInitialRoll = nil, nil, nil
        self.focusRangeAxis = nil
        self:UpdateAxisIndicators()
    end
end
function ZO_HousingEditorHud:OnDragMouseAxis()
    local selectedFurnitureId = HousingEditorGetSelectedFurnitureId()
    local axis = self.focusAxis
    if not selectedFurnitureId or not axis or not IsGameCameraUIModeActive() then
        self:UnregisterDragMouseAxis()
        return
    end
    local screenX, screenY = GuiRoot:GetDimensions()
    local mouseX, mouseY = GetUIMousePosition()
    local normalizedMouseX, normalizedMouseY = mouseX / screenX, mouseY / screenY
    local normalizedMouseOriginX, normalizedMouseOriginY = self.focusOriginX / screenX, self.focusOriginY / screenY
    local normalizedOffsetX = normalizedMouseX - normalizedMouseOriginX
    local normalizedOffsetY = normalizedMouseY - normalizedMouseOriginY
    local axisType = axis.axis
    if axisType >= HOUSING_EDITOR_POSITION_AXIS_X1 and axisType <= HOUSING_EDITOR_POSITION_AXIS_Z2 then
        self:OnDragMousePosition(normalizedOffsetX, normalizedOffsetY)
        return
    end
    if axisType >= HOUSING_EDITOR_ROTATION_AXIS_X1 and axisType <= HOUSING_EDITOR_ROTATION_AXIS_Z2 then
        local cameraX, cameraY, cameraZ = self:GetCameraOrigin()
        self:OnDragMouseRotation(cameraX, cameraY, cameraZ, normalizedOffsetX, normalizedOffsetY)
        return
    end
end
do
    local function InterpolateTranslationRange(translationRange, progress)
        local x = translationRange.minX + translationRange.deltaX * progress
        local y = translationRange.minY + translationRange.deltaY * progress
        local z = translationRange.minZ + translationRange.deltaZ * progress
        return x, y, z
    end
    function ZO_HousingEditorHud:OnDragMousePosition(normalizedOffsetX, normalizedOffsetY)
        local translationRange = self.focusRangeAxis
        if translationRange then
            local axisType = self.focusAxis.axis
            local baseOffset = translationRange.baseOffset
            local normalizedOffset
            if axisType == HOUSING_EDITOR_POSITION_AXIS_Y1 or axisType == HOUSING_EDITOR_POSITION_AXIS_Y2 then
                normalizedOffset = baseOffset + normalizedOffsetY
            else
                normalizedOffset = baseOffset + normalizedOffsetX
            end
            local x, y, z = InterpolateTranslationRange(translationRange, zo_clamp(normalizedOffset, 0, 1))
            local result = HousingEditorAdjustPrecisionEditingPosition(x, y, z)
            ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, result)
            self.axisIndicatorUpdateHandler()
        end
    end
end
function ZO_HousingEditorHud:OnDragMouseRotation(cameraX, cameraY, cameraZ, normalizedOffsetX, normalizedOffsetY)
    local axis = self.focusAxis
    local axisType = axis.axis
    local normalizedOffsetRadians = normalizedOffsetX * 2 * TWO_PI
    local axisIndicatorAngleRadians = normalizedOffsetRadians
    local indicatorX, indicatorY, indicatorZ = self:GetAxisIndicatorOrigin()
    local currentX, currentY, currentZ = HousingEditorGetFurnitureWorldPosition(HousingEditorGetSelectedFurnitureId())
    local relativeX, relativeY, relativeZ = cameraX - indicatorX, cameraY - indicatorY, cameraZ - indicatorZ
    local offsetAxis
    if axisType == HOUSING_EDITOR_ROTATION_AXIS_X1 or axisType == HOUSING_EDITOR_ROTATION_AXIS_X2 then
        offsetAxis = AXIS_TYPE_Y
    elseif axisType == HOUSING_EDITOR_ROTATION_AXIS_Y1 or axisType == HOUSING_EDITOR_ROTATION_AXIS_Y2 then
        offsetAxis = AXIS_TYPE_Z
    elseif axisType == HOUSING_EDITOR_ROTATION_AXIS_Z1 or axisType == HOUSING_EDITOR_ROTATION_AXIS_Z2 then
        offsetAxis = AXIS_TYPE_X
    end
    -- Update the rotation offset and/or axis indicator values to match the focused axis.
    if self:IsPrecisionEditingEnabled() then
        if offsetAxis == AXIS_TYPE_X then
            if relativeX > 0 then
                normalizedOffsetRadians, axisIndicatorAngleRadians = -normalizedOffsetRadians, -axisIndicatorAngleRadians
            end
        elseif offsetAxis == AXIS_TYPE_Y then
            normalizedOffsetRadians = -normalizedOffsetRadians
        elseif offsetAxis == AXIS_TYPE_Z then
            if relativeZ > 0 then
                normalizedOffsetRadians, axisIndicatorAngleRadians = -normalizedOffsetRadians, -axisIndicatorAngleRadians
            end
        end
    else
        if offsetAxis == AXIS_TYPE_X then
            normalizedOffsetRadians, axisIndicatorAngleRadians = -normalizedOffsetRadians, -axisIndicatorAngleRadians
        elseif offsetAxis == AXIS_TYPE_Y then
            normalizedOffsetRadians = -normalizedOffsetRadians
        elseif offsetAxis == AXIS_TYPE_Z then
            normalizedOffsetRadians, axisIndicatorAngleRadians = -normalizedOffsetRadians, -axisIndicatorAngleRadians
        end
    end
    if normalizedOffsetRadians then
        if self:IsPrecisionEditingEnabled() then
            HousingEditorAdjustPendingFurnitureRotation(HousingEditorCalculateRotationAboutAxis(offsetAxis, normalizedOffsetRadians, self.focusInitialPitch, self.focusInitialYaw, self.focusInitialRoll))
            self:RotateAndScaleAxisIndicator(axis.control, axisIndicatorAngleRadians)
        else
            local pitch, yaw, roll = 0, 0, 0
            local previousOffset = -(self.focusOffset or 0)
            self.focusOffset = normalizedOffsetRadians
            if offsetAxis == AXIS_TYPE_X then
                pitch = normalizedOffsetRadians + previousOffset
            elseif offsetAxis == AXIS_TYPE_Y then
                yaw = normalizedOffsetRadians + previousOffset
            else
                roll = normalizedOffsetRadians + previousOffset
            end
            HousingEditorAdjustPendingFurnitureRotation(pitch, yaw, roll)
            self:RotateAndScaleAxisIndicator(axis.control, axisIndicatorAngleRadians)
        end
    end
end
-- Sets the vertex UV coordinates for an axis indicator by the specified rotation angle (theta).
function ZO_HousingEditorHud:RotateAndScaleAxisIndicator(control, theta)
    local topLeftX, topLeftY = ZO_Rotate2D(theta, -0.5, -0.5)
    local topRightX, topRightY = ZO_Rotate2D(theta,  0.5, -0.5)
    local bottomLeftX, bottomLeftY = ZO_Rotate2D(theta, -0.5,  0.5)
    local bottomRightX, bottomRightY = ZO_Rotate2D(theta,  0.5,  0.5)
     control:SetVertexUV(VERTEX_POINTS_TOPLEFT, 0.5 + topLeftX, 0.5 + topLeftY)
     control:SetVertexUV(VERTEX_POINTS_TOPRIGHT, 0.5 + topRightX, 0.5 + topRightY)
     control:SetVertexUV(VERTEX_POINTS_BOTTOMLEFT, 0.5 + bottomLeftX, 0.5 + bottomLeftY)
     control:SetVertexUV(VERTEX_POINTS_BOTTOMRIGHT, 0.5 + bottomRightX, 0.5 + bottomRightY)
end
function ZO_HousingEditorHud:GetCameraOrigin()
    Set3DRenderSpaceToCurrentCamera(self.cameraControlName)
end
function ZO_HousingEditorHud:GetAxisIndicatorOrigin()
    return GuiRender3DPositionToWorldPosition(self.axisIndicatorWindow:Get3DRenderSpaceOrigin())
end
function ZO_HousingEditorHud:GetAxisIndicatorOrientation()
    return self.axisIndicatorWindow:Get3DRenderSpaceOrientation()
end
function ZO_HousingEditorHud:GetCameraAndAxisIndicatorOrigins()
    local cameraX, cameraY, cameraZ = self:GetCameraOrigin()
    local originX, originY, originZ = self:GetAxisIndicatorOrigin()
    return cameraX, cameraY, cameraZ, originX, originY, originZ
end
function ZO_HousingEditorHud:GetCameraForwardVector()
    Set3DRenderSpaceToCurrentCamera(self.cameraControlName)
    local forwardX, forwardY, forwardZ = self.cameraControl:Get3DRenderSpaceForward()
    return forwardX, forwardY, forwardZ
end
function ZO_HousingEditorHud:GetAxisIndicatorOffsetPosition(axis)
    local control = axis.control
    local originX, originY, originZ = control:GetParent():Get3DRenderSpaceOrigin()
    local offsetX, offsetY, offsetZ = control:Get3DRenderSpaceOrigin()
    return GuiRender3DPositionToWorldPosition(originX + offsetX, originY + offsetY, originZ + offsetZ)
end
function ZO_HousingEditorHud:CalculateDynamicAxisIndicatorScale(cameraX, cameraY, cameraZ, worldX, worldY, worldZ)
    local screenX, screenY = GuiRoot:GetDimensions()
    local distance = zo_distance3D(cameraX, cameraY, cameraZ, worldX, worldY, worldZ)
    local worldWidth, worldHeight = GetWorldDimensionsOfViewFrustumAtDepth(distance)
    local frustumScaleX, frustumScaleY = worldWidth / screenX, worldHeight / screenY
    local scaleX, scaleY = 1, 1
    if frustumScaleX < AXIS_INDICATOR_SCALE_MIN then
        scaleX = frustumScaleX / AXIS_INDICATOR_SCALE_MIN
    elseif frustumScaleX > AXIS_INDICATOR_SCALE_MAX then
        scaleX = frustumScaleX / AXIS_INDICATOR_SCALE_MAX
    end
    if frustumScaleY < AXIS_INDICATOR_SCALE_MIN then
        scaleY = frustumScaleY / AXIS_INDICATOR_SCALE_MIN
    elseif frustumScaleY > AXIS_INDICATOR_SCALE_MAX then
        scaleY = frustumScaleY / AXIS_INDICATOR_SCALE_MAX
    end
    return scaleX, scaleY
end
function ZO_HousingEditorHud:MoveAxisIndicators(worldX, worldY, worldZ, pitch, yaw, roll)
    local cameraX, cameraY, cameraZ = self:GetCameraOrigin()
    local axisIndicators, renderX, renderY, renderZ, renderYaw, scaleX, scaleY
    local isPrecisionEditing = self:IsPrecisionEditingEnabled()
    if isPrecisionEditing and self:IsPrecisionPlacementMoveMode() then
        axisIndicators = self.translationIndicators
    else
        axisIndicators = self.rotationIndicators
    end
    if isPrecisionEditing then
        renderX, renderY, renderZ = WorldPositionToGuiRender3DPosition(worldX, worldY, worldZ)
        if self:IsPrecisionPlacementRotationMode() then
            renderYaw = 0
        else
            renderYaw = yaw
        end
        scaleX, scaleY = self:CalculateDynamicAxisIndicatorScale(cameraX, cameraY, cameraZ, worldX, worldY, worldZ)
    else
        local distance = PICKUP_AXIS_INDICATOR_DISTANCE_CM
        local forwardX, forwardY, forwardZ = self:GetCameraForwardVector()
        local reticleX, reticleY, reticleZ = cameraX + forwardX * distance, cameraY + forwardY * distance, cameraZ + forwardZ * distance
        renderX, renderY, renderZ = WorldPositionToGuiRender3DPosition(reticleX, reticleY, reticleZ)
        renderYaw = GetPlayerCameraHeading()
        scaleX, scaleY = 1, 1
    end
    for index, axis in ipairs(axisIndicators) do
        local scaledX, scaledY = axis.sizeX * (axis.scale or 1) * scaleX, axis.sizeY * (axis.scale or 1) * scaleY
        axis.control:Set3DLocalDimensions(scaledX, scaledY)
        axis.control:Set3DRenderSpaceOrigin(scaledX * (axis.offsetX or 0), scaledY * (axis.offsetY or 0), scaledX * (axis.offsetZ or 0))
    end
    if not isPrecisionEditing then
        renderYaw = renderYaw - AXIS_INDICATOR_PICKUP_YAW_OFFSET_ANGLE
    end
    self.axisIndicatorWindow:Set3DRenderSpaceOrigin(renderX, renderY, renderZ)
    self.axisIndicatorWindow:Set3DRenderSpaceOrientation(0, renderYaw, 0)
end
function ZO_HousingEditorHud:UpdateAxisIndicators()
    if self.translationIndicators and self.rotationIndicators then
        local isPlacementMode = GetHousingEditorMode() == HOUSING_EDITOR_MODE_PLACEMENT
        local isPrecisionMode = self:IsPrecisionEditingEnabled()
        local isUIMode = IsGameCameraUIModeActive()
        if not isPlacementMode then
            EVENT_MANAGER:UnregisterForUpdate("HousingEditor_AxisIndicators")
            self.axisIndicatorWindow:SetHidden(true)
        else
            local hideTranslation = self:IsPrecisionPlacementRotationMode() or not isPrecisionMode
            local hideRotation = not hideTranslation
            if not hideTranslation then
                local cameraX, cameraY, cameraZ, originX, originY, originZ = self:GetCameraAndAxisIndicatorOrigins()
                local relativeX, relativeY, relativeZ = cameraX - originX, cameraY - originY, cameraZ - originZ
                local horizontalAngle = math.atan2(relativeX, relativeZ)
                local relativeXZ = math.sqrt(relativeX * relativeX + relativeZ * relativeZ)
                local verticalAngle = math.atan2(relativeY, relativeXZ)
                local _, indicatorYaw, _ = self:GetAxisIndicatorOrientation()
                local verticalIndicatorYaw = horizontalAngle - indicatorYaw
                -- Pitch the X- and Z-axis indicators to lay flat when significantly above or below the player.
                local pitch = zo_clamp(2 * verticalAngle, -HALF_PI, HALF_PI)
                pitch = math.abs(pitch) < QUARTER_PI and 0 or HALF_PI
                self.translationIndicators[1].control:Set3DRenderSpaceOrientation(pitch, self.translationIndicators[1].yaw, 0)
                self.translationIndicators[2].control:Set3DRenderSpaceOrientation(-pitch, self.translationIndicators[2].yaw, 0)
                self.translationIndicators[3].control:Set3DRenderSpaceOrientation(0, verticalIndicatorYaw, 0)
                self.translationIndicators[4].control:Set3DRenderSpaceOrientation(0, verticalIndicatorYaw, 0)
                self.translationIndicators[5].control:Set3DRenderSpaceOrientation(pitch, self.translationIndicators[5].yaw, 0)
                self.translationIndicators[6].control:Set3DRenderSpaceOrientation(-pitch, self.translationIndicators[6].yaw, 0)
            end
            local cameraX, cameraY, cameraZ = self:GetCameraOrigin()
            local forwardX, forwardY, forwardZ = self:GetCameraForwardVector()
            for _, indicator in ipairs(self.translationIndicators) do
                local alpha = indicator.control:GetAlpha()
                local hideIndicator = hideTranslation or alpha <= 0
                indicator.control:SetHidden(hideIndicator)
                if not hideIndicator then
                    local indicatorX, indicatorY, indicatorZ = self:GetAxisIndicatorOffsetPosition(indicator)
                    -- We cannot use distance squared reliably here as the result could exceed the maximum draw level for a control.
                    local horizontalDistance = math.sqrt((cameraX - indicatorX) * (cameraX - indicatorX) + (cameraZ - indicatorZ) * (cameraZ - indicatorZ))
                    local verticalCoefficient = forwardY > 0 and 1 or -1
                    local drawLevel = horizontalDistance + verticalCoefficient * (cameraY - indicatorY)
                    indicator.control:SetDrawLevel(drawLevel)
                end
            end
            for _, indicator in ipairs(self.rotationIndicators) do
                local alpha = indicator.control:GetAlpha()
                indicator.control:SetHidden(hideRotation or alpha <= 0)
            end
            EVENT_MANAGER:RegisterForUpdate("HousingEditor_AxisIndicators", 1, self.axisIndicatorUpdateHandler)
        end
    end
end
function ZO_HousingEditorHud:InitializeHudControls()
    do
        local yawLeftButton = self.buttonContainer:GetNamedChild("YawLeftButton")
        yawLeftButton.icon = yawLeftButton:GetNamedChild("Icon")
        yawLeftButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_yawCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(yawLeftButton:GetNamedChild("Text"), "HOUSING_EDITOR_YAW_LEFT")
        local yawRightButton = self.buttonContainer:GetNamedChild("YawRightButton")
        yawRightButton.icon = yawRightButton:GetNamedChild("Icon")
        yawRightButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_yawCCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(yawRightButton:GetNamedChild("Text"), "HOUSING_EDITOR_YAW_RIGHT")
        local pitchForwardButton = self.buttonContainer:GetNamedChild("PitchForwardButton")
        pitchForwardButton.icon = pitchForwardButton:GetNamedChild("Icon")
        pitchForwardButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_pitchCCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(pitchForwardButton:GetNamedChild("Text"), "HOUSING_EDITOR_PITCH_FORWARD")
        local pitchBackButton = self.buttonContainer:GetNamedChild("PitchBackButton")
        pitchBackButton.icon = pitchBackButton:GetNamedChild("Icon")
        pitchBackButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_pitchCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(pitchBackButton:GetNamedChild("Text"), "HOUSING_EDITOR_PITCH_BACKWARD")
        local rollLeftButton = self.buttonContainer:GetNamedChild("RollLeftButton")
        rollLeftButton.icon = rollLeftButton:GetNamedChild("Icon")
        rollLeftButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_rollCCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(rollLeftButton:GetNamedChild("Text"), "HOUSING_EDITOR_ROLL_LEFT")
        local rollRightButton = self.buttonContainer:GetNamedChild("RollRightButton")
        rollRightButton.icon = rollRightButton:GetNamedChild("Icon")
        rollRightButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_rollCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(rollRightButton:GetNamedChild("Text"), "HOUSING_EDITOR_ROLL_RIGHT")
    
        self.pickupRotateHudButtons =
        {
            yawLeftButton,
            yawRightButton,
            pitchForwardButton,
            pitchBackButton,
            rollLeftButton,
            rollRightButton,
        }
        for _, button in ipairs(self.pickupRotateHudButtons) do
            button.precisionMode = false
        end
    end
    do
        local moveLeftButton = self.precisionMoveButtons:GetNamedChild("PrecisionMoveLeftButton")
        moveLeftButton.icon = moveLeftButton:GetNamedChild("Icon")
        ZO_Keybindings_RegisterLabelForBindingUpdate(moveLeftButton:GetNamedChild("Text"), "HOUSING_EDITOR_YAW_LEFT")
        local moveRightButton = self.precisionMoveButtons:GetNamedChild("PrecisionMoveRightButton")
        moveRightButton.icon = moveRightButton:GetNamedChild("Icon")
        ZO_Keybindings_RegisterLabelForBindingUpdate(moveRightButton:GetNamedChild("Text"), "HOUSING_EDITOR_YAW_RIGHT")
        local moveForwardButton = self.precisionMoveButtons:GetNamedChild("PrecisionMoveForwardButton")
        moveForwardButton.icon = moveForwardButton:GetNamedChild("Icon")
        ZO_Keybindings_RegisterLabelForBindingUpdate(moveForwardButton:GetNamedChild("Text"), "HOUSING_EDITOR_PITCH_FORWARD")
        local moveBackButton = self.precisionMoveButtons:GetNamedChild("PrecisionMoveBackButton")
        moveBackButton.icon = moveBackButton:GetNamedChild("Icon")
        ZO_Keybindings_RegisterLabelForBindingUpdate(moveBackButton:GetNamedChild("Text"), "HOUSING_EDITOR_PITCH_BACKWARD")
        local moveUpButton = self.precisionMoveButtons:GetNamedChild("PrecisionMoveUpButton")
        moveUpButton.icon = moveUpButton:GetNamedChild("Icon")
        ZO_Keybindings_RegisterLabelForBindingUpdate(moveUpButton:GetNamedChild("Text"), "HOUSING_EDITOR_ROLL_RIGHT")
        local moveDownButton = self.precisionMoveButtons:GetNamedChild("PrecisionMoveDownButton")
        moveDownButton.icon = moveDownButton:GetNamedChild("Icon")
        ZO_Keybindings_RegisterLabelForBindingUpdate(moveDownButton:GetNamedChild("Text"), "HOUSING_EDITOR_ROLL_LEFT")
        self.precisionMoveHudButtons =
        {
            moveLeftButton,
            moveRightButton,
            moveForwardButton,
            moveBackButton,
            moveDownButton,
            moveUpButton,
        }
        for _, button in ipairs(self.precisionMoveHudButtons) do
            button.precisionMode = true
        end
    end
    do
        local rotateYawLeftButton = self.precisionRotateButtons:GetNamedChild("PrecisionYawLeftButton")
        rotateYawLeftButton.icon = rotateYawLeftButton:GetNamedChild("Icon")
        rotateYawLeftButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_yawCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(rotateYawLeftButton:GetNamedChild("Text"), "HOUSING_EDITOR_YAW_LEFT")
        local rotateYawRightButton = self.precisionRotateButtons:GetNamedChild("PrecisionYawRightButton")
        rotateYawRightButton.icon = rotateYawRightButton:GetNamedChild("Icon")
        rotateYawRightButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_yawCCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(rotateYawRightButton:GetNamedChild("Text"), "HOUSING_EDITOR_YAW_RIGHT")
        local rotatePitchForwardButton = self.precisionRotateButtons:GetNamedChild("PrecisionPitchForwardButton")
        rotatePitchForwardButton.icon = rotatePitchForwardButton:GetNamedChild("Icon")
        rotatePitchForwardButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_pitchCCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(rotatePitchForwardButton:GetNamedChild("Text"), "HOUSING_EDITOR_PITCH_FORWARD")
        local rotatePitchBackButton = self.precisionRotateButtons:GetNamedChild("PrecisionPitchBackButton")
        rotatePitchBackButton.icon = rotatePitchBackButton:GetNamedChild("Icon")
        rotatePitchBackButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_pitchCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(rotatePitchBackButton:GetNamedChild("Text"), "HOUSING_EDITOR_PITCH_BACKWARD")
        local rotateRollLeftButton = self.precisionRotateButtons:GetNamedChild("PrecisionRollLeftButton")
        rotateRollLeftButton.icon = rotateRollLeftButton:GetNamedChild("Icon")
        rotateRollLeftButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_rollCCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(rotateRollLeftButton:GetNamedChild("Text"), "HOUSING_EDITOR_ROLL_LEFT")
        local rotateRollRightButton = self.precisionRotateButtons:GetNamedChild("PrecisionRollRightButton")
        rotateRollRightButton.icon = rotateRollRightButton:GetNamedChild("Icon")
        rotateRollRightButton.icon:SetTexture("EsoUI/Art/Housing/housing_axisControlIcon_rollCW.dds")
        ZO_Keybindings_RegisterLabelForBindingUpdate(rotateRollRightButton:GetNamedChild("Text"), "HOUSING_EDITOR_ROLL_RIGHT")
        self.precisionRotateHudButtons =
        {
            rotateYawLeftButton,
            rotateYawRightButton,
            rotatePitchForwardButton,
            rotatePitchBackButton,
            rotateRollLeftButton,
            rotateRollRightButton,
        }
        for _, button in ipairs(self.precisionRotateHudButtons) do
            button.precisionMode = true
        end
    end
    local KEYBOARD_CONSTANTS =
    {
        frame = "EsoUI/Art/ActionBar/abilityFrame64_up.dds",
        dimensions = 50,
        font = "ZoFontGameSmall",
        labelOffsetY = 1,
        buttonOffsetX = 2,
        containerOffsetY = -110,
    }
    local GAMEPAD_CONSTANTS =
    {
        frame = "EsoUI/Art/ActionBar/Gamepad/gp_abilityFrame64.dds",
        dimensions = 64,
        font = "ZoFontGamepad18",
        labelOffsetY = -6,
        buttonOffsetX = 10,
        containerOffsetY = -160,
    }
    local function ApplyStyle(style)
        local allHudButtons = {self.pickupRotateHudButtons, self.precisionMoveHudButtons, self.precisionRotateHudButtons}
        for _, buttons in ipairs(allHudButtons) do
            local lastButton = nil
            for _, button in ipairs(buttons) do
                button:SetDimensions(style.dimensions, style.dimensions)
                button:GetNamedChild("Frame"):SetTexture(style.frame)
                button:GetNamedChild("Text"):SetFont(style.font)
                local isValid, point, relativeTo, relativePoint, offsetX, offsetY, constraints = button:GetNamedChild("Text"):GetAnchor(0)
                if isValid then
                    button:GetNamedChild("Text"):SetAnchor(point, relativeTo, relativePoint, offsetX, style.labelOffsetY, constraints)
                end
                if lastButton then
                    button:SetAnchor(LEFT, lastButton, RIGHT, style.buttonOffsetX, 0)
                end
                lastButton = button
            end
        end
        self.buttonContainer:SetAnchor(BOTTOM, nil, BOTTOM, 0, style.containerOffsetY)
        self.precisionMoveButtonContainer:SetAnchor(BOTTOM, nil, BOTTOM, 0, style.containerOffsetY)
        self.precisionRotateButtonContainer:SetAnchor(BOTTOM, nil, BOTTOM, 0, style.containerOffsetY)
    end
    ZO_PlatformStyle:New(ApplyStyle, KEYBOARD_CONSTANTS, GAMEPAD_CONSTANTS) 
end
do
    local ROTATE_YAW_RIGHT = 1
    local ROTATE_YAW_LEFT = 2
    local ROTATE_PITCH_FORWARD = 3
    local ROTATE_PITCH_BACKWARD = 4
    local ROTATE_ROLL_LEFT = 5
    local ROTATE_ROLL_RIGHT = 6
    local PUSH_FORWARD = 7
    local PULL_BACKWARD = 8
    local PRECISION_MOVE_LEFT = 9
    local PRECISION_MOVE_RIGHT = 10
    local PRECISION_MOVE_FORWARD = 11
    local PRECISION_MOVE_BACKWARD = 12
    local PRECISION_MOVE_UP = 13
    local PRECISION_MOVE_DOWN = 14
    local PRECISION_ROTATE_YAW_RIGHT = 15
    local PRECISION_ROTATE_YAW_LEFT = 16
    local PRECISION_ROTATE_PITCH_FORWARD = 17
    local PRECISION_ROTATE_PITCH_BACKWARD = 18
    local PRECISION_ROTATE_ROLL_LEFT = 19
    local PRECISION_ROTATE_ROLL_RIGHT = 20
    local KEYPRESS_MIN = 1
    local KEYPRESS_MAX = 20
    function ZO_HousingEditorHud:GetAdjacentPrecisionUnits(unitList, currentUnit, direction)
        local index = (ZO_IndexOfElementInNumericallyIndexedTable(unitList, currentUnit) or 1) - 1
        return unitList[((index + direction) % #unitList) + 1]
    end
    function ZO_HousingEditorHud:AdjustPrecisionUnits(unitType, adjustmentType)
        local direction
        if adjustmentType == PRECISION_UNIT_ADJUSTMENT_INCREMENT then
            direction = 1
        elseif adjustmentType == PRECISION_UNIT_ADJUSTMENT_DECREMENT then
            direction = -1
        end
        if unitType == HOUSING_EDITOR_PRECISION_PLACEMENT_MODE_MOVE then
            local unitList = PRECISION_MOVE_UNITS_CM
            local currentUnits = HousingEditorGetPrecisionMoveUnits()
            local newUnits = self:GetAdjacentPrecisionUnits(unitList, currentUnits, direction)
            HousingEditorSetPrecisionMoveUnits(newUnits)
            self.savedOptions.moveUnitsCentimeters = newUnits
        elseif unitType == HOUSING_EDITOR_PRECISION_PLACEMENT_MODE_ROTATE then
            local unitList = PRECISION_ROTATE_UNITS_DEG
            local currentUnits = zo_roundToNearest(math.deg(HousingEditorGetPrecisionRotateUnits()), 0.001)
            local newUnits = math.rad(self:GetAdjacentPrecisionUnits(unitList, currentUnits, direction))
            HousingEditorSetPrecisionRotateUnits(newUnits)
            self.savedOptions.rotateUnitsRadians = newUnits
        end
    end
    function ZO_HousingEditorHud:GetButtonDirection(axis)
        local precisionEditing = self:IsPrecisionEditingEnabled()
        local precisionEditingRotateMode = self:IsPrecisionPlacementRotationMode()
        -- Translate the specified axis' keypress states into the corresponding translational or rotational coefficient.
        if axis == AXIS_TYPE_Y then
            if precisionEditing then
                if precisionEditingRotateMode then
                    return (self.placementKeyPresses[PRECISION_ROTATE_YAW_LEFT] and 1 or 0) + (self.placementKeyPresses[PRECISION_ROTATE_YAW_RIGHT] and -1 or 0)
                else
                    return (self.placementKeyPresses[PRECISION_MOVE_UP] and 1 or 0) + (self.placementKeyPresses[PRECISION_MOVE_DOWN] and -1 or 0)
                end
            else
                return (self.placementKeyPresses[ROTATE_YAW_LEFT] and 1 or 0) + (self.placementKeyPresses[ROTATE_YAW_RIGHT] and -1 or 0)
            end
        elseif axis == AXIS_TYPE_X then
            if precisionEditing then
                if precisionEditingRotateMode then
                    return (self.placementKeyPresses[PRECISION_ROTATE_PITCH_BACKWARD] and 1 or 0) + (self.placementKeyPresses[PRECISION_ROTATE_PITCH_FORWARD] and -1 or 0)
                else
                    return (self.placementKeyPresses[PRECISION_MOVE_BACKWARD] and -1 or 0) + (self.placementKeyPresses[PRECISION_MOVE_FORWARD] and 1 or 0)
                end
            else
                return (self.placementKeyPresses[ROTATE_PITCH_BACKWARD] and 1 or 0) + (self.placementKeyPresses[ROTATE_PITCH_FORWARD] and -1 or 0)
            end
        elseif axis == AXIS_TYPE_Z then
            if precisionEditing then
                if precisionEditingRotateMode then
                    return (self.placementKeyPresses[PRECISION_ROTATE_ROLL_RIGHT] and 1 or 0) + (self.placementKeyPresses[PRECISION_ROTATE_ROLL_LEFT] and -1 or 0)
                else
                    return (self.placementKeyPresses[PRECISION_MOVE_LEFT] and 1 or 0) + (self.placementKeyPresses[PRECISION_MOVE_RIGHT] and -1 or 0)
                end
            else
                return (self.placementKeyPresses[ROTATE_ROLL_RIGHT] and 1 or 0) + (self.placementKeyPresses[ROTATE_ROLL_LEFT] and -1 or 0)
            end
        end
    end
    function ZO_HousingEditorHud:RefreshPlacementKeyPresses()
        local frameTimeMS = GetFrameTimeMilliseconds()
        local x, y, z, pitch, yaw, roll = 0, 0, 0, 0, 0, 0
        local furnitureId = HousingEditorGetSelectedFurnitureId()
        if furnitureId and self:IsPrecisionEditingEnabled() then
            x, y, z = HousingEditorGetFurnitureWorldCenter(furnitureId)
            pitch, yaw, roll = HousingEditorGetFurnitureOrientation(furnitureId)
            local nextPrecisionPositionOrOrientationUpdateMS = self.nextPrecisionPositionOrOrientationUpdateMS or 0
            if frameTimeMS > nextPrecisionPositionOrOrientationUpdateMS then
                self.nextPrecisionPositionOrOrientationUpdateMS = frameTimeMS + PRECISION_POSITION_OR_ORIENTATION_UPDATE_INTERVAL_MS
                if self:IsPrecisionPlacementMoveMode() then
                    local xText = string.format("%d", x)
                    local yText = string.format("%d", y)
                    local zText = string.format("%d", z)
                    local positionText = GetString(SI_HOUSING_EDITOR_CURRENT_FURNITURE_POSITION)
                    positionText = string.gsub(string.gsub(string.gsub(positionText, "<<1>>", xText), "<<2>>", yText), "<<3>>", zText)
                    self.precisionPositionLabel:SetText(positionText)
                elseif self:IsPrecisionPlacementRotationMode() then
                    pitch = math.deg(pitch or 0) % 360
                    yaw = math.deg(yaw or 0) % 360
                    roll = math.deg(roll or 0) % 360
                    if pitch > 359.94 then pitch = 0 end
                    if yaw > 359.94 then yaw = 0 end
                    if roll > 359.94 then roll = 0 end
                    local pitchText = string.format("%.1f", pitch)
                    local yawText = string.format("%.1f", yaw)
                    local rollText = string.format("%.1f", roll)
                    local orientationText = GetString(SI_HOUSING_EDITOR_CURRENT_FURNITURE_ORIENTATION)
                    orientationText = string.gsub(string.gsub(string.gsub(orientationText, "<<1>>", pitchText), "<<2>>", yawText), "<<3>>", rollText)
                    self.precisionOrientationLabel:SetText(orientationText)
                end
                self.precisionPositionLabel:SetHidden(false)
                self.precisionOrientationLabel:SetHidden(false)
            end
        else
            self.precisionPositionLabel:SetHidden(true)
            self.precisionOrientationLabel:SetHidden(true)
        end
        local isAnyKeyPressed = false
        local activeIntervalMS = 0
        for keypress = KEYPRESS_MIN, KEYPRESS_MAX do
            local key = self.placementKeys[keypress]
            if key then
                if self.placementKeyPresses[keypress] then
                    if not key.keypressStartMS then
                        key.keypressStartMS = frameTimeMS
                    end
                    key.keypressDurationMS = frameTimeMS - key.keypressStartMS
                    key.keypressIntervalMS = ZO_EaseOutQuadratic(math.min(1, key.keypressDurationMS / PRESS_AND_HOLD_ACCELERATION_INTERVAL_MS))
                    activeIntervalMS = math.max(activeIntervalMS, key.keypressIntervalMS)
                    isAnyKeyPressed = true
                elseif key.keypressStartMS then
                    key.keypressStartMS = nil
                    key.keypressDurationMS = nil
                    key.keypressIntervalMS = nil
                end
            end
        end
        local isPrecisionMode = self:IsPrecisionEditingEnabled()
        local rotationInterval = PICKUP_ROTATE_INTERVALS_MS
        if isPrecisionMode then
            local rotationUnits = zo_roundToNearest(math.deg(HousingEditorGetPrecisionRotateUnits()), 0.001)
            rotationInterval = PRECISION_ROTATE_INTERVALS_MS[rotationUnits] or 10000
        end
        for keypress = KEYPRESS_MIN, KEYPRESS_MAX do
            local key = self.placementKeys[keypress]
            if key then
                if key.keypressStartMS then
                    local duration = key.keypressDurationMS
                    local interval = key.keypressIntervalMS
                    local weight = zo_lerp(AXIS_KEYBIND_RGB_WEIGHT_MIN_PERCENTAGE, AXIS_KEYBIND_RGB_WEIGHT_MAX_PERCENTAGE, interval)
                    key.icon:SetTextureSampleProcessingWeight(TEX_SAMPLE_PROCESSING_RGB, 1 + weight)
                    if key.axis and key.precisionMode == isPrecisionMode then
                        local axis = key.axis
                        local axisType = axis.axis
                        local control = axis.control
                        local rotationOffset = (duration / rotationInterval) * TWO_PI
                        local rotation = axis.rotation or 0
                        local alpha = zo_lerp(key.axis.inactiveAlpha, AXIS_INDICATOR_ALPHA_MAX_PERCENTAGE, interval)
                        weight = zo_lerp(AXIS_INDICATOR_RGB_WEIGHT_MIN_PERCENTAGE, AXIS_INDICATOR_RGB_WEIGHT_MAX_PERCENTAGE, interval)
                        control:SetAlpha(alpha)
                        control:SetTextureSampleProcessingWeight(TEX_SAMPLE_PROCESSING_RGB, weight)
                        if axisType == HOUSING_EDITOR_ROTATION_AXIS_X1 then
                            rotation = rotation + rotationOffset
                        elseif axisType == HOUSING_EDITOR_ROTATION_AXIS_X2 then
                            rotation = rotation - rotationOffset
                        elseif axisType == HOUSING_EDITOR_ROTATION_AXIS_Y1 then
                            rotation = rotation + rotationOffset
                        elseif axisType == HOUSING_EDITOR_ROTATION_AXIS_Y2 then
                            rotation = rotation - rotationOffset
                        elseif axisType == HOUSING_EDITOR_ROTATION_AXIS_Z1 then
                            rotation = rotation + rotationOffset
                        elseif axisType == HOUSING_EDITOR_ROTATION_AXIS_Z2 then
                            rotation = rotation - rotationOffset
                        end
                        self:RotateAndScaleAxisIndicator(control, rotation)
                    end
                else
                    key.icon:SetTextureSampleProcessingWeight(TEX_SAMPLE_PROCESSING_RGB, 1)
                    if key.axis and key.precisionMode == isPrecisionMode then
                        local control = key.axis.control
                        local alpha = activeIntervalMS > 0 and 0 or key.axis.inactiveAlpha
                        control:SetAlpha(alpha)
                        control:SetTextureSampleProcessingWeight(TEX_SAMPLE_PROCESSING_RGB, AXIS_INDICATOR_RGB_WEIGHT_MIN_PERCENTAGE)
                    end
                end
            end
        end
    end
    function ZO_HousingEditorHud:ClearPlacementKeyPresses()
        if not self.placementKeyPresses then
            return
        end
        for i = KEYPRESS_MIN, KEYPRESS_MAX do
            self.placementKeyPresses[i] = false
            local key = self.placementKeys[i]
            if key and key.keypressStartMS then
                key.keypressStartMS = nil
                key.icon:SetTextureSampleProcessingWeight(TEX_SAMPLE_PROCESSING_RGB, 1)
            end
        end
    end
    function ZO_HousingEditorHud:InitializeKeybindDescriptors()
        local function PlacementCallback(direction, isUp)
            self.placementKeyPresses[direction] = not isUp and GetHousingEditorMode() == HOUSING_EDITOR_MODE_PLACEMENT
        end
        local function RefreshUnits()
            self:UpdateMovementControllerUnits()
            self:UpdateKeybinds()
        end
        
        -- Exit
        self.exitKeybindButtonStripDescriptor =
        {
            alignment = KEYBIND_STRIP_ALIGN_RIGHT,
            {
                name = GetString(SI_EXIT_BUTTON),
                keybind = "DISABLE_HOUSING_EDITOR",
                visible = function()
                        return GetHousingEditorMode() == HOUSING_EDITOR_MODE_SELECTION
                    end,
                callback = function()
                        HousingEditorRequestModeChange(HOUSING_EDITOR_MODE_DISABLED)
                    end,
                alignment = KEYBIND_STRIP_ALIGN_RIGHT,
            },
        }
        
        self.placementKeyPresses =
        {
            [ROTATE_YAW_RIGHT] = false,
            [ROTATE_YAW_LEFT] = false,
            [ROTATE_PITCH_FORWARD] = false,
            [ROTATE_PITCH_BACKWARD] = false,
            [ROTATE_ROLL_RIGHT] = false,
            [ROTATE_ROLL_LEFT] = false,
            [PUSH_FORWARD] = false,
            [PULL_BACKWARD] = false,
            [PRECISION_MOVE_RIGHT] = false,
            [PRECISION_MOVE_LEFT] = false,
            [PRECISION_MOVE_FORWARD] = false,
            [PRECISION_MOVE_BACKWARD] = false,
            [PRECISION_MOVE_UP] = false,
            [PRECISION_MOVE_DOWN] = false,
            [PRECISION_ROTATE_YAW_RIGHT] = false,
            [PRECISION_ROTATE_YAW_LEFT] = false,
            [PRECISION_ROTATE_PITCH_FORWARD] = false,
            [PRECISION_ROTATE_PITCH_BACKWARD] = false,
            [PRECISION_ROTATE_ROLL_RIGHT] = false,
            [PRECISION_ROTATE_ROLL_LEFT] = false,
        }
        self.placementKeys =
        {
            [ROTATE_YAW_RIGHT] = self.pickupRotateHudButtons[2],
            [ROTATE_YAW_LEFT] = self.pickupRotateHudButtons[1],
            [ROTATE_PITCH_FORWARD] = self.pickupRotateHudButtons[3],
            [ROTATE_PITCH_BACKWARD] = self.pickupRotateHudButtons[4],
            [ROTATE_ROLL_LEFT] = self.pickupRotateHudButtons[5],
            [ROTATE_ROLL_RIGHT] = self.pickupRotateHudButtons[6],
            [PUSH_FORWARD] = nil,
            [PULL_BACKWARD] = nil,
            [PRECISION_MOVE_LEFT] = self.precisionMoveHudButtons[1],
            [PRECISION_MOVE_RIGHT] = self.precisionMoveHudButtons[2],
            [PRECISION_MOVE_FORWARD] = self.precisionMoveHudButtons[3],
            [PRECISION_MOVE_BACKWARD] = self.precisionMoveHudButtons[4],
            [PRECISION_MOVE_DOWN] = self.precisionMoveHudButtons[5],
            [PRECISION_MOVE_UP] = self.precisionMoveHudButtons[6],
            [PRECISION_ROTATE_YAW_LEFT] = self.precisionRotateHudButtons[1],
            [PRECISION_ROTATE_YAW_RIGHT] = self.precisionRotateHudButtons[2],
            [PRECISION_ROTATE_PITCH_FORWARD] = self.precisionRotateHudButtons[3],
            [PRECISION_ROTATE_PITCH_BACKWARD] = self.precisionRotateHudButtons[4],
            [PRECISION_ROTATE_ROLL_LEFT] = self.precisionRotateHudButtons[5],
            [PRECISION_ROTATE_ROLL_RIGHT] = self.precisionRotateHudButtons[6],
        }
        do
            local axes = self.translationIndicators
            self.precisionMoveHudButtons[1].axis = axes[1]
            self.precisionMoveHudButtons[2].axis = axes[2]
            self.precisionMoveHudButtons[3].axis = axes[5]
            self.precisionMoveHudButtons[4].axis = axes[6]
            self.precisionMoveHudButtons[5].axis = axes[4]
            self.precisionMoveHudButtons[6].axis = axes[3]
        end
        do
            local axes = self.rotationIndicators
            self.pickupRotateHudButtons[1].axis = axes[1]
            self.pickupRotateHudButtons[2].axis = axes[2]
            self.pickupRotateHudButtons[3].axis = axes[5]
            self.pickupRotateHudButtons[4].axis = axes[6]
            self.pickupRotateHudButtons[5].axis = axes[3]
            self.pickupRotateHudButtons[6].axis = axes[4]
            self.precisionRotateHudButtons[1].axis = axes[1]
            self.precisionRotateHudButtons[2].axis = axes[2]
            self.precisionRotateHudButtons[3].axis = axes[5]
            self.precisionRotateHudButtons[4].axis = axes[6]
            self.precisionRotateHudButtons[5].axis = axes[3]
            self.precisionRotateHudButtons[6].axis = axes[4]
        end
        self.selectionModeKeybindStripDescriptor =
        {
            alignment = KEYBIND_STRIP_ALIGN_CENTER,
            --Primary (Selection/Placement)
            {
                name =  GetString(SI_HOUSING_EDITOR_SELECT),
                keybind = "HOUSING_EDITOR_PRIMARY_ACTION",
                callback =  function()
                                HousingEditorSetPlacementType(HOUSING_EDITOR_PLACEMENT_TYPE_PICKUP)
                                local result = HousingEditorSelectTargettedFurniture()
                                ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, result)
                                if result == HOUSING_REQUEST_RESULT_SUCCESS then
                                    PlaySound(SOUNDS.HOUSING_EDITOR_PICKUP_ITEM)
                                    return true
                                end
                                return false --if not successful return false so you can jump in editor with a gamepad
                            end,
                order = 10,
            },
            -- Link Furniture
            {
                name = GetString(SI_HOUSING_EDITOR_LINK),
                keybind = "HOUSING_EDITOR_BEGIN_FURNITURE_LINKING",
                callback =  function()
                                local result = HousingEditorBeginLinkingTargettedFurniture()
                                ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, result)
                                if result == HOUSING_REQUEST_RESULT_SUCCESS then
                                    PlaySound(SOUNDS.HOUSING_EDITOR_PICKUP_ITEM)
                                end
                            end,
                order = 15,
            },
            --Secondary
            {
                name = GetString(SI_HOUSING_EDITOR_BROWSE),
                keybind = "HOUSING_EDITOR_SECONDARY_ACTION",
                visible = function() 
                                return IsOwnerOfCurrentHouse()
                            end,
                callback =  function()
                                HousingEditorRequestModeChange(HOUSING_EDITOR_MODE_BROWSE)
                            end,
                order = 20,
            },
            --Tertiary
            {
                name = GetString(SI_HOUSING_EDITOR_PRECISION_EDIT),
                keybind = "HOUSING_EDITOR_TERTIARY_ACTION",
                callback =  function()
                                HousingEditorSetPlacementType(HOUSING_EDITOR_PLACEMENT_TYPE_PRECISION)
                                local result = HousingEditorSelectTargettedFurniture()
                                ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, result)
                                if result == HOUSING_REQUEST_RESULT_SUCCESS then
                                    TriggerTutorial(TUTORIAL_TRIGGER_HOUSING_EDITOR_ENTERED_PRECISION_PLACEMENT_MODE)
                                    PlaySound(SOUNDS.HOUSING_EDITOR_PICKUP_ITEM)
                                    return
                                end
                                HousingEditorSetPlacementType(HOUSING_EDITOR_PLACEMENT_TYPE_PICKUP)
                            end,
                order = 12,
            },
             --Jump to safe loc
            {
                name = GetString(SI_HOUSING_EDITOR_SAFE_LOC),
                keybind = "HOUSING_EDITOR_JUMP_TO_SAFE_LOC",
                callback =  function()
                                HousingEditorJumpToSafeLocation()
                            end,
                order = 60,
            },
            -- Undo
            {
                alignment = KEYBIND_STRIP_ALIGN_LEFT,
                name = GetString(SI_HOUSING_EDITOR_UNDO),
                keybind = "HOUSING_EDITOR_UNDO_ACTION",
                enabled = function() return CanUndoLastHousingEditorCommand() end,
                callback = function()
                                UndoLastHousingEditorCommand()
                           end,
            },
            -- Redo
            {
                alignment = KEYBIND_STRIP_ALIGN_LEFT,
                name = GetString(SI_HOUSING_EDITOR_REDO),
                keybind = "HOUSING_EDITOR_REDO_ACTION",
                enabled = function() return CanRedoLastHousingEditorCommand() end,
                callback = function()
                                RedoLastHousingEditorCommand()
                           end,
            },
        }
        self.placementModeKeybindStripDescriptor =
        {
            alignment = KEYBIND_STRIP_ALIGN_CENTER,
            --Negative
            {
                name = GetString(SI_HOUSING_EDITOR_CANCEL),
                keybind = "HOUSING_EDITOR_NEGATIVE_ACTION",
                callback = function()
                                HousingEditorRequestModeChange(HOUSING_EDITOR_MODE_SELECTION)
                            end,
                alignment = KEYBIND_STRIP_ALIGN_LEFT,
            },
            --Primary (Selection/Placement)
            {
                name =  function()
                            local stackCount = HousingEditorGetSelectedFurnitureStackCount()
                            if stackCount <= 1 then
                                return GetString(SI_HOUSING_EDITOR_PLACE)
                            else
                                return zo_strformat(SI_HOUSING_EDITOR_PLACE_WITH_STACK_COUNT, stackCount)
                            end
                        end,
                keybind = "HOUSING_EDITOR_PRIMARY_ACTION",
                callback =  function()
                                local result = HousingEditorRequestSelectedPlacement()
                                ZO_AlertEvent(EVENT_HOUSING_EDITOR_REQUEST_RESULT, result)
                                if result == HOUSING_REQUEST_RESULT_SUCCESS then
                                    PlaySound(SOUNDS.HOUSING_EDITOR_PLACE_ITEM)
                                end
                                self:ClearPlacementKeyPresses()
                            end,
                order = 10,
            },
            --Secondary
            {
                name = GetString(SI_HOUSING_EDITOR_PUT_AWAY),
                keybind = "HOUSING_EDITOR_SECONDARY_ACTION",
                visible = function(