Skip to content

Commit 6343459

Browse files
committed
good base
1 parent 2ac8a31 commit 6343459

File tree

8 files changed

+1184
-97
lines changed

8 files changed

+1184
-97
lines changed

LuaUI/main.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ _G[("%s_VERSION"):format(LUA_NAME:upper())] = LUA_VERSION -- creates LUAUI_VERSI
2020

2121
VFS.DEF_MODE = VFS.RAW_FIRST
2222

23+
VFS.Include("LuaUI/rml_setup2.lua", nil, VFS.DEF_MODE)
24+
2325

2426
-------------------------------------------------------------------------------
2527
-------------------------------------------------------------------------------

LuaUI/rml_setup2.lua

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
-- file: rml.lua
2+
-- brief: RmlUi Setup
3+
-- author: lov + ChrisFloofyKitsune
4+
--
5+
-- Copyright (C) 2024.
6+
-- Licensed under the terms of the GNU GPL, v2 or later.
7+
8+
if (RmlGuard or not RmlUi) then
9+
return
10+
end
11+
-- don't allow this initialization code to be run multiple times
12+
RmlGuard = true
13+
14+
--[[
15+
Recoil uses a custom set of Lua bindings (check out rts/Rml/SolLua/bind folder in the C++ engine code)
16+
Aside from the Lua API, the rest of the RmlUi documentation is still relevant
17+
https://mikke89.github.io/RmlUiDoc/index.html
18+
]]
19+
20+
--[[ create a common Context to be used for widgets
21+
pros:
22+
* Documents in the same Context can make use of the same DataModels, allowing for less duplicate data
23+
* Documents can be arranged in front/behind of each other dynamically
24+
cons:
25+
* Documents in the same Context can make use of the same data models, leading to side effects
26+
* DataModels must have unique names within the same Context
27+
28+
If you have lots of DataModel use you may want to create your own Context
29+
otherwise you should be able to just use the shared Context
30+
31+
Contexts created with the Lua API are automatically disposed of when the LuaUi environment is unloaded
32+
]]
33+
34+
local oldCreateContext = RmlUi.CreateContext
35+
36+
local function NewCreateContext(name)
37+
local context = oldCreateContext(name)
38+
39+
-- set up dp_ratio considering the user's UI scale preference and the screen resolution
40+
local viewSizeX, viewSizeY = Spring.GetViewGeometry()
41+
42+
local userScale = Spring.GetConfigFloat("ui_scale", 1)
43+
44+
local baseWidth = 1920
45+
local baseHeight = 1080
46+
local resFactor = math.min(viewSizeX / baseWidth, viewSizeY / baseHeight)
47+
48+
context.dp_ratio = resFactor * userScale
49+
50+
context.dp_ratio = math.floor(context.dp_ratio * 100) / 100
51+
return context
52+
end
53+
54+
RmlUi.CreateContext = NewCreateContext
55+
56+
-- Load fonts
57+
RmlUi.LoadFontFace("fonts/Poppins-Regular.ttf", true)
58+
local font_files = VFS.DirList('fonts/exo2', '*.ttf')
59+
for _, file in ipairs(font_files) do
60+
Spring.Echo("loading font", file)
61+
RmlUi.LoadFontFace(file, true)
62+
end
63+
64+
--RmlUi.LoadFontFace("fonts/fallbacks/SourceHanSans-Regular.ttc", true)
65+
--RmlUi.LoadFontFace("fonts/monospaced/SourceCodePro-Medium.otf")
66+
67+
-- Mouse Cursor Aliases
68+
--[[
69+
These let standard CSS cursor names be used when doing styling.
70+
If a cursor set via RCSS does not have an alias, it is unchanged.
71+
CSS cursor list: https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
72+
RmlUi documentation: https://mikke89.github.io/RmlUiDoc/pages/rcss/user_interface.html#cursor
73+
]]
74+
75+
-- when "cursor: normal" is set via RCSS, "cursornormal" will be sent to the engine... and so on for the rest
76+
RmlUi.SetMouseCursorAlias("default", 'cursornormal')
77+
RmlUi.SetMouseCursorAlias("pointer", 'Move') -- command cursors use the command name. TODO: replace with actual pointer cursor?
78+
RmlUi.SetMouseCursorAlias("move", 'uimove')
79+
RmlUi.SetMouseCursorAlias("nesw-resize", 'uiresized2')
80+
RmlUi.SetMouseCursorAlias("nwse-resize", 'uiresized1')
81+
RmlUi.SetMouseCursorAlias("ns-resize", 'uiresizev')
82+
RmlUi.SetMouseCursorAlias("ew-resize", 'uiresizeh')
83+
84+
RmlUi.CreateContext("shared")

LuaUI/rmlui/common.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* Hide horizontal scrollbar entirely */
2+
scrollbarhorizontal,
3+
scrollbarhorizontal slidertrack,
4+
scrollbarhorizontal sliderbar,
5+
scrollbarhorizontal sliderarrowdec,
6+
scrollbarhorizontal sliderarrowinc {
7+
display: none;
8+
}
9+
10+
/* Vertical scrollbar container */
11+
scrollbarvertical {
12+
width: 10dp; /* visible gutter */
13+
background-color: #1c1d20;
14+
}
15+
16+
/* Remove arrow buttons (optional, keeps things minimal) */
17+
scrollbarvertical sliderarrowdec,
18+
scrollbarvertical sliderarrowinc {
19+
width: 0dp;
20+
height: 0dp;
21+
}
22+
23+
/* Track + thumb (bar) */
24+
scrollbarvertical slidertrack {
25+
margin-left: 1dp; /* center the 8dp bar inside the 10dp gutter */
26+
width: 8dp;
27+
background-color: #121315;
28+
}
29+
30+
scrollbarvertical sliderbar {
31+
width: 8dp;
32+
min-height: 20dp; /* ensure it’s visible & draggable */
33+
background-color: #44484e;
34+
border: 1dp #2a2b2e;
35+
cursor: pointer;
36+
}
37+
38+
scrollbarvertical sliderbar:hover {
39+
background-color: #5fc878;
40+
}
41+

LuaUI/rmlui/dbg_dev_console.css

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/* ================================
2+
Developer Console Styles (RCSS-safe)
3+
================================ */
4+
5+
body#dev-console-body {
6+
position: absolute;
7+
left: 0;
8+
right: 500px;
9+
bottom: 80px;
10+
height: 300dp;
11+
padding: 0dp;
12+
font-family: Poppins;
13+
color: #c8d0e0;
14+
background-color: #1a1d219e;
15+
16+
/* border: 1dp solid #000000; */
17+
border-width: 1dp;
18+
border-color: #000000;
19+
}
20+
21+
#console-root {
22+
position: absolute;
23+
left: 0dp;
24+
right: 0dp;
25+
bottom: 0dp;
26+
}
27+
28+
.hidden { display: none; }
29+
.dev-console.hidden { display: none; }
30+
31+
/* ================================
32+
Header
33+
================================ */
34+
.header {
35+
overflow: hidden;
36+
margin-bottom: 8dp;
37+
}
38+
39+
.header .title {
40+
float: left;
41+
font-size: 18dp;
42+
font-weight: bold;
43+
color: #eef1ff;
44+
}
45+
46+
.dev-console::after {
47+
display: block;
48+
clear: both;
49+
}
50+
51+
/* ================================
52+
Toolbar
53+
================================ */
54+
.toolbar {
55+
margin: 5dp;
56+
gap: 5dp;
57+
display: flex; /* If flex is unsupported in your RmlUi build, swap to inline-blocks. */
58+
}
59+
60+
/* ================================
61+
Buttons (base)
62+
================================ */
63+
.dev-console button {
64+
flex: 1;
65+
padding: 6dp 12dp;
66+
text-align: center;
67+
font-size: 13dp;
68+
letter-spacing: 0.05em;
69+
color: #b8bcc4;
70+
background-color: #1c1d20;
71+
72+
/* border: 1dp solid #2a2b2e; */
73+
border-width: 1dp;
74+
border-color: #2a2b2e;
75+
76+
cursor: pointer;
77+
}
78+
79+
.dev-console button:hover {
80+
background-color: #2a2b2e;
81+
color: #d4d8df;
82+
}
83+
84+
.dev-console button:active {
85+
background-color: #1a1b1e;
86+
}
87+
88+
.dev-console button.ghost {
89+
background-color: transparent;
90+
color: #808590;
91+
}
92+
93+
/* ================================
94+
Toggle Buttons — DISTINCT LOOK
95+
(green only when ON)
96+
================================ */
97+
98+
/* OFF: different tint, rounded corners, bold+uppercase, permanent stripe */
99+
.dev-console button.toggle {
100+
/* Permanent stripe (visible even when OFF) */
101+
border-left-width: 6dp;
102+
border-left-color: #2e2f32;
103+
104+
/* Different body tint so toggles stand out from other buttons */
105+
background-color: #212528;
106+
color: #cfd4db;
107+
108+
/* Slightly different shape and weight */
109+
border-radius: 6dp;
110+
font-weight: bold;
111+
text-transform: uppercase;
112+
113+
/* Slight extra padding so stripe doesn’t crowd the label */
114+
padding-left: 18dp;
115+
}
116+
117+
/* OFF hover stays neutral (no green here) */
118+
.dev-console button.toggle:hover {
119+
background-color: #2a2e32;
120+
color: #e1e5eb;
121+
/* Stripe gets a touch brighter but remains gray */
122+
border-left-color: #4a4d52;
123+
}
124+
125+
/* ON state (is-active): green palette + thicker stripe */
126+
.dev-console button.toggle.is-active {
127+
background-color: #18241b;
128+
color: #79e68c;
129+
130+
/* thicker left stripe: ON */
131+
border-left-width: 6dp;
132+
border-left-color: #397848;
133+
134+
/* top/bottom edging for depth */
135+
border-top-width: 1dp;
136+
border-top-color: #111512;
137+
border-bottom-width: 1dp;
138+
border-bottom-color: #0a0e0b;
139+
}
140+
141+
/* ON hover: brighter, but clearly still ON */
142+
.dev-console button.toggle.is-active:hover {
143+
background-color: #1f3425;
144+
color: #9efca6;
145+
border-left-color: #5fc878;
146+
}
147+
148+
/* ================================
149+
Log Container
150+
================================ */
151+
.log-container {
152+
height: 240dp;
153+
font-size: 11dp;
154+
line-height: 12dp;
155+
color: #c8d0e0;
156+
overflow-y: scroll; /* always show vertical scrollbar */
157+
overflow-x: auto;
158+
white-space: pre;
159+
padding: 6dp;
160+
161+
/* remove if your build dislikes it */
162+
box-sizing: border-box;
163+
}
164+
165+
.log-container .log-line {
166+
display: block;
167+
margin-bottom: 2dp;
168+
}
169+
170+
.log-container .log-line:last-child {
171+
margin-bottom: 0dp;
172+
}
173+
174+
.log-container .log-line.severity-info {
175+
color: #c8d0e0;
176+
}
177+
178+
.log-container .log-line.severity-warning {
179+
color: #ffb84d;
180+
}
181+
182+
.log-container .log-line.severity-error {
183+
color: #ff6b6b;
184+
font-weight: bold;
185+
}
186+
187+
.log-container .log-link {
188+
color: #6ba3ff;
189+
text-decoration: underline;
190+
cursor: pointer;
191+
}

LuaUI/rmlui/dbg_dev_console.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<rml>
2+
<head>
3+
<title>Developer Console</title>
4+
<link rel="stylesheet" type="text/rcss" href="common.css" />
5+
<link rel="stylesheet" type="text/rcss" href="dbg_dev_console.css" />
6+
</head>
7+
<body id="dev-console-body">
8+
<div id="console-root">
9+
<div id="console" class="dev-console">
10+
<div class="header">
11+
<div class="title"></div>
12+
</div>
13+
14+
<div id="log-container" class="log-container" readonly="readonly"></div>
15+
16+
<div class="toolbar">
17+
<button id="btn-clear" onclick="widget:OnClearClicked(event)">Clear</button>
18+
<button id="btn-filter-problems" class="toggle" onclick="widget:OnFilterProblemsClicked(event)">Problems</button>
19+
<button id="btn-session" class="toggle" onclick="widget:OnSessionFilterClicked(event)">This session</button>
20+
<button id="btn-reload-luaui" onclick="widget:OnReloadLuaUIClicked(event)">LuaUI Reload</button>
21+
<button id="btn-reload-luarules" onclick="widget:OnReloadLuaRulesClicked(event)">LuaRules Reload</button>
22+
<button id="btn-cheating" class="toggle" onclick="widget:OnToggleCheating(event)">Cheating</button>
23+
<button id="btn-globallos" class="toggle" onclick="widget:OnToggleGlobalLos(event)">Global LOS</button>
24+
<button id="btn-godmode" class="toggle" onclick="widget:OnToggleGodMode(event)">GodMode</button>
25+
<button id="btn-restart" onclick="widget:OnRestartClicked(event)">Restart</button>
26+
<button id="btn-popup" class="toggle" onclick="widget:OnTogglePopupClicked(event)">Popup on error</button>
27+
<button id="btn-visibility" class="toggle" onclick="widget:OnToggleVisibilityClicked(event)">Hide (F8)</button>
28+
<button id="btn-debug-mode" class="toggle hidden" onclick="widget:OnToggleDebugMode(event)">Debug Mode</button>
29+
<button id="btn-profiler" class="toggle hidden" onclick="widget:OnToggleProfiler(event)">Toggle profiling</button>
30+
</div>
31+
</div>
32+
</div>
33+
</body>
34+
35+
36+
</rml>
37+

0 commit comments

Comments
 (0)