diff --git a/game/engines/default/engine/Tooltip.lua b/game/engines/default/engine/Tooltip.lua index 52dffc43a7c665512b3174597f556fe11590c7ab..9c46ba242282a28d407b79c43e667eea687a476a 100644 --- a/game/engines/default/engine/Tooltip.lua +++ b/game/engines/default/engine/Tooltip.lua @@ -217,6 +217,10 @@ end function _M:display() end +function _M:getDO() + return self.do_container +end + function _M:toScreen(x, y, nb_keyframes) self.last_display_x = x self.last_display_y = y diff --git a/game/engines/default/engine/ui/Button.lua b/game/engines/default/engine/ui/Button.lua index 21dc19627e747689b97ea6aa65c1d86c56d9dffa..c34f0d4e9153b5b214d45f91eb9fa6b66fda5934 100644 --- a/game/engines/default/engine/ui/Button.lua +++ b/game/engines/default/engine/ui/Button.lua @@ -33,6 +33,7 @@ function _M:init(t) self.all_buttons_fct = t.all_buttons_fct self.on_select = t.on_select self.force_w = t.width + self.hide = t.hide self.use_frame = t.use_frame if t.can_focus ~= nil then self.can_focus = t.can_focus end if t.can_focus_mouse ~= nil then self.can_focus_mouse = t.can_focus_mouse end diff --git a/game/engines/default/engine/ui/Dialog.lua b/game/engines/default/engine/ui/Dialog.lua index 53ebec9f6c121743b6ce6ea0f9f75cc5bad2977e..691c3c1c7bedbd900e8c47b25999b02bc15651f8 100644 --- a/game/engines/default/engine/ui/Dialog.lua +++ b/game/engines/default/engine/ui/Dialog.lua @@ -486,6 +486,7 @@ function _M:generate() self.full_container = core.renderer.container() self.renderer:add(self.full_container) self.renderer:zSort(true) + if self.allow_scroll then self.do_container = core.renderer.renderer():zSort(true) else @@ -503,6 +504,13 @@ function _M:generate() self.renderer_outer = self.renderer end + local Tooltip = require "engine.Tooltip" + local FontPackage = require "engine.FontPackage" + local font_mono, size_mono = FontPackage:getFont("mono_small", "mono") + self.use_tooltip = Tooltip.new(font_mono, size_mono, nil, colors.DARK_GREY, 400) + self.use_tooltip_container = core.renderer.container():add(self.use_tooltip:getDO()) + self.renderer:add(self.use_tooltip_container:shown(false)) + local b7 = self:getAtlasTexture(self.frame.b7) local b9 = self:getAtlasTexture(self.frame.b9) local b1 = self:getAtlasTexture(self.frame.b1) @@ -1045,7 +1053,11 @@ function _M:toScreen(x, y, nb_keyframes) self:innerDisplay(x, y, nb_keyframes) - if self.first_display then self:firstDisplay() self.first_display = false end + if self.first_display then + self:registerTooltip() + self:firstDisplay() + self.first_display = false + end -- Particles if self.frame.particles then @@ -1073,3 +1085,19 @@ function _M:toScreen(x, y, nb_keyframes) self.renderer_outer:toScreen() end + +function _M:registerTooltip() +end + +function _M:useTooltip(x, y, h, str) + if not x then self.use_tooltip_container:shown(false) return end + self.use_tooltip_container:shown(true) + if str then + self.use_tooltip:set(str) + if y + h + 20 + self.use_tooltip.h > game.h then + self.use_tooltip:getDO():translate(x, y - self.use_tooltip.h - 20, 50) + else + self.use_tooltip:getDO():translate(x, y + h + 20, 50) + end + end +end diff --git a/game/engines/default/engine/ui/LayoutContainer.lua b/game/engines/default/engine/ui/LayoutContainer.lua index 683b4621f6fb13f06873d848bdf762b2cf1b25c2..7cd5f87ef862995e7f2065bce3fb9ec3a6d4f646 100644 --- a/game/engines/default/engine/ui/LayoutContainer.lua +++ b/game/engines/default/engine/ui/LayoutContainer.lua @@ -70,6 +70,8 @@ end function _M:positioned(x, y, sx, sy, dialog) self.display_x, self.display_y = sx, sy + self.use_tooltip = dialog.use_tooltip + self.useTooltip = function(self, ...) return dialog:useTooltip(...) end end function _M:setupUI(resizex, resizey, on_resize, addmw, addmh) @@ -252,8 +254,17 @@ end function _M:mouseEvent(button, x, y, xrel, yrel, bx, by, event) -- Look for focus + self:useTooltip(false) for i = 1, #self.uis do local ui = self.uis[i] + if ui.has_tooltip and bx >= ui.x and bx <= ui.x + ui.ui.w and by >= ui.y and by <= ui.y + ui.ui.h then + self:useTooltip(true) + if self.last_tooltip ~= ui then + local dx, dy = ui.ui.do_container:getTranslate(true) + self:useTooltip(dx, dy, ui.ui.h, ui.has_tooltip) + end + self.last_tooltip = ui + end if (ui.ui.can_focus or ui.ui.can_focus_mouse) and bx >= ui.x and bx <= ui.x + ui.ui.w and by >= ui.y and by <= ui.y + ui.ui.h then self:setSubFocus(i, "mouse") @@ -287,3 +298,7 @@ function _M:on_focus_change(status) self:moveSubFocus(1) end end + +function _M:display(x, y, nb_keyframes, ox, oy) + -- self.floating_tooltip:toScreen(self.floating_tooltip_pos.x, self.floating_tooltip_pos.y) +end diff --git a/game/engines/default/engine/ui/LayoutEngine.lua b/game/engines/default/engine/ui/LayoutEngine.lua index fa608ed6adf01510d208b0b7c3a5d001114dc8ef..bccb8c7f83dcbfd248be57574a904801908d7085 100644 --- a/game/engines/default/engine/ui/LayoutEngine.lua +++ b/game/engines/default/engine/ui/LayoutEngine.lua @@ -56,11 +56,25 @@ function _M:makeUIByLines(lines) local class = ui[1] if not class:find("%.") then class = "engine.ui."..class end local c = require(class).new(args) + + if ui.x then + local p1 = ((j > 1) and line[j-1].pos.ui.w or 0) + line.padding + local p2 = ((j > 2) and line[j-2].pos.ui.w or 0) + line.padding + local p3 = ((j > 3) and line[j-3].pos.ui.w or 0) + line.padding + local p4 = ((j > 4) and line[j-4].pos.ui.w or 0) + line.padding + local p5 = ((j > 5) and line[j-5].pos.ui.w or 0) + line.padding + local w = c.w + local s = "return function(p1,p2,p3,p4,p5,w,x) return "..ui.x:gsub('%%', '*'..self.iw.."/100").." end" + s = loadstring(s)() + x = s(p1,p2,p3,p4,p5,w,x) + end + ui.pos = {left = x, top = y, ui=c} uis[#uis+1] = ui.pos x = x + math.max(c.w, use_w) + line.padding max_h = math.max(max_h, c.h) if ui[3] then self.nuis[ui[3]] = c end + if ui[4] then ui.pos.has_tooltip = ui[4] end end if line.vcenter then for j, ui in ipairs(line) do diff --git a/game/engines/default/modules/boot/class/Game.lua b/game/engines/default/modules/boot/class/Game.lua index 970c3ac7e112369a46fcd9c28c5e49e55f566999..53e59643cfa41dafee0e5bcf30b3686f392e1ffc 100644 --- a/game/engines/default/modules/boot/class/Game.lua +++ b/game/engines/default/modules/boot/class/Game.lua @@ -490,7 +490,7 @@ end function _M:tick() if self.stopped then engine.Game.tick(self) return true end - return false + return true end --- Called every game turns diff --git a/game/engines/default/modules/boot/dialogs/MainMenu.lua b/game/engines/default/modules/boot/dialogs/MainMenu.lua index 75248a73e026348624663a21a1759a43781b5751..f6c6d990aea40b4c0885949b5a45ef6c2f6d02e3 100644 --- a/game/engines/default/modules/boot/dialogs/MainMenu.lua +++ b/game/engines/default/modules/boot/dialogs/MainMenu.lua @@ -50,6 +50,9 @@ function _M:init() if not mod.team then fs.mount(fs.getRealPath(mod.dir), "/mod", false) else fs.mount(fs.getRealPath(mod.team), "/", false) end + package.loaded["engine.ui.Dialog"] = nil + package.loaded["engine.ui.LayoutContainer"] = nil + package.loaded["engine.ui.LayoutEngine"] = nil package.loaded["mod.dialogs.GameOptions2"] = nil local d = require("mod.dialogs.GameOptions2").new() function d:unload() diff --git a/game/modules/tome/class/Game.lua b/game/modules/tome/class/Game.lua index a9808c3693d472b4dfe33b1dd857281e3454339d..38ce00a55a5988429a56aa905663feb7ce37d354 100644 --- a/game/modules/tome/class/Game.lua +++ b/game/modules/tome/class/Game.lua @@ -2402,7 +2402,7 @@ do return end { _t"Character Sheet", function() self:unregisterDialog(menu) self.key:triggerVirtual("SHOW_CHARACTER_SHEET") end }, "keybinds", "language", - {_t"Game Options", function() self:unregisterDialog(menu) self:registerDialog(require("mod.dialogs.GameOptions").new()) end}, + {_t"Options", function() self:unregisterDialog(menu) self:registerDialog(require("mod.dialogs.GameOptions2").new()) end}, "video", "sound", "save", diff --git a/game/modules/tome/dialogs/GameOptions2.lua b/game/modules/tome/dialogs/GameOptions2.lua index 5eb29592404e628662f91146413a132c9505030c..28ebd122ce905a84961fc170316e22192cb827dc 100644 --- a/game/modules/tome/dialogs/GameOptions2.lua +++ b/game/modules/tome/dialogs/GameOptions2.lua @@ -61,7 +61,7 @@ function _M:init() self.c_tabs = Tabs.new{width=self.iw - 5, tabs=tabs, on_change=function(kind) self:switchTo(kind) end} - self.c_layout = LayoutContainer.new{width=self.iw, height=self.ih - self.c_tabs.h, uis={}} + self.c_layout = LayoutContainer.new{width=self.iw, height=self.ih - self.c_tabs.h, allow_scroll=true, uis={}} self:loadUI{ {left=0, top=0, ui=self.c_tabs}, @@ -150,28 +150,22 @@ function _M:switchTo(kind) local font_styles = FontPackage:list() local default_font_style = table.findValueSub(font_styles, config.settings.tome.fonts.type, "id") + self.use_tooltip:set("AZDAZPDPAD\nAZDAZPDPAD\nAZDAZPDPAD\nAZDAZPDPAD\nAZDAZPDPAD\nAZDAZPDPAD\nAZDAZPDPAD\n") self.c_layout:makeUIByLines{ {{"Header", {width=self.iw, text=_t"Display", color=colors.simple1(colors.GOLD)}}}, { vcenter = true, { "Textzone", {auto_width=true, auto_height=true, text=_t"Mode: "}}, - {w="40%-p1", "Dropdown", {default=default_mode, list=modes}, "resolution_mode"}, - { "Textzone", {auto_width=true, auto_height=true, text=_t"Resolution: "}}, - {w="40%-p1", "Dropdown", {default=default_resolution, list=resolutions}, "resolution_size"}, - {w="20%", "Button", {text="Apply", fct=function() self:changeResolution() end}}, + {w="30%-p1", "Dropdown", {default=default_mode, list=modes, fct=function() self.c_layout:getNUI("resolution_apply").hide = false end}, "resolution_mode"}, + {x="50%", "Textzone", {auto_width=true, auto_height=true, text=_t"Resolution: "}}, + {w="30%-p1", "Dropdown", {default=default_resolution, list=resolutions, fct=function() self.c_layout:getNUI("resolution_apply").hide = false end}, "resolution_size"}, + {x="100%-w-10", "Button", {text="Apply", fct=function() self:changeResolution() end, hide=true}, "resolution_apply"}, }, { vcenter = true, {w="50%", "NumberSlider", {title=_t"Max FPS: ", max=60, min=5, value=config.settings.display_fps, step=1, on_change=self:saveNumberValue("display_fps", function(v) core.game.setFPS(v) end)}}, - {w="50%", "NumberSlider", {title=_t"Gamma: ", max=300, min=50, value=config.settings.gamma_correction, step=5, on_change=self:saveNumberValue("gamma_correction", function(v) game:setGamma(v / 100) end)}}, + {w="50%", "NumberSlider", {title=_t"Gamma: ", max=300, min=50, value=config.settings.gamma_correction, step=5, on_change=self:saveNumberValue("gamma_correction", function(v) game:setGamma(v / 100) end)}, nil, _t"Gamma correction setting.\nIncrease this to get a brighter display.#WHITE#"}, }, { vcenter = true, - {w="50%", "NumberSlider", {title=_t"Zoom: ", max=400, min=50, value=config.settings.screen_zoom*100, step=5, on_change=self:saveFloatValue("screen_zoom", nil, nil, 1/100)}}, - }, - - {{"Header", {width=self.iw, text=_t"Shaders", color=colors.simple1(colors.GOLD)}}, vpadding_up=20}, - { vcenter = true, - {w="33%", "Checkbox", {title=_t"Shaders: Advanced", default=config.settings.shaders_kind_adv, on_change=self:saveBoolValue("shaders_kind_adv")}}, - {w="33%", "Checkbox", {title=_t"Shaders: Distortion", default=config.settings.shaders_kind_distort, on_change=self:saveBoolValue("shaders_kind_distort")}}, - {w="33%", "Checkbox", {title=_t"Shaders: Volumetric", default=config.settings.shaders_kind_volumetric, on_change=self:saveBoolValue("shaders_kind_volumetric")}}, + {w="50%", "NumberSlider", {title=_t"Zoom: ", max=400, min=50, value=config.settings.screen_zoom*100, step=5, on_change=self:saveFloatValue("screen_zoom", nil, nil, 1/100)}, nil, _t"If you have a very high DPI screen you may want to raise this value. Requires a restart to take effect.#WHITE#"}, }, {{"Header", {width=self.iw, text=_t"Fonts", color=colors.simple1(colors.GOLD)}}, vpadding_up=20}, @@ -181,12 +175,28 @@ function _M:switchTo(kind) {w="50%", "NumberSlider", {title=_t"Size: ", max=300, min=50, value=config.settings.font_scale, step=1, on_change=self:saveNumberValue("font_scale")}}, }, - {{"Header", {width=self.iw, text=_t"Misc", color=colors.simple1(colors.GOLD)}}, vpadding_up=20}, + {{"Header", {width=self.iw, text=_t"Visual Effects", color=colors.simple1(colors.GOLD)}}, vpadding_up=20}, + { vcenter = true, + {w="33%", "Checkbox", {title=_t"Shaders: Advanced", default=config.settings.shaders_kind_adv, on_change=self:saveBoolValue("shaders_kind_adv")}, nil, _t"Activates advanced shaders.\nThis option allows for advanced effects (like water surfaces, ...). Disabling it can improve performance.\n\n#LIGHT_RED#You must restart the game for it to take effect.#WHITE#"}, + {w="33%", "Checkbox", {title=_t"Shaders: Distortion", default=config.settings.shaders_kind_distort, on_change=self:saveBoolValue("shaders_kind_distort")}, nil, _t"Activates distorting shaders.\nThis option allows for distortion effects (like spell effects doing a visual distortion, ...). Disabling it can improve performance.\n\n#LIGHT_RED#You must restart the game for it to take effect.#WHITE#"}, + {w="33%", "Checkbox", {title=_t"Shaders: Volumetric", default=config.settings.shaders_kind_volumetric, on_change=self:saveBoolValue("shaders_kind_volumetric")}, nil, _t"Activates volumetric shaders.\nThis option allows for volumetricion effects (like deep starfields). Enabling it will severely reduce performance when shaders are displayed.\n\n#LIGHT_RED#You must restart the game for it to take effect.#WHITE#"}, + }, + { vcenter = true, + {w="33%", "Checkbox", {title=_t"Custom mouse cursor", default=config.settings.mouse_cursor, on_change=self:saveBoolValue("mouse_cursor")}, nil, _t"Use the custom cursor.\nDisabling it will use your normal operating system cursor.#WHITE#"}, + }, + { vcenter = true, + {w="100%", "NumberSlider", {title=_t"Particle effects density: ", max=100, min=0, value=config.settings.particles_density, step=1, on_change=self:saveNumberValue("particles_density")}, nil , _t"Controls the particle effects density.\nThis option allows to change the density of the many particle effects in the game.\nIf the game is slow when displaying spell effects try to lower this setting.#WHITE#"}, + }, + + {{"Header", {width=self.iw, text=_t"Map", color=colors.simple1(colors.GOLD)}}, vpadding_up=20}, + { vcenter = true, + {w="100%", "NumberSlider", {title=_t"Creatures visual movement speed: ", max=60, min=0, value=config.settings.tome.smooth_move, step=1, on_change=self:saveNumberValue("tome.smooth_move", function(v) if self:isTome() then engine.Map.smooth_scroll = v end end)}, nil, _t"Make the movement of creatures and projectiles 'smooth'. When set to 0 movement will be instantaneous.\nThe higher this value the slower the movements will appear.\n\nNote: This does not affect the turn-based idea of the game. You can move again while your character is still moving, and it will correctly update and compute a new animation."}, + }, { vcenter = true, - {w="50%", "NumberSlider", {title=_t"Particle effects density: ", max=100, min=0, value=config.settings.particles_density, step=1, on_change=self:saveNumberValue("particles_density")}}, + {w="33%", "Checkbox", {title=_t"Creatures attack animation", default=config.settings.tome.twitch_move, on_change=self:saveBoolValue("tome.twitch_move")}, nil, _t"Enables or disables 'twitch' movement.\nWhen enabled creatures will do small bumps when moving and attacking.#WHITE#"}, }, { vcenter = true, - {w="50%", "Checkbox", {title=_t"Custom mouse cursor", default=config.settings.mouse_cursor, on_change=self:saveBoolValue("mouse_cursor")}}, + {w="33%", "Checkbox", {title=_t"Visible grid lines", default=config.settings.tome.show_grid_lines, on_change=self:saveBoolValue("tome.show_grid_lines", function() if self:isTome() then game:createMapGridLines() end end)}, nil, _t"Draw faint lines to separate each grid, making visual positioning easier to see.#WHITE#"}, }, }