Skip to content

Commit fe8bd4f

Browse files
committed
assets use dynamic texture loading
1 parent e81a908 commit fe8bd4f

File tree

8 files changed

+150
-326
lines changed

8 files changed

+150
-326
lines changed

library/Core.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,6 @@ bool Core::InitSimulationThread()
16921692
}
16931693
std::cerr << "Initializing textures.\n";
16941694
Textures::init(con);
1695-
Textures::initDynamic(con);
16961695
// create mutex for syncing with interactive tasks
16971696
std::cerr << "Initializing plugins.\n";
16981697
// create plugin manager
@@ -2219,7 +2218,6 @@ void Core::onStateChange(color_ostream &out, state_change_event event)
22192218
}
22202219
break;
22212220
case SC_VIEWSCREEN_CHANGED:
2222-
Textures::init(out);
22232221
break;
22242222
default:
22252223
break;

library/LuaApi.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,18 +1710,7 @@ static const luaL_Reg dfhack_job_funcs[] = {
17101710
/***** Textures module *****/
17111711

17121712
static const LuaWrapper::FunctionReg dfhack_textures_module[] = {
1713-
WRAPM(Textures, getDfhackLogoTexposStart),
1714-
WRAPM(Textures, getGreenPinTexposStart),
1715-
WRAPM(Textures, getRedPinTexposStart),
1716-
WRAPM(Textures, getIconsTexposStart),
1717-
WRAPM(Textures, getOnOffTexposStart),
1718-
WRAPM(Textures, getMapUnsuspendTexposStart),
1719-
WRAPM(Textures, getControlPanelTexposStart),
1720-
WRAPM(Textures, getThinBordersTexposStart),
1721-
WRAPM(Textures, getMediumBordersTexposStart),
1722-
WRAPM(Textures, getBoldBordersTexposStart),
1723-
WRAPM(Textures, getPanelBordersTexposStart),
1724-
WRAPM(Textures, getWindowBordersTexposStart),
1713+
WRAPM(Textures, getAsset),
17251714
{ NULL, NULL }
17261715
};
17271716

library/include/modules/Textures.h

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#pragma once
22

3-
#include <vector>
43
#include <string>
4+
#include <vector>
55

6-
#include "Export.h"
76
#include "ColorText.h"
7+
#include "Export.h"
88

99
#include <SDL_surface.h>
1010

@@ -29,7 +29,8 @@ DFHACK_EXPORT TexposHandle loadTexture(SDL_Surface* surface);
2929
* Load tileset from image file.
3030
* Return vector of handles to obtain valid texposes.
3131
*/
32-
DFHACK_EXPORT std::vector<TexposHandle> loadTileset(const std::string& file, int tile_px_w, int tile_px_h);
32+
DFHACK_EXPORT std::vector<TexposHandle> loadTileset(const std::string& file, int tile_px_w,
33+
int tile_px_h);
3334

3435
/**
3536
* Get texpos by handle.
@@ -39,67 +40,21 @@ DFHACK_EXPORT std::vector<TexposHandle> loadTileset(const std::string& file, int
3940
DFHACK_EXPORT long getTexposByHandle(TexposHandle handle);
4041

4142
/**
42-
* Call this on DFHack init and on every viewscreen change so we can reload
43-
* and reindex textures as needed.
43+
* Get texpos for static asset with index in tileset.
4444
*/
45-
void init(DFHack::color_ostream& out);
45+
DFHACK_EXPORT long getAsset(const std::string asset, size_t index = 0);
4646

4747
/**
48-
* Call this on DFHack init just once to setup interposed handlers.
48+
* Call this on DFHack init just once to setup interposed handlers and
49+
* init static assets.
4950
*/
50-
void initDynamic(DFHack::color_ostream& out);
51+
void init(DFHack::color_ostream& out);
5152

5253
/**
5354
* Call this when DFHack is being unloaded.
5455
*
5556
*/
5657
void cleanup();
5758

58-
/**
59-
* Get first texpos for the DFHack logo. This texpos and the next 11 make up the
60-
* 4x3 grid of logo textures that can be displayed on the UI layer.
61-
*/
62-
DFHACK_EXPORT long getDfhackLogoTexposStart();
63-
64-
/**
65-
* Get the first texpos for the UI pin tiles. Each are 2x2 grids.
66-
*/
67-
DFHACK_EXPORT long getGreenPinTexposStart();
68-
DFHACK_EXPORT long getRedPinTexposStart();
69-
70-
/**
71-
* Get the first texpos for the DFHack icons. It's a 5x2 grid.
72-
*/
73-
DFHACK_EXPORT long getIconsTexposStart();
74-
75-
/**
76-
* Get the first texpos for the on and off icons. It's a 2x1 grid.
77-
*/
78-
DFHACK_EXPORT long getOnOffTexposStart();
79-
80-
/**
81-
* Get the first texpos for the pathable 32x32 sprites. It's a 2x1 grid.
82-
*/
83-
DFHACK_EXPORT long getMapPathableTexposStart();
84-
85-
/**
86-
* Get the first texpos for the unsuspend 32x32 sprites. It's a 5x1 grid.
87-
*/
88-
DFHACK_EXPORT long getMapUnsuspendTexposStart();
89-
90-
/**
91-
* Get the first texpos for the control panel icons. 10x2 grid.
92-
*/
93-
DFHACK_EXPORT long getControlPanelTexposStart();
94-
95-
/**
96-
* Get the first texpos for the DFHack borders. Each is a 7x3 grid.
97-
*/
98-
DFHACK_EXPORT long getThinBordersTexposStart();
99-
DFHACK_EXPORT long getMediumBordersTexposStart();
100-
DFHACK_EXPORT long getBoldBordersTexposStart();
101-
DFHACK_EXPORT long getPanelBordersTexposStart();
102-
DFHACK_EXPORT long getWindowBordersTexposStart();
103-
104-
}
105-
}
59+
} // namespace Textures
60+
} // namespace DFHack

library/lua/gui.lua

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -913,10 +913,10 @@ local BASE_FRAME = {
913913
}
914914

915915
local function make_frame(name, double_line)
916-
local texpos = dfhack.textures['get'..name..'BordersTexposStart']()
917916
local tp = function(offset)
917+
local texpos = dfhack.textures.getAsset('hack/data/art/border-'..name:lower()..'.png', offset)
918918
if texpos == -1 then return nil end
919-
return texpos + offset
919+
return texpos
920920
end
921921

922922
local frame = copyall(BASE_FRAME)
@@ -951,8 +951,40 @@ BOLD_FRAME = FRAME_BOLD
951951
INTERIOR_FRAME = FRAME_INTERIOR
952952
INTERIOR_MEDIUM_FRAME = FRAME_INTERIOR_MEDIUM
953953

954+
-- for compatibility with dynamic textures
955+
local function choose_frame_style(style)
956+
if style == FRAME_WINDOW then return make_frame('Window', true) end
957+
if style == FRAME_PANEL then return make_frame('Panel', true) end
958+
if style == FRAME_MEDIUM then return make_frame('Medium', true) end
959+
if style == FRAME_BOLD then return make_frame('Bold', true) end
960+
if style == FRAME_INTERIOR then
961+
local frame = make_frame('Thin', true)
962+
frame.signature_pen = false
963+
return frame
964+
end
965+
if style == FRAME_INTERIOR_MEDIUM then
966+
local frame = make_frame('Medium', true)
967+
frame.signature_pen = false
968+
return frame
969+
end
970+
if style == GREY_LINE_FRAME then return make_frame('Panel', true) end
971+
if style == WINDOW_FRAME then return make_frame('Window', true) end
972+
if style == PANEL_FRAME then return make_frame('Panel', true) end
973+
if style == MEDIUM_FRAME then return make_frame('Medium', true) end
974+
if style == INTERIOR_FRAME then
975+
local frame = make_frame('Thin', true)
976+
frame.signature_pen = false
977+
return frame
978+
end
979+
if style == INTERIOR_MEDIUM_FRAME then
980+
local frame = make_frame('Medium', true)
981+
frame.signature_pen = false
982+
return frame
983+
end
984+
end
954985

955-
function paint_frame(dc,rect,style,title,inactive,pause_forced,resizable)
986+
function paint_frame(dc, rect, style, title, inactive, pause_forced, resizable)
987+
style = choose_frame_style(style)
956988
local pen = style.frame_pen
957989
local x1,y1,x2,y2 = dc.x1+rect.x1, dc.y1+rect.y1, dc.x1+rect.x2, dc.y1+rect.y2
958990
dscreen.paintTile(style.lt_frame_pen or pen, x1, y1)

0 commit comments

Comments
 (0)