Skip to content

Commit

Permalink
Fix wireworld
Browse files Browse the repository at this point in the history
  • Loading branch information
bajdcc committed Mar 6, 2017
1 parent 53a2189 commit 53f9fba
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
7 changes: 5 additions & 2 deletions CCGameFramework/render/Direct2DRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ class WireworldAutomatonImageElement : public GraphicsElement<WireworldAutomaton
FLOAT GetOpacity()const;
void SetOpacity(FLOAT value);

void Refresh();
void Refresh(int arg);

protected:
CStringA text;
Expand All @@ -641,13 +641,16 @@ class WireworldAutomatonImageElementRenderer : public GraphicsImageRenderer<Wire
public:
void Render(CRect bounds)override;
~WireworldAutomatonImageElementRenderer();
void Refresh();
void Refresh(int arg);
private:
CComPtr<IWICBitmap> wic;
BYTE* buffer{ nullptr };
std::vector<byte> data;
WICRect rect;
D2D1_RECT_U d2dRect;
std::vector<INT> wires;
std::vector<INT> heads;
std::vector<INT> tails;
};

#pragma endregion Image
Expand Down
16 changes: 9 additions & 7 deletions CCGameFramework/render/Direct2DRenderImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ void WireworldAutomatonImageElement::SetOpacity(FLOAT value)
opacity = value;
}

void WireworldAutomatonImageElement::Refresh()
void WireworldAutomatonImageElement::Refresh(int arg)
{
std::dynamic_pointer_cast<WireworldAutomatonImageElementRenderer, IGraphicsRenderer>(renderer)->Refresh();
std::dynamic_pointer_cast<WireworldAutomatonImageElementRenderer, IGraphicsRenderer>(renderer)->Refresh(arg);
}

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

void WireworldAutomatonImageElementRenderer::Refresh()
void WireworldAutomatonImageElementRenderer::Refresh(int arg)
{
std::vector<INT> wires;
std::vector<INT> heads;
std::vector<INT> tails;
if (arg == 1) buffer = nullptr;
if (arg != 0) return;
wires.clear();
heads.clear();
tails.clear();
auto w = rect.Width, h = rect.Height;
int k;
auto d = data.data();
Expand Down
1 change: 1 addition & 0 deletions CCGameFramework/script/lib/ui/watm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function M:new(o)
o.type = 1102
o.text = o.text or ''
o.opacity = o.opacity or 1.0
o.start = false
setmetatable(o, self)
self.__index = self
return o;
Expand Down
17 changes: 9 additions & 8 deletions CCGameFramework/script/scene/visual/wireworld.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ function M:new(o)
o = o or {}
o.name = 'Wireworld Scene'
o.def = {
timerid = 10
timerid = 10,
state = true
}
setmetatable(o, self)
self.__index = self
Expand Down Expand Up @@ -92,17 +93,18 @@ function M:destroy()
end

function M:init_event()
self.path = './script/lib/resource/wireworld_computer.txt'
self.handler[self.win_event.created] = function(this)
UIExt.trace('Scene [Wireworld Page] Test created message!')
end
self.handler[self.win_event.timer] = function(this, id)
if id == 8 then
this.layers.watm.text = './script/lib/resource/wireworld_computer.txt'
this.layers.watm.text = this.path
this.layers.watm:update_and_paint()
UIExt.kill_timer(8)
UIExt.set_timer(5, 30)
elseif id == 5 then
UIExt.refresh(this.layers.watm)
elseif id == 5 and this.def.state then
UIExt.refresh(this.layers.watm, 0)
UIExt.paint()
end
end
Expand Down Expand Up @@ -152,8 +154,8 @@ function M:init_menu(info)
track_display = 0,
font_size = 16,
click = function()
CurrentScene.def.type = 1
path_restart(CurrentScene.def)
UIExt.refresh(CurrentScene.layers.watm, 1)
UIExt.paint()
end
}):attach(slider)
Button:new({
Expand All @@ -162,8 +164,7 @@ function M:init_menu(info)
track_display = 0,
font_size = 16,
click = function()
CurrentScene.def.type = 2
path_restart(CurrentScene.def)
CurrentScene.def.state = not CurrentScene.def.state
end
}):attach(slider)
Text:new({
Expand Down
5 changes: 3 additions & 2 deletions CCGameFramework/ui/window/WindowLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ int ui_update_obj(lua_State *L)

int ui_refresh_obj(lua_State *L)
{
luaL_checktype(L, 1, LUA_TTABLE);
auto arg = (cint)luaL_checkinteger(L, 2); lua_pop(L, 1);
luaL_checktype(L, -1, LUA_TTABLE);
lua_getfield(L, -1, "type");
auto type = ElementId(cint(luaL_checkinteger(L, -1))); lua_pop(L, 1);
lua_getfield(L, -1, "handle");
Expand Down Expand Up @@ -303,7 +304,7 @@ int ui_refresh_obj(lua_State *L)
{
auto obj = static_cast<WireworldAutomatonImageElement*>(o.get());
{
obj->Refresh();
obj->Refresh(arg);
}
}
break;
Expand Down

0 comments on commit 53f9fba

Please sign in to comment.