diff --git a/data/styles/20-tabbars.otui b/data/styles/20-tabbars.otui index a356921b..3d7dca02 100644 --- a/data/styles/20-tabbars.otui +++ b/data/styles/20-tabbars.otui @@ -104,7 +104,7 @@ TabBarVerticalButton < UIButton anchors.top: parent.top $!first: anchors.top: prev.bottom - margin-top: 5 + margin-top: 10 $hover !checked: color: white icon-color: #cccccc diff --git a/modules/client_options/game.otui b/modules/client_options/game.otui index e942a39e..2d81ea8e 100644 --- a/modules/client_options/game.otui +++ b/modules/client_options/game.otui @@ -21,6 +21,18 @@ Panel id: showLeftPanel !text: tr('Show left panel') + OptionCheckBox + id: displayNames + !text: tr('Display creature names') + + OptionCheckBox + id: displayHealth + !text: tr('Display creature health bars') + + OptionCheckBox + id: displayText + !text: tr('Display text messages') + Button id: changeLocale !text: tr('Change language') diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index 98d0588a..c6b54d3d 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -22,6 +22,9 @@ local defaultOptions = { musicSoundVolume = 100, enableLights = true, ambientLight = 25, + displayNames = true, + displayHealth = true, + displayText = true } local optionsWindow @@ -78,6 +81,32 @@ local function setupGraphicsEngines() end function init() + optionsWindow = g_ui.displayUI('options') + optionsWindow:hide() + optionsButton = modules.client_topmenu.addLeftButton('optionsButton', tr('Options'), '/images/topbuttons/options', toggle) + + addEvent(function() setup() end) + + g_keyboard.bindKeyDown('Ctrl+Shift+F', function() toggleOption('fullscreen') end) + g_keyboard.bindKeyDown('Ctrl+N', toggleDisplays) + + audioButton = modules.client_topmenu.addLeftButton('audioButton', tr('Audio'), '/images/topbuttons/audio', function() toggleOption('enableAudio') end) +end + +function terminate() + g_keyboard.unbindKeyDown('Ctrl+Shift+F') + g_keyboard.unbindKeyDown('Ctrl+N') + optionsWindow:destroy() + optionsButton:destroy() + audioButton:destroy() + optionsTabBar = nil + generalPanel = nil + consolePanel = nil + graphicsPanel = nil + audioPanel = nil +end + +function setup() -- load options for k,v in pairs(defaultOptions) do g_settings.setDefault(k, v) @@ -88,12 +117,6 @@ function init() end end - g_keyboard.bindKeyDown('Ctrl+Shift+F', function() toggleOption('fullscreen') end) - - optionsWindow = g_ui.displayUI('options') - optionsWindow:hide() - optionsButton = modules.client_topmenu.addLeftButton('optionsButton', tr('Options'), '/images/topbuttons/options', toggle) - optionsTabBar = optionsWindow:getChildById('optionsTabBar') optionsTabBar:setContentWidget(optionsWindow:getChildById('optionsTabContent')) @@ -109,24 +132,9 @@ function init() audioPanel = g_ui.loadUI('audio') optionsTabBar:addTab(tr('Audio'), audioPanel, '/images/optionstab/audio') - audioButton = modules.client_topmenu.addLeftButton('audioButton', tr('Audio'), '/images/topbuttons/audio', function() toggleOption('enableAudio') end) - setupGraphicsEngines() end -function terminate() - --g_keyboard.unbindKeyDown('Ctrl+D') - g_keyboard.unbindKeyDown('Ctrl+Shift+F') - optionsWindow:destroy() - optionsButton:destroy() - audioButton:destroy() - optionsTabBar = nil - generalPanel = nil - consolePanel = nil - graphicsPanel = nil - audioPanel = nil -end - function toggle() if optionsWindow:isVisible() then hide() @@ -145,12 +153,29 @@ function hide() optionsWindow:hide() end +function toggleDisplays() + if options['displayNames'] and options['displayHealth'] then + setOption('displayNames', false) + elseif options['displayHealth'] then + setOption('displayHealth', false) + else + if not options['displayNames'] and not options['displayHealth'] then + setOption('displayNames', true) + else + setOption('displayHealth', true) + end + end +end + function toggleOption(key) setOption(key, not getOption(key)) end function setOption(key, value) if options[key] == value then return end + local gameMapPanel = modules.game_interface.getMapPanel() + + local panel = nil if key == 'vsync' then g_window.setVerticalSync(value) elseif key == 'showFps' then @@ -165,6 +190,7 @@ function setOption(key, value) end) elseif key == 'fullscreen' then g_window.setFullscreen(value) + panel = graphicsPanel elseif key == 'enableAudio' then g_sounds.setAudioEnabled(value) addEvent(function() @@ -228,7 +254,25 @@ function setOption(key, value) end) elseif key == 'painterEngine' then g_graphics.selectPainterEngine(value) + elseif key == 'displayNames' then + gameMapPanel:setDrawNames(value) + panel = generalPanel + elseif key == 'displayHealth' then + gameMapPanel:setDrawHealthBars(value) + panel = generalPanel + elseif key == 'displayText' then + gameMapPanel:setDrawTexts(value) + panel = generalPanel + end + + -- change value for keybind updates + if panel then + local widget = panel:recursiveGetChildById(key) + if widget and widget:getStyle().__class == 'UICheckBox' then + widget:setChecked(value) + end end + g_settings.set(key, value) options[key] = value end diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index 3905181d..4b6e1ba9 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -106,7 +106,6 @@ function bindKeys() g_keyboard.bindKeyDown('Ctrl+Q', logout, gameRootPanel) g_keyboard.bindKeyDown('Ctrl+L', logout, gameRootPanel) g_keyboard.bindKeyDown('Ctrl+W', function() g_map.cleanTexts() modules.game_textmessage.clearMessages() end, gameRootPanel) - g_keyboard.bindKeyDown('Ctrl+N', function() gameMapPanel:setDrawTexts(not gameMapPanel:isDrawingTexts()) end, gameRootPanel) g_keyboard.bindKeyDown('Ctrl+.', nextViewMode, gameRootPanel) end diff --git a/src/client/const.h b/src/client/const.h index 337ace35..be072e7c 100644 --- a/src/client/const.h +++ b/src/client/const.h @@ -57,10 +57,14 @@ namespace Otc DrawStaticTexts = 512, DrawAnimatedTexts = 1024, DrawAnimations = 2048, + DrawBars = 4096, + DrawNames = 8192, + DrawLights = 16384, DrawWalls = DrawOnBottom | DrawOnTop, DrawEverything = DrawGround | DrawGroundBorders | DrawWalls | DrawItems | DrawCreatures | DrawEffects | DrawMissiles | DrawCreaturesInformation | - DrawStaticTexts | DrawAnimatedTexts | DrawAnimations + DrawStaticTexts | DrawAnimatedTexts | DrawAnimations | DrawBars | DrawNames | + DrawLights }; enum DatOpts { diff --git a/src/client/creature.cpp b/src/client/creature.cpp index d2943972..1ddc9da0 100644 --- a/src/client/creature.cpp +++ b/src/client/creature.cpp @@ -226,7 +226,7 @@ void Creature::drawOutfit(const Rect& destRect, bool resize) } } -void Creature::drawInformation(const Point& point, bool useGray, const Rect& parentRect) +void Creature::drawInformation(const Point& point, bool useGray, const Rect& parentRect, int drawFlags) { if(m_healthPercent < 1) // creature is dead return; @@ -255,17 +255,22 @@ void Creature::drawInformation(const Point& point, bool useGray, const Rect& par healthRect.setWidth((m_healthPercent / 100.0) * 25); // draw - g_painter->setColor(Color::black); - g_painter->drawFilledRect(backgroundRect); - if(g_game.getFeature(Otc::GameBlueNpcNameColor) && isNpc() && m_healthPercent == 100 && !useGray) - g_painter->setColor(Color(0x66, 0xcc, 0xff)); - else - g_painter->setColor(fillColor); + fillColor = Color(0x66, 0xcc, 0xff); - g_painter->drawFilledRect(healthRect); + if(drawFlags & Otc::DrawBars) { + g_painter->setColor(Color::black); + g_painter->drawFilledRect(backgroundRect); - m_nameCache.draw(textRect); + g_painter->setColor(fillColor); + g_painter->drawFilledRect(healthRect); + } + + if(drawFlags & Otc::DrawNames) { + if(g_painter->getColor() != fillColor) + g_painter->setColor(fillColor); + m_nameCache.draw(textRect); + } if(m_skull != Otc::SkullNone && m_skullTexture) { g_painter->setColor(Color::white); diff --git a/src/client/creature.h b/src/client/creature.h index dbe3cfc1..cc39a22a 100644 --- a/src/client/creature.h +++ b/src/client/creature.h @@ -48,7 +48,7 @@ public: void internalDrawOutfit(Point dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction, LightView *lightView = nullptr); void drawOutfit(const Rect& destRect, bool resize); - void drawInformation(const Point& point, bool useGray, const Rect& parentRect); + void drawInformation(const Point& point, bool useGray, const Rect& parentRect, int drawFlags); void setId(uint32 id) { m_id = id; } void setName(const std::string& name); diff --git a/src/client/luafunctions.cpp b/src/client/luafunctions.cpp index fc3d2896..6f88e777 100644 --- a/src/client/luafunctions.cpp +++ b/src/client/luafunctions.cpp @@ -557,6 +557,8 @@ void Client::registerLuaFunctions() g_lua.bindClassMemberFunction("setAutoViewMode", &UIMap::setAutoViewMode); g_lua.bindClassMemberFunction("setDrawFlags", &UIMap::setDrawFlags); g_lua.bindClassMemberFunction("setDrawTexts", &UIMap::setDrawTexts); + g_lua.bindClassMemberFunction("setDrawNames", &UIMap::setDrawNames); + g_lua.bindClassMemberFunction("setDrawHealthBars", &UIMap::setDrawHealthBars); g_lua.bindClassMemberFunction("setDrawLights", &UIMap::setDrawLights); g_lua.bindClassMemberFunction("setAnimated", &UIMap::setAnimated); g_lua.bindClassMemberFunction("setKeepAspectRatio", &UIMap::setKeepAspectRatio); @@ -566,6 +568,8 @@ void Client::registerLuaFunctions() g_lua.bindClassMemberFunction("isMultifloor", &UIMap::isMultifloor); g_lua.bindClassMemberFunction("isAutoViewModeEnabled", &UIMap::isAutoViewModeEnabled); g_lua.bindClassMemberFunction("isDrawingTexts", &UIMap::isDrawingTexts); + g_lua.bindClassMemberFunction("isDrawingNames", &UIMap::isDrawingNames); + g_lua.bindClassMemberFunction("isDrawingHealthBars", &UIMap::isDrawingHealthBars); g_lua.bindClassMemberFunction("isDrawingLights", &UIMap::isDrawingLights); g_lua.bindClassMemberFunction("isLimitVisibleRangeEnabled", &UIMap::isLimitVisibleRangeEnabled); g_lua.bindClassMemberFunction("isAnimating", &UIMap::isAnimating); diff --git a/src/client/mapview.cpp b/src/client/mapview.cpp index 1c09e928..7c80e2eb 100644 --- a/src/client/mapview.cpp +++ b/src/client/mapview.cpp @@ -204,7 +204,7 @@ void MapView::draw(const Rect& rect) float verticalStretchFactor = rect.height() / (float)srcRect.height(); // avoid drawing texts on map in far zoom outs - if(m_viewMode == NEAR_VIEW && m_drawTexts) { + if(m_viewMode == NEAR_VIEW) { for(const CreaturePtr& creature : m_cachedFloorVisibleCreatures) { if(!creature->canBeSeen()) continue; @@ -218,7 +218,10 @@ void MapView::draw(const Rect& rect) p.y = p.y * verticalStretchFactor; p += rect.topLeft(); - creature->drawInformation(p, g_map.isCovered(pos, m_cachedFirstVisibleFloor), rect); + int flags = 0; + if(m_drawNames){ flags = Otc::DrawNames; } + if(m_drawHealthBars) { flags |= Otc::DrawBars; } + creature->drawInformation(p, g_map.isCovered(pos, m_cachedFirstVisibleFloor), rect, flags); } } diff --git a/src/client/mapview.h b/src/client/mapview.h index 6b9d56b6..05b64a0b 100644 --- a/src/client/mapview.h +++ b/src/client/mapview.h @@ -98,12 +98,18 @@ public: void setDrawTexts(bool enable) { m_drawTexts = enable; } bool isDrawingTexts() { return m_drawTexts; } - void setAnimated(bool animated) { m_animated = animated; requestVisibleTilesCacheUpdate(); } - bool isAnimating() { return m_animated; } + void setDrawNames(bool enable) { m_drawNames = enable; } + bool isDrawingNames() { return m_drawNames; } + + void setDrawHealthBars(bool enable) { m_drawHealthBars = enable; } + bool isDrawingHealthBars() { return m_drawHealthBars; } void setDrawLights(bool enable); bool isDrawingLights() { return m_drawLights; } + void setAnimated(bool animated) { m_animated = animated; requestVisibleTilesCacheUpdate(); } + bool isAnimating() { return m_animated; } + void setShader(const PainterShaderProgramPtr& shader, float fadein, float fadeout); PainterShaderProgramPtr getShader() { return m_shader; } @@ -138,8 +144,11 @@ private: stdext::boolean m_animated; stdext::boolean m_autoViewMode; stdext::boolean m_drawTexts; - stdext::boolean m_smooth; + stdext::boolean m_drawNames; + stdext::boolean m_drawHealthBars; stdext::boolean m_drawLights; + stdext::boolean m_smooth; + stdext::boolean m_follow; std::vector m_cachedVisibleTiles; std::vector m_cachedFloorVisibleCreatures; diff --git a/src/client/uimap.h b/src/client/uimap.h index a4acebe2..6adbad4f 100644 --- a/src/client/uimap.h +++ b/src/client/uimap.h @@ -51,6 +51,8 @@ public: void setAutoViewMode(bool enable) { m_mapView->setAutoViewMode(enable); } void setDrawFlags(Otc::DrawFlags drawFlags) { m_mapView->setDrawFlags(drawFlags); } void setDrawTexts(bool enable) { m_mapView->setDrawTexts(enable); } + void setDrawNames(bool enable) { m_mapView->setDrawNames(enable); } + void setDrawHealthBars(bool enable) { m_mapView->setDrawHealthBars(enable); } void setDrawLights(bool enable) { m_mapView->setDrawLights(enable); } void setAnimated(bool enable) { m_mapView->setAnimated(enable); } void setKeepAspectRatio(bool enable); @@ -61,6 +63,8 @@ public: bool isMultifloor() { return m_mapView->isMultifloor(); } bool isAutoViewModeEnabled() { return m_mapView->isAutoViewModeEnabled(); } bool isDrawingTexts() { return m_mapView->isDrawingTexts(); } + bool isDrawingNames() { return m_mapView->isDrawingNames(); } + bool isDrawingHealthBars() { return m_mapView->isDrawingHealthBars(); } bool isDrawingLights() { return m_mapView->isDrawingLights(); } bool isAnimating() { return m_mapView->isAnimating(); } bool isKeepAspectRatioEnabled() { return m_keepAspectRatio; }