Client Upload Part 2

RD Core / Commit #5

Commit Client Upload Part 2

Alex Alex committed 19/10/2026 00:06 main Patch
1,244 files +271,215 -0
A RD_Client/modules/game_modaldialog/modaldialog.lua +136-0 View file
@@ -0,0 +1,136 @@
1+modalDialog = nil
2+lastDialogChoices = 0
3+lastDialogChoice = 0
4+lastDialogAnswer = 0
5+
6+function init()
7+ g_ui.importStyle('modaldialog')
8+
9+ connect(g_game, { onModalDialog = onModalDialog,
10+ onGameEnd = destroyDialog })
11+
12+ local dialog = rootWidget:recursiveGetChildById('modalDialog')
13+ if dialog then
14+ modalDialog = dialog
15+ end
16+end
17+
18+function terminate()
19+ disconnect(g_game, { onModalDialog = onModalDialog,
20+ onGameEnd = destroyDialog })
21+end
22+
23+function destroyDialog()
24+ if modalDialog then
25+ modalDialog:destroy()
26+ modalDialog = nil
27+ end
28+end
29+
30+function onModalDialog(id, title, message, buttons, enterButton, escapeButton, choices, priority)
31+ -- priority parameter is unused, not sure what its use is.
32+ if modalDialog then
33+ return
34+ end
35+
36+ modalDialog = g_ui.createWidget('ModalDialog', rootWidget)
37+
38+ local messageLabel = modalDialog:getChildById('messageLabel')
39+ local choiceList = modalDialog:getChildById('choiceList')
40+ local choiceScrollbar = modalDialog:getChildById('choiceScrollBar')
41+ local buttonsPanel = modalDialog:getChildById('buttonsPanel')
42+
43+ modalDialog:setText(title)
44+ messageLabel:setText(message)
45+
46+ local labelHeight
47+ for i = 1, #choices do
48+ local choiceId = choices[i][1]
49+ local choiceName = choices[i][2]
50+
51+ local label = g_ui.createWidget('ChoiceListLabel', choiceList)
52+ label.choiceId = choiceId
53+ label:setText(choiceName)
54+ label:setPhantom(false)
55+ if not labelHeight then
56+ labelHeight = label:getHeight()
57+ end
58+ end
59+ if #choices > 0 then
60+ if g_clock.millis() < lastDialogAnswer + 1000 and lastDialogChoices == #choices then
61+ choiceList:focusChild(choiceList:getChildByIndex(lastDialogChoice))
62+ else
63+ choiceList:focusChild(choiceList:getFirstChild())
64+ end
65+ end
66+
67+ local buttonsWidth = 0
68+ for i = 1, #buttons do
69+ local buttonId = buttons[i][1]
70+ local buttonText = buttons[i][2]
71+
72+ local button = g_ui.createWidget('ModalButton', buttonsPanel)
73+ button:setText(buttonText)
74+ button.onClick = function(self)
75+ local focusedChoice = choiceList:getFocusedChild()
76+ local choice = 0xFF
77+ if focusedChoice then
78+ choice = focusedChoice.choiceId
79+ lastDialogChoice = choiceList:getChildIndex(focusedChoice)
80+ lastDialogAnswer = g_clock.millis()
81+ end
82+ g_game.answerModalDialog(id, buttonId, choice)
83+ destroyDialog()
84+ end
85+ buttonsWidth = buttonsWidth + button:getWidth() + button:getMarginLeft() + button:getMarginRight()
86+ end
87+
88+ local additionalHeight = 0
89+ if #choices > 0 then
90+ choiceList:setVisible(true)
91+ choiceScrollbar:setVisible(true)
92+
93+ additionalHeight = math.min(modalDialog.maximumChoices, math.max(modalDialog.minimumChoices, #choices)) * labelHeight
94+ additionalHeight = additionalHeight + choiceList:getPaddingTop() + choiceList:getPaddingBottom()
95+ end
96+
97+ local horizontalPadding = modalDialog:getPaddingLeft() + modalDialog:getPaddingRight()
98+ buttonsWidth = buttonsWidth + horizontalPadding
99+
100+ local labelWidth = math.min(600, math.floor(message:len() * 1.5))
101+ modalDialog:setWidth(math.min(modalDialog.maximumWidth, math.max(buttonsWidth, labelWidth, modalDialog.minimumWidth)))
102+ messageLabel:setTextWrap(true)
103+
104+ modalDialog:setHeight(90 + additionalHeight + messageLabel:getHeight())
105+
106+ local enterFunc = function()
107+ local focusedChoice = choiceList:getFocusedChild()
108+ local choice = 0xFF
109+ if focusedChoice then
110+ choice = focusedChoice.choiceId
111+ lastDialogChoice = choiceList:getChildIndex(focusedChoice)
112+ lastDialogAnswer = g_clock.millis()
113+ end
114+ g_game.answerModalDialog(id, enterButton, choice)
115+ destroyDialog()
116+ end
117+
118+ local escapeFunc = function()
119+ local focusedChoice = choiceList:getFocusedChild()
120+ local choice = 0xFF
121+ if focusedChoice then
122+ choice = focusedChoice.choiceId
123+ lastDialogChoice = choiceList:getChildIndex(focusedChoice)
124+ lastDialogAnswer = g_clock.millis()
125+ end
126+ g_game.answerModalDialog(id, escapeButton, choice)
127+ destroyDialog()
128+ end
129+
130+ choiceList.onDoubleClick = enterFunc
131+
132+ modalDialog.onEnter = enterFunc
133+ modalDialog.onEscape = escapeFunc
134+
135+ lastDialogChoices = #choices
136+end
A RD_Client/modules/game_modaldialog/modaldialog.otmod +10-0 View file
@@ -0,0 +1,10 @@
1+Module
2+ name: game_modaldialog
3+ description: Show and process modal dialogs
4+ author: Summ
5+ website: https://github.com/edubart/otclient
6+ sandboxed: true
7+ dependencies: [ game_interface ]
8+ scripts: [ modaldialog ]
9+ @onLoad: init()
10+ @onUnload: terminate()
A RD_Client/modules/game_modaldialog/modaldialog.otui +74-0 View file
@@ -0,0 +1,74 @@
1+ChoiceListLabel < Label
2+ font: verdana-11px-monochrome
3+ background-color: alpha
4+ text-offset: 2 0
5+ focusable: true
6+
7+ $focus:
8+ background-color: #00000055
9+ color: #ffffff
10+
11+ChoiceList < TextList
12+ id: choiceList
13+ vertical-scrollbar: choiceScrollBar
14+ anchors.fill: parent
15+ anchors.top: prev.bottom
16+ anchors.bottom: next.top
17+ margin-top: 4
18+ margin-bottom: 10
19+ focusable: false
20+ visible: false
21+
22+ChoiceScrollBar < VerticalScrollBar
23+ id: choiceScrollBar
24+ anchors.top: choiceList.top
25+ anchors.bottom: choiceList.bottom
26+ anchors.right: choiceList.right
27+ step: 14
28+ pixels-scroll: true
29+ visible: false
30+
31+ModalButton < Button
32+ text-auto-resize: true
33+ margin-top: 2
34+ margin-bottom: 2
35+ margin-left: 2
36+
37+ $pressed:
38+ text-offset: 0 0
39+
40+ModalDialog < MainWindow
41+ id: modalDialog
42+ size: 280 97
43+ &minimumWidth: 300
44+ &maximumWidth: 600
45+ &minimumChoices: 4
46+ &maximumChoices: 10
47+
48+ Label
49+ id: messageLabel
50+ anchors.top: parent.top
51+ anchors.left: parent.left
52+ anchors.right: parent.right
53+ text-align: left
54+ text-auto-resize: true
55+ text-wrap: true
56+
57+ ChoiceList
58+
59+ HorizontalSeparator
60+ anchors.left: parent.left
61+ anchors.right: parent.right
62+ anchors.bottom: next.top
63+ margin-bottom: 5
64+
65+ Panel
66+ id: buttonsPanel
67+ anchors.left: parent.left
68+ anchors.right: parent.right
69+ anchors.bottom: parent.bottom
70+ height: 24
71+ layout: horizontalBox
72+ align-right: true
73+
74+ ChoiceScrollBar
A RD_Client/modules/game_nexusbox/nexus.otmod +13-0 View file
@@ -0,0 +1,13 @@
1+Module
2+ name: game_nexusbox
3+ description: Nexus Box
4+ author: Frenesy
5+ website: https://github.com/edubart/otclient
6+ sandboxed: true
7+ scripts: [ nexus ]
8+
9+ autoload: true
10+ autoload-priority: 1000
11+
12+ @onLoad: init()
13+ @onUnload: terminate()
Top