Skip to content

Commit 53f9fba

Browse files
committed
Fix wireworld
1 parent 53a2189 commit 53f9fba

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

CCGameFramework/render/Direct2DRender.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ class WireworldAutomatonImageElement : public GraphicsElement<WireworldAutomaton
627627
FLOAT GetOpacity()const;
628628
void SetOpacity(FLOAT value);
629629

630-
void Refresh();
630+
void Refresh(int arg);
631631

632632
protected:
633633
CStringA text;
@@ -641,13 +641,16 @@ class WireworldAutomatonImageElementRenderer : public GraphicsImageRenderer<Wire
641641
public:
642642
void Render(CRect bounds)override;
643643
~WireworldAutomatonImageElementRenderer();
644-
void Refresh();
644+
void Refresh(int arg);
645645
private:
646646
CComPtr<IWICBitmap> wic;
647647
BYTE* buffer{ nullptr };
648648
std::vector<byte> data;
649649
WICRect rect;
650650
D2D1_RECT_U d2dRect;
651+
std::vector<INT> wires;
652+
std::vector<INT> heads;
653+
std::vector<INT> tails;
651654
};
652655

653656
#pragma endregion Image

CCGameFramework/render/Direct2DRenderImage.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ void WireworldAutomatonImageElement::SetOpacity(FLOAT value)
280280
opacity = value;
281281
}
282282

283-
void WireworldAutomatonImageElement::Refresh()
283+
void WireworldAutomatonImageElement::Refresh(int arg)
284284
{
285-
std::dynamic_pointer_cast<WireworldAutomatonImageElementRenderer, IGraphicsRenderer>(renderer)->Refresh();
285+
std::dynamic_pointer_cast<WireworldAutomatonImageElementRenderer, IGraphicsRenderer>(renderer)->Refresh(arg);
286286
}
287287

288288
DWORD watm_clr[] =
@@ -360,7 +360,7 @@ void WireworldAutomatonImageElementRenderer::Render(CRect bounds)
360360
if (e->flags.self_visible && bitmap)
361361
{
362362
CComPtr<ID2D1RenderTarget> d2dRenderTarget = renderTarget.lock()->GetDirect2DRenderTarget();
363-
if (bounds.Width() > rect.Width * 2 && bounds.Height() > rect.Width / 2)
363+
if ((rect.Width > 1000 || rect.Height > 600) && bounds.Width() > rect.Width * 2 && bounds.Height() > rect.Width / 2)
364364
{
365365
d2dRenderTarget->DrawBitmap(
366366
bitmap,
@@ -422,11 +422,13 @@ bool CanHead(const BYTE* d, const INT& w, const INT& h, const INT& j, const INT&
422422
return n == 1 || n == 2;
423423
}
424424

425-
void WireworldAutomatonImageElementRenderer::Refresh()
425+
void WireworldAutomatonImageElementRenderer::Refresh(int arg)
426426
{
427-
std::vector<INT> wires;
428-
std::vector<INT> heads;
429-
std::vector<INT> tails;
427+
if (arg == 1) buffer = nullptr;
428+
if (arg != 0) return;
429+
wires.clear();
430+
heads.clear();
431+
tails.clear();
430432
auto w = rect.Width, h = rect.Height;
431433
int k;
432434
auto d = data.data();

CCGameFramework/script/lib/ui/watm.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function M:new(o)
1010
o.type = 1102
1111
o.text = o.text or ''
1212
o.opacity = o.opacity or 1.0
13+
o.start = false
1314
setmetatable(o, self)
1415
self.__index = self
1516
return o;

CCGameFramework/script/scene/visual/wireworld.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ function M:new(o)
2020
o = o or {}
2121
o.name = 'Wireworld Scene'
2222
o.def = {
23-
timerid = 10
23+
timerid = 10,
24+
state = true
2425
}
2526
setmetatable(o, self)
2627
self.__index = self
@@ -92,17 +93,18 @@ function M:destroy()
9293
end
9394

9495
function M:init_event()
96+
self.path = './script/lib/resource/wireworld_computer.txt'
9597
self.handler[self.win_event.created] = function(this)
9698
UIExt.trace('Scene [Wireworld Page] Test created message!')
9799
end
98100
self.handler[self.win_event.timer] = function(this, id)
99101
if id == 8 then
100-
this.layers.watm.text = './script/lib/resource/wireworld_computer.txt'
102+
this.layers.watm.text = this.path
101103
this.layers.watm:update_and_paint()
102104
UIExt.kill_timer(8)
103105
UIExt.set_timer(5, 30)
104-
elseif id == 5 then
105-
UIExt.refresh(this.layers.watm)
106+
elseif id == 5 and this.def.state then
107+
UIExt.refresh(this.layers.watm, 0)
106108
UIExt.paint()
107109
end
108110
end
@@ -152,8 +154,8 @@ function M:init_menu(info)
152154
track_display = 0,
153155
font_size = 16,
154156
click = function()
155-
CurrentScene.def.type = 1
156-
path_restart(CurrentScene.def)
157+
UIExt.refresh(CurrentScene.layers.watm, 1)
158+
UIExt.paint()
157159
end
158160
}):attach(slider)
159161
Button:new({
@@ -162,8 +164,7 @@ function M:init_menu(info)
162164
track_display = 0,
163165
font_size = 16,
164166
click = function()
165-
CurrentScene.def.type = 2
166-
path_restart(CurrentScene.def)
167+
CurrentScene.def.state = not CurrentScene.def.state
167168
end
168169
}):attach(slider)
169170
Text:new({

CCGameFramework/ui/window/WindowLua.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ int ui_update_obj(lua_State *L)
273273

274274
int ui_refresh_obj(lua_State *L)
275275
{
276-
luaL_checktype(L, 1, LUA_TTABLE);
276+
auto arg = (cint)luaL_checkinteger(L, 2); lua_pop(L, 1);
277+
luaL_checktype(L, -1, LUA_TTABLE);
277278
lua_getfield(L, -1, "type");
278279
auto type = ElementId(cint(luaL_checkinteger(L, -1))); lua_pop(L, 1);
279280
lua_getfield(L, -1, "handle");
@@ -303,7 +304,7 @@ int ui_refresh_obj(lua_State *L)
303304
{
304305
auto obj = static_cast<WireworldAutomatonImageElement*>(o.get());
305306
{
306-
obj->Refresh();
307+
obj->Refresh(arg);
307308
}
308309
}
309310
break;

0 commit comments

Comments
 (0)